diff --git a/openwrt/files/luci/controller/ua3f.lua b/openwrt/files/luci/controller/ua3f.lua index a6db873..f9dfb58 100644 --- a/openwrt/files/luci/controller/ua3f.lua +++ b/openwrt/files/luci/controller/ua3f.lua @@ -2,6 +2,7 @@ module("luci.controller.ua3f", package.seeall) function index() entry({ "admin", "services", "ua3f" }, cbi("ua3f"), _("UA3F"), 1) + entry({ "admin", "services", "ua3f", "status" }, call("get_status")).leaf = true entry({ "admin", "services", "ua3f", "download_log" }, call("action_download_log")).leaf = true entry({ "admin", "services", "ua3f", "clear_log" }, call("clear_log")).leaf = true entry({ "admin", "services", "ua3f", "get_rules" }, call("get_rules")).leaf = true @@ -10,6 +11,22 @@ end local fs = require("nixio.fs") +function get_status() + local http = require("luci.http") + local sys = require("luci.sys") + local json = require("luci.jsonc") + + http.prepare_content("application/json") + + local pid = sys.exec("pidof ua3f") + local running = (pid ~= nil and pid ~= "") + + http.write(json.stringify({ + running = running, + pid = running and pid:gsub("%s+", "") or nil + })) +end + function create_log_archive() local tmpfile = "/tmp/ua3f_logs.tar.gz" local copyCfg = "cp /etc/config/ua3f /var/log/ua3f/config >/dev/null 2>&1" diff --git a/openwrt/files/luci/model/cbi/ua3f/status.lua b/openwrt/files/luci/model/cbi/ua3f/status.lua index ceb3701..f72b190 100644 --- a/openwrt/files/luci/model/cbi/ua3f/status.lua +++ b/openwrt/files/luci/model/cbi/ua3f/status.lua @@ -2,7 +2,6 @@ local M = {} local cbi = require("luci.cbi") local i18n = require("luci.i18n") -local sys = require("luci.sys") local translate = i18n.translate local Flag = cbi.Flag @@ -14,17 +13,7 @@ function M.add_status_fields(section) -- Running Status Display local running = section:option(DummyValue, "running", translate("Status")) - running.rawhtml = true - running.cfgvalue = function(self, section) - local pid = sys.exec("pidof ua3f") - if pid == "" then - return "" - else - return "" - end - end + running.template = "ua3f/status" end return M diff --git a/openwrt/files/luci/view/ua3f/status.htm b/openwrt/files/luci/view/ua3f/status.htm new file mode 100644 index 0000000..d278259 --- /dev/null +++ b/openwrt/files/luci/view/ua3f/status.htm @@ -0,0 +1,58 @@ +