Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrobocoder <anthon.pang@gmail.com>2010-12-18 05:10:25 +0300
committerrobocoder <anthon.pang@gmail.com>2010-12-18 05:10:25 +0300
commit6a9e1c9c39aa935fc3b34a30b29d2b13fde9daec (patch)
treea1d31c227f53a93fad5bbd71556380eb8b1643bb /core/ProxyHeaders.php
parentefceb3bc244bc38180e93badbb4d942cf63d4c05 (diff)
fixes #1897 - Installation: detects proxy headers and adds them to config/config.ini.php; update script will add them if not already configured
git-svn-id: http://dev.piwik.org/svn/trunk@3457 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'core/ProxyHeaders.php')
-rw-r--r--core/ProxyHeaders.php100
1 files changed, 100 insertions, 0 deletions
diff --git a/core/ProxyHeaders.php b/core/ProxyHeaders.php
new file mode 100644
index 0000000000..8116f49236
--- /dev/null
+++ b/core/ProxyHeaders.php
@@ -0,0 +1,100 @@
+<?php
+/**
+ * Piwik - Open source web analytics
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ * @version $Id$
+ *
+ * @category Piwik
+ * @package Piwik
+ */
+
+/**
+ * Proxy headers
+ *
+ * @package Piwik
+ */
+class Piwik_ProxyHeaders
+{
+ /**
+ * Get protocol information, with the exception of HTTPS
+ *
+ * @return string protocol information
+ */
+ public static function getProtocolInformation()
+ {
+ if(Piwik_Common::getRequestVar('clientProtocol', 'http', 'string') == 'https')
+ {
+ return 'https';
+ }
+
+ if(isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)
+ {
+ return 'SERVER_PORT=443';
+ }
+
+ if(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https')
+ {
+ return 'X-Forwarded-Proto';
+ }
+
+ if(isset($_SERVER['HTTP_X_FORWARDED_SCHEME']) && strtolower($_SERVER['HTTP_X_FORWARDED_SCHEME']) == 'https')
+ {
+ return 'X-Forwarded-Scheme';
+ }
+
+ if(isset($_SERVER['HTTP_X_URL_SCHEME']) && strtolower($_SERVER['HTTP_X_URL_SCHEME']) == 'https')
+ {
+ return 'X-Url-Scheme';
+ }
+
+ return null;
+ }
+
+ /**
+ * Get headers present in the HTTP request
+ *
+ * @return array HTTP headers
+ */
+ private static function getHeaders($recognizedHeaders)
+ {
+ $headers = array();
+
+ foreach($recognizedHeaders as $header)
+ {
+ if(isset($_SERVER[$header]))
+ {
+ $headers[] = $header;
+ }
+ }
+
+ return $headers;
+ }
+
+ /**
+ * Detect proxy client headers
+ *
+ * @return array Proxy client HTTP headers
+ */
+ public static function getProxyClientHeaders()
+ {
+ return self::getHeaders(array(
+ 'HTTP_CF_CONNECTING_IP',
+ 'HTTP_CLIENT_IP',
+ 'HTTP_X_FORWARDED_FOR',
+ ));
+ }
+
+ /**
+ * Detect proxy host headers
+ *
+ * @return array Proxy host HTTP headers
+ */
+ public static function getProxyHostHeaders()
+ {
+ return self::getHeaders(array(
+ 'HTTP_X_FORWARDED_HOST',
+ ));
+ }
+}