mirror of
https://github.com/SunBK201/UA3F.git
synced 2025-12-18 09:46:58 +00:00
feat: add clear logs for luci
This commit is contained in:
parent
f1f93c073a
commit
29840b64fb
@ -97,6 +97,30 @@ logLines.default = "1000"
|
|||||||
logLines.datatype = "uinteger"
|
logLines.datatype = "uinteger"
|
||||||
logLines.rmempty = false
|
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([[
|
||||||
|
<script>
|
||||||
|
document.querySelector("input[name='cbid.ua3f.main._clearlog']").addEventListener("click", function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
fetch(']] .. luci.dispatcher.build_url("admin/services/ua3f/clear_log") .. [[', {method: 'POST'})
|
||||||
|
.then(resp => {
|
||||||
|
if (resp.ok) {
|
||||||
|
var textarea = document.getElementById('cbid.ua3f.main.log');
|
||||||
|
if (textarea) textarea.value = "";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
]])
|
||||||
|
end
|
||||||
|
|
||||||
download = general:taboption("log", Button, "_download", translate("Download Logs"))
|
download = general:taboption("log", Button, "_download", translate("Download Logs"))
|
||||||
download.inputtitle = translate("Download Logs")
|
download.inputtitle = translate("Download Logs")
|
||||||
download.inputstyle = "apply"
|
download.inputstyle = "apply"
|
||||||
|
|||||||
@ -2,7 +2,8 @@ module("luci.controller.ua3f", package.seeall)
|
|||||||
|
|
||||||
function index()
|
function index()
|
||||||
entry({ "admin", "services", "ua3f" }, cbi("ua3f"), _("UA3F"), 1)
|
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
|
end
|
||||||
|
|
||||||
function action_download_log()
|
function action_download_log()
|
||||||
@ -37,3 +38,13 @@ function action_download_log()
|
|||||||
|
|
||||||
nixio.fs.remove(tmpfile)
|
nixio.fs.remove(tmpfile)
|
||||||
end
|
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
|
||||||
|
|||||||
@ -77,6 +77,7 @@ end
|
|||||||
const doc = parser.parseFromString(text, "text/html");
|
const doc = parser.parseFromString(text, "text/html");
|
||||||
const newRewriteTable = doc.querySelector("#rewrite-stats-table");
|
const newRewriteTable = doc.querySelector("#rewrite-stats-table");
|
||||||
const newPassTable = doc.querySelector("#pass-stats-table");
|
const newPassTable = doc.querySelector("#pass-stats-table");
|
||||||
|
const newLog = doc.querySelector("#cbid\\.ua3f\\.main\\.log");
|
||||||
|
|
||||||
if (newRewriteTable) {
|
if (newRewriteTable) {
|
||||||
document.querySelector("#rewrite-stats-table").innerHTML = newRewriteTable.innerHTML;
|
document.querySelector("#rewrite-stats-table").innerHTML = newRewriteTable.innerHTML;
|
||||||
@ -84,6 +85,10 @@ end
|
|||||||
if (newPassTable) {
|
if (newPassTable) {
|
||||||
document.querySelector("#pass-stats-table").innerHTML = newPassTable.innerHTML;
|
document.querySelector("#pass-stats-table").innerHTML = newPassTable.innerHTML;
|
||||||
}
|
}
|
||||||
|
if (newLog) {
|
||||||
|
document.querySelector("#cbid\\.ua3f\\.main\\.log").value = newLog.value;
|
||||||
|
}
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("update stats error:", err);
|
console.error("update stats error:", err);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -85,3 +85,6 @@ msgstr "设置日志级别,请勿长时间将日志级别设置为 debug / inf
|
|||||||
|
|
||||||
msgid "Download Logs"
|
msgid "Download Logs"
|
||||||
msgstr "下载日志"
|
msgstr "下载日志"
|
||||||
|
|
||||||
|
msgid "Clear Logs"
|
||||||
|
msgstr "清除日志"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user