mirror of
https://github.com/SunBK201/UA3F.git
synced 2025-12-16 08:44:29 +00:00
feat: add clear logs for luci
This commit is contained in:
parent
be8d12355e
commit
abf36b6809
@ -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([[
|
||||
<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.inputtitle = translate("Download Logs")
|
||||
download.inputstyle = "apply"
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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 "下载日志"
|
||||
msgstr "下载日志"
|
||||
|
||||
msgid "Clear Logs"
|
||||
msgstr "清除日志"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user