support for second-tier squids in the ip parsing function
authorGabriel Wicke <gwicke@users.mediawiki.org>
Mon, 8 Mar 2004 18:44:20 +0000 (18:44 +0000)
committerGabriel Wicke <gwicke@users.mediawiki.org>
Mon, 8 Mar 2004 18:44:20 +0000 (18:44 +0000)
includes/Setup.php

index d39465d..d7fc9da 100644 (file)
@@ -20,14 +20,20 @@ if ( $wgProfiling and (0 == rand() % $wgProfileSampleRate ) ) {
 
 
 /* collect the originating ips */
-$wgIP = getenv("REMOTE_ADDR");
 if( $wgUseSquid && isset( $_SERVER["HTTP_X_FORWARDED_FOR"] ) ) {
        # If the web server is behind a reverse proxy, we need to find
        # out where our requests are really coming from.
-       $wgIP = trim( preg_replace( "/^(.*, )?([^,]+)$/", "$2",
-               $_SERVER['HTTP_X_FORWARDED_FOR'] ) );
+       $hopips = split(', ', $_SERVER['HTTP_X_FORWARDED_FOR'] );
+
+       while(in_array(trim(end($hopips)), $wgSquidServers)){
+               array_pop($hopips);
+       }
+       $wgIP = trim(end($hopips));
+} else {
+       $wgIP = getenv("REMOTE_ADDR");
 }
 
+
 $fname = "Setup.php";
 wfProfileIn( $fname );
 global $wgUseDynamicDates;