luci-app-nps: tidy up luci (#8218)

This commit is contained in:
Beginner 2021-11-14 23:21:23 +08:00 committed by GitHub
parent 2e5f50cde9
commit e3373ca72e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 66 additions and 53 deletions

View File

@ -10,7 +10,7 @@ LUCI_TITLE:=LuCI for Nps
LUCI_DEPENDS:=+wget +npc LUCI_DEPENDS:=+wget +npc
LUCI_PKGARCH:=all LUCI_PKGARCH:=all
PKG_VERSION:=1.1 PKG_VERSION:=1.1
PKG_RELEASE:=4 PKG_RELEASE:=5
include $(TOPDIR)/feeds/luci/luci.mk include $(TOPDIR)/feeds/luci/luci.mk

11
package/lean/luci-app-nps/luasrc/controller/nps.lua Executable file → Normal file
View File

@ -1,16 +1,17 @@
module("luci.controller.nps",package.seeall) module("luci.controller.nps",package.seeall)
function index() function index()
if not nixio.fs.access("/etc/config/nps") then if not nixio.fs.access("/etc/config/nps") then
return return
end end
entry({"admin", "services", "nps"}, cbi("nps"), _("Nps Setting"), 100).dependent = true entry({"admin", "services", "nps"}, cbi("nps"), _("Nps"), 100).dependent = true
entry({"admin", "services", "nps", "status"}, call("status")).leaf = true entry({"admin", "services", "nps", "status"}, call("act_status")).leaf = true
end end
function status() function act_status()
local e={} local e = {}
e.running=luci.sys.call("pgrep npc > /dev/null")==0 e.running = luci.sys.call("pgrep npc > /dev/null") == 0
luci.http.prepare_content("application/json") luci.http.prepare_content("application/json")
luci.http.write_json(e) luci.http.write_json(e)
end end

89
package/lean/luci-app-nps/luasrc/model/cbi/nps.lua Executable file → Normal file
View File

@ -1,45 +1,54 @@
m=Map("nps") m = Map("nps")
m.title=translate("Nps Setting") m.title = translate("Nps")
m.description=translate("Nps is a fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet.") m.description = translate("Nps is a fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet.")
m:section(SimpleSection).template="nps/nps_status" m:section(SimpleSection).template = "nps/nps_status"
s=m:section(TypedSection,"nps") s = m:section(TypedSection, "nps")
s.addremove=false s.addremove = false
s.anonymous=true s.anonymous = true
s:tab("basic",translate("Basic Setting")) enable = s:option(Flag, "enabled", translate("Enable"))
enable=s:taboption("basic",Flag,"enabled",translate("Enable")) enable.rmempty = false
enable.rmempty=false
server=s:taboption("basic",Value,"server_addr",translate("Server"),translate("Must an IPv4 address")) server = s:option(Value, "server_addr", translate("Server"))
server.datatype="ipaddr" server.description = translate("Must an IPv4 address")
server.optional=false server.datatype = "ipaddr"
server.rmempty=false server.optional = false
port=s:taboption("basic",Value,"server_port",translate("Port")) server.rmempty = false
port.datatype="port"
port.default="8024" port = s:option(Value, "server_port", translate("Port"))
port.optional=false port.datatype = "port"
port.rmempty=false port.default = "8024"
protocol=s:taboption("basic",ListValue,"protocol",translate("Protocol Type")) port.optional = false
protocol.default="tcp" port.rmempty = false
protocol:value("tcp",translate("TCP Protocol"))
protocol:value("kcp",translate("KCP Protocol")) protocol = s:option(ListValue, "protocol", translate("Protocol Type"))
vkey=s:taboption("basic",Value,"vkey",translate("vkey")) protocol:value("tcp", translate("TCP Protocol"))
vkey.optional=false protocol:value("kcp", translate("KCP Protocol"))
vkey.password=true protocol.default = "tcp"
vkey.rmempty=false
compress=s:taboption("basic",Flag,"compress",translate("Enable Compression"),translate("The contents will be compressed to speed up the traffic forwarding speed, but this will consume some additional cpu resources.")) vkey = s:option(Value, "vkey", translate("vkey"))
compress.default="1" vkey.optional = false
compress.rmempty=false vkey.password = true
crypt=s:taboption("basic",Flag,"crypt",translate("Enable Encryption"),translate("Encrypted the communication between Npc and Nps, will effectively prevent the traffic intercepted.")) vkey.rmempty = false
crypt.default="1"
crypt.rmempty=false compress = s:option(Flag, "compress", translate("Enable Compression"))
log_level=s:taboption("basic",ListValue,"log_level",translate("Log Level")) compress.description = translate("The contents will be compressed to speed up the traffic forwarding speed, but this will consume some additional cpu resources.")
log_level:value(0,"Emergency") compress.default = "1"
log_level:value(2,"Critical") compress.rmempty = false
log_level:value(3,"Error")
log_level:value(4,"Warning") crypt = s:option(Flag, "crypt", translate("Enable Encryption"))
log_level:value(7,"Debug") crypt.description = translate("Encrypted the communication between Npc and Nps, will effectively prevent the traffic intercepted.")
log_level.default="3" crypt.default = "1"
crypt.rmempty = false
log_level = s:option(ListValue,"log_level",translate("Log Level"))
log_level:value(0,"Emergency", translate("Emergency"))
log_level:value(2,"Critical", translate("Critical"))
log_level:value(3,"Error", translate("Error"))
log_level:value(4,"Warning", translate("Warning"))
log_level:value(7,"Debug", translate("Debug"))
log_level.default = "3"
return m return m

View File

@ -4,10 +4,10 @@ XHR.poll(3, '<%=url([[admin]], [[services]], [[nps]], [[status]])%>', null,
var tb = document.getElementById('nps_status'); var tb = document.getElementById('nps_status');
if (data && tb) { if (data && tb) {
if (data.running) { if (data.running) {
var links = "<em><b style='color:green;'>Nps <%:RUNNING%></b></em>"; var links = "<em><b><font color=green>Nps <%:RUNNING%></font></b></em>";
tb.innerHTML = links; tb.innerHTML = links;
} else { } else {
tb.innerHTML = "<em><b style='color:red;'>Nps <%:NOT RUNNING%></b></em>"; tb.innerHTML = "<em><b><font color=red>Nps <%:NOT RUNNING%></font></b></em>";
} }
} }
} }

