Compare commits

..
8 Commits
Author SHA1 Message Date
刘河 f0f50579fc ConfigFIle mode host bug 2019-04-03 17:15:50 +08:00
刘河 a831ccd8fa version 2019-04-01 23:58:23 +08:00
刘河 dd65e32fb5 Https defaule support 2019-04-01 23:54:03 +08:00
刘河 b1b91b0c53 Https send error bug 2019-04-01 13:25:12 +08:00
刘河 c29dd2ad36 client exit optimization 2019-03-31 22:12:51 +08:00
刘河 f56b9ea883 Web interface 2019-03-31 21:13:01 +08:00
刘河 d69ce38604 reset 2019-03-31 19:34:51 +08:00
刘河 92ea594ccf Reload 2019-03-31 19:23:25 +08:00
11 changed files with 65 additions and 42 deletions
+22 -19
View File
@@ -1,6 +1,7 @@
# nps
![](https://img.shields.io/github/stars/cnlh/nps.svg) ![](https://img.shields.io/github/forks/cnlh/nps.svg)
[![Gitter](https://badges.gitter.im/cnlh-nps/community.svg)](https://gitter.im/cnlh-nps/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
nps是一款轻量级、高性能、功能强大的**内网穿透**代理服务器。目前支持**tcp、udp流量转发**,可支持任何**tcp、udp**上层协议(访问内网网站、本地支付接口调试、ssh访问、远程桌面,内网dns解析等等……),此外还**支持内网http代理、内网socks5代理**、**p2p等**,并带有功能强大的web管理端。
@@ -35,7 +36,7 @@ nps是一款轻量级、高性能、功能强大的**内网穿透**代理服务
* [内网安全私密代理](#私密代理)
* [p2p穿透](#p2p服务)
* [简单的内网文件访问服务](#文件访问模式)
* [服务端](#web管理模式)
* [服务端](#web管理)
* [服务端启动](#服务端启动)
* [服务端测试](#服务端测试)
* [服务端启动](#服务端启动)
@@ -114,8 +115,8 @@ nps是一款轻量级、高性能、功能强大的**内网穿透**代理服务
## 安装
### release安装
> https://github.com/cnlh/nps/releases
### releases安装
> [releases](https://github.com/cnlh/nps/releases)
下载对应的系统版本即可,服务端和客户端是单独的,go语言开发,无需任何第三方依赖
@@ -154,7 +155,7 @@ nps是一款轻量级、高性能、功能强大的**内网穿透**代理服务
现在访问(http|https://)`a.proxy.com`,`b.proxy.com`即可成功
**https:** 如需使用https请在配置文件中将https端口设置为443,和将对应的证书文件路径添加到配置文件中,上面添加的这条记录将会把http、https都转发到内网目标
**https:** 如需使用https请进行相关配置,详见 [使用https](#使用https)
### tcp隧道
@@ -256,7 +257,7 @@ port=2001
## web管理模式
## web管理
![image](https://github.com/cnlh/nps/blob/master/image/web2.png?raw=true)
### 介绍
@@ -309,8 +310,6 @@ web_port | web管理端口
web_password | web界面管理密码
web_username | web界面管理账号
bridge_port | 服务端客户端通信端口
pem_path | ssl certFile绝对路径
key_path | ssl keyFile绝对路径
https_proxy_port | 域名代理https代理监听端口
http_proxy_port | 域名代理http代理监听端口
auth_key|web api密钥
@@ -327,13 +326,12 @@ p2p_port|p2p模式开启的udp端口
**方式一:** 类似于nginx实现https的处理
在配置文件中将https_proxy_port设置为443或者其他你想配置的端口,和将对应的证书文件路径添加到配置文件中,将`https_just_proxy`设置为false,然后就和http代理一样了,例如
在配置文件中将https_proxy_port设置为443或者其他你想配置的端口,和在web中对应域名编辑中设置对应的证书路径,将`https_just_proxy`设置为false,然后就和http代理一样了
- 需要访问`https://a.proxy.com` 对应内网`127.0.0.1:80`
**此外:** 可以在`nps.conf`中设置一个默认的https配置,当遇到未在web中设置https证书的域名解析时,将自动使用默认证书,另还有一种情况就是对于某些请求的clienthello不携带sni扩展信息,nps也将自动使用默认证书
- 在域名代理中添加`a.proxy.com` 内网目标`127.0.0.1:80` 即可将所有到达本代理的http(s)请求都转发到127.0.0.1:80
**方式二:**
**方式二:** 在内网对应服务器上设置https
在`nps.conf`中将`https_just_proxy`设置为true,并且打开`https_proxy_port`端口,然后nps将直接转发https请求到内网服务器上,由内网服务器进行https处理
@@ -404,7 +402,7 @@ web上可以自定义客户端连接的密钥,但是必须具有唯一性
可以将`nps.conf`中的`web_port`设置为空或者删除
### 服务端多用户登陆
如果将`nps.conf`中的`allow_user_login`设置为true,服务端web将支持多用户登陆,登陆用户名为user,密码为每个客户端的验证密钥,默认该功能是关闭的。
如果将`nps.conf`中的`allow_user_login`设置为true,服务端web将支持多用户登陆,登陆用户名为user,默认密码为每个客户端的验证密钥,登陆后可以进入客户端编辑修改web登陆的用户名和密码,默认该功能是关闭的。
### 监听指定ip
@@ -616,15 +614,19 @@ auto_reconnection=true
对于配置文件方式启动,设置
```ini
[common]
proxy_socks5_url=socks5://111:222@127.0.0.1:8024
proxy_url=socks5://111:222@127.0.0.1:8024
```
对于无配置文件模式,加上参数
```
-proxy=socks5://111:222@127.0.0.1:8024
```
支持socks5和http两种模式
即socks5://username:password@ip:port
或http://username:password@ip:port
#### 日志输出级别
```
-log_level=0~7
@@ -767,13 +769,14 @@ location=/static
```
time为有效小时数,例如time=2,在当前时间后的两小时内,本机公网ip都可以访问nps代理.
**方式二:**
此外nps的web登陆也可提供验证的功能,成功登陆nps web admin后将自动为本机ip注册两小时的允许访问权限。
此外nps的web登陆也可提供验证的功能,成功登陆nps web admin后将自动为登陆的ip注册两小时的允许访问权限。
**注意:** 本机公网ip并不是一成不变的,请自行注意有效期的设置,同时同一网络下,多人也可能是在公用同一个公网ip。
### 客户端最大连接数
为防止恶意大量长连接,影响服务端程序的稳定性,可以在web或客户端配置文件中为每个客户端设置最大连接数。该功能针对`socks5`、`http正向代理`、`域名代理`、`tcp代理`、`私密代理`生效。
为防止恶意大量长连接,影响服务端程序的稳定性,可以在web或客户端配置文件中为每个客户端设置最大连接数。该功能针对`socks5`、`http正向代理`、`域名代理`、`tcp代理`、`udp代理`、`私密代理`生效。
### 端口复用
在一些严格的网络环境中,对端口的个数等限制较大,nps支持强大端口复用功能。将`bridge_port`、 `http_proxy_port`、 `https_proxy_port` 、`web_port`都设置为同一端口,也能正常使用。
@@ -783,7 +786,7 @@ time为有效小时数,例如time=2,在当前时间后的两小时内,本
### 多路复用
nps默认支持多路复用,无需开启。
nps主要通信默认基于多路复用,无需开启。
### 环境变量渲染
npc支持环境变量渲染以适应在某些特殊场景下的要求。
@@ -854,10 +857,10 @@ health_http_url | 健康检查url,仅http模式适用
在域名代理模式中,可以通过request请求 header 中的 X-Forwarded-For 和 X-Real-IP 来获取用户真实 IP。
**本代理前会在每一个请求中添加了这两个 header。**
**本代理前会在每一个http(s)请求中添加了这两个 header。**
### 热更新支持
在web管理中的修改将实时使用,无需重启客户端或者服务端
对于绝大多数配置,在web管理中的修改将实时使用,无需重启客户端或者服务端
### 客户端地址显示
在web管理中将显示客户端的连接地址
@@ -914,7 +917,7 @@ POST /auth/getauthkey
- 解密串编码方式 十六进制
### 详细文档
- 此文档近期可能更新较慢,建议自行抓包
- **此文档近期可能更新较慢,建议自行抓包**
为方便第三方扩展,在web模式下可利用webAPI进行相关操作,详情见
[webAPI文档](https://github.com/cnlh/nps/wiki/webAPI%E6%96%87%E6%A1%A3)
+5 -10
View File
@@ -212,31 +212,26 @@ func NewConn(tp string, vkey string, server string, connType string, proxyUrl st
}
c := conn.NewConn(connection)
if _, err := c.Write([]byte(common.CONN_TEST)); err != nil {
logs.Error(err)
os.Exit(0)
return nil, err
}
if _, err := c.Write([]byte(crypt.Md5(version.GetVersion()))); err != nil {
logs.Error(err)
os.Exit(0)
return nil, err
}
if b, err := c.GetShortContent(32); err != nil || crypt.Md5(version.GetVersion()) != string(b) {
logs.Error("The client does not match the server version. The current version of the client is", version.GetVersion())
os.Exit(0)
}
if _, err := c.Write([]byte(common.Getverifyval(vkey))); err != nil {
logs.Error(err)
os.Exit(0)
return nil, err
}
if s, err := c.ReadFlag(); err != nil {
logs.Error(err)
os.Exit(0)
return nil, err
} else if s == common.VERIFY_EER {
logs.Error("Validation key %s incorrect", vkey)
os.Exit(0)
}
if _, err := c.Write([]byte(connType)); err != nil {
logs.Error(err)
os.Exit(0)
return nil, err
}
c.SetAlive(tp)
+1 -3
View File
@@ -6,10 +6,8 @@ import (
"github.com/cnlh/nps/lib/common"
"github.com/cnlh/nps/lib/daemon"
"github.com/cnlh/nps/lib/version"
"github.com/cnlh/nps/vender/github.com/astaxie/beego"
"github.com/cnlh/nps/vender/github.com/astaxie/beego/logs"
"os"
"path/filepath"
"strings"
"time"
)
@@ -61,7 +59,7 @@ func main() {
}
} else {
if *configPath == "" {
*configPath = filepath.Join(beego.AppPath, "conf", "npc.conf")
*configPath = "npc.conf"
}
client.StartFromFile(*configPath)
}
+4 -1
View File
@@ -3,10 +3,13 @@ appname = nps
runmode = pro
#HTTP(S) proxy port, no startup if empty
http_proxy_ip=0.0.0.0
http_proxy_port=80
https_proxy_port=443
https_just_proxy=true
http_proxy_ip=0.0.0.0
#default https certificate setting
https_default_cert_file=conf/server.pem
https_default_key_file=conf/server.key
##bridge
bridge_type=tcp
+1
View File
@@ -152,6 +152,7 @@ func dealCommon(s string) *CommonConfig {
func dealHost(s string) *file.Host {
h := &file.Host{}
h.Target = new(file.Target)
h.Scheme = "all"
var headerChange string
for _, v := range splitStr(s) {
item := strings.Split(v, "=")
+1 -1
View File
@@ -1,6 +1,6 @@
package version
const VERSION = "0.21.0"
const VERSION = "0.21.2"
// Compulsory minimum version, Minimum downward compatibility to this version
func GetVersion() string {
+1 -1
View File
@@ -78,7 +78,7 @@ func (s *BaseServer) CheckFlowAndConnNum(client *file.Client) error {
func (s *BaseServer) DealClient(c *conn.Conn, client *file.Client, addr string, rb []byte, tp string, f func(), flow *file.Flow) error {
link := conn.NewLink(tp, addr, client.Cnf.Crypt, client.Cnf.Compress, c.Conn.RemoteAddr().String())
if target, err := s.bridge.SendLinkInfo(client.Id, link, c.Conn.RemoteAddr().String(), s.task); err != nil {
logs.Warn("task id %d get connection from client id %d error %s", s.task.Id, client.Id, err.Error())
logs.Warn("get connection from client id %d error %s", client.Id, err.Error())
c.Close()
return err
} else {
+25 -7
View File
@@ -33,8 +33,20 @@ func (https *HttpsServer) Start() error {
https.handleHttps(c)
})
} else {
//start the default listener
certFile := beego.AppConfig.String("https_default_cert_file")
keyFile := beego.AppConfig.String("https_default_key_file")
if common.FileExists(certFile) && common.FileExists(keyFile) {
l := NewHttpsListener(https.listener)
https.NewHttps(l, certFile, keyFile)
https.httpsListenerMap.Store("default", l)
}
conn.Accept(https.listener, func(c net.Conn) {
serverName, rb := GetServerNameFromClientHello(c)
//if the clientHello does not contains sni ,use the default ssl certificate
if serverName == "" {
serverName = "default"
}
var l *HttpsListener
if v, ok := https.httpsListenerMap.Load(serverName); ok {
l = v.(*HttpsListener)
@@ -42,17 +54,23 @@ func (https *HttpsServer) Start() error {
r := buildHttpsRequest(serverName)
if host, err := file.GetDb().GetInfoByHost(serverName, r); err != nil {
c.Close()
logs.Notice("the url %s can't be parsed!", serverName)
logs.Notice("the url %s can't be parsed!,remote addr %s", serverName, c.RemoteAddr().String())
return
} else {
if !common.FileExists(host.CertFilePath) || !common.FileExists(host.KeyFilePath) {
c.Close()
logs.Error("the key %s cert %s file is not exist", host.KeyFilePath, host.CertFilePath)
return
//if the host cert file or key file is not set ,use the default file
if v, ok := https.httpsListenerMap.Load("default"); ok {
l = v.(*HttpsListener)
} else {
c.Close()
logs.Error("the key %s cert %s file is not exist", host.KeyFilePath, host.CertFilePath)
return
}
} else {
l = NewHttpsListener(https.listener)
https.NewHttps(l, host.CertFilePath, host.KeyFilePath)
https.httpsListenerMap.Store(serverName, l)
}
l = NewHttpsListener(https.listener)
https.NewHttps(l, host.CertFilePath, host.KeyFilePath)
https.httpsListenerMap.Store(serverName, l)
}
}
acceptConn := conn.NewConn(c)
+1
View File
@@ -44,6 +44,7 @@ func (s *BaseController) Prepare() {
s.Data["isAdmin"] = true
}
s.Data["https_just_proxy"], _ = beego.AppConfig.Bool("https_just_proxy")
s.Data["allow_user_login"], _ = beego.AppConfig.Bool("allow_user_login")
}
//加载模板
+2
View File
@@ -60,6 +60,7 @@
<span class="help-block m-b-none">unique, non-filling will be generated automatically</span>
</div>
</div>
{{if eq true .allow_user_login}}
<div class="form-group" id="web_username">
<label class="control-label col-sm-2" langtag="info-client-web-username">web登陆用户名</label>
<div class="col-sm-10">
@@ -74,6 +75,7 @@
placeholder="empty means to be unrestricted">
</div>
</div>
{{end}}
<div class="form-group" id="config_conn_allow">
<label class="control-label col-sm-2" langtag="info-config-conn-allow">是否允许客户端以配置文件模式连接</label>
<div class="col-sm-10">
+2
View File
@@ -64,6 +64,7 @@
</div>
</div>
{{end}}
{{if eq true .allow_user_login}}
<div class="form-group" id="web_username">
<label class="control-label col-sm-2" langtag="info-client-web-username">web登陆用户名</label>
<div class="col-sm-10">
@@ -78,6 +79,7 @@
placeholder="empty means to be unrestricted">
</div>
</div>
{{end}}
<div class="form-group" id="config_conn_allow">
<label class="control-label col-sm-2" langtag="info-config-conn-allow">是否允许客户端以配置文件模式连接</label>
<div class="col-sm-10">