11 / getRemoteIp - priorityHeader

11 / getRemoteIp - priorityHeader from env
This commit is contained in:
serogaq 2024-12-11 17:15:34 +03:00
parent 7a8a2a1388
commit f3b7e3cc6d
No known key found for this signature in database
GPG key ID: 6657A27160536D7E
3 changed files with 17 additions and 2 deletions

View file

@ -9,4 +9,5 @@ XUI_VLESS_SNI=""
#XUI_SUB_SUPPORT_URL="" #XUI_SUB_SUPPORT_URL=""
#XUI_SUB_PROFILE_WEB_PAGE_URL="" #XUI_SUB_PROFILE_WEB_PAGE_URL=""
#XUI_DEBUG="false" #XUI_DEBUG="false"
#XUI_LOG_LEVEL="info" #XUI_LOG_LEVEL="info"
#XUI_GETREMOTEIP_PRIORITY_HEADER=""

View file

@ -51,6 +51,7 @@ services:
XUI_SUB_PROFILE_TITLE: "${XUI_SUB_PROFILE_TITLE:-}" XUI_SUB_PROFILE_TITLE: "${XUI_SUB_PROFILE_TITLE:-}"
XUI_SUB_SUPPORT_URL: "${XUI_SUB_SUPPORT_URL:-}" XUI_SUB_SUPPORT_URL: "${XUI_SUB_SUPPORT_URL:-}"
XUI_SUB_PROFILE_WEB_PAGE_URL: "${XUI_SUB_PROFILE_WEB_PAGE_URL:-}" XUI_SUB_PROFILE_WEB_PAGE_URL: "${XUI_SUB_PROFILE_WEB_PAGE_URL:-}"
XUI_GETREMOTEIP_PRIORITY_HEADER: "${XUI_GETREMOTEIP_PRIORITY_HEADER:-}"
XUI_DEBUG: "${XUI_DEBUG:-false}" XUI_DEBUG: "${XUI_DEBUG:-false}"
XUI_LOG_LEVEL: "${XUI_LOG_LEVEL:-info}" XUI_LOG_LEVEL: "${XUI_LOG_LEVEL:-info}"
tty: true tty: true

View file

@ -3,6 +3,7 @@ package controller
import ( import (
"net" "net"
"net/http" "net/http"
"os"
"strings" "strings"
"x-ui/config" "x-ui/config"
@ -13,7 +14,19 @@ import (
) )
func getRemoteIp(c *gin.Context) string { func getRemoteIp(c *gin.Context) string {
value := c.GetHeader("X-Real-IP") var value string
priorityHeader := os.Getenv("XUI_GETREMOTEIP_PRIORITY_HEADER")
if priorityHeader != "" {
value = c.GetHeader(priorityHeader)
if strings.Contains(value, ",") {
ips := strings.Split(value, ",")
value = ips[0]
}
if value != "" {
return value
}
}
value = c.GetHeader("X-Real-IP")
if value != "" { if value != "" {
return value return value
} }