mirror of
https://github.com/Dichgrem/luci-app-nyn.git
synced 2025-12-17 22:22:00 -05:00
fix:stop_logic
This commit is contained in:
@@ -7,15 +7,46 @@ function index()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Menu
|
-- Menu
|
||||||
entry({"admin", "network", "nyn"}, firstchild(), _("NyN-Client"), 60).dependent = false
|
entry({"admin", "network", "nyn"}, cbi("nyn"), "NyN", 60).dependent = false
|
||||||
|
|
||||||
-- Settings
|
-- 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
|
-- Status API
|
||||||
entry({"admin", "network", "nyn", "get_status"}, call("act_status")).leaf = true
|
entry({"admin", "network", "nyn", "get_status"}, call("act_status")).leaf = true
|
||||||
end
|
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()
|
function act_status()
|
||||||
local sys = require "luci.sys"
|
local sys = require "luci.sys"
|
||||||
local util = require "luci.util"
|
local util = require "luci.util"
|
||||||
@@ -40,5 +71,3 @@ function act_status()
|
|||||||
luci.http.prepare_content("application/json")
|
luci.http.prepare_content("application/json")
|
||||||
luci.http.write_json(status)
|
luci.http.write_json(status)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,19 @@
|
|||||||
local m, s, o
|
local m, s, o
|
||||||
local sys = require "luci.sys"
|
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 认证客户端",
|
m = Map("nyn", "NYN 802.1x 认证客户端",
|
||||||
"配置使用 NYN 客户端进行网络访问的 802.1x 认证")
|
"配置使用 NYN 客户端进行网络访问的 802.1x 认证")
|
||||||
|
|
||||||
@@ -23,9 +36,21 @@ o.cfgvalue = function()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Enable/Disable
|
-- control buttons
|
||||||
o = s:option(Flag, "enabled", "启用服务")
|
control_buttons = s:option(DummyValue, "_control", "服务控制")
|
||||||
o.rmempty = false
|
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
|
-- Username
|
||||||
o = s:option(Value, "user", "用户名", "802.1x 认证用户名")
|
o = s:option(Value, "user", "用户名", "802.1x 认证用户名")
|
||||||
|
|||||||
BIN
screenshot.png
BIN
screenshot.png
Binary file not shown.
|
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 82 KiB |
Reference in New Issue
Block a user