From cc95016747e02fdcaf102e2d2ed806ac7c7744da Mon Sep 17 00:00:00 2001 From: SunBK201 Date: Sun, 2 Nov 2025 06:04:03 +0800 Subject: [PATCH] feat: enhance logging configuration and add translations for display lines --- ipkg/CONTROL/control | 2 +- ipkg/CONTROL/control-e | 2 +- openwrt/files/luci/cbi.lua | 36 ++++++++++++++++++++++++++++++++---- openwrt/files/ua3f.uci | 2 +- openwrt/po/zh_cn/ua3f.po | 6 ++++++ 5 files changed, 41 insertions(+), 7 deletions(-) diff --git a/ipkg/CONTROL/control b/ipkg/CONTROL/control index a3685fd..7395d33 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: 4362240 +Installed-Size: 4372480 Description: Advanced HTTP User-Agent Rewriting Tool. diff --git a/ipkg/CONTROL/control-e b/ipkg/CONTROL/control-e index a3685fd..7395d33 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: 4362240 +Installed-Size: 4372480 Description: Advanced HTTP User-Agent Rewriting Tool. diff --git a/openwrt/files/luci/cbi.lua b/openwrt/files/luci/cbi.lua index cb7b3f0..a1ebdfc 100644 --- a/openwrt/files/luci/cbi.lua +++ b/openwrt/files/luci/cbi.lua @@ -50,9 +50,12 @@ log_level:value("warn") log_level:value("error") log_level:value("fatal") log_level:value("panic") +log_level.description = translate( + "Sets the logging level. Do not keep the log level set to debug/info/warn for an extended period of time.") ua = general:taboption("general", Value, "ua", translate("User-Agent")) ua.placeholder = "FFF" +ua.description = translate("User-Agent to be rewritten") uaRegexPattern = general:taboption("general", Value, "ua_regex", translate("User-Agent Regex Pattern")) uaRegexPattern.description = translate("Regular expression pattern for matching User-Agent") @@ -62,12 +65,37 @@ partialRepalce.description = translate("Replace only the matched part of the User-Agent, only works when User-Agent Regex Pattern is not empty") partialRepalce.default = "0" -log = general:taboption("log", TextValue, "") +log = general:taboption("log", TextValue, "log") log.readonly = true -log.cfgvalue = function(self, section) - return luci.sys.exec("cat /var/log/ua3f/ua3f.log") -end log.rows = 30 +function log.cfgvalue(self, section) + local logfile = "/var/log/ua3f/ua3f.log" + local fs = require("nixio.fs") + if not fs.access(logfile) then + return "" + end + local n = tonumber(luci.model.uci.cursor():get("ua3f", section, "log_lines")) or 1000 + return luci.sys.exec("tail -n " .. n .. " " .. logfile) +end + +function log.write(self, section, value) end + +function log.render(self, section, scope) + TextValue.render(self, section, scope) + luci.http.write("") +end + +logLines = general:taboption("log", Value, "log_lines", translate("Display Lines")) +logLines.default = "1000" +logLines.datatype = "uinteger" +logLines.rmempty = false stats = general:taboption("stats", DummyValue, "") stats.template = "ua3f/statistics" diff --git a/openwrt/files/ua3f.uci b/openwrt/files/ua3f.uci index f7d6854..36575da 100644 --- a/openwrt/files/ua3f.uci +++ b/openwrt/files/ua3f.uci @@ -8,4 +8,4 @@ config 'ua3f' 'main' option ua 'FFF' option ua_regex '(Apple|iPhone|iPad|Macintosh|Mac OS X|Mac|Darwin|Microsoft|Windows|Linux|Android|OpenHarmony|HUAWEI|OPPO|Vivo|XiaoMi|Mobile|Dalvik)' option partial_replace false - option log_level 'info' \ No newline at end of file + option log_level 'error' \ No newline at end of file diff --git a/openwrt/po/zh_cn/ua3f.po b/openwrt/po/zh_cn/ua3f.po index 921a254..b55df3b 100644 --- a/openwrt/po/zh_cn/ua3f.po +++ b/openwrt/po/zh_cn/ua3f.po @@ -76,3 +76,9 @@ msgstr "放行次数" msgid "Last Host" msgstr "最后访问地址" + +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