diff --git a/openwrt/files/luci/cbi.lua b/openwrt/files/luci/cbi.lua index 874c3a4..d237167 100644 --- a/openwrt/files/luci/cbi.lua +++ b/openwrt/files/luci/cbi.lua @@ -97,6 +97,30 @@ logLines.default = "1000" logLines.datatype = "uinteger" logLines.rmempty = false +clearlog = general:taboption("log", Button, "_clearlog", translate("Clear Logs")) +clearlog.inputtitle = translate("Clear Logs") +clearlog.inputstyle = "reset" +function clearlog.write(self, section) +end + +function clearlog.render(self, section, scope) + Button.render(self, section, scope) + luci.http.write([[ + + ]]) +end + download = general:taboption("log", Button, "_download", translate("Download Logs")) download.inputtitle = translate("Download Logs") download.inputstyle = "apply" diff --git a/openwrt/files/luci/controller.lua b/openwrt/files/luci/controller.lua index 5f8fe5f..c031a74 100644 --- a/openwrt/files/luci/controller.lua +++ b/openwrt/files/luci/controller.lua @@ -2,7 +2,8 @@ module("luci.controller.ua3f", package.seeall) function index() entry({ "admin", "services", "ua3f" }, cbi("ua3f"), _("UA3F"), 1) - entry({ "admin", "services", "ua3f", "download_log" }, call("action_download_log"), _("Download Logs"), 11).leaf = true + entry({ "admin", "services", "ua3f", "download_log" }, call("action_download_log")).leaf = true + entry({ "admin", "services", "ua3f", "clear_log" }, call("clear_log")).leaf = true end function action_download_log() @@ -37,3 +38,13 @@ function action_download_log() nixio.fs.remove(tmpfile) end + +function clear_log() + local logfile = "/var/log/ua3f/ua3f.log" + local fs = require "nixio.fs" + if fs.access(logfile) then + fs.writefile(logfile, "") + end + luci.http.status(200, "OK") + luci.http.write("Log cleared") +end diff --git a/openwrt/files/luci/statistics.htm b/openwrt/files/luci/statistics.htm index 3b8591d..c51dfaf 100644 --- a/openwrt/files/luci/statistics.htm +++ b/openwrt/files/luci/statistics.htm @@ -77,6 +77,7 @@ end const doc = parser.parseFromString(text, "text/html"); const newRewriteTable = doc.querySelector("#rewrite-stats-table"); const newPassTable = doc.querySelector("#pass-stats-table"); + const newLog = doc.querySelector("#cbid\\.ua3f\\.main\\.log"); if (newRewriteTable) { document.querySelector("#rewrite-stats-table").innerHTML = newRewriteTable.innerHTML; @@ -84,6 +85,10 @@ end if (newPassTable) { document.querySelector("#pass-stats-table").innerHTML = newPassTable.innerHTML; } + if (newLog) { + document.querySelector("#cbid\\.ua3f\\.main\\.log").value = newLog.value; + } + } catch (err) { console.error("update stats error:", err); } diff --git a/openwrt/po/zh_cn/ua3f.po b/openwrt/po/zh_cn/ua3f.po index 5e3b193..c8e4295 100644 --- a/openwrt/po/zh_cn/ua3f.po +++ b/openwrt/po/zh_cn/ua3f.po @@ -84,4 +84,7 @@ msgid "Sets the logging level. Do not keep the log level set to debug/info/warn msgstr "设置日志级别,请勿长时间将日志级别设置为 debug / info / warn" msgid "Download Logs" -msgstr "下载日志" \ No newline at end of file +msgstr "下载日志" + +msgid "Clear Logs" +msgstr "清除日志"