diff --git a/luci-app-mentohust/Makefile b/luci-app-mentohust/Makefile index 7a85084..a42c48a 100644 --- a/luci-app-mentohust/Makefile +++ b/luci-app-mentohust/Makefile @@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-mentohust -PKG_VERSION:=1.0.0 +PKG_VERSION:=1.0.1 PKG_RELEASE:=1 LUCI_TITLE:=LuCI support for MentoHUST diff --git a/luci-app-mentohust/htdocs/luci-static/resources/view/mentohust.js b/luci-app-mentohust/htdocs/luci-static/resources/view/mentohust.js new file mode 100644 index 0000000..16c1b3c --- /dev/null +++ b/luci-app-mentohust/htdocs/luci-static/resources/view/mentohust.js @@ -0,0 +1,139 @@ +'use strict'; +'require form'; +'require poll'; +'require rpc'; +'require tools.widgets as widgets'; +'require uci'; +'require view'; + +var callServiceList = rpc.declare({ + object: 'service', + method: 'list', + params: ['name'], + expect: { '': {} } +}); + +function getServiceStatus() { + return L.resolveDefault(callServiceList('mentohust'), {}).then(function (res) { + var isRunning = false; + try { + isRunning = res['mentohust']['instances']['mentohust']['running']; + } catch (e) { } + return isRunning; + }); +} + +function renderStatus(isRunning) { + var spanTemp = '%s %s'; + var renderHTML; + if (isRunning) { + renderHTML = spanTemp.format('green', 'MentoHUST', _('RUNNING')); + } else { + renderHTML = spanTemp.format('red', 'MentoHUST', _('NOT RUNNING')); + } + + return renderHTML; +} + +return view.extend({ + render: function() { + var m, s, o; + + m = new form.Map('mentohust', _('MentoHUST'), + _('MentoHUST is a program that supports Ruijie authentication on Windows, Linux and Mac OS (with support for Searle authentication).')); + + s = m.section(form.TypedSection); + s.anonymous = true; + s.render = function () { + poll.add(function () { + return L.resolveDefault(getServiceStatus()).then(function (res) { + var view = document.getElementById('service_status'); + view.innerHTML = renderStatus(res); + }); + }); + + return E('div', { class: 'cbi-section', id: 'status_bar' }, [ + E('p', { id: 'service_status' }, _('Collecting data...')) + ]); + } + + s = m.section(form.NamedSection, 'config', 'mentohust'); + + o = s.option(form.Flag, 'enable', _('Enable')); + o.rmempty = false; + + o = s.option(form.Value, 'username', _('Username')); + o.rmempty = true; + + o = s.option(form.Value, 'password', _('Password')); + o.rmempty = true; + + o = s.option(widgets.DeviceSelect, 'interface', + _('Network interface')); + o.rmempty = false; + + o = s.option(form.Value, 'ipaddr', _('IP address'), + _('Leave blank or set 0.0.0.0 to use local IP (DHCP)')); + o.default = '0.0.0.0'; + o.rmempty = true; + + o = s.option(form.Value, 'gateway', _('Gateway')); + o.default = '0.0.0.0'; + o.rmempty = false; + + o = s.option(form.Value, 'mask', _('Subnet Mask')); + o.default = '255.255.255.0'; + o.rmempty = false; + + o = s.option(form.Value, 'dns', _('DNS')); + o.default = '0.0.0.0'; + o.rmempty = true; + + o = s.option(form.Value, 'ping', _('Ping Host'), + _('Ping host for drop detection, 0.0.0.0 to turn off this feature.')); + o.default = '0.0.0.0'; + o.rmempty = false; + + o = s.option(form.Value, 'timeout', _('Authentication Timeout (Seconds)')); + o.default = '8'; + o.rmempty = false; + + o = s.option(form.Value, 'interval', _('Response Interval (Seconds)')); + o.default = '30'; + o.rmempty = false; + + o = s.option(form.Value, 'wait', _('Await Failure(Seconds)')); + o.default = '15'; + o.rmempty = false; + + o = s.option(form.Value, 'fail_number', _('Allow Failure Count'), + _('Default 0, indicating no limit.')); + o.default = '0'; + o.rmempty = false; + + o = s.option(form.ListValue, 'multicast_address', _('Multicast Address')); + o.default = '1'; + o.value('0', _('Standard')); + o.value('1', _('Ruijie')); + o.value('2', _('Searle')); + + o = s.option(form.ListValue, 'dhcp_mode', _('DHCP Mode')); + o.default = '1'; + o.value('0', _('None')); + o.value('1', _('Two-factor authentication')); + o.value('2', _('After authentication')); + o.value('3', _('Before authentication')); + + o = s.option(form.Value, 'dhcp_script', _('DHCP Script'), + _('Default udhcpc -i')); + o.default = 'udhcpc -i'; + o.rmempty = true; + + o = s.option(form.Value, 'version', _('Client Version Number'), + _('Default 0.00,indicating compatibility with xrgsu')); + o.default = '0.00'; + o.rmempty = false; + + return m.render(); + } +}); diff --git a/luci-app-mentohust/luasrc/controller/mentohust.lua b/luci-app-mentohust/luasrc/controller/mentohust.lua deleted file mode 100644 index 2c532ce..0000000 --- a/luci-app-mentohust/luasrc/controller/mentohust.lua +++ /dev/null @@ -1,20 +0,0 @@ -module("luci.controller.mentohust", package.seeall) - -function index() - if not nixio.fs.access("/etc/config/mentohust") then - return - end - - local page = entry({"admin", "services", "mentohust"}, cbi("mentohust"), _("MentoHUST")) - page.dependent = true - page.acl_depends = { "luci-app-mentohust" } - - entry({"admin", "services", "mentohust", "status"}, call("act_status")).leaf = true -end - -function act_status() - local e = {} - e.running = luci.sys.call("pgrep mentohust >/dev/null") == 0 - luci.http.prepare_content("application/json") - luci.http.write_json(e) -end diff --git a/luci-app-mentohust/luasrc/model/cbi/mentohust.lua b/luci-app-mentohust/luasrc/model/cbi/mentohust.lua deleted file mode 100644 index fba52a8..0000000 --- a/luci-app-mentohust/luasrc/model/cbi/mentohust.lua +++ /dev/null @@ -1,95 +0,0 @@ -local i = require "luci.sys" -local m, e - -m = Map("mentohust", translate("MentoHUST")) -m.description = translate("MentoHUST is a program that supports Ruijie authentication on Windows, Linux and Mac OS (with support for Searle authentication).") - -m:section(SimpleSection).template = "mentohust/mentohust_status" - -e = m:section(TypedSection, "mentohust") -e.addremove = false -e.anonymous = true - -o = e:option(Flag, "enable", translate("Enable")) -o.rmempty = false - -o = e:option(Value, "username", translate("Username")) -o.datatype = "string" -o.rmempty = true - -o = e:option(Value, "password", translate("Password")) -o.datatype = "string" -o.password = true -o.rmempty = true - -o = e:option(Value, "interface", translate("Network interface")) -for t, e in ipairs(i.net.devices()) do - if e ~= 'lo' and not string.match(e, '^docker.*$') and not string.match(e, '^sit.*$') and not string.match(e, '^dummy.*$') and not string.match(e, '^teql.*$') and not string.match(e, '^veth.*$') and not string.match(e, '^ztly.*$') then - o:value(e) - end -end -o.rmempty = false - -o = e:option(Value, "ipaddr", translate("IP address")) -o.description = translate("Leave blank or set 0.0.0.0 to use local IP (DHCP)") -o.default = "0.0.0.0" -o.rmempty = true - -o = e:option(Value, "gateway", translate("Gateway")) -o.default = "0.0.0.0" -o.rmempty = false - -o = e:option(Value, "mask", translate("Subnet Mask")) -o.default = "255.255.255.0" -o.rmempty = false - -o = e:option(Value, "dns", translate("DNS")) -o.default = "0.0.0.0" -o.rmempty = true - -o = e:option(Value, "ping", translate("Ping Host")) -o.description = translate("Ping host for drop detection, 0.0.0.0 to turn off this feature.") -o.default = "0.0.0.0" -o.rmempty = false - -o = e:option(Value, "timeout", translate("Authentication Timeout (Seconds)")) -o.default = "8" -o.rmempty = false - -o = e:option(Value, "interval", translate("Response Interval (Seconds)")) -o.default = "30" -o.rmempty = false - -o = e:option(Value, "wait", translate("Await Failure(Seconds)")) -o.default = "15" -o.rmempty = false - -o = e:option(Value, "fail_number", translate("Allow Failure Count")) -o.description = translate("Default 0, indicating no limit.") -o.default = "0" -o.rmempty = false - -o = e:option(ListValue, "multicast_address", translate("Multicast Address")) -o.default = "1" -o:value("0", translate("Standard")) -o:value("1", translate("Ruijie")) -o:value("2", translate("Searle")) - -o = e:option(ListValue, "dhcp_mode", translate("DHCP Mode")) -o.default = "1" -o:value("0", translate("None")) -o:value("1", translate("Two-factor authentication")) -o:value("2", translate("After authentication")) -o:value("3", translate("Before authentication")) - -o = e:option(Value, "dhcp_script", translate("DHCP Script")) -o.description = translate("Default udhcpc -i") -o.default = "udhcpc -i" -o.rmempty = true - -o = e:option(Value, "version", translate("Client Version Number")) -o.description = translate("Default 0.00,indicating compatibility with xrgsu") -o.default = "0.00" -o.rmempty = false - -return m diff --git a/luci-app-mentohust/luasrc/view/mentohust/mentohust_status.htm b/luci-app-mentohust/luasrc/view/mentohust/mentohust_status.htm deleted file mode 100644 index ffd7390..0000000 --- a/luci-app-mentohust/luasrc/view/mentohust/mentohust_status.htm +++ /dev/null @@ -1,23 +0,0 @@ - - -
-

