From 2d20a52bb1d8864dde215f6652adba25a7890609 Mon Sep 17 00:00:00 2001 From: sbwml <984419930@qq.com> Date: Fri, 17 Feb 2023 17:01:20 +0800 Subject: [PATCH] add LuCI support for MentoHUST --- luci-app-mentohust/Makefile | 20 ++++ .../luasrc/controller/mentohust.lua | 20 ++++ .../luasrc/model/cbi/mentohust.lua | 91 ++++++++++++++++ .../view/mentohust/mentohust_status.htm | 23 ++++ luci-app-mentohust/po/zh_Hans/mentohust.po | 101 ++++++++++++++++++ luci-app-mentohust/root/etc/config/mentohust | 4 + luci-app-mentohust/root/etc/init.d/mentohust | 55 ++++++++++ .../root/etc/uci-defaults/luci-mentohust | 11 ++ .../share/rpcd/acl.d/luci-app-mentohust.json | 11 ++ 9 files changed, 336 insertions(+) create mode 100644 luci-app-mentohust/Makefile create mode 100644 luci-app-mentohust/luasrc/controller/mentohust.lua create mode 100644 luci-app-mentohust/luasrc/model/cbi/mentohust.lua create mode 100644 luci-app-mentohust/luasrc/view/mentohust/mentohust_status.htm create mode 100644 luci-app-mentohust/po/zh_Hans/mentohust.po create mode 100644 luci-app-mentohust/root/etc/config/mentohust create mode 100755 luci-app-mentohust/root/etc/init.d/mentohust create mode 100755 luci-app-mentohust/root/etc/uci-defaults/luci-mentohust create mode 100644 luci-app-mentohust/root/usr/share/rpcd/acl.d/luci-app-mentohust.json diff --git a/luci-app-mentohust/Makefile b/luci-app-mentohust/Makefile new file mode 100644 index 0000000..7a85084 --- /dev/null +++ b/luci-app-mentohust/Makefile @@ -0,0 +1,20 @@ +# Copyright (C) 2016 Openwrt.org +# +# This is free software, licensed under the Apache License, Version 2.0 . +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=luci-app-mentohust +PKG_VERSION:=1.0.0 +PKG_RELEASE:=1 + +LUCI_TITLE:=LuCI support for MentoHUST +LUCI_DEPENDS:=+mentohust +LUCI_PKGARCH:=all + +PKG_MAINTAINER:=sbwml + +include $(TOPDIR)/feeds/luci/luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/luci-app-mentohust/luasrc/controller/mentohust.lua b/luci-app-mentohust/luasrc/controller/mentohust.lua new file mode 100644 index 0000000..2c532ce --- /dev/null +++ b/luci-app-mentohust/luasrc/controller/mentohust.lua @@ -0,0 +1,20 @@ +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 new file mode 100644 index 0000000..241c02e --- /dev/null +++ b/luci-app-mentohust/luasrc/model/cbi/mentohust.lua @@ -0,0 +1,91 @@ +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" 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 new file mode 100644 index 0000000..ffd7390 --- /dev/null +++ b/luci-app-mentohust/luasrc/view/mentohust/mentohust_status.htm @@ -0,0 +1,23 @@ + + +
+

+ <%:Collecting data...%> +

