From d310a6cc2dcbf1223c45b7c0bf5064c11f0abc07 Mon Sep 17 00:00:00 2001 From: sbwml <984419930@qq.com> Date: Wed, 14 Sep 2022 21:26:57 +0800 Subject: [PATCH] luci-app-alist: Add password view --- luci-app-alist/luasrc/controller/alist.lua | 9 +++++++ .../luasrc/model/cbi/alist/basic.lua | 12 ++++----- .../luasrc/view/alist/admin_info.htm | 26 +++++++++++++++++++ luci-app-alist/po/zh-cn/alist.po | 21 ++++++++++----- 4 files changed, 55 insertions(+), 13 deletions(-) create mode 100644 luci-app-alist/luasrc/view/alist/admin_info.htm diff --git a/luci-app-alist/luasrc/controller/alist.lua b/luci-app-alist/luasrc/controller/alist.lua index bce25f9..28593a0 100644 --- a/luci-app-alist/luasrc/controller/alist.lua +++ b/luci-app-alist/luasrc/controller/alist.lua @@ -15,6 +15,7 @@ function index() 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 + entry({"admin", "nas", "alist", "admin_info"}, call("admin_info")).leaf = true end function alist_status() @@ -38,3 +39,11 @@ end function clear_log() luci.sys.call("cat /dev/null > $(uci -q get alist.@alist[0].temp_dir)/alist.log") end + +function admin_info() + local username = luci.sys.exec("/usr/bin/alist --conf /etc/alist/config.json password 2>&1 | tail -2 | awk 'NR==1 {print $2}'") + local password = luci.sys.exec("/usr/bin/alist --conf /etc/alist/config.json password 2>&1 | tail -2 | awk 'NR==2 {print $2}'") + + luci.http.prepare_content("application/json") + luci.http.write_json({username = username, password = password}) +end diff --git a/luci-app-alist/luasrc/model/cbi/alist/basic.lua b/luci-app-alist/luasrc/model/cbi/alist/basic.lua index 500d8b7..eaca6cc 100644 --- a/luci-app-alist/luasrc/model/cbi/alist/basic.lua +++ b/luci-app-alist/luasrc/model/cbi/alist/basic.lua @@ -1,12 +1,6 @@ local m, s ---local sys = require "luci.sys" ---if sys.call("pidof alist >/dev/null") == 0 then --- local password = sys.exec("/usr/bin/alist --conf /etc/alist/config.json password 2>&1 | tail -1 | awk -F': ' '{print $2}'") --- m = Map("alist", translate("Alist"), translate("A file list program that supports multiple storage.") .. " " .. translate("manage password:") .. "" .. password .. "" .. "
" .. [[]] .. translate("User Manual") .. [[]]) ---else - 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 = Map("alist", translate("Alist"), translate("A file list program that supports multiple storage.") .. "
" .. [[]] .. translate("User Manual") .. [[]]) m:section(SimpleSection).template = "alist/alist_status" @@ -44,4 +38,8 @@ o.datatype = "string" o.default = "/tmp/alist" o.rmempty = false +o = s:option(Button, "admin_info", translate("View Password")) +o.rawhtml = true +o.template = "alist/admin_info" + return m diff --git a/luci-app-alist/luasrc/view/alist/admin_info.htm b/luci-app-alist/luasrc/view/alist/admin_info.htm new file mode 100644 index 0000000..c593f28 --- /dev/null +++ b/luci-app-alist/luasrc/view/alist/admin_info.htm @@ -0,0 +1,26 @@ +<%+cbi/valueheader%> + + +<%=self.value%> +<%+cbi/valuefooter%> \ No newline at end of file diff --git a/luci-app-alist/po/zh-cn/alist.po b/luci-app-alist/po/zh-cn/alist.po index 319329e..2008c20 100644 --- a/luci-app-alist/po/zh-cn/alist.po +++ b/luci-app-alist/po/zh-cn/alist.po @@ -10,9 +10,6 @@ msgstr "打开 Web 界面" msgid "A file list program that supports multiple storage." msgstr "一款支持多种存储的目录文件列表程序。" -msgid "manage password:" -msgstr "管理密码:" - msgid "Basic Setting" msgstr "基本设置" @@ -55,11 +52,23 @@ msgstr "用户手册" msgid "Allow Access From Internet" msgstr "允许从外网访问" -msgid "Default username and password:" -msgstr "默认用户名和密码:" - msgid "Enable Logs" msgstr "启用日志" msgid "Clear logs" msgstr "清空日志" + +msgid "View Password" +msgstr "查看密码" + +msgid "Username:" +msgstr "用户名:" + +msgid "Password:" +msgstr "密码:" + +msgid "Reading..." +msgstr "读取中..." + +msgid "Read" +msgstr "读取"