From 641a8a91dc986af20be8bc637ac5a49db426a8d3 Mon Sep 17 00:00:00 2001
From: sbwml <984419930@qq.com>
Date: Mon, 12 Sep 2022 11:01:02 +0800
Subject: [PATCH] luci-app-alist: Add log preview support
---
luci-app-alist/luasrc/controller/alist.lua | 19 ++++++++++--
.../luasrc/model/cbi/{alist.lua => basic.lua} | 8 +++--
luci-app-alist/luasrc/model/cbi/log.lua | 5 ++++
luci-app-alist/luasrc/view/alist_log.htm | 29 +++++++++++++++++++
luci-app-alist/luasrc/view/alist_status.htm | 6 ++--
luci-app-alist/po/zh-cn/alist.po | 23 +++++++++------
luci-app-alist/root/etc/init.d/alist | 8 ++++-
7 files changed, 81 insertions(+), 17 deletions(-)
rename luci-app-alist/luasrc/model/cbi/{alist.lua => basic.lua} (90%)
create mode 100644 luci-app-alist/luasrc/model/cbi/log.lua
create mode 100644 luci-app-alist/luasrc/view/alist_log.htm
diff --git a/luci-app-alist/luasrc/controller/alist.lua b/luci-app-alist/luasrc/controller/alist.lua
index 1bb6640..bce25f9 100644
--- a/luci-app-alist/luasrc/controller/alist.lua
+++ b/luci-app-alist/luasrc/controller/alist.lua
@@ -5,9 +5,16 @@ function index()
return
end
+ local page = entry({"admin", "nas", "alist"}, alias("admin", "nas", "alist", "basic"), _("Alist"), 20)
+ page.dependent = true
+ page.acl_depends = { "luci-app-alist" }
+
entry({"admin", "nas"}, firstchild(), "NAS", 44).dependent = false
- entry({"admin", "nas", "alist"}, cbi("alist"), _("Alist"), 20).dependent = true
- entry({"admin", "nas", "alist_status"}, call("alist_status"))
+ entry({"admin", "nas", "alist", "basic"}, cbi("alist/basic"), _("Basic Setting"), 1).leaf = true
+ entry({"admin", "nas", "alist", "log"}, cbi("alist/log"), _("Logs"), 2).leaf = true
+ entry({"admin", "nas", "alist", "alist_status"}, call("alist_status")).leaf = true
+ entry({"admin", "nas", "alist", "get_log"}, call("get_log")).leaf = true
+ entry({"admin", "nas", "alist", "clear_log"}, call("clear_log")).leaf = true
end
function alist_status()
@@ -23,3 +30,11 @@ function alist_status()
luci.http.prepare_content("application/json")
luci.http.write_json(status)
end
+
+function get_log()
+ luci.http.write(luci.sys.exec("cat $(uci -q get alist.@alist[0].temp_dir)/alist.log"))
+end
+
+function clear_log()
+ luci.sys.call("cat /dev/null > $(uci -q get alist.@alist[0].temp_dir)/alist.log")
+end
diff --git a/luci-app-alist/luasrc/model/cbi/alist.lua b/luci-app-alist/luasrc/model/cbi/basic.lua
similarity index 90%
rename from luci-app-alist/luasrc/model/cbi/alist.lua
rename to luci-app-alist/luasrc/model/cbi/basic.lua
index 59bb815..500d8b7 100644
--- a/luci-app-alist/luasrc/model/cbi/alist.lua
+++ b/luci-app-alist/luasrc/model/cbi/basic.lua
@@ -8,9 +8,9 @@ local m, s
m = Map("alist", translate("Alist"), translate("A file list program that supports multiple storage.") .. translate("Default username and password:") .. "admin / admin" .. "
" .. [[]] .. translate("User Manual") .. [[]])
--end
-m:section(SimpleSection).template = "alist_status"
+m:section(SimpleSection).template = "alist/alist_status"
-s = m:section(TypedSection, "alist", translate("Global settings"))
+s = m:section(TypedSection, "alist")
s.addremove = false
s.anonymous = true
@@ -21,6 +21,10 @@ o = s:option(Value, "port", translate("Port"))
o.datatype = "and(port,min(1))"
o.rmempty = false
+o = s:option(Flag, "log", translate("Enable Logs"))
+o.default = 1
+o.rmempty = false
+
o = s:option(Flag, "ssl", translate("Enable SSL"))
o.rmempty=false
diff --git a/luci-app-alist/luasrc/model/cbi/log.lua b/luci-app-alist/luasrc/model/cbi/log.lua
new file mode 100644
index 0000000..4b6c36f
--- /dev/null
+++ b/luci-app-alist/luasrc/model/cbi/log.lua
@@ -0,0 +1,5 @@
+m = Map("alist")
+
+m:append(Template("alist/alist_log"))
+
+return m
diff --git a/luci-app-alist/luasrc/view/alist_log.htm b/luci-app-alist/luasrc/view/alist_log.htm
new file mode 100644
index 0000000..b77932e
--- /dev/null
+++ b/luci-app-alist/luasrc/view/alist_log.htm
@@ -0,0 +1,29 @@
+
+