+
diff --git a/luci-app-mentohust/po/zh_Hans/mentohust.po b/luci-app-mentohust/po/zh_Hans/mentohust.po new file mode 100644 index 0000000..d549c26 --- /dev/null +++ b/luci-app-mentohust/po/zh_Hans/mentohust.po @@ -0,0 +1,101 @@ +msgid "MentoHUST" +msgstr "锐捷认证" + +msgid "MentoHUST is a program that supports Ruijie authentication on Windows, Linux and Mac OS (with support for Searle authentication)." +msgstr "MentoHUST 是一个支持Windows、Linux、Mac OS下锐捷认证的程序(附带支持赛尔认证)" + +msgid "RUNNING" +msgstr "运行中" + +msgid "NOT RUNNING" +msgstr "未运行" + +msgid "Collecting data..." +msgstr "获取数据中..." + +msgid "Enable" +msgstr "启用" + +msgid "Username" +msgstr "用户名" + +msgid "Password" +msgstr "密码" + +msgid "Network interface" +msgstr "网络接口" + +msgid "IP address" +msgstr "IP 地址" + +msgid "Leave blank or set 0.0.0.0 to use local IP (DHCP)" +msgstr "留空或设置 0.0.0.0 则使用本机 IP(DHCP)" + +msgid "Gateway" +msgstr "网关" + +msgid "Subnet Mask" +msgstr "子网掩码" + +msgid "DNS" +msgstr "DNS" + +msgid "Ping Host" +msgstr "Ping 主机" + +msgid "Ping host for drop detection, 0.0.0.0 to turn off this feature." +msgstr "Ping 主机,用于掉线检测,0.0.0.0 表示禁用该功能" + +msgid "Authentication Timeout (Seconds)" +msgstr "认证超时(秒)" + +msgid "Response Interval (Seconds)" +msgstr "响应间隔(秒)" + +msgid "Await Failure(Seconds)" +msgstr "失败等待(秒)" + +msgid "Allow Failure Count" +msgstr "允许失败次数" + +msgid "Default 0, indicating no limit." +msgstr "默认 0,表示无限制" + +msgid "Multicast Address" +msgstr "组播地址" + +msgid "Standard" +msgstr "标准" + +msgid "Ruijie" +msgstr "锐捷" + +msgid "Searle" +msgstr "赛尔" + +msgid "DHCP Mode" +msgstr "DHCP 方式" + +msgid "None" +msgstr "不使用" + +msgid "Two-factor authentication" +msgstr "二次认证" + +msgid "After authentication" +msgstr "认证后" + +msgid "Before authentication" +msgstr "认证前" + +msgid "DHCP Script" +msgstr "DHCP 脚本" + +msgid "Default udhcpc -i" +msgstr "默认 udhcpc -i" + +msgid "Client Version Number" +msgstr "客户端版本号" + +msgid "Default 0.00,indicating compatibility with xrgsu" +msgstr "默认 0.00,表示兼容 xrgsu" diff --git a/luci-app-mentohust/root/etc/config/mentohust b/luci-app-mentohust/root/etc/config/mentohust new file mode 100644 index 0000000..00f7fe6 --- /dev/null +++ b/luci-app-mentohust/root/etc/config/mentohust @@ -0,0 +1,4 @@ + +config mentohust 'config' + option enable '0' + option interface '' diff --git a/luci-app-mentohust/root/etc/init.d/mentohust b/luci-app-mentohust/root/etc/init.d/mentohust new file mode 100755 index 0000000..af9ff94 --- /dev/null +++ b/luci-app-mentohust/root/etc/init.d/mentohust @@ -0,0 +1,55 @@ +#!/bin/sh /etc/rc.common + +START=99 +USE_PROCD=1 +PROG=/usr/sbin/mentohust + +get_config() { + config_load mentohust + config_get "enable" "config" "enable" "0" + config_get "username" "config" "username" + config_get "password" "config" "password" + config_get "interface" "config" "interface" + config_get "ipaddr" "config" "ipaddr" + config_get "gateway" "config" "gateway" "0.0.0.0" + config_get "mask" "config" "mask" "255.255.255.0" + config_get "dns" "config" "dns" "0.0.0.0" + config_get "ping" "config" "ping" "0.0.0.0" + config_get "timeout" "config" "timeout" "8" + config_get "interval" "config" "interval" "30" + config_get "wait" "config" "wait" "15" + config_get "fail_number" "config" "fail_number" "0" + config_get "multicast_address" "config" "multicast_address" "0" + config_get "dhcp_mode" "config" "dhcp_mode" "1" + config_get "dhcp_script" "config" "dhcp_script" + config_get "version" "config" "version" "0.00" +} + +start_service() { + get_config + [ "$enable" -ne "1" ] && return 1 + [ -n "$ipaddr" ] && IPADDR="-i$ipaddr" || IPADDR="" + [ -n "$dns" ] && DNS="-s$dns" || DNS="" + [ -n "$dhcp_script" ] && DHCP_SCRIPT="-c$dhcp_script" || DHCP_SCRIPT="" + procd_open_instance mentohust + procd_set_param command $PROG + procd_append_param command -u$username -p$password -n$interface $IPADDR -m$mask -g$gateway $DNS -o$ping -t$timeout -e$interval -r$wait -a$multicast_address -d$dhcp_mode -b0 -v$version $DHCP_SCRIPT + procd_set_param stdout 1 + procd_set_param stderr 1 + procd_set_param respawn + procd_close_instance mentohust +} + +service_triggers() { + procd_add_reload_trigger "mentohust" +} + +reload_service() { + stop + sleep 1 + start +} + +stop_service() { + pgrep -f /usr/sbin/mentohust | xargs kill -9 >/dev/null 2>&1 +} diff --git a/luci-app-mentohust/root/etc/uci-defaults/luci-mentohust b/luci-app-mentohust/root/etc/uci-defaults/luci-mentohust new file mode 100755 index 0000000..c85860c --- /dev/null +++ b/luci-app-mentohust/root/etc/uci-defaults/luci-mentohust @@ -0,0 +1,11 @@ +#!/bin/sh + +uci -q batch <<-EOF >/dev/null + delete ucitrack.@mentohust[-1] + add ucitrack mentohust + set ucitrack.@mentohust[-1].init=mentohust + commit ucitrack +EOF + +rm -rf /tmp/luci-indexcache* +exit 0 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 new file mode 100644 index 0000000..8c2d1cd --- /dev/null +++ b/luci-app-mentohust/root/usr/share/rpcd/acl.d/luci-app-mentohust.json @@ -0,0 +1,11 @@ +{ + "luci-app-mentohust": { + "description": "Grant UCI access for luci-app-mentohust", + "read": { + "uci": [ "mentohust" ] + }, + "write": { + "uci": [ "mentohust" ] + } + } +}