Revert r21158 and r21159 -- clearly broken code.
authorBrion Vibber <brion@users.mediawiki.org>
Wed, 18 Apr 2007 18:53:54 +0000 (18:53 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Wed, 18 Apr 2007 18:53:54 +0000 (18:53 +0000)
wfGetClientIPfromXFF() uses undeclared variables -- it will never return a non-null value, but will in most cases trigger PHP notices about accessing unused variables.
It's also not documented as to what it does or how it's supposed to differ from the functions above it.
Please document, rewrite, and test this function if it is required.

includes/ProxyTools.php

index 646f6b5..fcd6a90 100644 (file)
@@ -27,18 +27,18 @@ function wfGetForwardedFor() {
 
 function wfGetLastIPfromXFF( $xff ) {
        if ( $xff ) {
-               // Avoid annoyingly long xff hacks
-               $xff = substr( $xff, 0, 511 );
+       // Avoid annoyingly long xff hacks
+               $xff = substr( $xff, 0, 255 );
                // Look for the last IP, assuming they are separated by commas or spaces
-               $s = ( strrpos($xff, ',') ) ? strrpos($xff, ',') : strrpos($xff, ' ');
-               if ( $s !== false ) {
-                       $last = trim( substr( $xff, $s + 1 ) );
+               $n = ( strrpos($xff, ',') ) ? strrpos($xff, ',') : strrpos($xff, ' ');
+               if ( strrpos !== false ) {
+                       $last = trim( substr( $xff, $n + 1 ) );
                        // Make sure it is an IP
                        $m = preg_match('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#', $last, $last_ip4);
                        $n = preg_match('#:(:[0-9A-Fa-f]{1,4}){1,7}|[0-9A-Fa-f]{1,4}(:{1,2}[0-9A-Fa-f]{1,4}|::$){1,7}#', $last, $last_ip6);
-                       if ( $m )
+                       if ( $m > 0 )
                                $xff_ip = $last_ip4;
-                       else if ( $n ) 
+                       else if ( $n > 0 
                                $xff_ip = $last_ip6;
                        else 
                                $xff_ip = null;
@@ -51,25 +51,6 @@ function wfGetLastIPfromXFF( $xff ) {
        return $xff_ip;
 }
 
-function wfGetClientIPfromXFF( $xff ) {
-       if ( $xff ) {
-               // Avoid annoyingly long xff hacks
-               $xff = substr( $xff, 0, 511 );
-               // Look for the first IP
-               $m = preg_match('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#', $xff, $first_ip);
-               $n = preg_match('#:(:[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, $first_ip);
-               if ( $m )
-                       $xff_ip = $first_ip4;
-               else if ( $n ) 
-                       $xff_ip = $first_ip6;
-               else 
-                       $xff_ip = null;
-       } else {
-               $xff_ip = null;
-       }
-       return $xff_ip;
-}
-
 function wfGetAgent() {
        if( function_exists( 'apache_request_headers' ) ) {
                // More reliable than $_SERVER due to case and -/_ folding