MediaWiki  REL1_21
ProxyTools.php
Go to the documentation of this file.
00001 <?php
00030 function wfGetForwardedFor() {
00031         wfDeprecated( __METHOD__, '1.19' );
00032         global $wgRequest;
00033         return $wgRequest->getHeader( 'X-Forwarded-For' );
00034 }
00035 
00043 function wfGetAgent() {
00044         wfDeprecated( __METHOD__, '1.18' );
00045         global $wgRequest;
00046         return $wgRequest->getHeader( 'User-Agent' );
00047 }
00048 
00056 function wfGetIP() {
00057         wfDeprecated( __METHOD__, '1.19' );
00058         global $wgRequest;
00059         return $wgRequest->getIP();
00060 }
00061 
00070 function wfIsTrustedProxy( $ip ) {
00071         $trusted = wfIsConfiguredProxy( $ip );
00072         wfRunHooks( 'IsTrustedProxy', array( &$ip, &$trusted ) );
00073         return $trusted;
00074 }
00075 
00081 function wfIsConfiguredProxy( $ip ) {
00082         global $wgSquidServers, $wgSquidServersNoPurge;
00083         $trusted = in_array( $ip, $wgSquidServers ) ||
00084                 in_array( $ip, $wgSquidServersNoPurge );
00085         return $trusted;
00086 }
00087 
00092 function wfProxyCheck() {
00093         global $wgBlockOpenProxies, $wgProxyPorts, $wgProxyScriptPath;
00094         global $wgMemc, $wgProxyMemcExpiry, $wgRequest;
00095         global $wgProxyKey;
00096 
00097         if ( !$wgBlockOpenProxies ) {
00098                 return;
00099         }
00100 
00101         $ip = $wgRequest->getIP();
00102 
00103         # Get MemCached key
00104         $mcKey = wfMemcKey( 'proxy', 'ip', $ip );
00105         $mcValue = $wgMemc->get( $mcKey );
00106         $skip = (bool)$mcValue;
00107 
00108         # Fork the processes
00109         if ( !$skip ) {
00110                 $title = SpecialPage::getTitleFor( 'Blockme' );
00111                 $iphash = md5( $ip . $wgProxyKey );
00112                 $url = wfExpandUrl( $title->getFullURL( 'ip=' . $iphash ), PROTO_HTTP );
00113 
00114                 foreach ( $wgProxyPorts as $port ) {
00115                         $params = implode( ' ', array(
00116                                                 escapeshellarg( $wgProxyScriptPath ),
00117                                                 escapeshellarg( $ip ),
00118                                                 escapeshellarg( $port ),
00119                                                 escapeshellarg( $url )
00120                                                 ));
00121                         exec( "php $params >" . wfGetNull() . " 2>&1 &" );
00122                 }
00123                 # Set MemCached key
00124                 $wgMemc->set( $mcKey, 1, $wgProxyMemcExpiry );
00125         }
00126 }