feat: 连接列表显示客户端真实 IP,支持反代和 CDN 场景
新增可配置的 real_ip_headers(默认 CF-Connecting-IP > X-Real-IP > X-Forwarded-For 降级取值),trusted_proxies 用于 gin 代理信任链。 WebSocket 连接建立时捕获真实 IP 并在 /profile 和 /admin 连接列表展示, 登录会话 IP 同步改用真实 IP。
This commit is contained in:
@@ -80,7 +80,7 @@ func Login(c *gin.Context) {
|
||||
session := model.Session{
|
||||
SessionID: sessionID,
|
||||
UserID: user.ID,
|
||||
IP: c.ClientIP(),
|
||||
IP: middleware.GetRealIP(c),
|
||||
UserAgent: c.GetHeader("User-Agent"),
|
||||
ExpiresAt: time.Now().Add(24 * time.Hour),
|
||||
}
|
||||
|
||||
@@ -211,6 +211,7 @@ func UpdateVpnSettings(c *gin.Context) {
|
||||
type myVpnConnection struct {
|
||||
IP string `json:"ip"`
|
||||
IP6 string `json:"ip6,omitempty"`
|
||||
RealIP string `json:"real_ip"`
|
||||
ConnectedAt string `json:"connected_at"`
|
||||
}
|
||||
|
||||
@@ -232,6 +233,7 @@ func GetMyVpnConnections(c *gin.Context) {
|
||||
connections = append(connections, myVpnConnection{
|
||||
IP: ci.IP,
|
||||
IP6: ci.IP6,
|
||||
RealIP: ci.RealIP,
|
||||
ConnectedAt: ci.ConnectedAt,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user