MediaWiki  REL1_19
ProxyTools.php
Go to the documentation of this file.
00001 <?php
00015 function wfGetForwardedFor() {
00016         wfDeprecated( __METHOD__, '1.19' );
00017         global $wgRequest;
00018         return $wgRequest->getHeader( 'X-Forwarded-For' );
00019 }
00020 
00028 function wfGetAgent() {
00029         wfDeprecated( __METHOD__, '1.18' );
00030         global $wgRequest;
00031         return $wgRequest->getHeader( 'User-Agent' );
00032 }
00033 
00041 function wfGetIP() {
00042         wfDeprecated( __METHOD__, '1.19' );
00043         global $wgRequest;
00044         return $wgRequest->getIP();
00045 }
00046 
00055 function wfIsTrustedProxy( $ip ) {
00056         global $wgSquidServers, $wgSquidServersNoPurge;
00057 
00058         $trusted = in_array( $ip, $wgSquidServers ) ||
00059                 in_array( $ip, $wgSquidServersNoPurge );
00060         wfRunHooks( 'IsTrustedProxy', array( &$ip, &$trusted ) );
00061         return $trusted;
00062 }
00063 
00068 function wfProxyCheck() {
00069         global $wgBlockOpenProxies, $wgProxyPorts, $wgProxyScriptPath;
00070         global $wgMemc, $wgProxyMemcExpiry, $wgRequest;
00071         global $wgProxyKey;
00072 
00073         if ( !$wgBlockOpenProxies ) {
00074                 return;
00075         }
00076 
00077         $ip = $wgRequest->getIP();
00078 
00079         # Get MemCached key
00080         $mcKey = wfMemcKey( 'proxy', 'ip', $ip );
00081         $mcValue = $wgMemc->get( $mcKey );
00082         $skip = (bool)$mcValue;
00083 
00084         # Fork the processes
00085         if ( !$skip ) {
00086                 $title = SpecialPage::getTitleFor( 'Blockme' );
00087                 $iphash = md5( $ip . $wgProxyKey );
00088                 $url = wfExpandUrl( $title->getFullURL( 'ip='.$iphash ), PROTO_HTTP );
00089 
00090                 foreach ( $wgProxyPorts as $port ) {
00091                         $params = implode( ' ', array(
00092                                                 escapeshellarg( $wgProxyScriptPath ),
00093                                                 escapeshellarg( $ip ),
00094                                                 escapeshellarg( $port ),
00095                                                 escapeshellarg( $url )
00096                                                 ));
00097                         exec( "php $params >" . wfGetNull() . " 2>&1 &" );
00098                 }
00099                 # Set MemCached key
00100                 $wgMemc->set( $mcKey, 1, $wgProxyMemcExpiry );
00101         }
00102 }