mirror of
https://github.com/Dichgrem/luci-app-nyn.git
synced 2025-12-16 13:42:00 -05:00
style:format
This commit is contained in:
@@ -2,72 +2,71 @@
|
|||||||
module("luci.controller.zzz", package.seeall)
|
module("luci.controller.zzz", package.seeall)
|
||||||
|
|
||||||
function index()
|
function index()
|
||||||
if not nixio.fs.access("/etc/config/zzz") then
|
if not nixio.fs.access("/etc/config/zzz") then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Menu
|
-- Menu
|
||||||
entry({"admin", "network", "zzz"}, cbi("zzz"), "ZZZ", 60).dependent = false
|
entry({ "admin", "network", "zzz" }, cbi("zzz"), "ZZZ", 60).dependent = false
|
||||||
|
|
||||||
-- Settings
|
-- Settings
|
||||||
entry({"admin", "network", "zzz", "service_control"}, call("service_control")).leaf = true
|
entry({ "admin", "network", "zzz", "service_control" }, call("service_control")).leaf = true
|
||||||
|
|
||||||
-- Status API
|
-- Status API
|
||||||
entry({"admin", "network", "zzz", "get_status"}, call("act_status")).leaf = true
|
entry({ "admin", "network", "zzz", "get_status" }, call("act_status")).leaf = true
|
||||||
end
|
end
|
||||||
|
|
||||||
function service_control()
|
function service_control()
|
||||||
local sys = require "luci.sys"
|
local sys = require("luci.sys")
|
||||||
local action = luci.http.formvalue("action")
|
local action = luci.http.formvalue("action")
|
||||||
local result = { success = false, message = "" }
|
local result = { success = false, message = "" }
|
||||||
|
|
||||||
if action then
|
if action then
|
||||||
local cmd = ""
|
local cmd = ""
|
||||||
if action == "start" then
|
if action == "start" then
|
||||||
cmd = "/etc/rc.d/S99zzz start"
|
cmd = "/etc/rc.d/S99zzz start"
|
||||||
elseif action == "stop" then
|
elseif action == "stop" then
|
||||||
cmd = "/etc/rc.d/S99zzz stop"
|
cmd = "/etc/rc.d/S99zzz stop"
|
||||||
elseif action == "restart" then
|
elseif action == "restart" then
|
||||||
cmd = "/etc/rc.d/S99zzz stop && sleep 2 && /etc/rc.d/S99zzz start"
|
cmd = "/etc/rc.d/S99zzz stop && sleep 2 && /etc/rc.d/S99zzz start"
|
||||||
end
|
end
|
||||||
|
|
||||||
if cmd ~= "" then
|
if cmd ~= "" then
|
||||||
local ret = sys.call(cmd)
|
local ret = sys.call(cmd)
|
||||||
if ret == 0 then
|
if ret == 0 then
|
||||||
result.success = true
|
result.success = true
|
||||||
result.message = action .. " 成功"
|
result.message = action .. " 成功"
|
||||||
else
|
else
|
||||||
result.success = false
|
result.success = false
|
||||||
result.message = action .. " 失败"
|
result.message = action .. " 失败"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
luci.http.prepare_content("application/json")
|
luci.http.prepare_content("application/json")
|
||||||
luci.http.write_json(result)
|
luci.http.write_json(result)
|
||||||
end
|
end
|
||||||
|
|
||||||
function act_status()
|
function act_status()
|
||||||
local sys = require "luci.sys"
|
local sys = require("luci.sys")
|
||||||
local util = require "luci.util"
|
local util = require("luci.util")
|
||||||
local status = {}
|
local status = {}
|
||||||
|
|
||||||
-- Get status
|
-- Get status
|
||||||
status.running = (sys.call("pgrep -f zzz >/dev/null") == 0)
|
status.running = (sys.call("pgrep -f zzz >/dev/null") == 0)
|
||||||
|
|
||||||
-- Get process info
|
-- Get process info
|
||||||
if status.running then
|
if status.running then
|
||||||
status.process_info = util.trim(sys.exec("ps | grep -v grep | grep zzz"))
|
status.process_info = util.trim(sys.exec("ps | grep -v grep | grep zzz"))
|
||||||
end
|
end
|
||||||
|
-- Get log
|
||||||
|
local log_file = "/tmp/zzz.log"
|
||||||
|
if nixio.fs.access(log_file) then
|
||||||
|
status.log = util.trim(sys.exec("tail -20 " .. log_file))
|
||||||
|
else
|
||||||
|
status.log = util.trim(sys.exec("logread | grep zzz | tail -10"))
|
||||||
|
end
|
||||||
|
|
||||||
-- Get log
|
luci.http.prepare_content("application/json")
|
||||||
local log_file = "/tmp/zzz.log"
|
luci.http.write_json(status)
|
||||||
if nixio.fs.access(log_file) then
|
|
||||||
status.log = util.trim(sys.exec("tail -20 " .. log_file))
|
|
||||||
else
|
|
||||||
status.log = util.trim(sys.exec("logread | grep zzz | tail -10"))
|
|
||||||
end
|
|
||||||
|
|
||||||
luci.http.prepare_content("application/json")
|
|
||||||
luci.http.write_json(status)
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user