mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-03 16:23:56 +08:00
💋 Sync 2026-10-04 04:16:09
This commit is contained in:
1 parent
f6b2df73ec
commit
f62992fd80
745 files changed
+212416
-1173
No files matched your search
@@ -1,6 +1,78 @@
|
||||
-- luci-app-hermes — LuCI Controller (18.06 compat)
|
||||
module("luci.controller.hermes", package.seeall)
|
||||
|
||||
function index()
|
||||
entry({"admin", "services", "hermes"}, alias("admin", "services", "hermes", "config"), _("Hermes"), 30).dependent = true
|
||||
entry({"admin", "services", "hermes", "config"}, cbi("hermes"))
|
||||
-- luci 24.10+ uses menu.d JSON for registration; skip Lua menu
|
||||
if nixio.fs.access("/usr/share/luci/menu.d/luci-app-hermes.json") then
|
||||
return
|
||||
end
|
||||
|
||||
local page = entry({"admin", "services", "hermes"},
|
||||
alias("admin", "services", "hermes", "basic"), _("Hermes Agent"), 90)
|
||||
page.dependent = false
|
||||
|
||||
entry({"admin", "services", "hermes", "basic"},
|
||||
cbi("hermes"), _("Basic Settings"), 10).leaf = true
|
||||
entry({"admin", "services", "hermes", "console"},
|
||||
template("hermes/console"), _("Web Console"), 20).leaf = true
|
||||
entry({"admin", "services", "hermes", "terminal"},
|
||||
template("hermes/terminal"), _("Config Terminal"), 30).leaf = true
|
||||
|
||||
-- API endpoints (used by status.htm XHR)
|
||||
entry({"admin", "services", "hermes", "status_api"},
|
||||
call("action_status"), nil).leaf = true
|
||||
entry({"admin", "services", "hermes", "service_ctl"},
|
||||
call("action_service_ctl"), nil).leaf = true
|
||||
entry({"admin", "services", "hermes", "get_token"},
|
||||
call("action_get_token"), nil).leaf = true
|
||||
end
|
||||
|
||||
-- ── Status API ──
|
||||
function action_status()
|
||||
local http = require "luci.http"
|
||||
local sys = require "luci.sys"
|
||||
|
||||
local raw = sys.exec("/usr/share/hermes/luci-helper status 2>/dev/null")
|
||||
http.prepare_content("application/json")
|
||||
http.write(raw ~= "" and raw or '{}')
|
||||
end
|
||||
|
||||
-- ── Service Control API ──
|
||||
function action_service_ctl()
|
||||
local http = require "luci.http"
|
||||
local sys = require "luci.sys"
|
||||
|
||||
local action = http.formvalue("action") or ""
|
||||
local allowed = { start = true, stop = true, restart = true, enable = true, disable = true }
|
||||
|
||||
if not allowed[action] then
|
||||
http.prepare_content("application/json")
|
||||
http.write_json({ status = "error", message = "invalid action" })
|
||||
return
|
||||
end
|
||||
|
||||
if action == "stop" then
|
||||
sys.exec("/etc/init.d/hermes stop >/dev/null 2>&1")
|
||||
elseif action == "restart" then
|
||||
sys.exec("/etc/init.d/hermes stop >/dev/null 2>&1")
|
||||
sys.exec("sleep 2")
|
||||
sys.exec("/etc/init.d/hermes start >/dev/null 2>&1 &")
|
||||
else
|
||||
sys.exec("/etc/init.d/hermes " .. action .. " >/dev/null 2>&1 &")
|
||||
end
|
||||
|
||||
http.prepare_content("application/json")
|
||||
http.write_json({ status = "ok", action = action })
|
||||
end
|
||||
|
||||
-- ── Get Token API ──
|
||||
function action_get_token()
|
||||
local http = require "luci.http"
|
||||
local uci = require "luci.model.uci".cursor()
|
||||
|
||||
http.prepare_content("application/json")
|
||||
http.write_json({
|
||||
token = uci:get("hermes", "main", "token") or "",
|
||||
pty_token = uci:get("hermes", "main", "pty_token") or ""
|
||||
})
|
||||
end
|
||||
Reference in new issue
Block a user