View File

@ -1,4 +1,4 @@
msgid "Nps Setting" msgid "Nps"
msgstr "Nps 内网穿透" msgstr "Nps 内网穿透"
msgid "Nps is a fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet." msgid "Nps is a fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet."
@ -22,11 +22,11 @@ msgstr "压缩传输内容,加快流量转发速度,会额外消耗 CPU 资
msgid "Encrypted the communication between Npc and Nps, will effectively prevent the traffic intercepted." msgid "Encrypted the communication between Npc and Nps, will effectively prevent the traffic intercepted."
msgstr "加密传输 npc 与 nps 之间的通信内容,会有效防止流量被拦截。" msgstr "加密传输 npc 与 nps 之间的通信内容,会有效防止流量被拦截。"
msgid "<b style='color:green;'>Nps is running.</b>" msgid "RUNNING"
msgstr "<b style='color:green;'>Nps 运行中</b>" msgstr "运行中"
msgid "<b style='color:red;'>Nps is not running.</b>" msgid "NOT RUNNING"
msgstr "<b style='color:red;'>Nps 未运行</b>" msgstr "未运行"
msgid "Basic Setting" msgid "Basic Setting"
msgstr "基本设置" msgstr "基本设置"
@ -42,3 +42,6 @@ msgstr "TCP"
msgid "KCP Protocol" msgid "KCP Protocol"
msgstr "KCP" msgstr "KCP"
msgid "Log Level"
msgstr "日志级别"