Skip to content

Commit

Permalink
tls 独立端口
Browse files Browse the repository at this point in the history
  • Loading branch information
yisier committed Feb 27, 2024
1 parent 783e475 commit 91bcc55
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 20 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
## 更新日志


- 2024-01-31 v0.26.18
***新增***:nps.conf 新增 `tls_bridge_port=8025` 参数,当 `tls_enable=true` 时,nps 会监听8025端口,作为 tls 的连接端口。
客户端可以选择连接 tls 端口或者非 tls 端口: `npc.exe -server=xxx:8024 -vkey=xxx``npc.exe -server=xxx:8025 -vkey=xxx -tls_enable=true`


- 2024-01-31 v0.26.17
***说明***:考虑到 npc 历史版本客户端众多,版本号不同旧版本客户端无法连接,为了兼容,仓库版本号将继续沿用 0.26.xx

Expand Down
42 changes: 29 additions & 13 deletions bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,37 @@ func (s *Bridge) StartTunnel() error {
s.cliProcess(conn.NewConn(c))
})
} else {
listener, err := connection.GetBridgeListener(s.tunnelType)
if err != nil {
logs.Error(err)
os.Exit(0)
return err
}

conn.Accept(listener, func(c net.Conn) {
// tls
if ServerTlsEnable {
s.cliProcess(conn.NewConn(tls.Server(c, &tls.Config{Certificates: []tls.Certificate{crypt.GetCert()}})))
} else {
s.cliProcess(conn.NewConn(c))
go func() {
listener, err := connection.GetBridgeListener(s.tunnelType)
if err != nil {
logs.Error(err)
os.Exit(0)
return
}
})
conn.Accept(listener, func(c net.Conn) {
s.cliProcess(conn.NewConn(c))
})
}()

// tls
if ServerTlsEnable {
go func() {
// 监听TLS 端口
tlsBridgePort := beego.AppConfig.DefaultInt("tls_bridge_port", 8025)

logs.Info("tls server start, the bridge type is %s, the tls bridge port is %d", "tcp", tlsBridgePort)
tlsListener, tlsErr := net.ListenTCP("tcp", &net.TCPAddr{net.ParseIP(beego.AppConfig.String("bridge_ip")), tlsBridgePort, ""})
if tlsErr != nil {
logs.Error(tlsErr)
os.Exit(0)
return
}
conn.Accept(tlsListener, func(c net.Conn) {
s.cliProcess(conn.NewConn(tls.Server(c, &tls.Config{Certificates: []tls.Certificate{crypt.GetCert()}})))
})
}()
}
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#/bash/sh
export VERSION=0.26.17
export VERSION=0.26.18
export GOPROXY=direct

sudo apt-get update
Expand Down
3 changes: 2 additions & 1 deletion conf/nps.conf
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,5 @@ open_captcha=false


# 是否开启tls
tls_enable=true
tls_enable=true
tls_bridge_port=8025
2 changes: 1 addition & 1 deletion lib/version/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package version

const VERSION = "0.26.17"
const VERSION = "0.26.18"

// Compulsory minimum version, Minimum downward compatibility to this version
func GetVersion() string {
Expand Down
13 changes: 12 additions & 1 deletion web/controllers/base.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package controllers

import (
"ehang.io/nps/bridge"
"html"
"math"
"strconv"
Expand Down Expand Up @@ -83,7 +84,17 @@ func (s *BaseController) display(tpl ...string) {
if common.IsWindows() {
s.Data["win"] = ".exe"
}
s.Data["p"] = server.Bridge.TunnelPort

s.Data["p"] = strconv.Itoa(server.Bridge.TunnelPort)

if bridge.ServerTlsEnable {
tlsPort := strconv.Itoa(beego.AppConfig.DefaultInt("tls_bridge_port", 8025))
s.Data["tls_p"] = tlsPort
s.Data["p1"] = strconv.Itoa(server.Bridge.TunnelPort) + " / " + tlsPort
} else {
s.Data["p1"] = strconv.Itoa(server.Bridge.TunnelPort)
}

s.Data["proxyPort"] = beego.AppConfig.String("hostPort")
s.Layout = "public/layout.html"
s.TplName = tplname
Expand Down
2 changes: 1 addition & 1 deletion web/static/js/language.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
$.fn.cloudLang = function () {
$.ajax({
type: 'GET',
url: window.nps.web_base_url + '/static/page/languages.xml',
url: window.nps.web_base_url + '/static/page/languages.xml?v=20240227',
dataType: 'xml',
success: function (xml) {
languages['content'] = xml2json($(xml).children())['content'];
Expand Down
7 changes: 7 additions & 0 deletions web/static/page/languages.xml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@
<zh-CN>客户端命令</zh-CN>
<en-US>Command</en-US>
</lang>
<lang id="word-commandclient-tls">
<zh-CN>TLS 启动命令</zh-CN>
<en-US>TLS Command</en-US>
</lang>



<lang id="word-compress">
<zh-CN>压缩</zh-CN>
<en-US>Compress</en-US>
Expand Down
3 changes: 2 additions & 1 deletion web/views/client/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ <h5 langtag="page-clientlist"></h5>
+ '<b langtag="word-connectbyconfig"></b>: <span langtag="word-' + row.ConfigConnAllow + '"></span>&emsp;<br/><br/>'
+ '<b langtag="word-blackip"></b>: ' + row.BlackIpList + '&emsp;<br/><br/>'
+ '<b langtag="word-lastonlinetime"></b>: ' + row.LastOnlineTime + '&emsp;<br/><br/>'
+ '<b langtag="word-commandclient"></b>: ' + "<code>./npc{{.win}} -server={{.ip}}:{{.p}} -vkey=" + row.VerifyKey + " -type=" +{{.bridgeType}} +"</code>"
+ '<b langtag="word-commandclient"></b>: ' + "<code>./npc{{.win}} -server={{.ip}}:{{.p}} -vkey=" + row.VerifyKey + " -type=" +{{.bridgeType}} +"</code><br/>"
+ '<b langtag="word-commandclient-tls"></b>: ' + "<code>./npc{{.win}} -server={{.ip}}:{{.tls_p}} -vkey=" + row.VerifyKey + " -tls_enable=true</code>"
},
//表格的列
columns: [
Expand Down
2 changes: 1 addition & 1 deletion web/views/index/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<h5 langtag="word-connectionport"></h5>
</div>
<div class="ibox-content">
<h1 class="no-margins">{{.p}}</h1>
<h1 class="no-margins">{{.p1}}</h1>
</div>
</div>
</div>
Expand Down

0 comments on commit 91bcc55

Please sign in to comment.