Просмотр исходного кода

Added support for CF-Connecting-IP

Toby Chui 11 месяцев назад
Родитель
Сommit
77c1c6d5b4
3 измененных файлов с 15 добавлено и 4 удалено
  1. 1 1
      main.go
  2. 13 2
      mod/dynamicproxy/dpcore/dpcore.go
  3. 1 1
      reverseproxy.go

+ 1 - 1
main.go

@@ -52,7 +52,7 @@ var (
 	name        = "Zoraxy"
 	version     = "3.0.1"
 	nodeUUID    = "generic"
-	development = true //Set this to false to use embedded web fs
+	development = false //Set this to false to use embedded web fs
 	bootTime    = time.Now().Unix()
 
 	/*

+ 13 - 2
mod/dynamicproxy/dpcore/dpcore.go

@@ -298,8 +298,19 @@ func addXForwardedForHeader(req *http.Request) {
 		}
 
 		if req.Header.Get("X-Real-Ip") == "" {
-			//Not exists. Fill it in with client IP
-			req.Header.Set("X-Real-Ip", clientIP)
+			//Check if CF-Connecting-IP header exists
+			CF_Connecting_IP := req.Header.Get("CF-Connecting-IP")
+			if CF_Connecting_IP != "" {
+				//Use CF Connecting IP
+				req.Header.Set("X-Real-Ip", CF_Connecting_IP)
+			} else {
+				// Not exists. Fill it in with first entry in X-Forwarded-For
+				ips := strings.Split(clientIP, ",")
+				if len(ips) > 0 {
+					req.Header.Set("X-Real-Ip", strings.TrimSpace(ips[0]))
+				}
+			}
+
 		}
 
 	}

+ 1 - 1
reverseproxy.go

@@ -896,7 +896,7 @@ func HandleIncomingPortSet(w http.ResponseWriter, r *http.Request) {
 	}
 
 	proxyRoot := strings.TrimSuffix(dynamicProxyRouter.Root.Domain, "/")
-	if strings.HasPrefix(proxyRoot, "localhost:"+strconv.Itoa(newIncomingPortInt)) || strings.HasPrefix(proxyRoot, "127.0.0.1:"+strconv.Itoa(newIncomingPortInt)) {
+	if strings.EqualFold(proxyRoot, "localhost:"+strconv.Itoa(newIncomingPortInt)) || strings.EqualFold(proxyRoot, "127.0.0.1:"+strconv.Itoa(newIncomingPortInt)) {
 		//Listening port is same as proxy root
 		//Not allow recursive settings
 		utils.SendErrorResponse(w, "Recursive listening port! Check your proxy root settings.")