diff --git a/ipkg/CONTROL/control b/ipkg/CONTROL/control index 97f3e5c..59d1738 100644 --- a/ipkg/CONTROL/control +++ b/ipkg/CONTROL/control @@ -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. diff --git a/ipkg/CONTROL/control-e b/ipkg/CONTROL/control-e index 97f3e5c..59d1738 100644 --- a/ipkg/CONTROL/control-e +++ b/ipkg/CONTROL/control-e @@ -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. diff --git a/openwrt/files/luci/cbi.lua b/openwrt/files/luci/cbi.lua index d8111f9..874c3a4 100644 --- a/openwrt/files/luci/cbi.lua +++ b/openwrt/files/luci/cbi.lua @@ -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" diff --git a/openwrt/files/luci/controller.lua b/openwrt/files/luci/controller.lua index 2baff4f..5f8fe5f 100644 --- a/openwrt/files/luci/controller.lua +++ b/openwrt/files/luci/controller.lua @@ -1,5 +1,39 @@ module("luci.controller.ua3f", package.seeall) function index() - entry({"admin", "services", "ua3f"}, cbi("ua3f"), _("UA3F"), 1) -end \ No newline at end of file + 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 diff --git a/openwrt/po/zh_cn/ua3f.po b/openwrt/po/zh_cn/ua3f.po index b55df3b..5e3b193 100644 --- a/openwrt/po/zh_cn/ua3f.po +++ b/openwrt/po/zh_cn/ua3f.po @@ -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" \ No newline at end of file +msgstr "设置日志级别,请勿长时间将日志级别设置为 debug / info / warn" + +msgid "Download Logs" +msgstr "下载日志" \ No newline at end of file diff --git a/src/internal/log/log.go b/src/internal/log/log.go index 3c23849..b83f33d 100644 --- a/src/internal/log/log.go +++ b/src/internal/log/log.go @@ -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,