2005-03-31 09:10:25 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2012-05-11 08:34:29 +00:00
|
|
|
* Functions for dealing with proxies.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
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 ) {
|
2012-02-21 22:00:58 +00:00
|
|
|
$trusted = wfIsConfiguredProxy( $ip );
|
|
|
|
|
wfRunHooks( 'IsTrustedProxy', array( &$ip, &$trusted ) );
|
|
|
|
|
return $trusted;
|
|
|
|
|
}
|
2006-11-25 16:24:44 +00:00
|
|
|
|
2012-02-21 22:00:58 +00:00
|
|
|
/**
|
|
|
|
|
* Checks if an IP matches a proxy we've configured.
|
|
|
|
|
* @param $ip String
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
function wfIsConfiguredProxy( $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
|
|
|
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
|
|
|
}
|