German localisation updates, patch by ray.
[lhc/web/wiklou.git] / includes / ProxyTools.php
index ad5b22c..534ebbc 100644 (file)
 function wfGetForwardedFor() {
        if( function_exists( 'apache_request_headers' ) ) {
                // More reliable than $_SERVER due to case and -/_ folding
-               $set = apache_request_headers();
-               $index = 'X-Forwarded-For';
-               $index2 = 'Client-ip';
+               $set = array ();
+               foreach ( apache_request_headers() as $tempName => $tempValue ) {
+                       $set[ strtoupper( $tempName ) ] = $tempValue;
+               }
+               $index = strtoupper ( 'X-Forwarded-For' );
+               $index2 = strtoupper ( 'Client-ip' );
        } else {
                // Subject to spoofing with headers like X_Forwarded_For
                $set = $_SERVER;
                $index = 'HTTP_X_FORWARDED_FOR';
                $index2 = 'CLIENT-IP';
        }
+
        #Try a couple of headers
        if( isset( $set[$index] ) ) {
                return $set[$index];
@@ -31,25 +35,6 @@ function wfGetForwardedFor() {
        }
 }
 
-/**
- * Locates the client IP within a given XFF string
- * @param string $xff
- * @return string
- */
-function wfGetClientIPfromXFF( $xff ) {
-       if ( !$xff ) return null;
-       $xff = substr( $xff, 0, 511 );
-       // Just look for the first IP match
-       // We might have a mix of IPv4/IPv6
-       if ( preg_match('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|:(:[0-9A-Fa-f]{1,4}){1,7}|[0-9A-Fa-f]{1,4}(:{1,2}[0-9A-Fa-f]{1,4}|::$){1,7}#', $xff, $ip) ) {       
-               // Check if the numbers are valid
-               if ( IP::isIPAddress($ip) )
-                  return $ip;
-       }
-       
-       return null;
-}
-
 /**
  * Returns the browser/OS data from the request header
  * Note: headers are spoofable
@@ -58,8 +43,11 @@ function wfGetClientIPfromXFF( $xff ) {
 function wfGetAgent() {
        if( function_exists( 'apache_request_headers' ) ) {
                // More reliable than $_SERVER due to case and -/_ folding
-               $set = apache_request_headers();
-               $index = 'User-Agent';
+               $set = array ();
+               foreach ( apache_request_headers() as $tempName => $tempValue ) {
+                       $set[ strtoupper( $tempName ) ] = $tempValue;
+               }
+               $index = strtoupper ( 'User-Agent' );
        } else {
                // Subject to spoofing with headers like X_Forwarded_For
                $set = $_SERVER;
@@ -102,7 +90,7 @@ function wfGetIP() {
                $xff = array_reverse( $xff );
                $ipchain = array_merge( $ipchain, $xff );
        }
-       
+
        # Step through XFF list and find the last address in the list which is a trusted server
        # Set $ip to the IP address given by that trusted server, unless the address is not sensible (e.g. private)
        foreach ( $ipchain as $i => $curIP ) {
@@ -131,9 +119,9 @@ function wfGetIP() {
 function wfIsTrustedProxy( $ip ) {
        global $wgSquidServers, $wgSquidServersNoPurge;
 
-       if ( in_array( $ip, $wgSquidServers ) || 
-               in_array( $ip, $wgSquidServersNoPurge ) || 
-               wfIsAOLProxy( $ip ) 
+       if ( in_array( $ip, $wgSquidServers ) ||
+               in_array( $ip, $wgSquidServersNoPurge ) ||
+               wfIsAOLProxy( $ip )
        ) {
                $trusted = true;
        } else {
@@ -149,7 +137,7 @@ function wfIsTrustedProxy( $ip ) {
  */
 function wfProxyCheck() {
        global $wgBlockOpenProxies, $wgProxyPorts, $wgProxyScriptPath;
-       global $wgUseMemCached, $wgMemc, $wgProxyMemcExpiry;
+       global $wgMemc, $wgProxyMemcExpiry;
        global $wgProxyKey;
 
        if ( !$wgBlockOpenProxies ) {
@@ -159,14 +147,9 @@ function wfProxyCheck() {
        $ip = wfGetIP();
 
        # Get MemCached key
-       $skip = false;
-       if ( $wgUseMemCached ) {
-               $mcKey = wfMemcKey( 'proxy', 'ip', $ip );
-               $mcValue = $wgMemc->get( $mcKey );
-               if ( $mcValue ) {
-                       $skip = true;
-               }
-       }
+       $mcKey = wfMemcKey( 'proxy', 'ip', $ip );
+       $mcValue = $wgMemc->get( $mcKey );
+       $skip = (bool)$mcValue;
 
        # Fork the processes
        if ( !$skip ) {
@@ -184,9 +167,7 @@ function wfProxyCheck() {
                        exec( "php $params &>/dev/null &" );
                }
                # Set MemCached key
-               if ( $wgUseMemCached ) {
-                       $wgMemc->set( $mcKey, 1, $wgProxyMemcExpiry );
-               }
+               $wgMemc->set( $mcKey, 1, $wgProxyMemcExpiry );
        }
 }
 
@@ -276,7 +257,3 @@ function wfIsAOLProxy( $ip ) {
        }
        return false;
 }
-
-
-
-?>