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 are whitelisted.
53 function wfIsTrustedProxy( $ip ) {
54 global $wgSquidServers, $wgSquidServersNoPurge;
56 $trusted = in_array( $ip, $wgSquidServers ) ||
57 in_array( $ip, $wgSquidServersNoPurge );
58 wfRunHooks( 'IsTrustedProxy', array( &$ip, &$trusted ) );
63 * Forks processes to scan the originating IP for an open proxy server
64 * MemCached can be used to skip IPs that have already been scanned
66 function wfProxyCheck() {
67 global $wgBlockOpenProxies, $wgProxyPorts, $wgProxyScriptPath;
68 global $wgMemc, $wgProxyMemcExpiry, $wgRequest;
71 if ( !$wgBlockOpenProxies ) {
75 $ip = $wgRequest->getIP();
78 $mcKey = wfMemcKey( 'proxy', 'ip', $ip );
79 $mcValue = $wgMemc->get( $mcKey );
80 $skip = (bool)$mcValue;
84 $title = SpecialPage
::getTitleFor( 'Blockme' );
85 $iphash = md5( $ip . $wgProxyKey );
86 $url = wfExpandUrl( $title->getFullURL( 'ip='.$iphash ), PROTO_HTTP
);
88 foreach ( $wgProxyPorts as $port ) {
89 $params = implode( ' ', array(
90 escapeshellarg( $wgProxyScriptPath ),
91 escapeshellarg( $ip ),
92 escapeshellarg( $port ),
93 escapeshellarg( $url )
95 exec( "php $params >" . wfGetNull() . " 2>&1 &" );
98 $wgMemc->set( $mcKey, 1, $wgProxyMemcExpiry );