2005-03-31 09:10:25 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Functions for dealing with proxies
|
2010-08-14 17:42:40 +00:00
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @file
|
2005-03-31 09:10:25 +00:00
|
|
|
*/
|
|
|
|
|
|
2007-04-23 18:06:37 +00:00
|
|
|
/**
|
|
|
|
|
* Extracts the XFF string from the request header
|
|
|
|
|
* Note: headers are spoofable
|
2011-08-18 20:03:30 +00:00
|
|
|
*
|
|
|
|
|
* @deprecated in 1.19; use $wgRequest->getHeader( 'X-Forwarded-For' ) instead.
|
2007-04-23 18:06:37 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2006-06-01 08:19:02 +00:00
|
|
|
function wfGetForwardedFor() {
|
2011-12-13 19:51:03 +00:00
|
|
|
wfDeprecated( __METHOD__, '1.19' );
|
2011-08-18 20:03:30 +00:00
|
|
|
global $wgRequest;
|
|
|
|
|
return $wgRequest->getHeader( 'X-Forwarded-For' );
|
2007-02-12 01:02:35 +00:00
|
|
|
}
|
|
|
|
|
|
2007-04-23 18:06:37 +00:00
|
|
|
/**
|
|
|
|
|
* Returns the browser/OS data from the request header
|
|
|
|
|
* Note: headers are spoofable
|
2011-06-03 10:41:53 +00:00
|
|
|
*
|
2011-07-18 23:01:08 +00:00
|
|
|
* @deprecated in 1.18; use $wgRequest->getHeader( 'User-Agent' ) instead.
|
2007-04-23 18:06:37 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2007-02-12 01:02:35 +00:00
|
|
|
function wfGetAgent() {
|
2011-12-13 19:51:03 +00:00
|
|
|
wfDeprecated( __METHOD__, '1.18' );
|
2011-08-18 20:03:30 +00:00
|
|
|
global $wgRequest;
|
|
|
|
|
return $wgRequest->getHeader( 'User-Agent' );
|
2006-06-01 08:19:02 +00:00
|
|
|
}
|
2006-01-07 21:44:10 +00:00
|
|
|
|
2007-04-23 18:06:37 +00:00
|
|
|
/**
|
|
|
|
|
* Work out the IP address based on various globals
|
|
|
|
|
* For trusted proxies, use the XFF client IP (first of the chain)
|
2011-08-18 20:03:30 +00:00
|
|
|
*
|
|
|
|
|
* @deprecated in 1.19; call $wgRequest->getIP() directly.
|
2007-04-23 18:06:37 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2011-08-18 20:03:30 +00:00
|
|
|
function wfGetIP() {
|
2011-12-13 19:51:03 +00:00
|
|
|
wfDeprecated( __METHOD__, '1.19' );
|
2011-08-18 20:03:30 +00:00
|
|
|
global $wgRequest;
|
|
|
|
|
return $wgRequest->getIP();
|
2006-06-01 08:19:02 +00:00
|
|
|
}
|
|
|
|
|
|
2007-04-23 18:06:37 +00:00
|
|
|
/**
|
2011-08-18 21:04:29 +00:00
|
|
|
* Checks if an IP is a trusted proxy providor.
|
|
|
|
|
* Useful to tell if X-Fowarded-For data is possibly bogus.
|
|
|
|
|
* Squid cache servers for the site are whitelisted.
|
|
|
|
|
*
|
2009-12-11 22:19:37 +00:00
|
|
|
* @param $ip String
|
2007-04-23 18:06:37 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2006-11-25 16:24:44 +00:00
|
|
|
function wfIsTrustedProxy( $ip ) {
|
|
|
|
|
global $wgSquidServers, $wgSquidServersNoPurge;
|
|
|
|
|
|
2011-04-25 21:25:45 +00:00
|
|
|
$trusted = in_array( $ip, $wgSquidServers ) ||
|
|
|
|
|
in_array( $ip, $wgSquidServersNoPurge );
|
2006-11-25 16:24:44 +00:00
|
|
|
wfRunHooks( 'IsTrustedProxy', array( &$ip, &$trusted ) );
|
|
|
|
|
return $trusted;
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-01 08:19:02 +00:00
|
|
|
/**
|
|
|
|
|
* Forks processes to scan the originating IP for an open proxy server
|
|
|
|
|
* MemCached can be used to skip IPs that have already been scanned
|
|
|
|
|
*/
|
|
|
|
|
function wfProxyCheck() {
|
|
|
|
|
global $wgBlockOpenProxies, $wgProxyPorts, $wgProxyScriptPath;
|
2011-08-18 20:03:30 +00:00
|
|
|
global $wgMemc, $wgProxyMemcExpiry, $wgRequest;
|
2008-09-03 02:28:41 +00:00
|
|
|
global $wgProxyKey;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2006-06-01 08:19:02 +00:00
|
|
|
if ( !$wgBlockOpenProxies ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2005-09-05 02:22:20 +00:00
|
|
|
|
2011-08-18 20:03:30 +00:00
|
|
|
$ip = $wgRequest->getIP();
|
2006-06-01 07:22:49 +00:00
|
|
|
|
2006-06-01 08:19:02 +00:00
|
|
|
# Get MemCached key
|
2008-03-01 15:08:49 +00:00
|
|
|
$mcKey = wfMemcKey( 'proxy', 'ip', $ip );
|
|
|
|
|
$mcValue = $wgMemc->get( $mcKey );
|
|
|
|
|
$skip = (bool)$mcValue;
|
2005-09-05 02:22:20 +00:00
|
|
|
|
2006-06-01 08:19:02 +00:00
|
|
|
# Fork the processes
|
|
|
|
|
if ( !$skip ) {
|
2006-10-30 06:25:31 +00:00
|
|
|
$title = SpecialPage::getTitleFor( 'Blockme' );
|
2008-09-03 02:28:41 +00:00
|
|
|
$iphash = md5( $ip . $wgProxyKey );
|
2011-08-19 17:31:40 +00:00
|
|
|
$url = wfExpandUrl( $title->getFullURL( 'ip='.$iphash ), PROTO_HTTP );
|
2006-06-01 08:19:02 +00:00
|
|
|
|
|
|
|
|
foreach ( $wgProxyPorts as $port ) {
|
|
|
|
|
$params = implode( ' ', array(
|
|
|
|
|
escapeshellarg( $wgProxyScriptPath ),
|
|
|
|
|
escapeshellarg( $ip ),
|
|
|
|
|
escapeshellarg( $port ),
|
|
|
|
|
escapeshellarg( $url )
|
|
|
|
|
));
|
2009-08-25 15:47:46 +00:00
|
|
|
exec( "php $params >" . wfGetNull() . " 2>&1 &" );
|
2006-06-01 08:19:02 +00:00
|
|
|
}
|
|
|
|
|
# Set MemCached key
|
2008-03-01 15:08:49 +00:00
|
|
|
$wgMemc->set( $mcKey, 1, $wgProxyMemcExpiry );
|
2005-12-01 10:37:47 +00:00
|
|
|
}
|
2006-06-01 08:19:02 +00:00
|
|
|
}
|