summaryrefslogtreecommitdiffstats
path: root/lib/request.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/request.php')
-rwxr-xr-xlib/request.php45
1 files changed, 43 insertions, 2 deletions
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
*/