mirror of
https://github.com/SunBK201/UA3F.git
synced 2025-12-16 08:44:29 +00:00
feat: add download logs functionality and update log file size limit
This commit is contained in:
parent
5a1d10af8f
commit
be8d12355e
@ -7,5 +7,5 @@ License: GPL-3.0-only
|
||||
Section: net
|
||||
SourceDateEpoch: 1711267200
|
||||
Architecture: all
|
||||
Installed-Size: 4495360
|
||||
Installed-Size: 4505600
|
||||
Description: Advanced HTTP User-Agent Rewriting Tool.
|
||||
|
||||
@ -7,5 +7,5 @@ License: GPL-3.0-only
|
||||
Section: net
|
||||
SourceDateEpoch: 1711267200
|
||||
Architecture: all
|
||||
Installed-Size: 4495360
|
||||
Installed-Size: 4505600
|
||||
Description: Advanced HTTP User-Agent Rewriting Tool.
|
||||
|
||||
@ -97,6 +97,13 @@ logLines.default = "1000"
|
||||
logLines.datatype = "uinteger"
|
||||
logLines.rmempty = false
|
||||
|
||||
download = general:taboption("log", Button, "_download", translate("Download Logs"))
|
||||
download.inputtitle = translate("Download Logs")
|
||||
download.inputstyle = "apply"
|
||||
function download.write(self, section)
|
||||
luci.http.redirect(luci.dispatcher.build_url("admin/services/ua3f/download_log"))
|
||||
end
|
||||
|
||||
stats = general:taboption("stats", DummyValue, "")
|
||||
stats.template = "ua3f/statistics"
|
||||
|
||||
|
||||
@ -1,5 +1,39 @@
|
||||
module("luci.controller.ua3f", package.seeall)
|
||||
|
||||
function index()
|
||||
entry({"admin", "services", "ua3f"}, cbi("ua3f"), _("UA3F"), 1)
|
||||
end
|
||||
entry({ "admin", "services", "ua3f" }, cbi("ua3f"), _("UA3F"), 1)
|
||||
entry({ "admin", "services", "ua3f", "download_log" }, call("action_download_log"), _("Download Logs"), 11).leaf = true
|
||||
end
|
||||
|
||||
function action_download_log()
|
||||
local nixio = require "nixio"
|
||||
local fs = require "nixio.fs"
|
||||
local http = require "luci.http"
|
||||
local tmpfile = "/tmp/ua3f_logs.tar.gz"
|
||||
|
||||
local cmd = "cd /var/log && tar -czf " .. tmpfile .. " ua3f >/dev/null 2>&1"
|
||||
os.execute(cmd)
|
||||
|
||||
if not fs.access(tmpfile) then
|
||||
http.status(500, "Internal Server Error")
|
||||
http.prepare_content("text/plain")
|
||||
http.write("Failed to create archive")
|
||||
return
|
||||
end
|
||||
|
||||
http.header("Content-Type", "application/gzip")
|
||||
http.header("Content-Disposition", 'attachment; filename="ua3f_logs.tar.gz"')
|
||||
http.header("Content-Length", tostring(fs.stat(tmpfile).size))
|
||||
|
||||
local fp = io.open(tmpfile, "rb")
|
||||
if fp then
|
||||
while true do
|
||||
local chunk = fp:read(2048)
|
||||
if not chunk then break end
|
||||
http.write(chunk)
|
||||
end
|
||||
fp:close()
|
||||
end
|
||||
|
||||
nixio.fs.remove(tmpfile)
|
||||
end
|
||||
|
||||
@ -81,4 +81,7 @@ msgid "Display Lines"
|
||||
msgstr "显示行数"
|
||||
|
||||
msgid "Sets the logging level. Do not keep the log level set to debug/info/warn for an extended period of time."
|
||||
msgstr "设置日志级别,请勿长时间将日志级别设置为 debug / info / warn"
|
||||
msgstr "设置日志级别,请勿长时间将日志级别设置为 debug / info / warn"
|
||||
|
||||
msgid "Download Logs"
|
||||
msgstr "下载日志"
|
||||
@ -39,7 +39,7 @@ func SetLogConf(level string) {
|
||||
writer2 := os.Stdout
|
||||
writer3 := &lumberjack.Logger{
|
||||
Filename: log_file,
|
||||
MaxSize: 2, // megabytes
|
||||
MaxSize: 5, // megabytes
|
||||
MaxBackups: 5,
|
||||
MaxAge: 7, //days
|
||||
LocalTime: true,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user