From ab2b79cda682a697baba2128a21d3a9b5e90853c Mon Sep 17 00:00:00 2001 From: Stefan Herbrechtsmeier Date: Sun, 9 Sep 2012 12:54:47 +0200 Subject: add multiple domains reverse proxy support Add support for a reverse proxy that handles multiple domains via different web roots (http[s]://proxy.tld/domain.tld/owncloud). As the reverse proxy web root is transparent for the web server the REQUEST_URI and SCRIPT_NAME need manual adjustments. This patch replace the direct use of this _SERVER variables with function calls and extend this functions to overwrite the web root. Additionally it adds a Sabre request backend that extends the Sabre_HTTP_Request to use the same functions. --- lib/request.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'lib/request.php') diff --git a/lib/request.php b/lib/request.php index f2f15c21103..4c056ce9b2f 100755 --- a/lib/request.php +++ b/lib/request.php @@ -58,6 +58,38 @@ class OC_Request { return $proto; } + /** + * @brief Returns the request uri + * @returns the request uri + * + * Returns the request uri, even if the website uses one or more + * reverse proxies + */ + public static function requestUri() { + $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; + if (OC_Config::getValue('overwritewebroot', '') <> '') { + $uri = self::scriptName() . substr($uri, strlen($_SERVER['SCRIPT_NAME'])); + } + return $uri; + } + + /** + * @brief Returns the script name + * @returns the script name + * + * Returns the script name, even if the website uses one or more + * reverse proxies + */ + public static function scriptName() { + $name = $_SERVER['SCRIPT_NAME']; + if (OC_Config::getValue('overwritewebroot', '') <> '') { + $serverroot = str_replace("\\", '/', substr(__DIR__, 0, -4)); + $suburi = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen($serverroot))); + $name = OC_Config::getValue('overwritewebroot', '') . $suburi; + } + return $name; + } + /** * @brief get Path info from request * @returns string Path info or false when not found -- cgit v1.2.3 From 7747f49263bb45674228318a81bb0f2bd214df34 Mon Sep 17 00:00:00 2001 From: herbrechtsmeier Date: Sun, 6 Jan 2013 12:24:40 +0100 Subject: add SSL proxy support Add support for a reverse proxy that only forwards SSL connections unencrypted to the web server. This patch allows to detect the reverse proxy via regular expression for the remote IP address and conditional overwrite the host name, protocol and web root. --- config/config.sample.php | 3 +++ lib/request.php | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'lib/request.php') diff --git a/config/config.sample.php b/config/config.sample.php index ebe73fbec7b..5264e948200 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -41,6 +41,9 @@ $CONFIG = array( /* The automatic webroot detection of ownCloud can fail in certain reverse proxy situations. This option allows to manually override the automatic detection. For example "/domain.tld/ownCloud" */ "overwritewebroot" => "", +/* The automatic detection of ownCloud can fail in certain reverse proxy situations. This option allows to define a manually override condition as regular expression for the remote ip address. For example "^10\.0\.0\.[1-3]$" */ +"overwritecondaddr" => "", + /* A proxy to use to connect to the internet. For example "myproxy.org:88" */ "proxy" => "", diff --git a/lib/request.php b/lib/request.php index 4c056ce9b2f..1661a1406ca 100755 --- a/lib/request.php +++ b/lib/request.php @@ -7,6 +7,15 @@ */ class OC_Request { + /** + * @brief Check overwrite condition + * @returns true/false + */ + private static function isOverwriteCondition() { + $regex = '/' . OC_Config::getValue('overwritecondaddr', '') . '/'; + return $regex === '//' or preg_match($regex, $_SERVER['REMOTE_ADDR']) === 1; + } + /** * @brief Returns the server host * @returns the server host @@ -18,7 +27,7 @@ class OC_Request { if(OC::$CLI) { return 'localhost'; } - if(OC_Config::getValue('overwritehost', '')<>'') { + if(OC_Config::getValue('overwritehost', '')<>'' and self::isOverwriteCondition()) { return OC_Config::getValue('overwritehost'); } if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { @@ -43,7 +52,7 @@ class OC_Request { * Returns the server protocol. It respects reverse proxy servers and load balancers */ public static function serverProtocol() { - if(OC_Config::getValue('overwriteprotocol', '')<>'') { + if(OC_Config::getValue('overwriteprotocol', '')<>'' and self::isOverwriteCondition()) { return OC_Config::getValue('overwriteprotocol'); } if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) { @@ -67,7 +76,7 @@ class OC_Request { */ public static function requestUri() { $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; - if (OC_Config::getValue('overwritewebroot', '') <> '') { + if (OC_Config::getValue('overwritewebroot', '') <> '' and self::isOverwriteCondition()) { $uri = self::scriptName() . substr($uri, strlen($_SERVER['SCRIPT_NAME'])); } return $uri; @@ -82,7 +91,7 @@ class OC_Request { */ public static function scriptName() { $name = $_SERVER['SCRIPT_NAME']; - if (OC_Config::getValue('overwritewebroot', '') <> '') { + if (OC_Config::getValue('overwritewebroot', '') <> '' and self::isOverwriteCondition()) { $serverroot = str_replace("\\", '/', substr(__DIR__, 0, -4)); $suburi = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen($serverroot))); $name = OC_Config::getValue('overwritewebroot', '') . $suburi; -- cgit v1.2.3