Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d30f7a4b0 | ||
|
|
b09d3ec22c | ||
|
|
b43abb4b5d | ||
|
|
d42710497c | ||
|
|
42a73fa392 | ||
|
|
00a4a33c5f | ||
|
|
006ddbc871 |
@@ -43,7 +43,6 @@ nps是一款轻量级、高性能、功能强大的**内网穿透**代理服务
|
||||
* [服务端配置文件重载](#服务端配置文件重载)
|
||||
* [服务端停止或重启](#服务端停止或重启)
|
||||
* [配置文件说明](#服务端配置文件)
|
||||
|
||||
* [使用https](#使用https)
|
||||
* [与nginx配合](#与nginx配合)
|
||||
* [关闭http|https代理](#关闭代理)
|
||||
@@ -53,6 +52,7 @@ nps是一款轻量级、高性能、功能强大的**内网穿透**代理服务
|
||||
* [关闭公钥访问](#关闭公钥访问)
|
||||
* [关闭web管理](#关闭web管理)
|
||||
* [服务端多用户登陆](#服务端多用户登陆)
|
||||
* [监听指定ip](#监听指定ip)
|
||||
* [客户端](#客户端)
|
||||
* [客户端启动](#客户端启动)
|
||||
* [无配置文件模式](#无配置文件模式)
|
||||
@@ -72,6 +72,7 @@ nps是一款轻量级、高性能、功能强大的**内网穿透**代理服务
|
||||
* [重载配置文件](#重载配置文件)
|
||||
* [通过代理连接nps](#通过代理连接nps)
|
||||
* [日志输出级别](#日志输出级别)
|
||||
* [群晖支持](#群晖支持)
|
||||
|
||||
* [相关功能](#相关功能)
|
||||
* [数据压缩支持](#数据压缩支持)
|
||||
@@ -93,6 +94,7 @@ nps是一款轻量级、高性能、功能强大的**内网穿透**代理服务
|
||||
* [限制ip访问](#限制ip访问)
|
||||
* [客户端最大连接数限制](#客户端最大连接数)
|
||||
* [端口复用](#端口复用)
|
||||
* [多路复用](#多路复用)
|
||||
* [环境变量渲染](#环境变量渲染)
|
||||
* [健康检查](#健康检查)
|
||||
|
||||
@@ -103,11 +105,6 @@ nps是一款轻量级、高性能、功能强大的**内网穿透**代理服务
|
||||
* [获取用户真实ip](#获取用户真实ip)
|
||||
* [客户端地址显示](#客户端地址显示)
|
||||
* [客户端与服务端版本对比](#客户端与服务端版本对比)
|
||||
* [简单的性能测试](#简单的性能测试)
|
||||
* [qps](#qps)
|
||||
* [速度测试](#速度测试)
|
||||
* [内存和cpu](#内存和cpu)
|
||||
* [额外消耗连接数](#额外消耗连接数)
|
||||
* [webAPI](#webAPI)
|
||||
* [贡献](#贡献)
|
||||
* [交流群](#交流群)
|
||||
@@ -408,6 +405,12 @@ web上可以自定义客户端连接的密钥,但是必须具有唯一性
|
||||
### 服务端多用户登陆
|
||||
如果将`nps.conf`中的`allow_user_login`设置为true,服务端web将支持多用户登陆,登陆用户名为user,密码为每个客户端的验证密钥,默认该功能是关闭的。
|
||||
|
||||
### 监听指定ip
|
||||
|
||||
nps支持每个隧道监听不同的服务端端口,可在web中控制,或者npc配置文件中(可忽略,默认为0.0.0.0)
|
||||
```ini
|
||||
server_ip=xxx
|
||||
```
|
||||
|
||||
## 客户端
|
||||
|
||||
@@ -427,8 +430,8 @@ web上可以自定义客户端连接的密钥,但是必须具有唯一性
|
||||
##### 全局配置
|
||||
```ini
|
||||
[common]
|
||||
server=1.1.1.1:8284
|
||||
tp=tcp
|
||||
server_addr=1.1.1.1:8284
|
||||
conn_type=tcp
|
||||
vkey=123
|
||||
username=111
|
||||
password=222
|
||||
@@ -441,11 +444,11 @@ max_conn=10
|
||||
```
|
||||
项 | 含义
|
||||
---|---
|
||||
server | 服务端ip:port
|
||||
tp | 与服务端通信模式(tcp或kcp)
|
||||
server_addr | 服务端ip:port
|
||||
conn_type | 与服务端通信模式(tcp或kcp)
|
||||
vkey|服务端配置文件中的密钥(非web)
|
||||
username|socks5或http(s)密码保护用户名(可忽略)
|
||||
username|socks5或http(s)密码保护密码(可忽略)
|
||||
password|socks5或http(s)密码保护密码(可忽略)
|
||||
compress|是否压缩传输(true或false或忽略)
|
||||
crypt|是否加密传输(true或false或忽略)
|
||||
rate_limit|速度限制,可忽略
|
||||
@@ -456,11 +459,11 @@ max_conn|最大连接数,可忽略
|
||||
|
||||
```ini
|
||||
[common]
|
||||
server=1.1.1.1:8284
|
||||
server_addr=1.1.1.1:8284
|
||||
vkey=123
|
||||
[web1]
|
||||
host=a.proxy.com
|
||||
target=127.0.0.1:8080,127.0.0.1:8082
|
||||
target_addr=127.0.0.1:8080,127.0.0.1:8082
|
||||
host_change=www.proxy.com
|
||||
header_set_proxy=nps
|
||||
```
|
||||
@@ -468,7 +471,7 @@ header_set_proxy=nps
|
||||
---|---
|
||||
web1 | 备注
|
||||
host | 域名(http|https都可解析)
|
||||
target|内网目标,负载均衡时多个目标,逗号隔开
|
||||
target_addr|内网目标,负载均衡时多个目标,逗号隔开
|
||||
host_change|请求host修改
|
||||
header_xxx|请求header修改或添加,header_proxy表示添加header proxy:nps
|
||||
|
||||
@@ -476,96 +479,96 @@ header_xxx|请求header修改或添加,header_proxy表示添加header proxy:np
|
||||
|
||||
```ini
|
||||
[common]
|
||||
server=1.1.1.1:8284
|
||||
server_addr=1.1.1.1:8284
|
||||
vkey=123
|
||||
[tcp]
|
||||
mode=tcp
|
||||
target=127.0.0.1:8080
|
||||
port=9001
|
||||
target_addr=127.0.0.1:8080
|
||||
server_port=9001
|
||||
```
|
||||
项 | 含义
|
||||
---|---
|
||||
mode | tcp
|
||||
port | 在服务端的代理端口
|
||||
target|内网目标
|
||||
server_port | 在服务端的代理端口
|
||||
tartget_addr|内网目标
|
||||
|
||||
##### udp隧道模式
|
||||
|
||||
```ini
|
||||
[common]
|
||||
server=1.1.1.1:8284
|
||||
server_addr=1.1.1.1:8284
|
||||
vkey=123
|
||||
[udp]
|
||||
mode=udp
|
||||
target=127.0.0.1:8080
|
||||
port=9002
|
||||
target_addr=127.0.0.1:8080
|
||||
server_port=9002
|
||||
```
|
||||
项 | 含义
|
||||
---|---
|
||||
mode | udp
|
||||
port | 在服务端的代理端口
|
||||
target|内网目标
|
||||
server_port | 在服务端的代理端口
|
||||
target_addr|内网目标
|
||||
##### http代理模式
|
||||
|
||||
```ini
|
||||
[common]
|
||||
server=1.1.1.1:8284
|
||||
server_addr=1.1.1.1:8284
|
||||
vkey=123
|
||||
[http]
|
||||
mode=httpProxy
|
||||
port=9003
|
||||
server_port=9003
|
||||
```
|
||||
项 | 含义
|
||||
---|---
|
||||
mode | httpProxy
|
||||
port | 在服务端的代理端口
|
||||
server_port | 在服务端的代理端口
|
||||
##### socks5代理模式
|
||||
|
||||
```ini
|
||||
[common]
|
||||
server=1.1.1.1:8284
|
||||
server_addr=1.1.1.1:8284
|
||||
vkey=123
|
||||
[socks5]
|
||||
mode=socks5
|
||||
port=9004
|
||||
server_port=9004
|
||||
```
|
||||
项 | 含义
|
||||
---|---
|
||||
mode | socks5
|
||||
port | 在服务端的代理端口
|
||||
server_port | 在服务端的代理端口
|
||||
##### 私密代理模式
|
||||
|
||||
```ini
|
||||
[common]
|
||||
server=1.1.1.1:8284
|
||||
server_addr=1.1.1.1:8284
|
||||
vkey=123
|
||||
[secret_ssh]
|
||||
mode=secret
|
||||
password=ssh2
|
||||
target=10.1.50.2:22
|
||||
target_addr=10.1.50.2:22
|
||||
```
|
||||
项 | 含义
|
||||
---|---
|
||||
mode | secret
|
||||
password | 唯一密钥
|
||||
target|内网目标
|
||||
target_addr|内网目标
|
||||
|
||||
##### p2p代理模式
|
||||
|
||||
```ini
|
||||
[common]
|
||||
server=1.1.1.1:8284
|
||||
server_addr=1.1.1.1:8284
|
||||
vkey=123
|
||||
[p2p_ssh]
|
||||
mode=p2p
|
||||
password=ssh2
|
||||
target=10.1.50.2:22
|
||||
target_addr=10.1.50.2:22
|
||||
```
|
||||
项 | 含义
|
||||
---|---
|
||||
mode | p2p
|
||||
password | 唯一密钥
|
||||
target|内网目标
|
||||
target_addr|内网目标
|
||||
|
||||
|
||||
##### 文件访问模式
|
||||
@@ -573,11 +576,11 @@ target|内网目标
|
||||
|
||||
```ini
|
||||
[common]
|
||||
server=1.1.1.1:8284
|
||||
server_addr=1.1.1.1:8284
|
||||
vkey=123
|
||||
[file]
|
||||
mode=file
|
||||
port=9100
|
||||
server_port=9100
|
||||
local_path=/tmp/
|
||||
strip_pre=/web/
|
||||
````
|
||||
@@ -585,7 +588,7 @@ strip_pre=/web/
|
||||
项 | 含义
|
||||
---|---
|
||||
mode | file
|
||||
port | 服务端开启的端口
|
||||
server_port | 服务端开启的端口
|
||||
local_path|本地文件目录
|
||||
strip_pre|前缀
|
||||
|
||||
@@ -635,6 +638,9 @@ LevelWarning->4 LevelNotice->5
|
||||
LevelInformational->6 LevelDebug->7
|
||||
```
|
||||
默认为全输出,级别为0到7
|
||||
|
||||
#### 群晖支持
|
||||
可在releases中下载spk群晖套件,例如`npc_x64-6.1_0.19.0-1.spk`
|
||||
## 相关功能
|
||||
|
||||
### 数据压缩支持
|
||||
@@ -698,8 +704,8 @@ allow_ports=9001-9009,10001,11000-12000
|
||||
```ini
|
||||
[tcp]
|
||||
mode=tcp
|
||||
port=9001-9009,10001,11000-12000
|
||||
target=8001-8009,10002,13000-14000
|
||||
server_port=9001-9009,10001,11000-12000
|
||||
target_port=8001-8009,10002,13000-14000
|
||||
```
|
||||
|
||||
逗号分隔,可单个或者范围,注意上下端口的对应关系,无法一一对应将不能成功
|
||||
@@ -707,11 +713,11 @@ target=8001-8009,10002,13000-14000
|
||||
```ini
|
||||
[tcp]
|
||||
mode=tcp
|
||||
port=9001-9009,10001,11000-12000
|
||||
target=8001-8009,10002,13000-14000
|
||||
targetAddr=10.1.50.2
|
||||
server_port=9001-9009,10001,11000-12000
|
||||
target_port=8001-8009,10002,13000-14000
|
||||
target_ip=10.1.50.2
|
||||
```
|
||||
填写targetAddr后则表示映射的该地址机器的端口,忽略则便是映射本地127.0.0.1,仅范围映射时有效
|
||||
填写target_ip后则表示映射的该地址机器的端口,忽略则便是映射本地127.0.0.1,仅范围映射时有效
|
||||
### 守护进程
|
||||
本代理支持守护进程,使用示例如下,服务端客户端所有模式通用,支持linux,darwin,windows。
|
||||
```
|
||||
@@ -736,11 +742,11 @@ KCP 是一个快速可靠协议,能以比 TCP浪费10%-20%的带宽的代价
|
||||
```ini
|
||||
[web1]
|
||||
host=a.proxy.com
|
||||
target=127.0.0.1:7001
|
||||
target_addr=127.0.0.1:7001
|
||||
location=/test
|
||||
[web2]
|
||||
host=a.proxy.com
|
||||
target=127.0.0.1:7002
|
||||
target_addr=127.0.0.1:7002
|
||||
location=/static
|
||||
```
|
||||
对于`a.proxy.com/test`将转发到`web1`,对于`a.proxy.com/static`将转发到`web2`
|
||||
@@ -774,6 +780,10 @@ time为有效小时数,例如time=2,在当前时间后的两小时内,本
|
||||
- 使用时将需要复用的端口设置为与`bridge_port`一致即可,将自动识别。
|
||||
- 如需将web管理的端口也复用,需要配置`web_host`也就是一个二级域名以便区分
|
||||
|
||||
### 多路复用
|
||||
|
||||
nps默认支持多路复用,无需开启。
|
||||
|
||||
### 环境变量渲染
|
||||
npc支持环境变量渲染以适应在某些特殊场景下的要求。
|
||||
|
||||
@@ -788,13 +798,13 @@ export NPC_SERVER_VKEY=xxxxx
|
||||
**在配置文件启动模式下:**
|
||||
```ini
|
||||
[common]
|
||||
server={{.NPC_SERVER_ADDR}}
|
||||
tp=tcp
|
||||
server_addr={{.NPC_SERVER_ADDR}}
|
||||
conn_type=tcp
|
||||
vkey={{.NPC_SERVER_VKEY}}
|
||||
auto_reconnection=true
|
||||
[web]
|
||||
host={{.NPC_WEB_HOST}}
|
||||
target={{.NPC_WEB_TARGET}}
|
||||
target_addr={{.NPC_WEB_TARGET}}
|
||||
```
|
||||
在配置文件中填入相应的环境变量名称,npc将自动进行渲染配置文件替换环境变量
|
||||
|
||||
@@ -825,6 +835,7 @@ health_check_target=127.0.0.1:8083,127.0.0.1:8082
|
||||
第一种是tcp模式,也就是以tcp的方式与目标建立连接,能成功建立连接表示成功
|
||||
|
||||
如果失败次数超过`health_check_max_failed`,nps则会移除该npc下的所有该目标,如果失败后目标重新上线,nps将自动将目标重新加入。
|
||||
|
||||
项 | 含义
|
||||
---|---
|
||||
health_check_timeout | 健康检查超时时间
|
||||
@@ -859,26 +870,6 @@ health_http_url | 健康检查url,仅http模式适用
|
||||
### 客户端与服务端版本对比
|
||||
为了程序正常运行,客户端与服务端的版本必须一致,否则将导致客户端无法成功连接致服务端。
|
||||
|
||||
## 简单的性能测试
|
||||
|
||||
### qps
|
||||

|
||||
### 速度测试
|
||||
**测试环境:** 1M带宽云服务器,理论125kb/s,带宽与代理无关,与服务器带宽和内网客户端外网带宽关系较大。
|
||||

|
||||
|
||||
|
||||
### 内存和cpu
|
||||
|
||||
**1000次性能测试后**
|
||||

|
||||
|
||||
**启动时**
|
||||

|
||||
|
||||
### 额外消耗连接数
|
||||
为了最大化的提升效率和并发,客户端与服务端之间仅两条tcp连接,减少建立连接的时间消耗和多余socket连接对机器性能的影响。
|
||||
|
||||
## webAPI
|
||||
|
||||
### webAPI验证说明
|
||||
|
||||
+13
-12
@@ -200,20 +200,28 @@ func (s *Bridge) cliProcess(c *conn.Conn) {
|
||||
|
||||
func (s *Bridge) DelClient(id int) {
|
||||
if v, ok := s.Client.Load(id); ok {
|
||||
if c, err := file.GetCsvDb().GetClient(id); err == nil && c.NoStore {
|
||||
s.CloseClient <- c.Id
|
||||
}
|
||||
if v.(*Client).signal != nil {
|
||||
v.(*Client).signal.Close()
|
||||
}
|
||||
s.Client.Delete(id)
|
||||
if file.GetCsvDb().IsPubClient(id) {
|
||||
return
|
||||
}
|
||||
if c, err := file.GetCsvDb().GetClient(id); err == nil && c.NoStore {
|
||||
s.CloseClient <- c.Id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//use different
|
||||
func (s *Bridge) typeDeal(typeVal string, c *conn.Conn, id int) {
|
||||
isPub := file.GetCsvDb().IsPubClient(id)
|
||||
switch typeVal {
|
||||
case common.WORK_MAIN:
|
||||
if isPub {
|
||||
c.Close()
|
||||
return
|
||||
}
|
||||
//the vKey connect by another ,close the client of before
|
||||
if v, ok := s.Client.LoadOrStore(id, NewClient(nil, nil, c)); ok {
|
||||
if v.(*Client).signal != nil {
|
||||
@@ -229,16 +237,8 @@ func (s *Bridge) typeDeal(typeVal string, c *conn.Conn, id int) {
|
||||
v.(*Client).tunnel = muxConn
|
||||
}
|
||||
case common.WORK_CONFIG:
|
||||
var isPub bool
|
||||
client, err := file.GetCsvDb().GetClient(id)
|
||||
if err == nil {
|
||||
if client.VerifyKey == beego.AppConfig.String("public_vkey") {
|
||||
isPub = true
|
||||
} else {
|
||||
isPub = false
|
||||
}
|
||||
}
|
||||
if !isPub && !client.ConfigConnAllow {
|
||||
if err != nil || (!isPub && !client.ConfigConnAllow) {
|
||||
c.Close()
|
||||
return
|
||||
}
|
||||
@@ -458,6 +458,7 @@ loop:
|
||||
tl := new(file.Tunnel)
|
||||
tl.Mode = t.Mode
|
||||
tl.Port = ports[i]
|
||||
tl.ServerIp = t.ServerIp
|
||||
if len(ports) == 1 {
|
||||
tl.Target = t.Target
|
||||
tl.Remark = t.Remark
|
||||
|
||||
+9
-3
@@ -228,7 +228,13 @@ loop:
|
||||
}
|
||||
|
||||
func (s *TRPClient) Close() {
|
||||
s.tunnel.Close()
|
||||
s.signal.Close()
|
||||
s.ticker.Stop()
|
||||
if s.tunnel != nil {
|
||||
s.tunnel.Close()
|
||||
}
|
||||
if s.signal != nil {
|
||||
s.signal.Close()
|
||||
}
|
||||
if s.ticker != nil {
|
||||
s.ticker.Stop()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,6 +163,7 @@ re:
|
||||
}
|
||||
|
||||
c.Close()
|
||||
logs.Notice("Temporary access login key ", vkey)
|
||||
NewRPClient(cnf.CommonConfig.Server, vkey, cnf.CommonConfig.Tp, cnf.CommonConfig.ProxyUrl, cnf).Start()
|
||||
CloseLocalServer()
|
||||
goto re
|
||||
|
||||
+14
-15
@@ -1,6 +1,6 @@
|
||||
[common]
|
||||
server=127.0.0.1:8024
|
||||
tp=tcp
|
||||
server_addr=127.0.0.1:8024
|
||||
conn_type=tcp
|
||||
vkey=123
|
||||
auto_reconnection=true
|
||||
|
||||
@@ -20,39 +20,38 @@ health_check_type=tcp
|
||||
health_check_target=127.0.0.1:8083,127.0.0.1:8082
|
||||
[web]
|
||||
host=b.o.com
|
||||
target=127.0.0.1:8080
|
||||
target_addr=127.0.0.1:8080,127.0.0.1:8082
|
||||
|
||||
[tcp]
|
||||
mode=tcp
|
||||
target=127.0.0.1:8083,127.0.0.1:8082
|
||||
port=9006
|
||||
targetAddr=123.206.77.88
|
||||
target_addr=127.0.0.1:8080
|
||||
server_port=10000
|
||||
|
||||
[socks5]
|
||||
mode=socks5
|
||||
port=9005
|
||||
server_port=9005
|
||||
|
||||
[http]
|
||||
mode=httpProxy
|
||||
port=9004
|
||||
server_port=9004
|
||||
|
||||
|
||||
[file]
|
||||
mode=file
|
||||
port=9009
|
||||
server_port=9009
|
||||
local_path=./
|
||||
strip_pre=/web/
|
||||
|
||||
[udp]
|
||||
mode=udp
|
||||
port=53
|
||||
target=114.114.114.114:53
|
||||
server_port=53
|
||||
target_addr=114.114.114.114:53
|
||||
|
||||
[secret_ssh]
|
||||
port=2001
|
||||
local_port=2001
|
||||
password=sec
|
||||
|
||||
[p2p_ssh]
|
||||
port=2002
|
||||
password=c
|
||||
target=123.206.77.88:22
|
||||
local_port=2002
|
||||
password=ppp
|
||||
target_addr=192.168.74.199:22
|
||||
@@ -6,6 +6,7 @@ runmode = pro
|
||||
http_proxy_port=80
|
||||
https_proxy_port=443
|
||||
https_just_proxy=true
|
||||
http_proxy_ip=0.0.0.0
|
||||
#certFile absolute path
|
||||
#pem_path=conf/server.pem
|
||||
#KeyFile absolute path
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
9988,tcp,127.0.0.1:8080,1,3,11,,0,504,
|
||||
9999,tcp,,1,3,11,,0,0,,0.0.0.0
|
||||
|
||||
|
+14
-9
@@ -20,6 +20,7 @@ type CommonConfig struct {
|
||||
type LocalServer struct {
|
||||
Type string
|
||||
Port int
|
||||
Ip string
|
||||
Password string
|
||||
Target string
|
||||
}
|
||||
@@ -112,11 +113,11 @@ func dealCommon(s string) *CommonConfig {
|
||||
item = append(item, "")
|
||||
}
|
||||
switch item[0] {
|
||||
case "server":
|
||||
case "server_addr":
|
||||
c.Server = item[1]
|
||||
case "vkey":
|
||||
c.VKey = item[1]
|
||||
case "tp":
|
||||
case "conn_type":
|
||||
c.Tp = item[1]
|
||||
case "auto_reconnection":
|
||||
c.AutoReconnection = common.GetBoolByStr(item[1])
|
||||
@@ -156,11 +157,11 @@ func dealHost(s string) *file.Host {
|
||||
switch strings.TrimSpace(item[0]) {
|
||||
case "host":
|
||||
h.Host = item[1]
|
||||
case "target":
|
||||
case "target_addr":
|
||||
h.Target = strings.Replace(item[1], ",", "\n", -1)
|
||||
case "host_change":
|
||||
h.HostChange = item[1]
|
||||
case "schemego":
|
||||
case "scheme":
|
||||
h.Scheme = item[1]
|
||||
case "location":
|
||||
h.Location = item[1]
|
||||
@@ -211,13 +212,15 @@ func dealTunnel(s string) *file.Tunnel {
|
||||
item = append(item, "")
|
||||
}
|
||||
switch strings.TrimSpace(item[0]) {
|
||||
case "port":
|
||||
case "server_port":
|
||||
t.Ports = item[1]
|
||||
case "server_ip":
|
||||
t.ServerIp = item[1]
|
||||
case "mode":
|
||||
t.Mode = item[1]
|
||||
case "target":
|
||||
case "target_port", "target_addr":
|
||||
t.Target = strings.Replace(item[1], ",", "\n", -1)
|
||||
case "targetAddr":
|
||||
case "target_ip":
|
||||
t.TargetAddr = item[1]
|
||||
case "password":
|
||||
t.Password = item[1]
|
||||
@@ -241,11 +244,13 @@ func delLocalService(s string) *LocalServer {
|
||||
item = append(item, "")
|
||||
}
|
||||
switch item[0] {
|
||||
case "port":
|
||||
case "local_port":
|
||||
l.Port = common.GetIntNoErrByStr(item[1])
|
||||
case "local_ip":
|
||||
l.Ip = item[1]
|
||||
case "password":
|
||||
l.Password = item[1]
|
||||
case "target":
|
||||
case "target_addr":
|
||||
l.Target = item[1]
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -316,7 +316,7 @@ func (s *Conn) SendTaskInfo(t *file.Tunnel) (int, error) {
|
||||
*/
|
||||
raw := bytes.NewBuffer([]byte{})
|
||||
binary.Write(raw, binary.LittleEndian, []byte(common.NEW_TASK))
|
||||
common.BinaryWrite(raw, t.Mode, t.Ports, t.Target, t.Remark, t.TargetAddr, t.Password, t.LocalPath, t.StripPre)
|
||||
common.BinaryWrite(raw, t.Mode, t.Ports, t.Target, t.Remark, t.TargetAddr, t.Password, t.LocalPath, t.StripPre, t.ServerIp)
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
return s.Write(raw.Bytes())
|
||||
@@ -345,6 +345,9 @@ func (s *Conn) GetTaskInfo() (t *file.Tunnel, err error) {
|
||||
t.Password = arr[5]
|
||||
t.LocalPath = arr[6]
|
||||
t.StripPre = arr[7]
|
||||
if len(arr) > 8 {
|
||||
t.ServerIp = arr[8]
|
||||
}
|
||||
t.NoStore = true
|
||||
}
|
||||
return
|
||||
|
||||
@@ -24,21 +24,25 @@ func InitDaemon(f string, runPath string, pidPath string) {
|
||||
switch os.Args[1] {
|
||||
case "start":
|
||||
start(args, f, pidPath, runPath)
|
||||
os.Exit(0)
|
||||
case "stop":
|
||||
stop(f, args[0], pidPath)
|
||||
os.Exit(0)
|
||||
case "restart":
|
||||
stop(f, args[0], pidPath)
|
||||
start(args, f, pidPath, runPath)
|
||||
os.Exit(0)
|
||||
case "status":
|
||||
if status(f, pidPath) {
|
||||
log.Printf("%s is running", f)
|
||||
} else {
|
||||
log.Printf("%s is not running", f)
|
||||
}
|
||||
os.Exit(0)
|
||||
case "reload":
|
||||
reload(f, pidPath)
|
||||
os.Exit(0)
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func reload(f string, pidPath string) {
|
||||
|
||||
+23
-1
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/cnlh/nps/lib/common"
|
||||
"github.com/cnlh/nps/lib/crypt"
|
||||
"github.com/cnlh/nps/lib/rate"
|
||||
"github.com/cnlh/nps/vender/github.com/astaxie/beego"
|
||||
"github.com/cnlh/nps/vender/github.com/astaxie/beego/logs"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -59,6 +60,7 @@ func (s *Csv) StoreTasksToCsv() {
|
||||
strconv.Itoa(int(task.Flow.ExportFlow)),
|
||||
strconv.Itoa(int(task.Flow.InletFlow)),
|
||||
task.Password,
|
||||
task.ServerIp,
|
||||
}
|
||||
err := writer.Write(record)
|
||||
if err != nil {
|
||||
@@ -111,6 +113,11 @@ func (s *Csv) LoadTaskFromCsv() {
|
||||
if post.Client, err = s.GetClient(common.GetIntNoErrByStr(item[5])); err != nil {
|
||||
continue
|
||||
}
|
||||
if len(item) > 10 {
|
||||
post.ServerIp = item[10]
|
||||
} else {
|
||||
post.ServerIp = "0.0.0.0"
|
||||
}
|
||||
s.Tasks.Store(post.Id, post)
|
||||
if post.Id > int(s.TaskIncreaseId) {
|
||||
s.TaskIncreaseId = int32(s.TaskIncreaseId)
|
||||
@@ -440,7 +447,7 @@ func (s *Csv) UpdateClient(t *Client) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Csv) GetClientList(start, length int, search string) ([]*Client, int) {
|
||||
func (s *Csv) GetClientList(start, length int, search string, clientId int) ([]*Client, int) {
|
||||
list := make([]*Client, 0)
|
||||
var cnt int
|
||||
keys := common.GetMapKeys(s.Clients)
|
||||
@@ -450,6 +457,9 @@ func (s *Csv) GetClientList(start, length int, search string) ([]*Client, int) {
|
||||
if v.NoDisplay {
|
||||
continue
|
||||
}
|
||||
if clientId != 0 && clientId != v.Id {
|
||||
continue
|
||||
}
|
||||
if search != "" && !(v.Id == common.GetIntNoErrByStr(search) || strings.Contains(v.VerifyKey, search) || strings.Contains(v.Remark, search)) {
|
||||
continue
|
||||
}
|
||||
@@ -464,6 +474,18 @@ func (s *Csv) GetClientList(start, length int, search string) ([]*Client, int) {
|
||||
return list, cnt
|
||||
}
|
||||
|
||||
func (s *Csv) IsPubClient(id int) bool {
|
||||
client, err := s.GetClient(id)
|
||||
if err == nil {
|
||||
if client.VerifyKey == beego.AppConfig.String("public_vkey") {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *Csv) GetClient(id int) (c *Client, err error) {
|
||||
if v, ok := s.Clients.Load(id); ok {
|
||||
c = v.(*Client)
|
||||
|
||||
+3
-2
@@ -111,8 +111,9 @@ func (s *Client) HasHost(h *Host) bool {
|
||||
}
|
||||
|
||||
type Tunnel struct {
|
||||
Id int //Id
|
||||
Port int //服务端监听端口
|
||||
Id int //Id
|
||||
Port int //服务端监听端口
|
||||
ServerIp string
|
||||
Mode string //启动方式
|
||||
Target string //目标
|
||||
TargetArr []string //目标
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package version
|
||||
|
||||
const VERSION = "0.20.0"
|
||||
const VERSION = "0.20.2"
|
||||
|
||||
// Compulsory minimum version, Minimum downward compatibility to this version
|
||||
func GetVersion() string {
|
||||
|
||||
@@ -50,7 +50,7 @@ func GetHttpListener() (net.Listener, error) {
|
||||
return pMux.GetHttpListener(), nil
|
||||
}
|
||||
logs.Info("start http listener, port is", httpPort)
|
||||
return getTcpListener("", httpPort)
|
||||
return getTcpListener(beego.AppConfig.String("http_proxy_ip"), httpPort)
|
||||
}
|
||||
|
||||
func GetHttpsListener() (net.Listener, error) {
|
||||
@@ -59,7 +59,7 @@ func GetHttpsListener() (net.Listener, error) {
|
||||
return pMux.GetHttpsListener(), nil
|
||||
}
|
||||
logs.Info("start https listener, port is", httpsPort)
|
||||
return getTcpListener("", httpsPort)
|
||||
return getTcpListener(beego.AppConfig.String("http_proxy_ip"), httpsPort)
|
||||
}
|
||||
|
||||
func GetWebManagerListener() (net.Listener, error) {
|
||||
|
||||
@@ -251,7 +251,7 @@ func (s *Sock5ModeServer) Auth(c net.Conn) error {
|
||||
|
||||
//start
|
||||
func (s *Sock5ModeServer) Start() error {
|
||||
return conn.NewTcpListenerAndProcess(":"+strconv.Itoa(s.task.Port), func(c net.Conn) {
|
||||
return conn.NewTcpListenerAndProcess(s.task.ServerIp+":"+strconv.Itoa(s.task.Port), func(c net.Conn) {
|
||||
if err := s.CheckFlowAndConnNum(s.task.Client); err != nil {
|
||||
logs.Warn("client id %d, task id %d, error %s, when socks5 connection", s.task.Client.Id, s.task.Id, err.Error())
|
||||
c.Close()
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ func NewTunnelModeServer(process process, bridge *bridge.Bridge, task *file.Tunn
|
||||
|
||||
//开始
|
||||
func (s *TunnelModeServer) Start() error {
|
||||
return conn.NewTcpListenerAndProcess(":"+strconv.Itoa(s.task.Port), func(c net.Conn) {
|
||||
return conn.NewTcpListenerAndProcess(s.task.ServerIp+":"+strconv.Itoa(s.task.Port), func(c net.Conn) {
|
||||
if err := s.CheckFlowAndConnNum(s.task.Client); err != nil {
|
||||
logs.Warn("client id %d, task id %d,error %s, when tcp connection", s.task.Client.Id, s.task.Id, err.Error())
|
||||
c.Close()
|
||||
|
||||
+4
-1
@@ -26,7 +26,10 @@ func NewUdpModeServer(bridge *bridge.Bridge, task *file.Tunnel) *UdpModeServer {
|
||||
//开始
|
||||
func (s *UdpModeServer) Start() error {
|
||||
var err error
|
||||
s.listener, err = net.ListenUDP("udp", &net.UDPAddr{net.ParseIP("0.0.0.0"), s.task.Port, ""})
|
||||
if s.task.ServerIp == "" {
|
||||
s.task.ServerIp = "0.0.0.0"
|
||||
}
|
||||
s.listener, err = net.ListenUDP("udp", &net.UDPAddr{net.ParseIP(s.task.ServerIp), s.task.Port, ""})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+2
-2
@@ -255,8 +255,8 @@ func GetTunnel(start, length int, typeVal string, clientId int, search string) (
|
||||
}
|
||||
|
||||
//获取客户端列表
|
||||
func GetClientList(start, length int, search string) (list []*file.Client, cnt int) {
|
||||
list, cnt = file.GetCsvDb().GetClientList(start, length, search)
|
||||
func GetClientList(start, length int, search string, clientId int) (list []*file.Client, cnt int) {
|
||||
list, cnt = file.GetCsvDb().GetClientList(start, length, search, clientId)
|
||||
dealClientData()
|
||||
return
|
||||
}
|
||||
|
||||
+12
-2
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/cnlh/nps/lib/file"
|
||||
"github.com/cnlh/nps/server"
|
||||
"github.com/cnlh/nps/vender/github.com/astaxie/beego"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -29,7 +30,7 @@ func (s *BaseController) Prepare() {
|
||||
timestamp := s.GetIntNoErr("timestamp")
|
||||
configKey := beego.AppConfig.String("auth_key")
|
||||
timeNowUnix := time.Now().Unix()
|
||||
if !(((timeNowUnix - int64(timestamp)) <= 20) && ((timeNowUnix - int64(timestamp)) >= -20) && (crypt.Md5(configKey+strconv.Itoa(timestamp)) == md5Key)) {
|
||||
if !((math.Abs(float64(timeNowUnix-int64(timestamp))) <= 20) && (crypt.Md5(configKey+strconv.Itoa(timestamp)) == md5Key)) {
|
||||
if s.GetSession("auth") != true {
|
||||
s.Redirect("/login/index", 302)
|
||||
}
|
||||
@@ -140,7 +141,16 @@ func (s *BaseController) SetType(name string) {
|
||||
|
||||
func (s *BaseController) CheckUserAuth() {
|
||||
if s.controllerName == "client" {
|
||||
s.StopRun()
|
||||
if s.actionName == "add" {
|
||||
s.StopRun()
|
||||
return
|
||||
}
|
||||
if id := s.GetIntNoErr("id"); id != 0 {
|
||||
if id != s.GetSession("clientId").(int) {
|
||||
s.StopRun()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
if s.controllerName == "index" {
|
||||
if id := s.GetIntNoErr("id"); id != 0 {
|
||||
|
||||
@@ -19,7 +19,14 @@ func (s *ClientController) List() {
|
||||
return
|
||||
}
|
||||
start, length := s.GetAjaxParams()
|
||||
list, cnt := server.GetClientList(start, length, s.GetString("search"))
|
||||
clientIdSession := s.GetSession("clientId")
|
||||
var clientId int
|
||||
if clientIdSession == nil {
|
||||
clientId = 0
|
||||
} else {
|
||||
clientId = clientIdSession.(int)
|
||||
}
|
||||
list, cnt := server.GetClientList(start, length, s.GetString("search"), clientId)
|
||||
s.AjaxTable(list, cnt, cnt)
|
||||
}
|
||||
|
||||
@@ -100,9 +107,11 @@ func (s *ClientController) Edit() {
|
||||
c.Cnf.P = s.GetString("p")
|
||||
c.Cnf.Compress = common.GetBoolByStr(s.GetString("compress"))
|
||||
c.Cnf.Crypt = s.GetBoolNoErr("crypt")
|
||||
c.Flow.FlowLimit = int64(s.GetIntNoErr("flow_limit"))
|
||||
c.RateLimit = s.GetIntNoErr("rate_limit")
|
||||
c.MaxConn = s.GetIntNoErr("max_conn")
|
||||
if s.GetSession("isAdmin").(bool) {
|
||||
c.Flow.FlowLimit = int64(s.GetIntNoErr("flow_limit"))
|
||||
c.RateLimit = s.GetIntNoErr("rate_limit")
|
||||
c.MaxConn = s.GetIntNoErr("max_conn")
|
||||
}
|
||||
c.ConfigConnAllow = s.GetBoolNoErr("config_conn_allow")
|
||||
if c.Rate != nil {
|
||||
c.Rate.Stop()
|
||||
|
||||
@@ -91,6 +91,7 @@ func (s *IndexController) Add() {
|
||||
} else {
|
||||
t := &file.Tunnel{
|
||||
Port: s.GetIntNoErr("port"),
|
||||
ServerIp: s.GetString("server_ip"),
|
||||
Mode: s.GetString("type"),
|
||||
Target: s.GetString("target"),
|
||||
Id: int(file.GetCsvDb().GetTaskId()),
|
||||
@@ -144,7 +145,12 @@ func (s *IndexController) Edit() {
|
||||
if t, err := file.GetCsvDb().GetTask(id); err != nil {
|
||||
s.error()
|
||||
} else {
|
||||
t.Port = s.GetIntNoErr("port")
|
||||
var portChange bool
|
||||
if s.GetIntNoErr("port") != t.Port {
|
||||
portChange = true
|
||||
t.Port = s.GetIntNoErr("port")
|
||||
}
|
||||
t.ServerIp = s.GetString("server_ip")
|
||||
t.Mode = s.GetString("type")
|
||||
t.Target = s.GetString("target")
|
||||
t.Password = s.GetString("password")
|
||||
@@ -152,7 +158,7 @@ func (s *IndexController) Edit() {
|
||||
t.LocalPath = s.GetString("local_path")
|
||||
t.StripPre = s.GetString("strip_pre")
|
||||
t.Remark = s.GetString("remark")
|
||||
if !tool.TestServerPort(t.Port, t.Mode) {
|
||||
if portChange && !tool.TestServerPort(t.Port, t.Mode) {
|
||||
s.AjaxErr("The port cannot be opened because it may has been occupied or is no longer allowed.")
|
||||
}
|
||||
if t.Client, err = file.GetCsvDb().GetClient(s.GetIntNoErr("client_id")); err != nil {
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
placeholder="remark">
|
||||
</div>
|
||||
</div>
|
||||
{{if eq true .isAdmin}}
|
||||
<div class="form-group" id="flow_limit">
|
||||
<label class="col-sm-2 control-label" langtag="info-flow-limit">流量限制</label>
|
||||
<div class="col-sm-10">
|
||||
@@ -36,6 +37,7 @@
|
||||
placeholder="empty means to be unrestricted">
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
<div class="form-group" id="u">
|
||||
<label class="control-label col-sm-2" langtag="info-web-auth-username">basic权限认证用户名</label>
|
||||
<div class="col-sm-10">
|
||||
|
||||
+16
-12
@@ -15,15 +15,18 @@
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="table-responsive">
|
||||
<div id="toolbar">
|
||||
<a href="/client/add" class="btn btn-primary dim" type="button" langtag="info-new">新增</a>
|
||||
</div>
|
||||
<table id="taskList_table" class="table-striped table-hover"
|
||||
data-mobile-responsive="true"></table>
|
||||
<div class="content">
|
||||
{{if eq true .isAdmin}}
|
||||
|
||||
<div class="table-responsive">
|
||||
<div id="toolbar">
|
||||
<a href="/client/add" class="btn btn-primary dim" type="button" langtag="info-new">新增</a>
|
||||
</div>
|
||||
<table id="taskList_table" class="table-striped table-hover"
|
||||
data-mobile-responsive="true"></table>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
<div class="ibox-content">
|
||||
|
||||
<table id="table"></table>
|
||||
@@ -194,7 +197,7 @@
|
||||
},
|
||||
{
|
||||
field: 'Status',//域值
|
||||
title: 'setting status',//内容
|
||||
title: 'run',//内容
|
||||
visible: true,//false表示不显示
|
||||
sortable: true,//启用排序
|
||||
formatter: function (value, row, index) {
|
||||
@@ -207,7 +210,7 @@
|
||||
},
|
||||
{
|
||||
field: 'IsConnect',//域值
|
||||
title: 'client status',//内容
|
||||
title: 'status',//内容
|
||||
visible: true,//false表示不显示
|
||||
sortable: true,//启用排序
|
||||
formatter: function (value, row, index) {
|
||||
@@ -225,11 +228,12 @@
|
||||
sortable: true,//启用排序
|
||||
formatter: function (value, row, index) {
|
||||
btn_group = '<div class="btn-group">'
|
||||
btn = `<button onclick="del(` + row.Id + `)" class="btn-danger"><i class="fa fa-trash"></i></button><button onclick="edit(` + row.Id + `)" class="btn-primary"><i class="fa fa-edit"></i></button></div>`
|
||||
btn = `{{if eq true .isAdmin}}<button onclick="del(` + row.Id + `)" class="btn-danger"><i class="fa fa-trash"></i></button>{{end}}<button onclick="edit(` + row.Id + `)" class="btn-primary"><i class="fa fa-edit"></i></button></div>`
|
||||
|
||||
if (row.Status) {
|
||||
return btn_group + `<button onclick="stop(` + row.Id + `)" class="btn-warning"><i class="fa fa-close"></i></button>` + btn
|
||||
return btn_group {{if eq true .isAdmin}}+ `<button onclick="stop(` + row.Id + `)" class="btn-warning"><i class="fa fa-close"></i></button>`{{end}}+ btn
|
||||
} else {
|
||||
return btn_group + `<button onclick="start(` + row.Id + `)" class="btn-warning"><i class="fa fa-check"></i></button>` + btn
|
||||
return btn_group {{if eq true .isAdmin}}+ `<button onclick="start(` + row.Id + `)" class="btn-warning"><i class="fa fa-check"></i></button>`{{end}}+ btn
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -28,6 +28,14 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" id="server_ip">
|
||||
<label class="col-sm-2 control-label" langtag="info-server-ip">服务端ip</label>
|
||||
<div class="col-sm-10">
|
||||
<input class="form-control" type="text" value="0.0.0.0" name="server_ip"
|
||||
placeholder="such as 0.0.0.0">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" id="port">
|
||||
<label class="col-sm-2 control-label" langtag="info-server-port">服务端端口</label>
|
||||
<div class="col-sm-10">
|
||||
|
||||
@@ -28,7 +28,13 @@
|
||||
placeholder="empty means to be unrestricted">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" id="server_ip">
|
||||
<label class="col-sm-2 control-label" langtag="info-server-ip">服务端ip</label>
|
||||
<div class="col-sm-10">
|
||||
<input class="form-control" type="text" value="{{.t.ServerIp}}" name="server_ip"
|
||||
placeholder="such as 0.0.0.0">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group" id="port">
|
||||
<label class="col-sm-2 control-label" langtag="info-server-port">服务端端口</label>
|
||||
<div class="col-sm-10">
|
||||
|
||||
@@ -38,7 +38,13 @@
|
||||
{{/*<img alt="image" class="img-circle" src="/static/img/profile_small.jpg"/>*/}}
|
||||
</span>
|
||||
<a href="#">
|
||||
<span class="clear"> <span class="block m-t-xs"> <strong class="font-bold">admin</strong>
|
||||
<span class="clear"> <span class="block m-t-xs"> <strong class="font-bold">
|
||||
{{if eq true .isAdmin}}
|
||||
admin
|
||||
{{else}}
|
||||
user
|
||||
{{end}}
|
||||
</strong>
|
||||
</span> <span class="text-muted text-xs block">system </span> </span>
|
||||
</a>
|
||||
</div>
|
||||
@@ -46,7 +52,6 @@
|
||||
NPS
|
||||
</div>
|
||||
</li>
|
||||
{{if eq true .isAdmin}}
|
||||
<li class="{{if eq "index" .menu}}active{{end}}">
|
||||
<a href="/"><i class="fa fa-dashboard"></i> <span langtag="menu-dashboard"
|
||||
class="nav-label">仪表盘</span></a>
|
||||
@@ -55,7 +60,6 @@
|
||||
<a href="/client/list"><i class="fa fa-clipboard"></i> <span langtag="menu-client"
|
||||
class="nav-label">客户端</span></a>
|
||||
</li>
|
||||
{{end}}
|
||||
<li class="{{if eq "host" .menu}}active{{end}}">
|
||||
<a href="/index/hostlist"><i class="fa fa-paperclip"></i> <span langtag="menu-host"
|
||||
class="nav-label">域名解析</span></a>
|
||||
|
||||
Reference in New Issue
Block a user