diff --git a/luci-app-nyn/luasrc/controller/nyn.lua b/luci-app-nyn/luasrc/controller/nyn.lua index 5cfa638..9b38854 100644 --- a/luci-app-nyn/luasrc/controller/nyn.lua +++ b/luci-app-nyn/luasrc/controller/nyn.lua @@ -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 - - diff --git a/luci-app-nyn/luasrc/model/cbi/nyn.lua b/luci-app-nyn/luasrc/model/cbi/nyn.lua index 46f12be..04ab8ea 100644 --- a/luci-app-nyn/luasrc/model/cbi/nyn.lua +++ b/luci-app-nyn/luasrc/model/cbi/nyn.lua @@ -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 [[ +
+ + + +
+ ]] +end -- Username o = s:option(Value, "user", "用户名", "802.1x 认证用户名") diff --git a/screenshot.png b/screenshot.png index 487f447..2e85be7 100644 Binary files a/screenshot.png and b/screenshot.png differ