From d7587bde9d8cb5eeeab4dd7dbdcfc9fe3a09df05 Mon Sep 17 00:00:00 2001 From: Matthew Sheppard Date: Sat, 26 Oct 2019 23:46:14 +0800 Subject: [PATCH] Add luci-app-nps (#1883) https://github.com/cnlh/nps --- package/lean/luci-app-nps/Makefile | 19 +++++ .../luci-app-nps/luasrc/controller/nps.lua | 17 +++++ .../luci-app-nps/luasrc/i18n/nps.zh-cn.lmo | Bin 0 -> 296 bytes .../luci-app-nps/luasrc/i18n/nps.zh_CN.po | 28 +++++++ .../luci-app-nps/luasrc/model/cbi/nps.lua | 47 ++++++++++++ .../luasrc/view/nps/nps_status.htm | 22 ++++++ package/lean/luci-app-nps/root/etc/config/nps | 11 +++ package/lean/luci-app-nps/root/etc/init.d/nps | 68 +++++++++++++++++ .../root/etc/uci-defaults/luci-nps | 11 +++ package/lean/npc/Makefile | 70 ++++++++++++++++++ 10 files changed, 293 insertions(+) create mode 100644 package/lean/luci-app-nps/Makefile create mode 100755 package/lean/luci-app-nps/luasrc/controller/nps.lua create mode 100644 package/lean/luci-app-nps/luasrc/i18n/nps.zh-cn.lmo create mode 100644 package/lean/luci-app-nps/luasrc/i18n/nps.zh_CN.po create mode 100755 package/lean/luci-app-nps/luasrc/model/cbi/nps.lua create mode 100755 package/lean/luci-app-nps/luasrc/view/nps/nps_status.htm create mode 100755 package/lean/luci-app-nps/root/etc/config/nps create mode 100755 package/lean/luci-app-nps/root/etc/init.d/nps create mode 100755 package/lean/luci-app-nps/root/etc/uci-defaults/luci-nps create mode 100644 package/lean/npc/Makefile diff --git a/package/lean/luci-app-nps/Makefile b/package/lean/luci-app-nps/Makefile new file mode 100644 index 000000000..11e25ed05 --- /dev/null +++ b/package/lean/luci-app-nps/Makefile @@ -0,0 +1,19 @@ +# +# Copyright (C) 2008-2014 The LuCI Team +# +# 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 + + diff --git a/package/lean/luci-app-nps/luasrc/controller/nps.lua b/package/lean/luci-app-nps/luasrc/controller/nps.lua new file mode 100755 index 000000000..04fb7ced2 --- /dev/null +++ b/package/lean/luci-app-nps/luasrc/controller/nps.lua @@ -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 diff --git a/package/lean/luci-app-nps/luasrc/i18n/nps.zh-cn.lmo b/package/lean/luci-app-nps/luasrc/i18n/nps.zh-cn.lmo new file mode 100644 index 0000000000000000000000000000000000000000..940bd4e7dc167aaadd5c74bdafca9a22f93a1043 GIT binary patch literal 296 zcmeY(D1O@3`h4%i=PUQWZ0KirvUmUUDJ!1#bwA&;^2weBFZNAlfQfZ2c)Gp~CWfp6 zXu#8TJKyi=c?wjrfAzDijW65#U+i7;w148uhWSr-EdxqD*)!|qqPb6(OnbJi<3+=C zh2(-#g%?{}p6!~zzyQ()Gg%?8AX(wbjy@n=tng%K_si*9p3iD|*)Z$L{)KRRfQCJr z)A?*_$IBU;o~>O3wQ$kuXWh%5b*y5DQ~%Fc{KjcD0|SEv5PLP)1bzNmvBMb1ZUJKd v*7vU!_c-o-2V@HXvC!qelI|-T0tJC=5a7R_zV}Y literal 0 HcmV?d00001 diff --git a/package/lean/luci-app-nps/luasrc/i18n/nps.zh_CN.po b/package/lean/luci-app-nps/luasrc/i18n/nps.zh_CN.po new file mode 100644 index 000000000..8910c020c --- /dev/null +++ b/package/lean/luci-app-nps/luasrc/i18n/nps.zh_CN.po @@ -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 \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 之间的通信内容,会有效防止流量被拦截" \ No newline at end of file diff --git a/package/lean/luci-app-nps/luasrc/model/cbi/nps.lua b/package/lean/luci-app-nps/luasrc/model/cbi/nps.lua new file mode 100755 index 000000000..ea7a4e0ec --- /dev/null +++ b/package/lean/luci-app-nps/luasrc/model/cbi/nps.lua @@ -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 + + diff --git a/package/lean/luci-app-nps/luasrc/view/nps/nps_status.htm b/package/lean/luci-app-nps/luasrc/view/nps/nps_status.htm new file mode 100755 index 000000000..5952344bb --- /dev/null +++ b/package/lean/luci-app-nps/luasrc/view/nps/nps_status.htm @@ -0,0 +1,22 @@ + + +
+

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

+
diff --git a/package/lean/luci-app-nps/root/etc/config/nps b/package/lean/luci-app-nps/root/etc/config/nps new file mode 100755 index 000000000..5b166cd1d --- /dev/null +++ b/package/lean/luci-app-nps/root/etc/config/nps @@ -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' + diff --git a/package/lean/luci-app-nps/root/etc/init.d/nps b/package/lean/luci-app-nps/root/etc/init.d/nps new file mode 100755 index 000000000..be3db8f5d --- /dev/null +++ b/package/lean/luci-app-nps/root/etc/init.d/nps @@ -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 +} diff --git a/package/lean/luci-app-nps/root/etc/uci-defaults/luci-nps b/package/lean/luci-app-nps/root/etc/uci-defaults/luci-nps new file mode 100755 index 000000000..f4f0996aa --- /dev/null +++ b/package/lean/luci-app-nps/root/etc/uci-defaults/luci-nps @@ -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 diff --git a/package/lean/npc/Makefile b/package/lean/npc/Makefile new file mode 100644 index 000000000..882fe69bf --- /dev/null +++ b/package/lean/npc/Makefile @@ -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)))