diff options
-rw-r--r-- | core/Http.php | 31 | ||||
-rw-r--r-- | core/Mail.php | 2 | ||||
-rw-r--r-- | core/Url.php | 27 |
3 files changed, 47 insertions, 13 deletions
diff --git a/core/Http.php b/core/Http.php index e14cd952aa..df9df3e5aa 100644 --- a/core/Http.php +++ b/core/Http.php @@ -172,11 +172,8 @@ class Http $rangeHeader = 'Range: bytes=' . $byteRange[0] . '-' . $byteRange[1] . "\r\n"; } - // proxy configuration - $proxyHost = Config::getInstance()->proxy['host']; - $proxyPort = Config::getInstance()->proxy['port']; - $proxyUser = Config::getInstance()->proxy['username']; - $proxyPassword = Config::getInstance()->proxy['password']; + list($proxyHost, $proxyPort, $proxyUser, $proxyPassword) = self::getProxyConfiguration($aUrl); + $aUrl = trim($aUrl); @@ -830,4 +827,28 @@ class Http } return $modifiedSince; } + + /** + * Returns Proxy to use for connecting via HTTP to given URL + * + * @param string $url + * @return array + */ + private static function getProxyConfiguration($url) + { + $hostname = UrlHelper::getHostFromUrl($url); + $localHostnames = Url::getLocalHostnames(); + + if(in_array($hostname, $localHostnames)) { + return array(null, null, null, null); + } + + // proxy configuration + $proxyHost = Config::getInstance()->proxy['host']; + $proxyPort = Config::getInstance()->proxy['port']; + $proxyUser = Config::getInstance()->proxy['username']; + $proxyPassword = Config::getInstance()->proxy['password']; + + return array($proxyHost, $proxyPort, $proxyUser, $proxyPassword); + } } diff --git a/core/Mail.php b/core/Mail.php index 2c5405cf46..b44e01c341 100644 --- a/core/Mail.php +++ b/core/Mail.php @@ -150,6 +150,6 @@ class Mail extends Zend_Mail */ protected function isHostDefinedAndNotLocal($url) { - return isset($url['host']) && !in_array($url['host'], array('localhost', '127.0.0.1'), true); + return isset($url['host']) && !in_array($url['host'], Url::getLocalHostnames(), true); } } diff --git a/core/Url.php b/core/Url.php index 7578088de4..ae19c528ba 100644 --- a/core/Url.php +++ b/core/Url.php @@ -51,11 +51,6 @@ use Piwik\Network\IPUtils; class Url { /** - * List of hosts that are never checked for validity. - */ - private static $alwaysTrustedHosts = array('localhost', '127.0.0.1', '::1', '[::1]'); - - /** * Returns the current URL. * * @return string eg, `"http://example.org/dir1/dir2/index.php?param1=value1¶m2=value2"` @@ -222,7 +217,7 @@ class Url } } // if host is in hardcoded whitelist, assume it's valid - if (in_array($host, self::$alwaysTrustedHosts)) { + if (in_array($host, self::getAlwaysTrustedHosts())) { return true; } @@ -669,6 +664,24 @@ class Url } } - return in_array($host, self::$alwaysTrustedHosts); + return in_array($host, self::getAlwaysTrustedHosts()); + } + + /** + * List of hosts that are never checked for validity. + * + * @return array + */ + private static function getAlwaysTrustedHosts() + { + return self::getLocalHostnames(); + } + + /** + * @return array + */ + public static function getLocalHostnames() + { + return array('localhosts', '127.0.0.1', '::1', '[::1]'); } } |