diff --git a/luci-app-daed/Makefile b/luci-app-daed/Makefile index ff102937b..ff7b570c6 100644 --- a/luci-app-daed/Makefile +++ b/luci-app-daed/Makefile @@ -1,13 +1,15 @@ -# SPDX-License-Identifier: Apache-2.0 -# -# Copyright (C) 2023 ImmortalWrt.org - include $(TOPDIR)/rules.mk -LUCI_TITLE:=LuCI app for dae dashboard -LUCI_DEPENDS:=+daed +daed-geoip +daed-geosite +PKG_NAME:=luci-app-daed +PKG_VERSION:=1.4 +PKG_RELEASE:=2 + +LUCI_TITLE:=LuCI Support for DAED +LUCI_DEPENDS:=+daed +zoneinfo-asia +luci-compat LUCI_PKGARCH:=all -include $(TOPDIR)/feeds/luci/luci.mk +define Package/$(PKG_NAME)/conffiles +endef +include $(TOPDIR)/feeds/luci/luci.mk # call BuildPackage - OpenWrt buildroot signature diff --git a/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js b/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js deleted file mode 100644 index edecbf86b..000000000 --- a/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js +++ /dev/null @@ -1,93 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -'use strict'; -'require form'; -'require poll'; -'require rpc'; -'require uci'; -'require view'; - -const callServiceList = rpc.declare({ - object: 'service', - method: 'list', - params: ['name'], - expect: { '': {} } -}); - -function getServiceStatus() { - return L.resolveDefault(callServiceList('daed'), {}).then(function(res) { - let isRunning = false; - try { - isRunning = res['daed']['instances']['daed']['running']; - } catch (e) { } - return isRunning; - }); -} - -function renderStatus(isRunning, port) { - let spanTemp = '%s %s'; - let renderHTML; - if (isRunning) { - let button = String.format(' %s', - window.location.hostname, port, _('Open Web Interface')); - renderHTML = spanTemp.format('green', _('daed'), _('RUNNING')) + button; - } else { - renderHTML = spanTemp.format('red', _('daed'), _('NOT RUNNING')); - } - - return renderHTML; -} - -return view.extend({ - load: function() { - return Promise.all([ - uci.load('daed') - ]); - }, - - render: function(data) { - let m, s, o; - let webport = (uci.get(data[0], 'config', 'address') || '0.0.0.0:2023').split(':').slice(-1)[0]; - - m = new form.Map('daed', _('daed'), - _('A modern dashboard for dae.')); - - s = m.section(form.TypedSection); - s.anonymous = true; - s.render = function() { - poll.add(function() { - return L.resolveDefault(getServiceStatus()).then(function(res) { - let view = document.getElementById('service_status'); - view.innerHTML = renderStatus(res, webport); - }); - }); - - return E('div', { class: 'cbi-section', id: 'status_bar' }, [ - E('p', { id: 'service_status' }, _('Collecting data…')) - ]); - } - - s = m.section(form.NamedSection, 'config', 'daed'); - - o = s.option(form.Flag, 'enabled', _('Enable')); - o.default = o.disabled; - o.rmempty = false; - - o = s.option(form.Value, 'listen_addr', _('Listening address')); - o.datatype = 'ipaddrport(1)'; - o.default = '0.0.0.0:2023'; - o.rmempty = false; - - o = s.option(form.Value, 'log_maxbackups', _('Max log backups'), - _('The maximum number of old log files to retain.')); - o.datatype = 'uinteger'; - o.default = '1'; - - o = s.option(form.Value, 'log_maxsize', _('Max log size'), - _('The maximum size in megabytes of the log file before it gets rotated.')); - o.datatype = 'uinteger'; - o.default = '5'; - - return m.render(); - } -}); diff --git a/luci-app-daed/htdocs/luci-static/resources/view/daed/log.js b/luci-app-daed/htdocs/luci-static/resources/view/daed/log.js deleted file mode 100644 index 79c0326d3..000000000 --- a/luci-app-daed/htdocs/luci-static/resources/view/daed/log.js +++ /dev/null @@ -1,94 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -'use strict'; -'require dom'; -'require fs'; -'require poll'; -'require view'; - -return view.extend({ - render() { - /* Thanks to luci-app-aria2 */ - let css = ' \ - #log_textarea { \ - text-align: left; \ - } \ - #log_textarea pre { \ - padding: .5rem; \ - word-break: break-all; \ - margin: 0; \ - } \ - .description { \ - background-color: #33ccff; \ - }'; - - let log_textarea = E('div', { 'id': 'log_textarea' }, - E('img', { - 'src': L.resource('icons/loading.svg'), - 'alt': _('Loading...'), - 'style': 'vertical-align:middle' - }, _('Collecting data…')) - ); - - poll.add(L.bind(function() { - return fs.read_direct('/var/log/daed/daed.log', 'text') - .then(function(content) { - let log = E('pre', { 'wrap': 'pre' }, [ - content.trim() || _('Log is empty.') - ]); - - dom.content(log_textarea, log); - }).catch(function(e) { - let log; - - if (e.toString().includes('NotFoundError')) - log = E('pre', { 'wrap': 'pre' }, [ - _('Log file does not exist.') - ]); - else - log = E('pre', { 'wrap': 'pre' }, [ - _('Unknown error: %s').format(e) - ]); - - dom.content(log_textarea, log); - }); - })); - - const scrollDownButton = E('button', { - 'id': 'scrollDownButton', - 'class': 'cbi-button cbi-button-neutral', - }, _('Scroll to tail', 'scroll to bottom (the tail) of the log file') - ); - scrollDownButton.addEventListener('click', () => { - scrollUpButton.focus(); - }); - - const scrollUpButton = E('button', { - 'id' : 'scrollUpButton', - 'class': 'cbi-button cbi-button-neutral', - }, _('Scroll to head', 'scroll to top (the head) of the log file') - ); - scrollUpButton.addEventListener('click', () => { - scrollDownButton.focus(); - }); - - return E([ - E('style', [ css ]), - E('h2', {}, [ _('Log') ]), - E('div', {'class': 'cbi-map'}, [ - E('div', {'style': 'padding-bottom: 20px'}, [scrollDownButton]), - E('div', {'class': 'cbi-section'}, [ - log_textarea, - E('div', {'style': 'text-align:right'}, - E('small', {}, _('Refresh every %s seconds.').format(L.env.pollinterval)) - ) - ]), - E('div', {'style': 'padding-bottom: 20px'}, [scrollUpButton]) - ]) - ]); - }, - - handleSaveApply: null, - handleSave: null, - handleReset: null -}); diff --git a/luci-app-daed/luasrc/controller/daed.lua b/luci-app-daed/luasrc/controller/daed.lua new file mode 100644 index 000000000..29e9e1f63 --- /dev/null +++ b/luci-app-daed/luasrc/controller/daed.lua @@ -0,0 +1,34 @@ +local sys = require "luci.sys" +local http = require "luci.http" + +module("luci.controller.daed", package.seeall) + +function index() + if not nixio.fs.access("/etc/config/daed") then + return + end + + entry({"admin", "services", "daed"}, alias("admin", "services", "daed", "setting"),_("DAED"), 58).dependent = true + entry({"admin", "services", "daed", "setting"}, cbi("daed/basic"), _("Base Setting"), 1).leaf=true + entry({"admin", "services", "daed", "daed"}, template("daed/daed"), _("Dashboard"), 2).leaf = true + entry({"admin", "services", "daed", "log"}, cbi("daed/log"), _("Logs"), 3).leaf = true + entry({"admin", "services", "daed_status"}, call("act_status")) + entry({"admin", "services", "daed", "get_log"}, call("get_log")).leaf = true + entry({"admin", "services", "daed", "clear_log"}, call("clear_log")).leaf = true +end + +function act_status() + local sys = require "luci.sys" + local e = { } + e.running = sys.call("pidof daed >/dev/null") == 0 + luci.http.prepare_content("application/json") + luci.http.write_json(e) +end + +function get_log() + http.write(sys.exec("cat /var/log/daed/daed.log")) +end + +function clear_log() + sys.call("true > /var/log/daed/daed.log") +end diff --git a/luci-app-daed/luasrc/model/cbi/daed/basic.lua b/luci-app-daed/luasrc/model/cbi/daed/basic.lua new file mode 100644 index 000000000..372ccd34c --- /dev/null +++ b/luci-app-daed/luasrc/model/cbi/daed/basic.lua @@ -0,0 +1,35 @@ +local m, s ,o + +m = Map("daed") +m.title = translate("DAED") +m.description = translate("DAE is a Linux high-performance transparent proxy solution based on eBPF, And DAED is a modern dashboard for dae.") + +m:section(SimpleSection).template = "daed/daed_status" + +s = m:section(TypedSection, "daed", translate("Global Settings")) +s.addremove = false +s.anonymous = true + +o = s:option(Flag,"enabled",translate("Enable")) +o.default = 0 + +o = s:option(Value, "log_maxbackups", translate("Logfile retention count")) +o.default = 1 + +o = s:option(Value, "log_maxsize", translate("Logfile Max Size (MB)")) +o.default = 5 + +o = s:option(Value, "listen_addr",translate("Set the DAED listen address")) +o.default = '0.0.0.0:2023' + +o = s:option(Value, "dashboard_port", translate("Dashboard Access Port")) +o.placeholder = translate("Leave empty to use listen port") +o.datatype = "range(1,65535)" +o.description = translate("For reverse proxy scenarios, leave empty to use the port from listen address") + +m.apply_on_parse = true +m.on_after_apply = function(self,map) + luci.sys.exec("/etc/init.d/daed restart") +end + +return m \ No newline at end of file diff --git a/luci-app-daed/luasrc/model/cbi/daed/log.lua b/luci-app-daed/luasrc/model/cbi/daed/log.lua new file mode 100644 index 000000000..fca66fc47 --- /dev/null +++ b/luci-app-daed/luasrc/model/cbi/daed/log.lua @@ -0,0 +1,5 @@ +m = Map("daed") + +m:append(Template("daed/daed_log")) + +return m diff --git a/luci-app-daed/luasrc/view/daed/daed.htm b/luci-app-daed/luasrc/view/daed/daed.htm new file mode 100644 index 000000000..a9b30abb9 --- /dev/null +++ b/luci-app-daed/luasrc/view/daed/daed.htm @@ -0,0 +1,56 @@ +<%+header%> +<% + local running = luci.sys.exec("pgrep -x /usr/bin/daed") +%> +<% if tonumber(running) ~= nil then %> +
+ +
+ + +<% else %> + +
+ +

