From ed1a361fd015f9cd95c3864e27b47f168046d388 Mon Sep 17 00:00:00 2001 From: yisier <1340976576@qq.com> Date: Thu, 23 Jan 2025 17:31:55 +0800 Subject: [PATCH] 0.26.22 --- README.md | 13 +++++++++++++ cmd/npc/npc.go | 15 +++++++++++++++ lib/common/util.go | 12 ++++++++++-- server/proxy/https.go | 32 +++++++++++++++++++++++++++++++- web/static/page/languages.xml | 4 ++-- web/views/index/hadd.html | 6 ++++-- web/views/index/hedit.html | 8 ++++++-- 7 files changed, 81 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 9de5e62..cea4cf1 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,21 @@ https://natnps.com/ ![image](image/new/payCode.png) +## 提示 +强烈推荐使用无配置文件模式启动客户端(删除掉npc.exe 目录下的`conf`文件夹即可),所有数据应该在服务端保存和配置,而客户端只做连接转发。客户端配置文件对小白极不友好,配置繁琐,容易出错。 +0.26.21 版本后的客户端,无需再通过命令行方式启动、安装、卸载客户端,直接双击运行,按照提示输入指令即可完成,非常方便。 + ## 更新日志 +- 2025-01-23 v0.26.22 + 优化: + - 客户端注册系统服务时,(新版客户端注册方式,非 install 命令) 将按照 `npc-[vkey].log` 格式保存日志,每个客户端VKEY单独一个日志文件,windows 日志位于 `npc.exe` 同级目录下,linux 位于 `/var/log/`目录。 + - 域名模式,HTTPS证书支持上传文件和文件路径,系统将自动识别路径还是证书内容。 [#175](https://github.com/yisier/nps/issues/175) + + 修复: + - ipv6地址显示不全 [#237](https://github.com/yisier/nps/issues/237) + + - 2025-01-07 v0.26.21 新增: - 客户端列表页面新增【快捷启动命令】,此命令为连接地址+链接秘钥的base64编码,方便一键启动、一键安装客户端。 diff --git a/cmd/npc/npc.go b/cmd/npc/npc.go index a9d35f2..cbea6d7 100644 --- a/cmd/npc/npc.go +++ b/cmd/npc/npc.go @@ -431,6 +431,21 @@ func systemPro(flag string, serAddr string, vkey string) { svcConfig.Arguments = append(svcConfig.Arguments, "-server="+serAddr) svcConfig.Arguments = append(svcConfig.Arguments, "-vkey="+vkey) svcConfig.Arguments = append(svcConfig.Arguments, "-debug=false") + + *logPath = common.GetNpcLogPath() + if common.IsWindows() { + *logPath = strings.Replace(*logPath, "\\", "\\\\", -1) + } + + *logPath = strings.Replace(*logPath, "npc.log", "npc-"+vkey+".log", -1) + svcConfig.Arguments = append(svcConfig.Arguments, "-log_path="+*logPath) + + logs.NewLogger() + logs.Reset() + logs.EnableFuncCallDepth(true) + logs.SetLogFuncCallDepth(3) + logs.SetLogger(logs.AdapterFile, `{"level":`+*logLevel+`,"filename":"`+*logPath+`","daily":false,"maxlines":100000,"color":true}`) + install.InstallNpc() err := service.Control(s, "install") if err != nil { diff --git a/lib/common/util.go b/lib/common/util.go index 8fbf473..27b249f 100755 --- a/lib/common/util.go +++ b/lib/common/util.go @@ -265,8 +265,16 @@ func FormatAddress(s string) string { // get address from the complete address func GetIpByAddr(addr string) string { - arr := strings.Split(addr, ":") - return arr[0] + // 如果是 IPv6 地址,可能的格式为[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:8080或[2001:0db8:85a3:0000:0000:8a2e:0370:7334] + // IPv4 地址,可能的格式为192.168.1.1:80或192.168.1.1 + // 截取地址 + if strings.Contains(addr, "[") { + addr = strings.Split(addr, "[")[1] + addr = strings.Split(addr, "]")[0] + } else { + addr = strings.Split(addr, ":")[0] + } + return addr } // get port from the complete address diff --git a/server/proxy/https.go b/server/proxy/https.go index 4e4d4f2..79af848 100644 --- a/server/proxy/https.go +++ b/server/proxy/https.go @@ -4,6 +4,7 @@ import ( "net" "net/http" "net/url" + "strings" "sync" "ehang.io/nps/lib/cache" @@ -48,7 +49,36 @@ func (https *HttpsServer) Start() error { https.handleHttps2(c, serverName, rb, r) } else { logs.Debug("使用上传证书") - https.cert(host, c, rb, host.CertFilePath, host.KeyFilePath) + + // 判断是路径还是证书,-----BEGIN 开头的为证书 + if strings.Contains(host.CertFilePath, "-----BEGIN") || strings.Contains(host.KeyFilePath, "-----BEGIN") { + logs.Debug("通过上传文件加载证书") + https.cert(host, c, rb, host.CertFilePath, host.KeyFilePath) + } else { + logs.Debug("通过路径加载证书") + if !common.FileExists(host.CertFilePath) || !common.FileExists(host.KeyFilePath) { + c.Close() + logs.Error("证书或秘钥文件不存在", host.KeyFilePath, host.CertFilePath) + return + } + + cert, err := common.ReadAllFromFile(host.CertFilePath) + if err != nil { + c.Close() + logs.Error("加载证书失败", err) + return + } + key, err := common.ReadAllFromFile(host.KeyFilePath) + if err != nil { + c.Close() + logs.Error("加载证书秘钥失败", err) + return + } + + https.cert(host, c, rb, string(cert), string(key)) + + } + } } }) diff --git a/web/static/page/languages.xml b/web/static/page/languages.xml index af91037..d65cc24 100644 --- a/web/static/page/languages.xml +++ b/web/static/page/languages.xml @@ -285,13 +285,13 @@ HTTP port - HTTPS 证书(pem格式) + HTTPS 证书(或证书路径) HTTPS cert HTTPS - HTTPS 密钥(key格式) + HTTPS 密钥(或秘钥路径) HTTPS key diff --git a/web/views/index/hadd.html b/web/views/index/hadd.html index 5feb7bb..10523f6 100644 --- a/web/views/index/hadd.html +++ b/web/views/index/hadd.html @@ -50,14 +50,16 @@
+ placeholder="请将证书文件拖拽或将内容复制粘贴到此处,证书文件格式为:xxxx_example.com.pem。 +或者配置证书文件路径。">
+ placeholder="请将私钥文件拖拽或复制粘贴到此处,证书秘钥格式为:xxxx_example.com.key。 +或者配置秘钥文件路径。">
diff --git a/web/views/index/hedit.html b/web/views/index/hedit.html index 20c7ba6..45f0d83 100644 --- a/web/views/index/hedit.html +++ b/web/views/index/hedit.html @@ -48,13 +48,17 @@
- +
- +