Compare commits

..
13 Commits
Author SHA1 Message Date
yisier b39f0c30ef v0.26.32 2026-03-27 16:00:27 -06:00
yisier c1753a6d19 客户端注册参数未正确处理 2026-03-27 15:52:33 -06:00
yisier 8f384eaac4 Merge pull request #312 from okawao/dev
修复https反向代理bug
2026-03-27 06:33:25 +08:00
yisier a51d6bc50a v0.26.31 2026-03-23 17:03:28 +08:00
yisier 43144804c7 v0.26.31 2026-03-23 17:02:32 +08:00
yisier dfe4748e97 TCP隧道增加Basic认证 2026-03-23 16:43:29 +08:00
yisier 30af159034 新增隧道出现secret mode keys must be unique 2026-03-23 15:37:11 +08:00
yisier 8819907be5 域名解析记录开关功能 2026-03-23 15:16:29 +08:00
okawao 1a29ab0046 在建立tls连接时不应比较location 2026-03-14 20:05:16 +08:00
okawao 0ffec7df7f Merge branch 'master' into dev 2026-03-14 17:24:01 +08:00
okawao 876b2d2588 修复无法正确解析分段client hello;新增兼容ip证书 2026-03-14 16:44:44 +08:00
yisier af4be7f130 readme 2026-03-13 11:38:53 +08:00
yisier 0e6cc0f40f 0.26.30 2026-03-12 15:49:43 +08:00
14 changed files with 187 additions and 34 deletions
+39 -12
View File
@@ -1,31 +1,58 @@
# NPS
[新特性文档](https://dqg9t9eulqq.feishu.cn/wiki/FmVVwDcEGiTZxekYJl5ccuFanlg?from=from_copylink)
[新特性文档](https://dqg9t9eulqq.feishu.cn/wiki/FmVVwDcEGiTZxekYJl5ccuFanlg?from=from_copylink)
[原版文档](https://ehang.io/nps/documents)
# 说明
由于nps已经停更多年,存留了不少bug和未完善的功能。
此版本基于 nps 0.26.10的基础上二次开发而来。
### 交流
聊天灌水QQ群:619833483,热心群主可提供免费远程协助👍👍👍
***DockerHub***: [NPS](https://hub.docker.com/r/yisier1/nps) [NPC](https://hub.docker.com/r/yisier1/npc)
***宝塔面板***:[宝塔面板 Docker](docs/bt.md)
# 交流群
聊天灌水QQ群:619833483(2000人群),770569342
# 广告
[NPS云穿透](https://natnps.com/register?utm_from=MQ==),免费4M带宽,2条隧道;6.8元12M带宽,10条隧道;13.8元24M带宽,20条隧道。
雨云,500M带宽服务器;云服务器15元起,[专属连接,首月5折](https://www.rainyun.com/MjY0MzY1_)。
# 提示
强烈推荐使用无配置文件模式启动客户端(删除掉npc.exe 目录下的`conf`文件夹即可),所有数据应该在服务端保存和配置,而客户端只做连接转发。客户端配置文件对小白极不友好,配置繁琐,容易出错。
0.26.21 版本后的客户端,无需再通过命令行方式启动、安装、卸载客户端,直接双击运行,按照提示输入指令即可完成,非常方便。
# 广告
[NPS云穿透](https://natnps.com/register?utm_from=MQ==),免费3M带宽,2条隧道;6.8元12M带宽,10条隧道;13.8元24M带宽,20条隧道。
雨云,500M带宽服务器;云服务器15元起,[专属连接,首月5折](https://www.rainyun.com/MjY0MzY1_)。
# 快速上手
***服务端启动/安装:***`./npc(.exe) -server`
![img.png](image/new/server.png)
***客户端启动/安装:*** `./npc(.exe)`
![image](image/new/cmd.png)
# 更新日志
- 2026-03-27 v0.26.32
- 修复:
- 客户端注册参数未正确处理[快捷启动命令]和[TLS快捷启动命令] [#303](https://github.com/yisier/nps/issues/303)
- 修复https反向代理bug,感谢[okawao](https://github.com/okawao) 的 PR
- 2026-03-23 v0.26.31
- 新增:
- 域名解析记录开关功能 [#314](https://github.com/yisier/nps/issues/314)
- TCP隧道增加Basic认证 [306](https://github.com/yisier/nps/issues/306)
- 修复:
- 新增隧道出现secret mode keys must be unique [301](https://github.com/yisier/nps/issues/301)
- 2026-03-12 v0.26.30
修复:
- http 协议 websocket 错误,感谢[xiaozonglong](https://github.com/xiaozonglong) 提供的 home assistant 环境 ,[#268](https://github.com/yisier/nps/issues/268),[#296](https://github.com/yisier/nps/issues/296)
- 域名解析中,主机url点击无法跳转非80端口 [311](https://github.com/yisier/nps/issues/311)
- 新增的主机配置页面,客户端ID异常 [#310](https://github.com/yisier/nps/issues/310)
- 自动 HTTPS(301) 按照 `https_proxy_port` 配置的端口号跳转
- 2026-01-24 v0.26.29
新增:
GUI 客户端,基于 Wails 开发,[点击查看了解更多](https://github.com/yisier/nps/blob/master/cmd/npc/npc-gui/README.md),需要 WebView2 运行时,可通过两种方式添加客户端。
+1 -1
View File
@@ -1,5 +1,5 @@
#/bash/sh
export VERSION=0.26.29
export VERSION=0.26.32
export GOPROXY=direct
sudo apt-get update
+1 -1
View File
@@ -14,7 +14,7 @@
},
"info": {
"productName": "NPS Client",
"productVersion": "0.26.29",
"productVersion": "0.26.32",
"companyName": "NPS",
"copyright": "Copyright © 2026 NPS"
},
+6 -1
View File
@@ -410,8 +410,13 @@ func systemService(flag string) {
for _, item := range cmdArray {
array := strings.Fields(item)
// tls
tls := "false"
if len(array) > 2 {
tls = array[2]
}
// tls
if tls == "-tls_enable=true" || tls == "true" {
systemPro(flag, array[0], array[1], true)
} else {
systemPro(flag, array[0], array[1], false)
+8 -1
View File
@@ -96,7 +96,7 @@ func (s *DbUtils) GetIdByVerifyKey(vKey string, addr string) (id int, err error)
func (s *DbUtils) NewTask(t *Tunnel) (err error) {
s.JsonDb.Tasks.Range(func(key, value interface{}) bool {
v := value.(*Tunnel)
if (v.Mode == "secret" || v.Mode == "p2p") && v.Password == t.Password {
if (v.Mode == "secret" || v.Mode == "p2p") && v.Password == t.Password && t.Password != "" {
err = errors.New(fmt.Sprintf("secret mode keys %s must be unique", t.Password))
return false
}
@@ -377,6 +377,13 @@ func (s *DbUtils) GetInfoByHost(host string, r *http.Request) (h *Host, err erro
if v.Location == "" {
v.Location = "/"
}
// "*" means SNI-based HTTPS lookup where actual URI is unknown, skip location filter
if r.RequestURI == "*" {
if h == nil || (len(v.Location) > len(h.Location)) {
h = v
}
continue
}
if strings.Index(r.RequestURI, v.Location) == 0 {
if h == nil || (len(v.Location) > len(h.Location)) {
h = v
+1 -1
View File
@@ -1,6 +1,6 @@
package version
const VERSION = "0.26.29"
const VERSION = "0.26.32"
// Compulsory minimum version, Minimum downward compatibility to this version
func GetVersion() string {
+2 -1
View File
@@ -11,6 +11,7 @@ import (
"ehang.io/nps/lib/goroutine"
"ehang.io/nps/server/connection"
"encoding/json"
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
"io"
"net"
@@ -113,7 +114,7 @@ func (s *httpServer) handleTunneling(w http.ResponseWriter, r *http.Request) {
// 自动 http 301 https
if host.AutoHttps && r.TLS == nil {
http.Redirect(w, r, "https://"+r.Host+r.RequestURI, http.StatusMovedPermanently)
http.Redirect(w, r, "https://"+host.Host+":"+beego.AppConfig.String("https_proxy_port"), http.StatusMovedPermanently)
return
}
+61 -13
View File
@@ -1,6 +1,7 @@
package proxy
import (
"io"
"net"
"net/http"
"net/url"
@@ -38,10 +39,14 @@ func (https *HttpsServer) Start() error {
conn.Accept(https.listener, func(c net.Conn) {
serverName, rb := GetServerNameFromClientHello(c)
if serverName == "" {
serverName = getFallbackServerName()
logs.Debug("https fallback server name result, remote addr %s, server name %q", c.RemoteAddr().String(), serverName)
}
r := buildHttpsRequest(serverName)
if host, err := file.GetDb().GetInfoByHost(serverName, r); err != nil {
c.Close()
logs.Debug("the url %s can't be parsed!,remote addr %s", serverName, c.RemoteAddr().String())
logs.Debug("https host lookup failed, server name %q, remote addr %s, error %v", serverName, c.RemoteAddr().String(), err)
return
} else {
if host.CertFilePath == "" || host.KeyFilePath == "" {
@@ -140,6 +145,35 @@ func (https *HttpsServer) Start() error {
return nil
}
func getFallbackServerName() string {
global := file.GetDb().GetGlobal()
if global == nil {
return ""
}
serverName := strings.TrimSpace(global.ServerUrl)
if serverName == "" {
return ""
}
if strings.Contains(serverName, "://") {
if u, err := url.Parse(serverName); err == nil && u.Host != "" {
serverName = u.Host
}
}
if i := strings.Index(serverName, "/"); i >= 0 {
serverName = serverName[:i]
}
serverName = common.GetIpByAddr(serverName)
serverName = strings.TrimSpace(serverName)
if serverName == "" {
return ""
}
ip := net.ParseIP(serverName)
if ip != nil && ip.IsUnspecified() {
return ""
}
return serverName
}
func (https *HttpsServer) cert(host *file.Host, c net.Conn, rb []byte, certFileUrl string, keyFileUrl string) {
var l *HttpsListener
i := 0
@@ -300,27 +334,41 @@ func (httpsListener *HttpsListener) Addr() net.Addr {
return httpsListener.parentListener.Addr()
}
// get server name from connection by read client hello bytes
// get server name from connection by read full client hello bytes
func GetServerNameFromClientHello(c net.Conn) (string, []byte) {
buf := make([]byte, 4096)
data := make([]byte, 4096)
n, err := c.Read(buf)
header := make([]byte, 5)
headerN, err := io.ReadFull(c, header)
if err != nil {
return "", nil
return "", header[:headerN]
}
if n < 42 {
return "", nil
if header[0] != 0x16 {
return "", header
}
copy(data, buf[:n])
recordLen := int(header[3])<<8 | int(header[4])
if recordLen <= 0 {
return "", header
}
body := make([]byte, recordLen)
bodyN, err := io.ReadFull(c, body)
if err != nil {
return "", append(header, body[:bodyN]...)
}
rawBytes := append(header, body...)
clientHello := new(crypt.ClientHelloMsg)
clientHello.Unmarshal(data[5:n])
return clientHello.GetServerName(), buf[:n]
if !clientHello.Unmarshal(body) {
return "", rawBytes
}
return clientHello.GetServerName(), rawBytes
}
// build https request
// build https request for SNI-based host lookup.
// RequestURI is set to "*" to skip Location filtering in GetInfoByHost,
// because at TLS handshake stage the actual HTTP request path is unknown.
func buildHttpsRequest(hostName string) *http.Request {
r := new(http.Request)
r.RequestURI = "/"
r.RequestURI = "*"
r.URL = new(url.URL)
r.URL.Scheme = "https"
r.Host = hostName
+17
View File
@@ -9,6 +9,7 @@ import (
"net/http"
"path/filepath"
"strconv"
"time"
"ehang.io/nps/bridge"
"ehang.io/nps/lib/common"
@@ -107,6 +108,22 @@ func ProcessTunnel(c *conn.Conn, s *TunnelModeServer) error {
return err
}
if s.task.Client.Cnf.U != "" && s.task.Client.Cnf.P != "" {
c.Conn.SetReadDeadline(time.Now().Add(time.Millisecond * 200))
_, _, rb, err, r := c.GetHost()
c.Conn.SetReadDeadline(time.Time{})
if err == nil && !common.CheckAuth(r, s.task.Client.Cnf.U, s.task.Client.Cnf.P) {
c.Write([]byte(common.UnauthorizedBytes))
c.Close()
return errors.New("401 Unauthorized")
}
if err == nil {
return s.DealClient(c, s.task.Client, targetAddr, rb, common.CONN_TCP,
nil, s.task.Client.Flow, s.task.Target.LocalProxy, s.task)
}
}
return s.DealClient(c, s.task.Client, targetAddr, nil, common.CONN_TCP, nil, s.task.Client.Flow, s.task.Target.LocalProxy, s.task)
}
+2 -2
View File
@@ -99,8 +99,8 @@ func NewHttpReverseProxy(s *httpServer) *HttpReverseProxy {
local, _ := net.ResolveTCPAddr("tcp", "127.0.0.1")
proxy := NewReverseProxy(&httputil.ReverseProxy{
Director: func(r *http.Request) {
host := r.Context().Value("host").(*file.Host)
common.ChangeHostAndHeader(r, host.HostChange, host.HeaderChange, "")
//host := r.Context().Value("host").(*file.Host)
//common.ChangeHostAndHeader(r, host.HostChange, host.HeaderChange, "")
},
Transport: &http.Transport{
ResponseHeaderTimeout: rp.responseHeaderTimeout,
+4
View File
@@ -65,6 +65,10 @@ func (s *BaseController) Prepare() {
s.Data["allow_tunnel_num_limit"], _ = beego.AppConfig.Bool("allow_tunnel_num_limit")
s.Data["allow_local_proxy"], _ = beego.AppConfig.Bool("allow_local_proxy")
s.Data["allow_user_change_username"], _ = beego.AppConfig.Bool("allow_user_change_username")
httpPort := beego.AppConfig.String("http_proxy_port")
if httpPort != "80" {
s.Data["http_proxy_port"] = ":" + beego.AppConfig.String("http_proxy_port")
}
}
// 加载模板
+20
View File
@@ -301,6 +301,26 @@ func (s *IndexController) DelHost() {
s.AjaxOk("delete success")
}
func (s *IndexController) HostStop() {
id := s.GetIntNoErr("id")
if h, err := file.GetDb().GetHostById(id); err != nil {
s.AjaxErr("stop error")
} else {
h.IsClose = true
}
s.AjaxOk("stop success")
}
func (s *IndexController) HostStart() {
id := s.GetIntNoErr("id")
if h, err := file.GetDb().GetHostById(id); err != nil {
s.AjaxErr("start error")
} else {
h.IsClose = false
}
s.AjaxOk("start success")
}
func (s *IndexController) AddHost() {
if s.Ctx.Request.Method == "GET" {
s.Data["client_id"] = s.getEscapeString("client_id")
+1
View File
@@ -187,6 +187,7 @@
var option = "<option value=\"" + data.rows[i].Id + "\"";
option += ">" + data.rows[i].Id + '-' + data.rows[i].Remark + "</option>"; //动态添加数据
$("select[name='client_id']").append(option);
$("select[name='client_id']").find("option[value='{{.client_id}}']").attr("selected", true);
}
}
}
+24 -1
View File
@@ -109,7 +109,7 @@
halign: 'center',
visible: true,//false表示不显示
formatter: function (value, row, index) {
return "<a href='http://" + row.Host + "' target='_blank'>" + row.Host + "</a>"
return "<a href='http://" + row.Host + '{{.http_proxy_port}}' + "' target='_blank'>" + row.Host + '{{.http_proxy_port}}' + "</a>"
}
},
{
@@ -136,6 +136,20 @@
halign: 'center',
visible: true//false表示不显示
},
{
field: 'IsClose',//域值
title: '<span langtag="word-status"></span>',//内容
align: 'center',
halign: 'center',
visible: true,//false表示不显示
formatter: function (value, row, index) {
if (!value) {
return '<span class="badge badge-primary" langtag="word-open"></span>'
} else {
return '<span class="badge badge-badge" langtag="word-close"></span>'
}
}
},
{
field: '',//域值
title: '<span langtag="word-clientstatus"></span>',//内容
@@ -159,6 +173,15 @@
visible: true,//false表示不显示
formatter: function (value, row, index) {
btn_group = '<div class="btn-group">'
if (!row.IsClose) {
btn_group += "<a onclick=\"submitform('stop', '{{.web_base_url}}/index/hoststop', {'id':" + row.Id
btn_group += '})" class="btn btn-outline btn-warning"><i class="fa fa-pause"></i></a>'
} else {
btn_group += "<a onclick=\"submitform('start', '{{.web_base_url}}/index/hoststart', {\'id\':" + row.Id
btn_group += '})" class="btn btn-outline btn-primary"><i class="fa fa-play"></i></a>'
}
btn_group += "<a onclick=\"submitform('delete', '{{.web_base_url}}/index/delhost', {'id':" + row.Id
btn_group += '})" class="btn btn-outline btn-danger"><i class="fa fa-trash"></i></a>'
btn_group += '<a href="{{.web_base_url}}/index/edithost?id=' + row.Id