diff --git a/README.md b/README.md
index d3130e4..208a485 100644
--- a/README.md
+++ b/README.md
@@ -27,6 +27,12 @@ https://natnps.com/
# 更新日志
+- 2025-12-06 v0.26.28
+ -【全局参数】页面新增`服务地址`配置项,用于客户端命令地址显示、隧道访问地址显示 [293](https://github.com/yisier/nps/issues/293)。
+ -【IP授权功能优化】,通过穿透的端口去提交 IP 认证,感谢 [Aqamoe](https://github.com/Aqamoe) 的建议 [291](https://github.com/yisier/nps/issues/291)。
+ -【重构限速器实现】提升性能和准确性
+
+
- 2025-11-05 v0.26.27
新增:
- 1.客户端新增【IP白名单】,可通过两种方式添加IP:
diff --git a/lib/goroutine/pool.go b/lib/goroutine/pool.go
index e4648bc..8c4c338 100644
--- a/lib/goroutine/pool.go
+++ b/lib/goroutine/pool.go
@@ -74,9 +74,16 @@ func CopyBuffer(dst io.Writer, src io.Reader, flow *file.Flow, task *file.Tunnel
}
firstLine := lines[0]
- if strings.HasPrefix(firstLine, "POST /authIp?pass=") {
- pass := strings.Split(firstLine, " ")[1]
- pass = strings.ReplaceAll(pass, "/authIp?pass=", "")
+ // 优先处理客户端直接访问的 POST /authIp 请求,直接响应给客户端,不经隧道转发
+ if strings.HasPrefix(firstLine, "POST /authIp") {
+ pass := ""
+ parts := strings.Split(firstLine, " ")
+ if len(parts) > 1 {
+ path := parts[1]
+ if strings.Contains(path, "/authIp?pass=") {
+ pass = strings.ReplaceAll(path, "/authIp?pass=", "")
+ }
+ }
if pass == task.Client.IpWhitePass {
task.Client.IpWhiteList = append(task.Client.IpWhiteList, ip)
file.GetDb().UpdateClient(task.Client)
@@ -87,12 +94,24 @@ func CopyBuffer(dst io.Writer, src io.Reader, flow *file.Flow, task *file.Tunnel
jsonBytes, err = json.Marshal(map[string]interface{}{"success": false, "message": "密码错误"})
}
response := fmt.Sprintf("HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: %d\r\nConnection: close\r\n\r\n%s", len(jsonBytes), jsonBytes)
- dst.Write([]byte(response))
+ // 如果 src 是真实的客户端连接(net.Conn),直接写回客户端并关闭连接,避免走隧道转发
+ if connSrc, ok := src.(net.Conn); ok {
+ connSrc.Write([]byte(response))
+ connSrc.Close()
+ } else {
+ dst.Write([]byte(response))
+ }
return
}
+ // 非授权IP,返回授权页面(同样优先返回给客户端)
response := fmt.Sprintf("HTTP/1.1 401 Unauthorized\r\nContent-Type: text/html; charset=utf-8\r\nContent-Length: %d\r\nConnection: close\r\n\r\n%s", len(authHtml), authHtml)
- dst.Write([]byte(response))
+ if connSrc, ok := src.(net.Conn); ok {
+ connSrc.Write([]byte(response))
+ connSrc.Close()
+ } else {
+ dst.Write([]byte(response))
+ }
return
}
}
diff --git a/web/static/page/languages.xml b/web/static/page/languages.xml
index 1f5444f..54be2fa 100644
--- a/web/static/page/languages.xml
+++ b/web/static/page/languages.xml
@@ -762,8 +762,8 @@
- 客户端命令地址显示、隧道访问显示、白名单IP认证地址
- Server URL, Tunnel Access, White IP Authentication URL
+ 客户端命令地址显示、隧道访问显示
+ Server URL, Tunnel Access