* @return string
*/
function wfGetIP() {
- global $wgIP, $wgUsePrivateIPs;
+ global $wgIP, $wgUsePrivateIPs, $wgCommandLineMode;
# Return cached result
if ( !empty( $wgIP ) ) {
return $wgIP;
}
+ $ipchain = array();
+ $ip = false;
+
/* collect the originating ips */
# Client connecting to this webserver
- if ( isset( $_SERVER['REMOTE_ADDR'] ) && IP::canonicalize( $_SERVER['REMOTE_ADDR'] ) ) {
- $ipchain = array( IP::canonicalize( $_SERVER['REMOTE_ADDR'] ) );
- } else {
- # Running on CLI or REMOTE_ADDR is broken
- $ipchain = array( '127.0.0.1' );
+ if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
+ $ip = IP::canonicalize( $_SERVER['REMOTE_ADDR'] );
+ } elseif( $wgCommandLineMode ) {
+ $ip = '127.0.0.1';
+ }
+ if( $ip ) {
+ $ipchain[] = $ip;
}
- $ip = $ipchain[0];
# Append XFF on to $ipchain
$forwardedFor = wfGetForwardedFor();
}
}
+ if( !$ip ) {
+ throw new MWException( "Unable to determine IP" );
+ }
+
wfDebug( "IP: $ip\n" );
$wgIP = $ip;
return $ip;
* 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 and AOL are whitelisted
- * @param string $ip
+ * @param $ip String
* @return bool
*/
function wfIsTrustedProxy( $ip ) {
escapeshellarg( $port ),
escapeshellarg( $url )
));
- exec( "php $params &>/dev/null &" );
+ exec( "php $params >" . wfGetNull() . " 2>&1 &" );
}
# Set MemCached key
$wgMemc->set( $mcKey, 1, $wgProxyMemcExpiry );
*/
function wfIsLocallyBlockedProxy( $ip ) {
global $wgProxyList;
- $fname = 'wfIsLocallyBlockedProxy';
if ( !$wgProxyList ) {
return false;
}
- wfProfileIn( $fname );
+ wfProfileIn( __METHOD__ );
if ( !is_array( $wgProxyList ) ) {
# Load from the specified file
} else {
$ret = false;
}
- wfProfileOut( $fname );
+ wfProfileOut( __METHOD__ );
return $ret;
}