mirror of
https://github.com/kenzok8/small-package
synced 2025-09-20 19:11:30 +08:00
update 2024-02-17 14:17:25
This commit is contained in:
18
luci-app-daed-next/Makefile
Normal file
18
luci-app-daed-next/Makefile
Normal file
@ -0,0 +1,18 @@
|
||||
# Copyright (C) 2016 Openwrt.org
|
||||
#
|
||||
# This is free software, licensed under the Apache License, Version 2.0 .
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=luci-app-daed-next
|
||||
PKG_VERSION:=1.0.0
|
||||
PKG_RELEASE:=1
|
||||
|
||||
LUCI_TITLE:=LuCI support for daed-next
|
||||
LUCI_PKGARCH:=all
|
||||
LUCI_DEPENDS:=+daed-next +bash +luci-compat
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
36
luci-app-daed-next/luasrc/controller/daed-next.lua
Normal file
36
luci-app-daed-next/luasrc/controller/daed-next.lua
Normal file
@ -0,0 +1,36 @@
|
||||
local sys = require "luci.sys"
|
||||
local http = require "luci.http"
|
||||
|
||||
module("luci.controller.daed-next", package.seeall)
|
||||
|
||||
function index()
|
||||
if not nixio.fs.access("/etc/config/daed-next") then
|
||||
return
|
||||
end
|
||||
|
||||
local page = entry({"admin", "services", "daed-next"}, alias("admin", "services", "daed-next", "basic"), _("DAED Next"), -1)
|
||||
page.dependent = true
|
||||
page.acl_depends = { "luci-app-daed-next" }
|
||||
|
||||
entry({"admin", "services", "daed-next", "basic"}, cbi("daed-next/basic"), _("Basic Setting"), 1).leaf = true
|
||||
entry({"admin", "services", "daed-next", "dashboard"}, template("daed-next/dashboard"), _("Dashboard"), 2).leaf = true
|
||||
entry({"admin", "services", "daed-next", "log"}, cbi("daed-next/log"), _("Logs"), 3).leaf = true
|
||||
entry({"admin", "services", "daed-next", "status"}, call("act_status")).leaf = true
|
||||
entry({"admin", "services", "daed-next", "get_log"}, call("get_log")).leaf = true
|
||||
entry({"admin", "services", "daed-next", "clear_log"}, call("clear_log")).leaf = true
|
||||
end
|
||||
|
||||
function act_status()
|
||||
local e = {}
|
||||
e.running = sys.call("pgrep -x /usr/bin/dae-wing >/dev/null") == 0
|
||||
http.prepare_content("application/json")
|
||||
http.write_json(e)
|
||||
end
|
||||
|
||||
function get_log()
|
||||
http.write(sys.exec("cat /var/log/daed-next/daed-next.log"))
|
||||
end
|
||||
|
||||
function clear_log()
|
||||
sys.call("true > /var/log/daed-next/daed-next.log")
|
||||
end
|
76
luci-app-daed-next/luasrc/model/cbi/daed-next/basic.lua
Normal file
76
luci-app-daed-next/luasrc/model/cbi/daed-next/basic.lua
Normal file
@ -0,0 +1,76 @@
|
||||
local m, s
|
||||
|
||||
m = Map("daed-next", translate("DAE Dashboard"))
|
||||
m.description = translate("A Linux high-performance transparent proxy solution based on eBPF")
|
||||
|
||||
m:section(SimpleSection).template = "daed-next/daed-next_status"
|
||||
|
||||
s = m:section(TypedSection, "daed-next")
|
||||
s.addremove = false
|
||||
s.anonymous = true
|
||||
|
||||
if nixio.fs.stat("/sys/fs/bpf","type") ~= "dir" then
|
||||
s.rawhtml = true
|
||||
s.template = "daed-next/daed-next_error"
|
||||
end
|
||||
|
||||
o = s:option(Flag, "enabled", translate("Enabled"))
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Button, "Dashboard Toggle", translate("Dashboard Toggle"))
|
||||
o.inputtitle = translate("Toggle")
|
||||
o.inputstyle = "reload"
|
||||
o.description = translate("Dashboard is a frontend management panel, meant for configuration use only.")
|
||||
o.write = function()
|
||||
luci.sys.exec("/etc/daed-next/dashboard.sh &> /dev/null &")
|
||||
end
|
||||
|
||||
enable = s:option(Flag, "subscribe_auto_update", translate("Enable Auto Subscribe Update"))
|
||||
enable.rmempty = false
|
||||
|
||||
o = s:option(Value, "daed_username", translate("Username"))
|
||||
o.default = Username
|
||||
o.password = true
|
||||
o:depends('subscribe_auto_update', '1')
|
||||
|
||||
o = s:option(Value, "daed_password", translate("Password"))
|
||||
o.default = Password
|
||||
o.password = true
|
||||
o:depends('subscribe_auto_update', '1')
|
||||
|
||||
o = s:option(ListValue, "subscribe_update_week_time", translate("Update Cycle"))
|
||||
o:value("*", translate("Every Day"))
|
||||
o:value("1", translate("Every Monday"))
|
||||
o:value("2", translate("Every Tuesday"))
|
||||
o:value("3", translate("Every Wednesday"))
|
||||
o:value("4", translate("Every Thursday"))
|
||||
o:value("5", translate("Every Friday"))
|
||||
o:value("6", translate("Every Saturday"))
|
||||
o:value("7", translate("Every Sunday"))
|
||||
o.default = "*"
|
||||
o:depends('subscribe_auto_update', '1')
|
||||
|
||||
update_time = s:option(ListValue, "subscribe_update_day_time", translate("Update Time (Every Day)"))
|
||||
for t = 0, 23 do
|
||||
update_time:value(t, t..":00")
|
||||
end
|
||||
update_time.default = 0
|
||||
update_time:depends('subscribe_auto_update', '1')
|
||||
|
||||
o = s:option(Value, "listen_port", translate("Web Listen port"))
|
||||
o.datatype = "and(port,min(1))"
|
||||
o.default = 3000
|
||||
|
||||
o = s:option(Flag, "log_enabled", translate("Enable Logs"))
|
||||
o.default = 0
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Value, "log_maxbackups", translate("Logfile retention count"))
|
||||
o.default = 1
|
||||
o:depends("log_enabled", "1")
|
||||
|
||||
o = s:option(Value, "log_maxsize", translate("Logfile Max Size (MB)"))
|
||||
o.default = 1
|
||||
o:depends("log_enabled", "1")
|
||||
|
||||
return m
|
5
luci-app-daed-next/luasrc/model/cbi/daed-next/log.lua
Normal file
5
luci-app-daed-next/luasrc/model/cbi/daed-next/log.lua
Normal file
@ -0,0 +1,5 @@
|
||||
m = Map("daed-next")
|
||||
|
||||
m:append(Template("daed-next/daed-next_log"))
|
||||
|
||||
return m
|
File diff suppressed because one or more lines are too long
33
luci-app-daed-next/luasrc/view/daed-next/daed-next_log.htm
Normal file
33
luci-app-daed-next/luasrc/view/daed-next/daed-next_log.htm
Normal file
@ -0,0 +1,33 @@
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
function clear_log(btn) {
|
||||
XHR.get('<%=url([[admin]], [[services]], [[daed-next]], [[clear_log]])%>', null,
|
||||
function(x, data) {
|
||||
if(x && x.status == 200) {
|
||||
var log_textarea = document.getElementById('log_textarea');
|
||||
log_textarea.innerHTML = "";
|
||||
log_textarea.scrollTop = log_textarea.scrollHeight;
|
||||
}
|
||||
location.reload();
|
||||
}
|
||||
);
|
||||
}
|
||||
var scrolled = false;
|
||||
XHR.poll(2, '<%=url([[admin]], [[services]], [[daed-next]], [[get_log]])%>', null,
|
||||
function(x, data) {
|
||||
if(x && x.status == 200) {
|
||||
var log_textarea = document.getElementById('log_textarea');
|
||||
log_textarea.innerHTML = x.responseText;
|
||||
if (!scrolled) {
|
||||
log_textarea.scrollTop = log_textarea.scrollHeight;
|
||||
scrolled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
//]]>
|
||||
</script>
|
||||
<fieldset class="cbi-section" id="_log_fieldset">
|
||||
<input class="cbi-button cbi-input-remove" type="button" onclick="clear_log()" value="<%:Clear logs%>" style="margin-left: 10px; margin-top: 10px;">
|
||||
<textarea id="log_textarea" class="cbi-input-textarea" style="width: calc(100% - 20px); height: 645px; margin: 10px;" data-update="change" rows="5" wrap="off" readonly="readonly"></textarea>
|
||||
</fieldset>
|
@ -0,0 +1,46 @@
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
XHR.poll(5, '<%=url("admin/services/daed-next/status")%>', null,
|
||||
function(x, data)
|
||||
{
|
||||
var tb = document.getElementById('daed-next_status');
|
||||
if (data && tb)
|
||||
{
|
||||
if (data.running)
|
||||
{
|
||||
tb.innerHTML = '<em style=\"color:green\"><b><%:dae-wing%> <%:RUNNING%></b></em>';
|
||||
}
|
||||
else
|
||||
{
|
||||
tb.innerHTML = '<em style=\"color:red\"><b><%:dae-wing%> <%:NOT RUNNING%></b></em>';
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
//]]></script>
|
||||
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
XHR.poll(5, '<%=url("admin/services/daed-next/dashboardstatus")%>', null,
|
||||
function(x, data) {
|
||||
console.log('Received data:', data);
|
||||
|
||||
var dashboardstatus = document.getElementById('daed-next_dashboardstatus');
|
||||
var dashboardPidExists = <%=luci.sys.exec("[ -e '/tmp/log/daed-next/dashboard.pid' ] && echo '1' || echo '0'")%>;
|
||||
|
||||
if (dashboardPidExists) {
|
||||
dashboardstatus.innerHTML = '<em style=\"color:green\"><b><%:Dashboard%> <%:RUNNING%></b></em>';
|
||||
} else {
|
||||
dashboardstatus.innerHTML = '<em style=\"color:red\"><b><%:Dashboard%> <%:NOT RUNNING%></b></em>';
|
||||
}
|
||||
}
|
||||
);
|
||||
//]]></script>
|
||||
|
||||
<style>.mar-10 {margin-left: 50px; margin-right: 10px;}</style>
|
||||
<fieldset class="cbi-section">
|
||||
<p id="daed-next_status">
|
||||
<em><b><%:Collecting data...%></b></em>
|
||||
</p>
|
||||
<p id="daed-next_dashboardstatus">
|
||||
<em><b><%:Collecting data...%></b></em>
|
||||
</p>
|
||||
</fieldset>
|
27
luci-app-daed-next/luasrc/view/daed-next/dashboard.htm
Normal file
27
luci-app-daed-next/luasrc/view/daed-next/dashboard.htm
Normal file
File diff suppressed because one or more lines are too long
1
luci-app-daed-next/po/zh-cn
Symbolic link
1
luci-app-daed-next/po/zh-cn
Symbolic link
@ -0,0 +1 @@
|
||||
zh_Hans
|
86
luci-app-daed-next/po/zh_Hans/daed-next.po
Normal file
86
luci-app-daed-next/po/zh_Hans/daed-next.po
Normal file
@ -0,0 +1,86 @@
|
||||
msgid "DAED Next"
|
||||
msgstr ""
|
||||
|
||||
msgid "DAE Dashboard"
|
||||
msgstr "DAE 仪表板"
|
||||
|
||||
msgid "A Linux high-performance transparent proxy solution based on eBPF"
|
||||
msgstr "一个基于 eBPF 的 Linux 高性能透明代理解决方案"
|
||||
|
||||
msgid "Enabled"
|
||||
msgstr "启用"
|
||||
|
||||
msgid "Web Listen port"
|
||||
msgstr "Web 监听端口"
|
||||
|
||||
msgid "Enable Logs"
|
||||
msgstr "启用日志"
|
||||
|
||||
msgid "Logfile retention count"
|
||||
msgstr "日志文件保留数量"
|
||||
|
||||
msgid "Logfile Max Size (MB)"
|
||||
msgstr "日志文件大小(MB)"
|
||||
|
||||
msgid "Logs"
|
||||
msgstr "日志"
|
||||
|
||||
msgid "Clear logs"
|
||||
msgstr "清空日志"
|
||||
|
||||
msgid "Basic Setting"
|
||||
msgstr "基本设置"
|
||||
|
||||
msgid "RUNNING"
|
||||
msgstr "运行中"
|
||||
|
||||
msgid "NOT RUNNING"
|
||||
msgstr "未运行"
|
||||
|
||||
msgid "Collecting data..."
|
||||
msgstr "收集数据..."
|
||||
|
||||
msgid "Open Web Interface"
|
||||
msgstr "打开 Web 界面"
|
||||
|
||||
msgid "The kernel does not support eBPF"
|
||||
msgstr "内核不支持 eBPF"
|
||||
|
||||
msgid "Dashboard"
|
||||
msgstr "仪表板"
|
||||
|
||||
msgid "DAED Next is not running"
|
||||
msgstr "DAED Next 未运行"
|
||||
|
||||
msgid "Please start the DAED Next service first and try again"
|
||||
msgstr "请先启动 DAED Next 服务后重试"
|
||||
|
||||
msgid "dae-wing or dashboard is not running"
|
||||
msgstr "DAE-WING 或 仪表板 未运行"
|
||||
|
||||
msgid "Please start the dae-wing service and the dashboard service first and try again"
|
||||
msgstr "请先启动 DAE-WING 和 仪表板 服务后重试"
|
||||
|
||||
msgid "Enable Auto Subscribe Update"
|
||||
msgstr "启用订阅自动更新"
|
||||
|
||||
msgid "Update Cycle"
|
||||
msgstr "更新周期"
|
||||
|
||||
msgid "Update Time (Every Day)"
|
||||
msgstr "更新时间(每天)"
|
||||
|
||||
msgid "Username"
|
||||
msgstr "用户名"
|
||||
|
||||
msgid "Password"
|
||||
msgstr "密码"
|
||||
|
||||
msgid "Dashboard Toggle"
|
||||
msgstr "仪表板开关"
|
||||
|
||||
msgid "Toggle"
|
||||
msgstr "开/关"
|
||||
|
||||
msgid "Dashboard is a frontend management panel, meant for configuration use only."
|
||||
msgstr "仪表板是一个前端管理面板,仅应在配置过程中启用。"
|
36
luci-app-daed-next/root/etc/daed-next/daed-next_sub.sh
Executable file
36
luci-app-daed-next/root/etc/daed-next/daed-next_sub.sh
Executable file
@ -0,0 +1,36 @@
|
||||
#!/bin/sh
|
||||
|
||||
USERNAME=$(uci -q get daed-next.config.daed_username)
|
||||
PASSWORD=$(uci -q get daed-next.config.daed_password)
|
||||
PORT=2023
|
||||
GRAPHQL_URL="http://127.0.0.1:"$PORT"/graphql"
|
||||
CRON_FILE="/etc/crontabs/root"
|
||||
RANDOM_SEED=$RANDOM
|
||||
RANDOM_NUM=$((RANDOM_SEED % 10 + 1))
|
||||
|
||||
login() {
|
||||
LOGIN=$(curl -s -X POST -H "Content-Type: application/json" -d '{"query":"query Token($username: String!, $password: String!) {\n token(username: $username, password: $password)\n}","variables":{"username":"'"$USERNAME"'","password":"'"$PASSWORD"'"}}' $GRAPHQL_URL)
|
||||
JSON=${LOGIN#\"}
|
||||
JSON=${LOGIN%\"}
|
||||
TOKEN=$(echo $JSON | sed -n 's/.*"token":"\([^"]*\)".*/\1/p')
|
||||
}
|
||||
|
||||
update_subscription() {
|
||||
SUBSCRIPTION_ID_LIST=$(curl -s -X POST -H "Authorization: $TOKEN" -d '{"query": "query Subscriptions {\n subscriptions {\nid\ntag\nstatus\nlink\ninfo\nupdatedAt\nnodes {\nedges {\nid\nname\nprotocol\nlink\n}\n}\n}\n}", "operationName": "Subscriptions"}' $GRAPHQL_URL | grep -o '"id":"[^"]*","tag"' | grep -o 'id":"[^"]*' | grep -o '[^"]*$')
|
||||
echo "$SUBSCRIPTION_ID_LIST" | while read -r id; do
|
||||
curl -X POST -H "Authorization: $TOKEN" -d '{"query":"mutation UpdateSubscription($id: ID!) {\n updateSubscription(id: $id) {\n id\n }\n}","variables":{"id":"'"$id"'"},"operationName":"UpdateSubscription"}' $GRAPHQL_URL
|
||||
done
|
||||
}
|
||||
|
||||
reload() {
|
||||
curl -X POST -H "Authorization: $TOKEN" -d '{"query":"mutation Run($dry: Boolean!) {\n run(dry: $dry)\n}","variables":{"dry":false},"operationName":"Run"}' $GRAPHQL_URL
|
||||
}
|
||||
|
||||
resetcron() {
|
||||
touch $CRON_FILE
|
||||
sed -i '/daed-next_sub.sh/d' $CRON_FILE 2>/dev/null
|
||||
[ "$(uci -q get daed-next.config.subscribe_auto_update)" -eq 1 ] && echo "${RANDOM_NUM} $(uci -q get daed-next.config.subscribe_update_day_time) * * $(uci -q get daed-next.config.subscribe_update_week_time) /etc/daed-next/daed-next_sub.sh >/dev/null 2>&1" >>$CRON_FILE
|
||||
crontab $CRON_FILE
|
||||
}
|
||||
|
||||
login && update_subscription && reload && resetcron
|
37
luci-app-daed-next/root/etc/daed-next/dashboard.sh
Executable file
37
luci-app-daed-next/root/etc/daed-next/dashboard.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/bin/sh
|
||||
|
||||
NODE_BIN=/usr/bin/node
|
||||
WEB_SQUASHFS=/usr/share/daed-next/daed-web.squashfs
|
||||
PID_FILE=/tmp/log/daed-next/dashboard.pid
|
||||
DAED_NEXT_DIR=/var/daed-next
|
||||
|
||||
start_server() {
|
||||
listen_port=$(uci -q get daed-next.config.listen_port)
|
||||
if [ ! -d "$DAED_NEXT_DIR" ]; then
|
||||
mkdir -p "$DAED_NEXT_DIR"
|
||||
fi
|
||||
mount -t squashfs "$WEB_SQUASHFS" "$DAED_NEXT_DIR" || { echo "Mount failed"; }
|
||||
|
||||
ARGS="PORT=$listen_port HOSTNAME=0.0.0.0"
|
||||
/bin/sh -c "$ARGS $NODE_BIN $DAED_NEXT_DIR/server.js" &
|
||||
echo $! > "$PID_FILE"
|
||||
}
|
||||
|
||||
stop_server() {
|
||||
if [ -f "$PID_FILE" ]; then
|
||||
PID=$(cat "$PID_FILE")
|
||||
kill "$PID" || { echo "Failed to kill process $PID"; }
|
||||
rm -f "$PID_FILE"
|
||||
|
||||
mount_points=$(mount | grep '/tmp/daed-next' | awk '{print $3}')
|
||||
for mp in $mount_points; do
|
||||
umount -l "$mp" || { echo "Failed to force unmount $mp"; }
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
if [ -e "$PID_FILE" ]; then
|
||||
stop_server
|
||||
else
|
||||
start_server
|
||||
fi
|
44
luci-app-daed-next/root/etc/init.d/luci_daed-next
Executable file
44
luci-app-daed-next/root/etc/init.d/luci_daed-next
Executable file
@ -0,0 +1,44 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2023 Tianling Shen <cnsztl@immortalwrt.org>
|
||||
|
||||
USE_PROCD=0
|
||||
START=99
|
||||
|
||||
CONF="daed-next"
|
||||
PROG="/usr/bin/dae-wing"
|
||||
LOG="/var/log/daed-next/daed-next.log"
|
||||
CRON_FILE="/etc/crontabs/root"
|
||||
RANDOM_SEED=$RANDOM
|
||||
RANDOM_NUM=$((RANDOM_SEED % 10 + 1))
|
||||
|
||||
setcron() {
|
||||
touch $CRON_FILE
|
||||
sed -i '/daed-next_sub.sh/d' $CRON_FILE 2>/dev/null
|
||||
[ "$(uci -q get daed-next.config.subscribe_auto_update)" -eq 1 ] && echo "${RANDOM_NUM} $(uci -q get daed-next.config.subscribe_update_day_time) * * $(uci -q get daed-next.config.subscribe_update_week_time) /etc/daed-next/daed-next_sub.sh >/dev/null 2>&1" >>$CRON_FILE
|
||||
crontab $CRON_FILE
|
||||
}
|
||||
|
||||
delcron() {
|
||||
sed -i '/daed-next_sub.sh/d' $CRON_FILE 2>/dev/null
|
||||
crontab $CRON_FILE
|
||||
}
|
||||
|
||||
start_service() {
|
||||
config_load "$CONF"
|
||||
|
||||
local enabled
|
||||
config_get_bool enabled "config" "enabled" "0"
|
||||
if [ "$enabled" -eq 0 ]; then
|
||||
delcron
|
||||
return 1
|
||||
fi
|
||||
setcron
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
delcron
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger "$CONF"
|
||||
}
|
5
luci-app-daed-next/root/etc/uci-defaults/luci-daed-next
Executable file
5
luci-app-daed-next/root/etc/uci-defaults/luci-daed-next
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
rm -rf /tmp/luci-*
|
||||
|
||||
exit 0
|
@ -0,0 +1,11 @@
|
||||
{
|
||||
"luci-app-daed-next": {
|
||||
"description": "Grant UCI access for luci-app-daed-next",
|
||||
"read": {
|
||||
"uci": [ "daed-next" ]
|
||||
},
|
||||
"write": {
|
||||
"uci": [ "daed-next" ]
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user