diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2013-01-31 14:01:32 -0800 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2013-01-31 14:01:32 -0800 |
commit | 317261d6dfa2b95234628c6e6649bcb94999552a (patch) | |
tree | 567e77c00d793ed56d6cc189e67df24bb089bcd9 /lib | |
parent | 206c6c1e1e09d2793b778200cbbe446260465f84 (diff) | |
parent | 7747f49263bb45674228318a81bb0f2bd214df34 (diff) | |
download | nextcloud-server-317261d6dfa2b95234628c6e6649bcb94999552a.tar.gz nextcloud-server-317261d6dfa2b95234628c6e6649bcb94999552a.zip |
Merge pull request #1099 from herbrechtsmeier/ssl-proxy
add multiple domains reverse SSL proxy support
Diffstat (limited to 'lib')
-rw-r--r-- | lib/app.php | 2 | ||||
-rw-r--r-- | lib/base.php | 6 | ||||
-rw-r--r-- | lib/connector/sabre/request.php | 50 | ||||
-rw-r--r-- | lib/public/util.php | 22 | ||||
-rwxr-xr-x | lib/request.php | 45 | ||||
-rwxr-xr-x | lib/util.php | 2 |
6 files changed, 120 insertions, 7 deletions
diff --git a/lib/app.php b/lib/app.php index 7aafeb36295..fa3e14ce4d2 100644 --- a/lib/app.php +++ b/lib/app.php @@ -506,7 +506,7 @@ class OC_App{ * @return string */ public static function getCurrentApp() { - $script=substr($_SERVER["SCRIPT_NAME"], strlen(OC::$WEBROOT)+1); + $script=substr(OC_Request::scriptName(), strlen(OC::$WEBROOT)+1); $topFolder=substr($script, 0, strpos($script, '/')); if (empty($topFolder)) { $path_info = OC_Request::getPathInfo(); diff --git a/lib/base.php b/lib/base.php index ea5c939cd80..232350b59e2 100644 --- a/lib/base.php +++ b/lib/base.php @@ -129,7 +129,7 @@ class OC // calculate the root directories OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4)); OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT))); - $scriptName = $_SERVER["SCRIPT_NAME"]; + $scriptName = OC_Request::scriptName(); if (substr($scriptName, -1) == '/') { $scriptName .= 'index.php'; //make sure suburi follows the same rules as scriptName @@ -230,7 +230,7 @@ class OC header('Strict-Transport-Security: max-age=31536000'); ini_set("session.cookie_secure", "on"); if (OC_Request::serverProtocol() <> 'https' and !OC::$CLI) { - $url = "https://" . OC_Request::serverHost() . $_SERVER['REQUEST_URI']; + $url = "https://" . OC_Request::serverHost() . OC_Request::requestUri(); header("Location: $url"); exit(); } @@ -764,7 +764,7 @@ class OC if (OC_User::login($_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"])) { //OC_Log::write('core',"Logged in with HTTP Authentication", OC_Log::DEBUG); OC_User::unsetMagicInCookie(); - $_REQUEST['redirect_url'] = (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''); + $_REQUEST['redirect_url'] = OC_Request::requestUri(); OC_Util::redirectToDefaultPage(); } return true; diff --git a/lib/connector/sabre/request.php b/lib/connector/sabre/request.php new file mode 100644 index 00000000000..97a27996bf3 --- /dev/null +++ b/lib/connector/sabre/request.php @@ -0,0 +1,50 @@ +<?php + +/** + * ownCloud + * + * @author Stefan Herbrechtsmeier + * @copyright 2012 Stefan Herbrechtsmeier <stefan@herbrechtsmeier.net> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library 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 AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + */ + +class OC_Connector_Sabre_Request extends Sabre_HTTP_Request { + /** + * Returns the requested uri + * + * @return string + */ + public function getUri() { + return OC_Request::requestUri(); + } + + /** + * Returns a specific item from the _SERVER array. + * + * Do not rely on this feature, it is for internal use only. + * + * @param string $field + * @return string + */ + public function getRawServerValue($field) { + if($field == 'REQUEST_URI'){ + return $this->getUri(); + } + else{ + return isset($this->_SERVER[$field])?$this->_SERVER[$field]:null; + } + } +} diff --git a/lib/public/util.php b/lib/public/util.php index 413dbcccd28..a78a52f326e 100644 --- a/lib/public/util.php +++ b/lib/public/util.php @@ -219,6 +219,28 @@ class Util { } /** + * @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 getRequestUri() { + return(\OC_Request::requestUri()); + } + + /** + * @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 getScriptName() { + return(\OC_Request::scriptName()); + } + + /** * @brief Creates path to an image * @param string $app app * @param string $image image name diff --git a/lib/request.php b/lib/request.php index f2f15c21103..1661a1406ca 100755 --- a/lib/request.php +++ b/lib/request.php @@ -8,6 +8,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'])) { @@ -59,6 +68,38 @@ class OC_Request { } /** + * @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', '') <> '' and self::isOverwriteCondition()) { + $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', '') <> '' 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; + } + return $name; + } + + /** * @brief get Path info from request * @returns string Path info or false when not found */ diff --git a/lib/util.php b/lib/util.php index e8057abe9ae..809f6a88be7 100755 --- a/lib/util.php +++ b/lib/util.php @@ -312,7 +312,7 @@ class OC_Util { public static function checkLoggedIn() { // Check if we are a user if( !OC_User::isLoggedIn()) { - header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php', array('redirect_url' => $_SERVER["REQUEST_URI"]))); + header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php', array('redirect_url' => OC_Request::requestUri()))); exit(); } } |