IP授权功能优化
This commit is contained in:
@@ -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:
|
||||
|
||||
+24
-5
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -762,8 +762,8 @@
|
||||
</lang>
|
||||
|
||||
<lang id="info-servertips">
|
||||
<zh-CN>客户端命令地址显示、隧道访问显示、白名单IP认证地址</zh-CN>
|
||||
<en-US>Server URL, Tunnel Access, White IP Authentication URL</en-US>
|
||||
<zh-CN>客户端命令地址显示、隧道访问显示</zh-CN>
|
||||
<en-US>Server URL, Tunnel Access</en-US>
|
||||
</lang>
|
||||
|
||||
<lang id="info-suchasblackiplist">
|
||||
|
||||
Reference in New Issue
Block a user