Add luci-app-nps (#1883)

https://github.com/cnlh/nps
This commit is contained in:
Matthew Sheppard 2019-10-26 23:46:14 +08:00 committed by coolsnowwolf
parent 586ff91baa
commit d7587bde9d
10 changed files with 293 additions and 0 deletions

View File

@ -0,0 +1,19 @@
#
# Copyright (C) 2008-2014 The LuCI Team <luci@lists.subsignal.org>
#
# This is free software, licensed under the Apache License, Version 2.0 .
#
include $(TOPDIR)/rules.mk
LUCI_TITLE:=LuCI for Nps
LUCI_DEPENDS:=+wget +npc
LUCI_PKGARCH:=all
PKG_VERSION:=1.1
PKG_RELEASE:=2
include $(TOPDIR)/feeds/luci/luci.mk
# call BuildPackage - OpenWrt buildroot signature

View File

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

Binary file not shown.

View File

@ -0,0 +1,28 @@
# zh_CN translation for npc.
# Copyright (C) 2015 Yoyodyne, Inc. (msgids)
# This file is distributed under the same license as the gettext package.
#
msgid ""
msgstr ""
"PO-Revision-Date: 2015-09-01 09:53中国标准时间\n"
"Last-Translator: Ardentwheel <Ardentwheel@gmail.com>\n"
"Language: zh_CN\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
msgid "Nps Setting"
msgstr "Nps内网穿透"
msgid "Enable Compression"
msgstr "使用压缩传输"
msgid "Enable Encryption"
msgstr "使用加密传输"
msgid "The contents will be compressed to speed up the traffic forwarding speed, but this will consume some additional cpu resources"
msgstr "压缩传输内容,加快流量转发速度,会额外消耗 cpu 资源"
msgid "Encrypted the communication between Npc and Nps, will effectively prevent the traffic intercepted."
msgstr "加密传输 npc 与 nps 之间的通信内容,会有效防止流量被拦截"

View File

@ -0,0 +1,47 @@
m=Map("nps")
m.title=translate("Nps Setting")
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"
s=m:section(TypedSection,"nps")
s.addremove=false
s.anonymous=true
s:tab("basic",translate("Basic Setting"))
enable=s:taboption("basic",Flag,"enabled",translate("Enable"))
enable.rmempty=false
server=s:taboption("basic",Value,"server_addr",translate("Server"),translate("Must an IPv4 address"))
server.datatype="ipaddr"
server.optional=false
server.rmempty=false
port=s:taboption("basic",Value,"server_port",translate("Port"))
port.datatype="port"
port.default="8024"
port.optional=false
port.rmempty=false
protocol=s:taboption("basic",ListValue,"protocol",translate("Protocol Type"))
protocol.default="tcp"
protocol:value("tcp",translate("TCP Protocol"))
protocol:value("kcp",translate("KCP Protocol"))
vkey=s:taboption("basic",Value,"vkey",translate("vkey"))
vkey.optional=false
vkey.password=true
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."))
compress.default="1"
compress.rmempty=false
crypt=s:taboption("basic",Flag,"crypt",translate("Enable Encryption"),translate("Encrypted the communication between Npc and Nps, will effectively prevent the traffic intercepted."))
crypt.default="1"
crypt.rmempty=false
log_level=s:taboption("basic",ListValue,"log_level",translate("Log Level"))
log_level:value(0,"Emergency")
log_level:value(2,"Critical")
log_level:value(3,"Error")
log_level:value(4,"Warning")
log_level:value(7,"Debug")
log_level.default="3"
return m

View File

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

View File

@ -0,0 +1,11 @@
config npc 'config'
option enabled '1'
option server_addr '1.1.1.1'
option server_port '8024'
option protocol 'tcp'
option compress '1'
option crypt '1'
option vkey 'aaa'
option log_level '4'

View File

@ -0,0 +1,68 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2006-2011 OpenWrt.org
START=50
SERVICE_WRITE_PID=1
SERVICE_DAEMONIZE=1
LOGFILE="/var/etc/nps.log"
tmpconf="/tmp/etc/nps.conf"
nps_header() {
local enabled server_addr server_port protocol vkey compress crypt log_level
config_get enabled $1 enabled
config_get server_addr $1 server_addr
config_get server_port $1 server_port
config_get protocol $1 protocol
config_get vkey $1 vkey
config_get compress $1 compress
config_get crypt $1 crypt
config_get log_level $1 log_level
[ -f $tmpconf ] && rm $tmpconf
echo "[common]" >$tmpconf
echo "server_addr=${server_addr}:${server_port}" >>$tmpconf
echo "conn_type=${protocol}" >>$tmpconf
echo "vkey=${vkey}" >>$tmpconf
nps_write_bool compress $1
nps_write_bool crypt $1
Log_level=$log_level
Enabled=$enabled
}
nps_write_bool() {
local opt="$1"
local config="$2"
local val
config_get_bool val $config "$opt"
if [ "$val" -eq 0 ]; then
echo "${opt}=false" >> $tmpconf
else
echo "${opt}=true" >> $tmpconf
fi
}
start() {
config_load nps
config_foreach nps_header nps
if [ "$Enabled" = "0" ];then
stop
else
logger -t FRPC 'Starting Nps service'
service_start /usr/bin/npc -config=$tmpconf -log_level=$Log_level -log_path=$LOGFILE
fi
return 0
}
stop() {
service_stop /usr/bin/npc
rm $tmpconf
logger -t FRPC 'Nps service stopped'
return 0
}

View File

@ -0,0 +1,11 @@
#!/bin/sh
uci -q batch <<-EOF >/dev/null
delete ucitrack.@nps[-1]
add ucitrack nps
set ucitrack.@nps[-1].init=nps
commit ucitrack
EOF
rm -f /tmp/luci-indexcache
exit 0

70
package/lean/npc/Makefile Normal file
View File

@ -0,0 +1,70 @@
#
# Copyright (C) 2015-2016 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v3.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=npc
PKG_VERSION:=0.23.2
PKG_RELEASE:=1
ifeq ($(ARCH),mipsel)
NPC_ARCH:=mipsle
endif
ifeq ($(ARCH),mips)
NPC_ARCH:=mips
endif
ifeq ($(ARCH),i386)
NPC_ARCH:=386
endif
ifeq ($(ARCH),x86_64)
NPC_ARCH:=amd64
endif
ifeq ($(ARCH),arm)
NPC_ARCH:=arm
endif
ifeq ($(ARCH),aarch64)
NPC_ARCH:=arm64
endif
PKG_LICENSE:=Apache-2.0
PKG_SOURCE_URL:=https://github.com/cnlh/nps/releases/download/v$(PKG_VERSION)
PKG_SOURCE:=linux_$(NPC_ARCH)_client.tar.gz
PKG_BUILD_DIR:=$(BUILD_DIR)/nps
PKG_HASH:=skip
include $(INCLUDE_DIR)/package.mk
define Package/$(PKG_NAME)
SECTION:=net
CATEGORY:=Network
TITLE:=NPC Client
DEPENDS:=
URL:=https://github.com/cnlh/nps/releases
endef
define Package/$(PKG_NAME)/description
npc is a fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet
endef
define Build/Prepare
$(PKG_UNPACK)
endef
define Build/Configure
endef
define Build/Compile
endef
define Package/$(PKG_NAME)/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/npc $(1)/usr/bin/
endef
$(eval $(call BuildPackage,$(PKG_NAME)))