mirror of
https://github.com/caiwx86/small-packages.git
synced 2026-07-28 01:11:21 +08:00
56 lines
1.7 KiB
Lua
56 lines
1.7 KiB
Lua
local sys = require "luci.sys"
|
|
local http = require "luci.http"
|
|
local nixio = require "nixio"
|
|
|
|
module("luci.controller.dae", package.seeall)
|
|
|
|
function index()
|
|
if not nixio.fs.access("/etc/config/dae") then
|
|
return
|
|
end
|
|
|
|
-- Main page
|
|
local page = entry({"admin", "services", "dae"}, firstchild(), _("DAE"), -1)
|
|
page.dependent = true
|
|
page.acl_depends = { "luci-app-dae" }
|
|
|
|
-- Status entry
|
|
entry({"admin", "services", "dae", "status"}, call("act_status")).leaf = true
|
|
|
|
-- Configuration pages
|
|
entry({"admin", "services", "dae", "global"}, cbi("dae/global"), _("Global Settings"), 1)
|
|
entry({"admin", "services", "dae", "dns"}, cbi("dae/dns"), _("DNS Settings"), 2)
|
|
entry({"admin", "services", "dae", "node"}, cbi("dae/node"), _("Node Settings"), 3)
|
|
entry({"admin", "services", "dae", "route"}, cbi("dae/route"), _("Routing Settings"), 4)
|
|
entry({"admin", "services", "dae", "log"}, cbi("dae/log"), _("Logs"), 5)
|
|
entry({"admin", "services", "dae", "get_log"}, call("get_log"))
|
|
entry({"admin", "services", "dae", "clear_log"}, call("clear_log"))
|
|
end
|
|
|
|
function act_status()
|
|
local sys = require "luci.sys"
|
|
local fs = require "nixio.fs"
|
|
local e = { }
|
|
local pid = sys.exec("pidof dae | cut -d' ' -f1"):gsub("\n", "")
|
|
e.running = (pid ~= "")
|
|
if e.running then
|
|
local status = fs.readfile("/proc/" .. pid .. "/status")
|
|
if status then
|
|
local rss = status:match("VmRSS:%s+(%d+)%s+kB")
|
|
if rss then
|
|
e.memory = string.format("%.1f MB", tonumber(rss) / 1024)
|
|
end
|
|
end
|
|
end
|
|
luci.http.prepare_content("application/json")
|
|
luci.http.write_json(e)
|
|
end
|
|
|
|
function get_log()
|
|
http.write(sys.exec("tail -n 1000 /var/log/dae/dae.log 2>/dev/null"))
|
|
end
|
|
|
|
function clear_log()
|
|
sys.call("true > /var/log/dae/dae.log")
|
|
end
|