From 007c54f48463236269622d63088d9f62ece2e704 Mon Sep 17 00:00:00 2001 From: sbwml Date: Sat, 9 Apr 2022 12:43:14 +0800 Subject: [PATCH] Add log preview --- luasrc/controller/mosdns.lua | 15 +++++++++++++-- luasrc/model/cbi/mosdns/log.lua | 5 +++++ luasrc/view/mosdns/mosdns_log.htm | 28 ++++++++++++++++++++++++++++ po/zh-cn/mosdns.po | 8 +++++++- root/etc/init.d/mosdns | 1 + 5 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 luasrc/model/cbi/mosdns/log.lua create mode 100644 luasrc/view/mosdns/mosdns_log.htm diff --git a/luasrc/controller/mosdns.lua b/luasrc/controller/mosdns.lua index 13511b4..8050df0 100644 --- a/luasrc/controller/mosdns.lua +++ b/luasrc/controller/mosdns.lua @@ -4,15 +4,18 @@ function index() if not nixio.fs.access("/etc/config/mosdns") then return end - + local page = entry({"admin", "services", "mosdns"}, alias("admin", "services", "mosdns", "basic"), _("MosDNS"), 30) page.dependent = true page.acl_depends = { "luci-app-mosdns" } - + entry({"admin", "services", "mosdns", "basic"}, cbi("mosdns/basic"), _("Basic Setting"), 1).leaf = true entry({"admin", "services", "mosdns", "whitelist"}, cbi("mosdns/whitelist"), _("ADblock whitelist"), 2).leaf = true entry({"admin", "services", "mosdns", "update"}, cbi("mosdns/update"), _("Geodata Update"), 3).leaf = true + entry({"admin", "services", "mosdns", "log"}, cbi("mosdns/log"), _("Logs"), 4).leaf = true entry({"admin", "services", "mosdns", "status"}, call("act_status")).leaf = true + entry({"admin", "services", "mosdns", "get_log"}, call("get_log")).leaf = true + entry({"admin", "services", "mosdns", "clear_log"}, call("clear_log")).leaf = true end function act_status() @@ -21,3 +24,11 @@ function act_status() luci.http.prepare_content("application/json") luci.http.write_json(e) end + +function get_log() + luci.http.write(luci.sys.exec("[ -f $(uci -q get mosdns.mosdns.logfile) ] && cat $(uci -q get mosdns.mosdns.logfile)")) +end + +function clear_log() + luci.sys.call("echo '' > $(uci -q get mosdns.mosdns.logfile)") +end diff --git a/luasrc/model/cbi/mosdns/log.lua b/luasrc/model/cbi/mosdns/log.lua new file mode 100644 index 0000000..79fc1a9 --- /dev/null +++ b/luasrc/model/cbi/mosdns/log.lua @@ -0,0 +1,5 @@ +m = Map("mosdns") + +m:append(Template("mosdns/mosdns_log")) + +return m diff --git a/luasrc/view/mosdns/mosdns_log.htm b/luasrc/view/mosdns/mosdns_log.htm new file mode 100644 index 0000000..ac16e26 --- /dev/null +++ b/luasrc/view/mosdns/mosdns_log.htm @@ -0,0 +1,28 @@ + +
+ + +
diff --git a/po/zh-cn/mosdns.po b/po/zh-cn/mosdns.po index 91c3956..c2206f6 100644 --- a/po/zh-cn/mosdns.po +++ b/po/zh-cn/mosdns.po @@ -34,7 +34,7 @@ msgstr "启用 DNS 广告过滤" msgid "View the Custom YAML Configuration file used by this MosDNS. You can edit it as you own need." msgstr "注意!此页的更改仅当 'MosDNS 配置文件选择' 为 '自定义配置' 时才会生效" -msgid "ADblock whitelist only apply to 'Def Config' profiles" +msgid "ADblock whitelist only apply to 'Def Config' profiles." msgstr "注意!广告过滤白名单仅当 'MosDNS 配置文件选择' 为 '内置预设' 时才会生效" msgid "ADblock whitelist" @@ -114,3 +114,9 @@ msgstr "覆盖最小 TTL 值" msgid "Maximum TTL" msgstr "覆盖最大 TTL 值" + +msgid "Logs" +msgstr "日志" + +msgid "Clear logs" +msgstr "清空日志" diff --git a/root/etc/init.d/mosdns b/root/etc/init.d/mosdns index 510207a..732f64a 100755 --- a/root/etc/init.d/mosdns +++ b/root/etc/init.d/mosdns @@ -70,6 +70,7 @@ start_service() { [ $enabled != 1 ] && return 1 delcron setcron + echo '' > $(uci -q get mosdns.mosdns.logfile) procd_open_instance mosdns procd_set_param command $PROG -dir $RES_DIR -c "$CONF" procd_set_param user root