Add log preview

This commit is contained in:
sbwml 2022-04-09 12:43:14 +08:00
parent f6fd96413d
commit 007c54f484
5 changed files with 54 additions and 3 deletions

View File

@ -12,7 +12,10 @@ function index()
entry({"admin", "services", "mosdns", "basic"}, cbi("mosdns/basic"), _("Basic Setting"), 1).leaf = true 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", "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", "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", "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 end
function act_status() function act_status()
@ -21,3 +24,11 @@ function act_status()
luci.http.prepare_content("application/json") luci.http.prepare_content("application/json")
luci.http.write_json(e) luci.http.write_json(e)
end 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

View File

@ -0,0 +1,5 @@
m = Map("mosdns")
m:append(Template("mosdns/mosdns_log"))
return m

View File

@ -0,0 +1,28 @@
<script type="text/javascript">
//<![CDATA[
function clear_log(btn) {
XHR.get('<%=url([[admin]], [[services]], [[mosdns]], [[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;
}
}
);
}
XHR.poll(1, '<%=url([[admin]], [[services]], [[mosdns]], [[get_log]])%>', null,
function(x, data) {
if(x && x.status == 200) {
var log_textarea = document.getElementById('log_textarea');
log_textarea.innerHTML = x.responseText;
log_textarea.scrollTop = log_textarea.scrollHeight;
}
}
);
//]]>
</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: 600px; margin: 10px;" data-update="change" rows="5" wrap="off" readonly="readonly"></textarea>
</fieldset>

View File

@ -34,7 +34,7 @@ msgstr "启用 DNS 广告过滤"
msgid "<font color=\"ff0000\"><strong>View the Custom YAML Configuration file used by this MosDNS. You can edit it as you own need.</strong></font>" msgid "<font color=\"ff0000\"><strong>View the Custom YAML Configuration file used by this MosDNS. You can edit it as you own need.</strong></font>"
msgstr "<font color=\"ff0000\"><strong>注意!此页的更改仅当 'MosDNS 配置文件选择' 为 '自定义配置' 时才会生效</strong></font>" msgstr "<font color=\"ff0000\"><strong>注意!此页的更改仅当 'MosDNS 配置文件选择' 为 '自定义配置' 时才会生效</strong></font>"
msgid "<font color=\"ff0000\"><strong>ADblock whitelist only apply to 'Def Config' profiles</strong></font>" msgid "<font color=\"ff0000\"><strong>ADblock whitelist only apply to 'Def Config' profiles.</strong></font>"
msgstr "<font color=\"ff0000\"><strong>注意!广告过滤白名单仅当 'MosDNS 配置文件选择' 为 '内置预设' 时才会生效</strong></font>" msgstr "<font color=\"ff0000\"><strong>注意!广告过滤白名单仅当 'MosDNS 配置文件选择' 为 '内置预设' 时才会生效</strong></font>"
msgid "ADblock whitelist" msgid "ADblock whitelist"
@ -114,3 +114,9 @@ msgstr "覆盖最小 TTL 值"
msgid "Maximum TTL" msgid "Maximum TTL"
msgstr "覆盖最大 TTL 值" msgstr "覆盖最大 TTL 值"
msgid "Logs"
msgstr "日志"
msgid "Clear logs"
msgstr "清空日志"

View File

@ -70,6 +70,7 @@ start_service() {
[ $enabled != 1 ] && return 1 [ $enabled != 1 ] && return 1
delcron delcron
setcron setcron
echo '' > $(uci -q get mosdns.mosdns.logfile)
procd_open_instance mosdns procd_open_instance mosdns
procd_set_param command $PROG -dir $RES_DIR -c "$CONF" procd_set_param command $PROG -dir $RES_DIR -c "$CONF"
procd_set_param user root procd_set_param user root