fix:stop_logic

This commit is contained in:
dichgrem
2025-09-18 09:51:20 +08:00
parent ac3cf9ba14
commit af7580f556
3 changed files with 61 additions and 7 deletions

View File

@@ -7,15 +7,46 @@ function index()
end
-- Menu
entry({"admin", "network", "nyn"}, firstchild(), _("NyN-Client"), 60).dependent = false
entry({"admin", "network", "nyn"}, cbi("nyn"), "NyN", 60).dependent = false
-- Settings
entry({"admin", "network", "nyn", "config"}, cbi("nyn"), _("Settings"), 1).leaf = true
entry({"admin", "network", "nyn", "service_control"}, call("service_control")).leaf = true
-- Status API
entry({"admin", "network", "nyn", "get_status"}, call("act_status")).leaf = true
end
function service_control()
local sys = require "luci.sys"
local action = luci.http.formvalue("action")
local result = { success = false, message = "" }
if action then
local cmd = ""
if action == "start" then
cmd = "/etc/rc.d/S99nyn start"
elseif action == "stop" then
cmd = "/etc/rc.d/S99nyn stop"
elseif action == "restart" then
cmd = "/etc/rc.d/S99nyn stop && sleep 2 && /etc/rc.d/S99nyn start"
end
if cmd ~= "" then
local ret = sys.call(cmd)
if ret == 0 then
result.success = true
result.message = action .. " 成功"
else
result.success = false
result.message = action .. " 失败"
end
end
end
luci.http.prepare_content("application/json")
luci.http.write_json(result)
end
function act_status()
local sys = require "luci.sys"
local util = require "luci.util"
@@ -40,5 +71,3 @@ function act_status()
luci.http.prepare_content("application/json")
luci.http.write_json(status)
end

View File

@@ -2,6 +2,19 @@
local m, s, o
local sys = require "luci.sys"
-- control
local start_action = luci.http.formvalue("cbid.nyn.auth.start_service")
local stop_action = luci.http.formvalue("cbid.nyn.auth.stop_service")
local restart_action = luci.http.formvalue("cbid.nyn.auth.restart_service")
if start_action then
sys.call("/etc/rc.d/S99nyn start")
elseif stop_action then
sys.call("/etc/rc.d/S99nyn stop")
elseif restart_action then
sys.call("/etc/rc.d/S99nyn stop; sleep 2; /etc/rc.d/S99nyn start")
end
m = Map("nyn", "NYN 802.1x 认证客户端",
"配置使用 NYN 客户端进行网络访问的 802.1x 认证")
@@ -23,9 +36,21 @@ o.cfgvalue = function()
end
end
-- Enable/Disable
o = s:option(Flag, "enabled", "启用服务")
o.rmempty = false
-- control buttons
control_buttons = s:option(DummyValue, "_control", "服务控制")
control_buttons.rawhtml = true
control_buttons.cfgvalue = function()
return [[
<div style="display: flex; gap: 10px; align-items: center; flex-wrap: wrap;">
<input type="submit" class="cbi-button cbi-button-apply"
name="cbid.nyn.auth.start_service" value="启动服务" />
<input type="submit" class="cbi-button cbi-button-remove"
name="cbid.nyn.auth.stop_service" value="停止服务" />
<input type="submit" class="cbi-button cbi-button-reload"
name="cbid.nyn.auth.restart_service" value="重启服务" />
</div>
]]
end
-- Username
o = s:option(Value, "user", "用户名", "802.1x 认证用户名")

Binary file not shown.

Before

Width:  |  Height:  |  Size: 74 KiB

After

Width:  |  Height:  |  Size: 82 KiB