- <%:Collecting data...%> -

-
diff --git a/luci-app-mentohust/root/usr/share/luci/menu.d/luci-app-mentohust.json b/luci-app-mentohust/root/usr/share/luci/menu.d/luci-app-mentohust.json new file mode 100644 index 0000000..9c34e0b --- /dev/null +++ b/luci-app-mentohust/root/usr/share/luci/menu.d/luci-app-mentohust.json @@ -0,0 +1,13 @@ +{ + "admin/services/mentohust": { + "title": "MentoHUST", + "action": { + "type": "view", + "path": "mentohust" + }, + "depends": { + "acl": [ "luci-app-mentohust" ], + "uci": { "mentohust": true } + } + } +} diff --git a/luci-app-mentohust/root/usr/share/rpcd/acl.d/luci-app-mentohust.json b/luci-app-mentohust/root/usr/share/rpcd/acl.d/luci-app-mentohust.json index 8c2d1cd..e104e49 100644 --- a/luci-app-mentohust/root/usr/share/rpcd/acl.d/luci-app-mentohust.json +++ b/luci-app-mentohust/root/usr/share/rpcd/acl.d/luci-app-mentohust.json @@ -2,6 +2,9 @@ "luci-app-mentohust": { "description": "Grant UCI access for luci-app-mentohust", "read": { + "ubus": { + "service": [ "list" ] + }, "uci": [ "mentohust" ] }, "write": {