From: Brion Vibber Date: Tue, 24 Apr 2007 14:31:52 +0000 (+0000) Subject: Reverting more fucked up untested code from r21448 and r21449 X-Git-Tag: 1.31.0-rc.0~53250 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/One?a=commitdiff_plain;h=cc8e3c5a4b4b68f13c55b2317e90acfa6aae1dbc;p=lhc%2Fweb%2Fwiklou.git Reverting more fucked up untested code from r21448 and r21449 --- diff --git a/includes/ProxyTools.php b/includes/ProxyTools.php index ad5b22c794..eff02682e8 100644 --- a/includes/ProxyTools.php +++ b/includes/ProxyTools.php @@ -32,22 +32,32 @@ function wfGetForwardedFor() { } /** - * Locates the client IP within a given XFF string - * @param string $xff - * @return string + * @todo FUCKING DOCUMENT THIS FUCKING FUNCTION */ -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; +function wfGetLastIPfromXFF( $xff ) { + if ( $xff ) { + // Avoid annoyingly long xff hacks + $xff = substr( $xff, 0, 255 ); + // Look for the last IP, assuming they are separated by commas or spaces + $n = ( strrpos($xff, ',') ) ? strrpos($xff, ',') : strrpos($xff, ' '); + if ( $n !== 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); + $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); + if ( $m > 0 ) + $xff_ip = $last; + else if ( $n > 0 ) + $xff_ip = $last; + else + $xff_ip = null; + } else { + $xff_ip = null; + } + } else { + $xff_ip = null; } - - return null; + return $xff_ip; } /**