From 8f5d64dd2c21c65fee3b7d6464dedf21f55fca5e Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Mon, 12 Feb 2007 01:02:35 +0000 Subject: [PATCH] * Added useragent and an xff function and header --- includes/ProxyTools.php | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/includes/ProxyTools.php b/includes/ProxyTools.php index 683b6d6f04..d957f380b9 100644 --- a/includes/ProxyTools.php +++ b/includes/ProxyTools.php @@ -8,10 +8,56 @@ function wfGetForwardedFor() { // More reliable than $_SERVER due to case and -/_ folding $set = apache_request_headers(); $index = 'X-Forwarded-For'; + $index2 = '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]; + } else if( isset( $set[$index2] ) ) { + return $set[$index2]; + } else { + return null; + } +} + +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 + $n = strrpos( $xff, ',' ); + if ( strrpos !== false ) { + $last = 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_ip); + if ( $m > 0 ) + $xff_ip = $last_ip; + else + $xff_ip = null; + } 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 + $set = apache_request_headers(); + $index = 'User-Agent'; + } else { + // Subject to spoofing with headers like X_Forwarded_For + $set = $_SERVER; + $index = 'HTTP_USER_AGENT'; } if( isset( $set[$index] ) ) { return $set[$index]; -- 2.20.1