<%:DAED is not running%>

+

<%:Please start the DAED service first and try again%>

+
+<% end -%> + +<%+footer%> \ No newline at end of file diff --git a/luci-app-daed/luasrc/view/daed/daed_log.htm b/luci-app-daed/luasrc/view/daed/daed_log.htm new file mode 100644 index 000000000..7016dc32a --- /dev/null +++ b/luci-app-daed/luasrc/view/daed/daed_log.htm @@ -0,0 +1,33 @@ + +
+ + +
diff --git a/luci-app-daed/luasrc/view/daed/daed_status.htm b/luci-app-daed/luasrc/view/daed/daed_status.htm new file mode 100644 index 000000000..457efedcc --- /dev/null +++ b/luci-app-daed/luasrc/view/daed/daed_status.htm @@ -0,0 +1,24 @@ + + +
+

+ <%:Collecting data...%> +

+
diff --git a/luci-app-daed/po/templates/daed.pot b/luci-app-daed/po/templates/daed.pot deleted file mode 100644 index 4807fbc04..000000000 --- a/luci-app-daed/po/templates/daed.pot +++ /dev/null @@ -1,97 +0,0 @@ -msgid "" -msgstr "Content-Type: text/plain; charset=UTF-8" - -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js:53 -msgid "A modern dashboard for dae." -msgstr "" - -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js:66 -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/log.js:30 -msgid "Collecting data…" -msgstr "" - -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js:72 -msgid "Enable" -msgstr "" - -#: applications/luci-app-daed/root/usr/share/rpcd/acl.d/luci-app-daed.json:3 -msgid "Grant access to daed configuration" -msgstr "" - -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js:76 -msgid "Listening address" -msgstr "" - -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/log.js:28 -msgid "Loading..." -msgstr "" - -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/log.js:77 -#: applications/luci-app-daed/root/usr/share/luci/menu.d/luci-app-daed.json:22 -msgid "Log" -msgstr "" - -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/log.js:46 -msgid "Log file does not exist." -msgstr "" - -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/log.js:37 -msgid "Log is empty." -msgstr "" - -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js:81 -msgid "Max log backups" -msgstr "" - -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js:86 -msgid "Max log size" -msgstr "" - -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js:35 -msgid "NOT RUNNING" -msgstr "" - -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js:32 -msgid "Open Web Interface" -msgstr "" - -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js:33 -msgid "RUNNING" -msgstr "" - -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/log.js:83 -msgid "Refresh every %s seconds." -msgstr "" - -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/log.js:69 -msgctxt "scroll to top (the head) of the log file" -msgid "Scroll to head" -msgstr "" - -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/log.js:60 -msgctxt "scroll to bottom (the tail) of the log file" -msgid "Scroll to tail" -msgstr "" - -#: applications/luci-app-daed/root/usr/share/luci/menu.d/luci-app-daed.json:14 -msgid "Settings" -msgstr "" - -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js:82 -msgid "The maximum number of old log files to retain." -msgstr "" - -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js:87 -msgid "The maximum size in megabytes of the log file before it gets rotated." -msgstr "" - -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/log.js:50 -msgid "Unknown error: %s" -msgstr "" - -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js:33 -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js:35 -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js:52 -#: applications/luci-app-daed/root/usr/share/luci/menu.d/luci-app-daed.json:3 -msgid "daed" -msgstr "" diff --git a/luci-app-daed/po/zh_Hans/daed.po b/luci-app-daed/po/zh_Hans/daed.po index d9fba2b25..239b1fd43 100644 --- a/luci-app-daed/po/zh_Hans/daed.po +++ b/luci-app-daed/po/zh_Hans/daed.po @@ -1,104 +1,68 @@ msgid "" -msgstr "" -"Content-Type: text/plain; charset=UTF-8\n" -"Project-Id-Version: PACKAGE VERSION\n" -"Last-Translator: Automatically generated\n" -"Language-Team: none\n" -"Language: zh-Hans\n" -"MIME-Version: 1.0\n" -"Content-Transfer-Encoding: 8bit\n" +msgstr "Content-Type: text/plain; charset=UTF-8" -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js:53 -msgid "A modern dashboard for dae." -msgstr "dae 现代化控制面板。" +msgid "DAED" +msgstr "DAED" -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js:66 -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/log.js:30 -msgid "Collecting data…" -msgstr "正在收集数据中…" +msgid "DAE is a Linux high-performance transparent proxy solution based on eBPF, And DAED is a modern dashboard for dae." +msgstr "DAE是一个基于eBPF的Linux高性能透明代理解决方案,而DAED是DAE的管理面板。" -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js:72 -msgid "Enable" -msgstr "启用" +msgid "Base Setting" +msgstr "基本设置" -#: applications/luci-app-daed/root/usr/share/rpcd/acl.d/luci-app-daed.json:3 -msgid "Grant access to daed configuration" -msgstr "授予访问 daed 配置的权限" +msgid "Dashboard" +msgstr "仪表板" -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js:76 -msgid "Listening address" -msgstr "监听地址" - -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/log.js:28 -msgid "Loading..." -msgstr "加载中..." - -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/log.js:77 -#: applications/luci-app-daed/root/usr/share/luci/menu.d/luci-app-daed.json:22 -msgid "Log" +msgid "Logs" msgstr "日志" -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/log.js:46 -msgid "Log file does not exist." -msgstr "日志文件不存在。" +msgid "Clear logs" +msgstr "清空日志" -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/log.js:37 -msgid "Log is empty." -msgstr "日志为空" - -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js:81 -msgid "Max log backups" -msgstr "最大日志备份" - -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js:86 -msgid "Max log size" -msgstr "最大日志大小" - -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js:35 -msgid "NOT RUNNING" -msgstr "未运行" - -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js:32 -msgid "Open Web Interface" -msgstr "打开 Web 界面" - -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js:33 msgid "RUNNING" msgstr "运行中" -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/log.js:83 -msgid "Refresh every %s seconds." -msgstr "每 %s 秒刷新。" +msgid "NOT RUNNING" +msgstr "未运行" -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/log.js:69 -msgctxt "scroll to top (the head) of the log file" -msgid "Scroll to head" -msgstr "滚动到顶部" +msgid "Collecting data..." +msgstr "收集数据..." -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/log.js:60 -msgctxt "scroll to bottom (the tail) of the log file" -msgid "Scroll to tail" -msgstr "滚动到尾部" +msgid "Logfile retention count" +msgstr "日志文件保留数量" -#: applications/luci-app-daed/root/usr/share/luci/menu.d/luci-app-daed.json:14 -msgid "Settings" -msgstr "设置" +msgid "Logfile Max Size (MB)" +msgstr "日志文件大小(MB)" -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js:82 -msgid "The maximum number of old log files to retain." -msgstr "要保留的最大旧日志文件数量。" +msgid "Set the DAED listen address" +msgstr "设置监听地址" -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js:87 -msgid "The maximum size in megabytes of the log file before it gets rotated." -msgstr "要保留的最大日志大小(单位:MB)。" +msgid "Dashboard Access Port" +msgstr "仪表板访问端口" -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/log.js:50 -msgid "Unknown error: %s" -msgstr "未知错误:%s" +msgid "Leave empty to use listen port" +msgstr "留空则使用监听端口" -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js:33 -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js:35 -#: applications/luci-app-daed/htdocs/luci-static/resources/view/daed/config.js:52 -#: applications/luci-app-daed/root/usr/share/luci/menu.d/luci-app-daed.json:3 -msgid "daed" -msgstr "daed" +msgid "For reverse proxy scenarios, leave empty to use the port from listen address" +msgstr "用于反向代理场景,留空则使用监听地址的端口" + +msgid "DAED is not running" +msgstr "DAED 未运行" + +msgid "Please start the DAED service first and try again" +msgstr "请先启动 DAED 服务后重试" + +msgid "Enable Auto Subscribe Update" +msgstr "启用订阅自动更新" + +msgid "Update Cycle" +msgstr "更新周期" + +msgid "Update Time (Every Day)" +msgstr "更新时间(每天)" + +msgid "Username" +msgstr "用户名" + +msgid "Password" +msgstr "密码" \ No newline at end of file diff --git a/luci-app-daed/root/etc/hotplug.d/iface/98-daed b/luci-app-daed/root/etc/hotplug.d/iface/98-daed new file mode 100755 index 000000000..83df5ffdd --- /dev/null +++ b/luci-app-daed/root/etc/hotplug.d/iface/98-daed @@ -0,0 +1,31 @@ +#!/bin/sh + +[ "$ACTION" = "ifup" ] || [ "$ACTION" = "ifupdate" ] || exit 0 +[ "$ACTION" = "ifupdate" ] && [ -z "$IFUPDATE_ADDRESSES" ] && [ -z "$IFUPDATE_DATA" ] && exit 0 + +UPTIME=$(cut -d. -f1 /proc/uptime 2>/dev/null) +[ -n "$UPTIME" ] && [ "$UPTIME" -lt 30 ] && exit 0 + +. /lib/functions/network.sh +network_find_wan6 NET_IF6 +network_find_wan NET_IF +[ "$INTERFACE" != "$NET_IF6" ] && [ "$INTERFACE" != "$NET_IF" ] && exit 0 + +[ "$(uci -q get daed.config.enabled)" = "1" ] || exit 0 + +DEBOUNCE_FILE="/tmp/run/daed_hotplug_gen" +mkdir -p /tmp/run + +my_gen="$$.$(date +%s)" +echo "$my_gen" > "$DEBOUNCE_FILE" + +( + sleep 5 + [ "$(cat "$DEBOUNCE_FILE" 2>/dev/null)" = "$my_gen" ] || exit 0 + + if /etc/init.d/daed running; then + /etc/init.d/daed restart + else + /etc/init.d/daed start + fi +) & diff --git a/luci-app-daed/root/etc/init.d/luci_daed b/luci-app-daed/root/etc/init.d/luci_daed new file mode 100755 index 000000000..8d70ad1f3 --- /dev/null +++ b/luci-app-daed/root/etc/init.d/luci_daed @@ -0,0 +1,93 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2023 Tianling Shen + +USE_PROCD=0 +START=98 + +CONF="daed" +PROG="/usr/bin/daed" +LOG="/var/log/daed/daed.log" +RESOLV_DAED="/tmp/resolv.conf.daed" + +update_cron() { + local temp_cron="/tmp/root.cron" + + if [ -f /etc/crontabs/root ]; then + grep -v '/etc/daed/daed_sub.sh' /etc/crontabs/root > "$temp_cron" 2>/dev/null + fi + : >> "$temp_cron" + + local auto_update + auto_update=$(uci -q get daed.config.subscribe_auto_update) + if [ "$1" = "add" ] && [ "${auto_update:-0}" -eq 1 ]; then + local min=$((RANDOM % 60)) + local hr=$(uci -q get daed.config.subscribe_update_day_time) + local wk=$(uci -q get daed.config.subscribe_update_week_time) + echo "$min ${hr:-*} * * ${wk:-*} /etc/daed/daed_sub.sh >/dev/null 2>&1" >> "$temp_cron" + fi + + crontab "$temp_cron" 2>/dev/null + rm -f "$temp_cron" +} + +hijack_resolv_conf() { + grep -q ' /tmp/resolv\.conf ' /proc/mounts && return 0 + + grep -E '^(search|domain) ' /tmp/resolv.conf > "$RESOLV_DAED" 2>/dev/null + + local dns_list LOGICAL_WAN + . /lib/functions/network.sh + network_find_wan LOGICAL_WAN 2>/dev/null + if [ -n "$LOGICAL_WAN" ]; then + dns_list=$(ubus call "network.interface.$LOGICAL_WAN" status 2>/dev/null | \ + jsonfilter -e '@["dns-server"][*]' 2>/dev/null) + fi + + if [ -z "$dns_list" ] && [ -f "/tmp/resolv.conf.d/resolv.conf.auto" ]; then + dns_list=$(awk '/^nameserver/{print $2}' "/tmp/resolv.conf.d/resolv.conf.auto") + fi + + [ -z "$dns_list" ] && dns_list="119.29.29.29 223.5.5.5" + + for dns in $dns_list; do + echo "nameserver $dns" >> "$RESOLV_DAED" + done + + mount --bind "$RESOLV_DAED" /tmp/resolv.conf + mount -o remount,ro,bind /tmp/resolv.conf +} + +restore_resolv_conf() { + grep -q ' /tmp/resolv\.conf ' /proc/mounts || return 0 + mount -o remount,rw,bind /tmp/resolv.conf 2>/dev/null + umount /tmp/resolv.conf 2>/dev/null + rm -f "$RESOLV_DAED" +} + +start_service() { + [ -f "/etc/init.d/daed" ] && grep -q "DAE_LOCATION_ASSET" "/etc/init.d/daed" || sed -i '/run/i\ procd_set_param env DAE_LOCATION_ASSET="/usr/share/v2ray"' "/etc/init.d/daed" + config_load "$CONF" + + local enabled + config_get_bool enabled "config" "enabled" "0" + if [ "$enabled" -eq 0 ]; then + update_cron "remove" + restore_resolv_conf + return 1 + fi + update_cron "add" + hijack_resolv_conf +} + +stop_service() { + update_cron "remove" + restore_resolv_conf +} + +service_triggers() { + procd_add_reload_trigger "$CONF" +} + +reload_service() { + restart +} diff --git a/luci-app-daed/root/usr/share/luci/menu.d/luci-app-daed.json b/luci-app-daed/root/usr/share/luci/menu.d/luci-app-daed.json deleted file mode 100644 index 7dd5e2b48..000000000 --- a/luci-app-daed/root/usr/share/luci/menu.d/luci-app-daed.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "admin/services/daed": { - "title": "daed", - "order": 20, - "action": { - "type": "firstchild" - }, - "depends": { - "acl": [ "luci-app-daed" ], - "uci": { "daed": true } - } - }, - "admin/services/daed/config": { - "title": "Settings", - "order": 10, - "action": { - "type": "view", - "path": "daed/config" - } - }, - "admin/services/daed/log": { - "title": "Log", - "order": 20, - "action": { - "type": "view", - "path": "daed/log" - } - } -} diff --git a/luci-app-daed/root/usr/share/rpcd/acl.d/luci-app-daed.json b/luci-app-daed/root/usr/share/rpcd/acl.d/luci-app-daed.json index 8ec379d9d..8fc50b822 100644 --- a/luci-app-daed/root/usr/share/rpcd/acl.d/luci-app-daed.json +++ b/luci-app-daed/root/usr/share/rpcd/acl.d/luci-app-daed.json @@ -1,13 +1,7 @@ { "luci-app-daed": { - "description": "Grant access to daed configuration", + "description": "Grant UCI access for luci-app-daed", "read": { - "file": { - "/var/log/daed/daed.log": [ "read" ] - }, - "ubus": { - "service": [ "list" ] - }, "uci": [ "daed" ] }, "write": {