luci-app-mentohust: convert to JS

Signed-off-by: sbwml <admin@cooluc.com>
This commit is contained in:
sbwml 2024-08-10 05:11:38 +08:00
parent 20c1a31c01
commit 6e008735b9
7 changed files with 156 additions and 139 deletions

View File

@ -6,7 +6,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-mentohust PKG_NAME:=luci-app-mentohust
PKG_VERSION:=1.0.0 PKG_VERSION:=1.0.1
PKG_RELEASE:=1 PKG_RELEASE:=1
LUCI_TITLE:=LuCI support for MentoHUST LUCI_TITLE:=LuCI support for MentoHUST

View File

@ -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 = '<em><span style="color:%s"><strong>%s %s</strong></span></em>';
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.00indicating compatibility with xrgsu'));
o.default = '0.00';
o.rmempty = false;
return m.render();
}
});

View File

@ -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

View File

@ -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.00indicating compatibility with xrgsu")
o.default = "0.00"
o.rmempty = false
return m

View File

@ -1,23 +0,0 @@
<script type="text/javascript">//<![CDATA[
XHR.poll(1, '<%=url([[admin]], [[services]], [[mentohust]], [[status]])%>', null,
function(x, data) {
var tb = document.getElementById('mentohust_status');
if (data && tb) {
if (data.running) {
var links = '<em style=\"color:green\"><b>MentoHUST <%:RUNNING%></b></em>';
tb.innerHTML = links;
} else {
tb.innerHTML = '<em style=\"color:red\"><b>MentoHUST <%:NOT RUNNING%></b></em>';
}
}
}
);
//]]>
</script>
<style>.mar-10 {margin-left: 50px; margin-right: 10px;}</style>
<fieldset class="cbi-section">
<p id="mentohust_status">
<em><%:Collecting data...%></em>
</p>
</fieldset>

View File

@ -0,0 +1,13 @@
{
"admin/services/mentohust": {
"title": "MentoHUST",
"action": {
"type": "view",
"path": "mentohust"
},
"depends": {
"acl": [ "luci-app-mentohust" ],
"uci": { "mentohust": true }
}
}
}

View File

@ -2,6 +2,9 @@
"luci-app-mentohust": { "luci-app-mentohust": {
"description": "Grant UCI access for luci-app-mentohust", "description": "Grant UCI access for luci-app-mentohust",
"read": { "read": {
"ubus": {
"service": [ "list" ]
},
"uci": [ "mentohust" ] "uci": [ "mentohust" ]
}, },
"write": { "write": {