From e5cf69c072c7cc1e736080df1b2c2953bfc822b0 Mon Sep 17 00:00:00 2001 From: kenzok8 Date: Thu, 10 Oct 2024 00:24:05 +0800 Subject: [PATCH] update 2024-10-10 00:24:05 --- .../luasrc/controller/ddns-go.lua | 22 ++++- luci-app-ddns-go/luasrc/model/cbi/ddns-go.lua | 2 +- .../luasrc/view/{ => ddns-go}/ddns-go.htm | 0 .../luasrc/view/ddns-go/ddns-go_log.htm | 90 +++++++++++++++++++ .../view/{ => ddns-go}/ddns-go_status.htm | 0 luci-app-ddns-go/po/zh-cn/ddns-go.po | 3 + luci-app-ddns-go/po/zh_Hans/ddns-go.po | 3 + 7 files changed, 118 insertions(+), 2 deletions(-) rename luci-app-ddns-go/luasrc/view/{ => ddns-go}/ddns-go.htm (100%) create mode 100644 luci-app-ddns-go/luasrc/view/ddns-go/ddns-go_log.htm rename luci-app-ddns-go/luasrc/view/{ => ddns-go}/ddns-go_status.htm (100%) diff --git a/luci-app-ddns-go/luasrc/controller/ddns-go.lua b/luci-app-ddns-go/luasrc/controller/ddns-go.lua index 152c1ca0d..9dae76674 100644 --- a/luci-app-ddns-go/luasrc/controller/ddns-go.lua +++ b/luci-app-ddns-go/luasrc/controller/ddns-go.lua @@ -12,8 +12,11 @@ function index() e.dependent=false e.acl_depends={ "luci-app-ddns-go" } entry({"admin", "services", "ddns-go", "setting"}, cbi("ddns-go"), _("Base Setting"), 20).leaf=true - entry({"admin", "services", "ddns-go", "ddns-go"}, template("ddns-go"), _("DDNS-GO Control panel"), 30).leaf = true + entry({"admin", "services", "ddns-go", "ddns-go"}, template("ddns-go/ddns-go"), _("DDNS-GO Control panel"), 30).leaf = true entry({"admin", "services", "ddnsgo_status"}, call("act_status")) + entry({"admin", "services", "ddns-go", "log"}, template("ddns-go/ddns-go_log"), _("Log"), 40).leaf = true + entry({"admin", "services", "ddns-go", "fetch_log"}, call("fetch_log"), nil).leaf = true + entry({"admin", "services", "ddns-go", "clear_log"}, call("clear_log")).leaf = true end function act_status() @@ -23,3 +26,20 @@ function act_status() luci.http.prepare_content("application/json") luci.http.write_json(e) end +function fetch_log() + local fs = require "nixio.fs" + local log_file = "/var/log/ddns-go.log" + local log_content = fs.readfile(log_file) or "No Log." + luci.http.write(log_content) +end +function clear_log() + local fs = require "nixio.fs" + local log_file = "/var/log/ddns-go.log" + local f = io.open(log_file, "w") + if f then + f:close() + luci.http.status(204, "No Content") + else + luci.http.status(500, "Internal Server Error") + end +end diff --git a/luci-app-ddns-go/luasrc/model/cbi/ddns-go.lua b/luci-app-ddns-go/luasrc/model/cbi/ddns-go.lua index 8c8e29c14..37c417a7b 100644 --- a/luci-app-ddns-go/luasrc/model/cbi/ddns-go.lua +++ b/luci-app-ddns-go/luasrc/model/cbi/ddns-go.lua @@ -6,7 +6,7 @@ m = Map("ddns-go") m.title = translate("DDNS-GO") m.description = translate("DDNS-GO automatically obtains your public IPv4 or IPv6 address and resolves it to the corresponding domain name service.")..translate("
For specific usage, see:")..translate("GitHub @sirpdboy/luci-app-ddns-go ") -m:section(SimpleSection).template = "ddns-go_status" +m:section(SimpleSection).template = "ddns-go/ddns-go_status" s = m:section(TypedSection, "basic", translate("Global Settings")) s.addremove = false diff --git a/luci-app-ddns-go/luasrc/view/ddns-go.htm b/luci-app-ddns-go/luasrc/view/ddns-go/ddns-go.htm similarity index 100% rename from luci-app-ddns-go/luasrc/view/ddns-go.htm rename to luci-app-ddns-go/luasrc/view/ddns-go/ddns-go.htm diff --git a/luci-app-ddns-go/luasrc/view/ddns-go/ddns-go_log.htm b/luci-app-ddns-go/luasrc/view/ddns-go/ddns-go_log.htm new file mode 100644 index 000000000..62a27e211 --- /dev/null +++ b/luci-app-ddns-go/luasrc/view/ddns-go/ddns-go_log.htm @@ -0,0 +1,90 @@ +<%+header%> +
+ + +
+
+<%
+local fs = require "nixio.fs"
+local log_file_path = "/var/log/ddns-go.log"
+local raw_log_content = fs.readfile(log_file_path) or "No Log."
+local log_lines = {}
+for line in raw_log_content:gmatch("[^\r\n]+") do
+    table.insert(log_lines, line)
+end
+for i=1, math.floor(#log_lines / 2) do
+    log_lines[i], log_lines[#log_lines - i + 1] = log_lines[#log_lines - i + 1], log_lines[i]
+end
+local log_content = table.concat(log_lines, "\n")
+%>
+<%=log_content%>
+
+ <%+footer%> + + \ No newline at end of file diff --git a/luci-app-ddns-go/luasrc/view/ddns-go_status.htm b/luci-app-ddns-go/luasrc/view/ddns-go/ddns-go_status.htm similarity index 100% rename from luci-app-ddns-go/luasrc/view/ddns-go_status.htm rename to luci-app-ddns-go/luasrc/view/ddns-go/ddns-go_status.htm diff --git a/luci-app-ddns-go/po/zh-cn/ddns-go.po b/luci-app-ddns-go/po/zh-cn/ddns-go.po index b94df0125..74ac3fd3f 100644 --- a/luci-app-ddns-go/po/zh-cn/ddns-go.po +++ b/luci-app-ddns-go/po/zh-cn/ddns-go.po @@ -16,6 +16,9 @@ msgstr "运行状态" msgid "DDNS-GO Control panel" msgstr "DDNS-GO操作台" +msgid "Log" +msgstr "日志" + msgid "The DDNS-GO service is running." msgstr "DDNS-GO服务已启动" diff --git a/luci-app-ddns-go/po/zh_Hans/ddns-go.po b/luci-app-ddns-go/po/zh_Hans/ddns-go.po index b94df0125..74ac3fd3f 100644 --- a/luci-app-ddns-go/po/zh_Hans/ddns-go.po +++ b/luci-app-ddns-go/po/zh_Hans/ddns-go.po @@ -16,6 +16,9 @@ msgstr "运行状态" msgid "DDNS-GO Control panel" msgstr "DDNS-GO操作台" +msgid "Log" +msgstr "日志" + msgid "The DDNS-GO service is running." msgstr "DDNS-GO服务已启动"