small-package/luci-app-mosdns/luasrc/controller/mosdns.lua

35 lines
1.3 KiB
Lua
Raw Normal View History

2022-04-21 17:19:22 +08:00
module("luci.controller.mosdns", package.seeall)
function index()
if not nixio.fs.access("/etc/config/mosdns") then
return
end
local page = entry({"admin", "services", "mosdns"}, alias("admin", "services", "mosdns", "basic"), _("MosDNS"), 30)
page.dependent = true
page.acl_depends = { "luci-app-mosdns" }
entry({"admin", "services", "mosdns", "basic"}, cbi("mosdns/basic"), _("Basic Setting"), 1).leaf = true
2022-05-12 21:23:11 +08:00
entry({"admin", "services", "mosdns", "rule_list"}, cbi("mosdns/rule_list"), _("Rule List"), 2).leaf = true
entry({"admin", "services", "mosdns", "update"}, cbi("mosdns/update"), _("Geodata Update"), 3).leaf = true
entry({"admin", "services", "mosdns", "log"}, cbi("mosdns/log"), _("Logs"), 4).leaf = true
2022-04-21 17:19:22 +08:00
entry({"admin", "services", "mosdns", "status"}, call("act_status")).leaf = true
2022-05-12 21:23:11 +08:00
entry({"admin", "services", "mosdns", "get_log"}, call("get_log")).leaf = true
entry({"admin", "services", "mosdns", "clear_log"}, call("clear_log")).leaf = true
2022-04-21 17:19:22 +08:00
end
function act_status()
local e = {}
e.running = luci.sys.call("pgrep -f mosdns >/dev/null") == 0
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end
2022-05-12 21:23:11 +08:00
function get_log()
2022-10-02 23:46:41 +08:00
luci.http.write(luci.sys.exec("cat $(/etc/mosdns/library.sh logfile)"))
2022-05-12 21:23:11 +08:00
end
function clear_log()
2022-10-02 23:46:41 +08:00
luci.sys.call("cat /dev/null > $(/etc/mosdns/library.sh logfile)")
2022-05-12 21:23:11 +08:00
end