3 * Functions for dealing with proxies
9 * Extracts the XFF string from the request header
10 * Note: headers are spoofable
12 * @deprecated in 1.19; use $wgRequest->getHeader( 'X-Forwarded-For' ) instead.
15 function wfGetForwardedFor() {
17 return $wgRequest->getHeader( 'X-Forwarded-For' );
21 * Returns the browser/OS data from the request header
22 * Note: headers are spoofable
24 * @deprecated in 1.18; use $wgRequest->getHeader( 'User-Agent' ) instead.
27 function wfGetAgent() {
28 wfDeprecated( __FUNCTION__
);
30 return $wgRequest->getHeader( 'User-Agent' );
34 * Work out the IP address based on various globals
35 * For trusted proxies, use the XFF client IP (first of the chain)
37 * @deprecated in 1.19; call $wgRequest->getIP() directly.
42 return $wgRequest->getIP();
46 * Checks if an IP is a trusted proxy providor
47 * Useful to tell if X-Fowarded-For data is possibly bogus
48 * Squid cache servers for the site and AOL are whitelisted
52 function wfIsTrustedProxy( $ip ) {
53 global $wgSquidServers, $wgSquidServersNoPurge;
55 $trusted = in_array( $ip, $wgSquidServers ) ||
56 in_array( $ip, $wgSquidServersNoPurge );
57 wfRunHooks( 'IsTrustedProxy', array( &$ip, &$trusted ) );
62 * Forks processes to scan the originating IP for an open proxy server
63 * MemCached can be used to skip IPs that have already been scanned
65 function wfProxyCheck() {
66 global $wgBlockOpenProxies, $wgProxyPorts, $wgProxyScriptPath;
67 global $wgMemc, $wgProxyMemcExpiry, $wgRequest;
70 if ( !$wgBlockOpenProxies ) {
74 $ip = $wgRequest->getIP();
77 $mcKey = wfMemcKey( 'proxy', 'ip', $ip );
78 $mcValue = $wgMemc->get( $mcKey );
79 $skip = (bool)$mcValue;
83 $title = SpecialPage
::getTitleFor( 'Blockme' );
84 $iphash = md5( $ip . $wgProxyKey );
85 $url = $title->getFullURL( 'ip='.$iphash );
87 foreach ( $wgProxyPorts as $port ) {
88 $params = implode( ' ', array(
89 escapeshellarg( $wgProxyScriptPath ),
90 escapeshellarg( $ip ),
91 escapeshellarg( $port ),
92 escapeshellarg( $url )
94 exec( "php $params >" . wfGetNull() . " 2>&1 &" );
97 $wgMemc->set( $mcKey, 1, $wgProxyMemcExpiry );