From 32b9e009b06eb9dbf86e764e9c36d2a67dbb8148 Mon Sep 17 00:00:00 2001 From: Eugene Molotov Date: Mon, 29 Oct 2018 16:22:03 +0500 Subject: [PATCH 1/6] [core] Added IGNORE_CUSTOM_CACHE_TIMEOUT option --- config.default.ini.php | 5 +++++ index.php | 2 +- lib/BridgeCard.php | 2 +- lib/Configuration.php | 5 +++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/config.default.ini.php b/config.default.ini.php index 5909ad8806c..5a5867b5323 100644 --- a/config.default.ini.php +++ b/config.default.ini.php @@ -11,6 +11,11 @@ ; false = disabled (default) custom_timeout = false +; Ignore specified custom timeout for specific requests. +; true = enabled +; false = disabled (default) +ignore_custom_timeout = false + [proxy] ; Sets the proxy url (i.e. "tcp://192.168.0.0:32") diff --git a/index.php b/index.php index 69e5009db17..e475e8a2e8f 100644 --- a/index.php +++ b/index.php @@ -180,7 +180,7 @@ // Cache timeout $cache_timeout = -1; - if(array_key_exists('_cache_timeout', $params)) { + if(!IGNORE_CUSTOM_CACHE_TIMEOUT && array_key_exists('_cache_timeout', $params)) { if(!CUSTOM_CACHE_TIMEOUT) { throw new \HttpException('This server doesn\'t support "_cache_timeout"!'); diff --git a/lib/BridgeCard.php b/lib/BridgeCard.php index 28e74fe67d6..71b13b4e201 100644 --- a/lib/BridgeCard.php +++ b/lib/BridgeCard.php @@ -220,7 +220,7 @@ static function displayBridgeCard($bridgeName, $formats, $isActive = true){ ); } - if(CUSTOM_CACHE_TIMEOUT) { + if(CUSTOM_CACHE_TIMEOUT && !IGNORE_CUSTOM_CACHE_TIMEOUT) { $parameters['global']['_cache_timeout'] = array( 'name' => 'Cache timeout in seconds', 'type' => 'number', diff --git a/lib/Configuration.php b/lib/Configuration.php index b76744f5cca..1dc08ab1d70 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -82,6 +82,11 @@ public static function loadConfiguration() { define('CUSTOM_CACHE_TIMEOUT', self::getConfig('cache', 'custom_timeout')); + if(!is_bool(self::getConfig('cache', 'ignore_custom_timeout'))) + die('Parameter [cache] => "ignore_custom_timeout" is not a valid Boolean! Please check "config.ini.php"!'); + + define('IGNORE_CUSTOM_CACHE_TIMEOUT', self::getConfig('cache', 'ignore_custom_timeout')); + if(!is_bool(self::getConfig('authentication', 'enable'))) die('Parameter [authentication] => "enable" is not a valid Boolean! Please check "config.ini.php"!'); From 23d591d1bc565ed117e5eb8b127e31d82f896b15 Mon Sep 17 00:00:00 2001 From: Eugene Molotov Date: Sun, 11 Nov 2018 16:17:23 +0500 Subject: [PATCH 2/6] [core] Added redirect if user uses _cache_timeout and IGNORE_CUSTOM_CACHE is set --- index.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/index.php b/index.php index e475e8a2e8f..9e904cefc34 100644 --- a/index.php +++ b/index.php @@ -188,6 +188,11 @@ $cache_timeout = filter_var($params['_cache_timeout'], FILTER_VALIDATE_INT); + } else if(IGNORE_CUSTOM_CACHE_TIMEOUT && array_key_exists('_cache_timeout', $params)) { + unset($params['_cache_timeout']); + header('Location: '. parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?' . http_build_query($params), true, 301); + die(); + } else { $cache_timeout = $bridge->getCacheTimeout(); } From 8342fd835a0bda2d25a19c096649993d09409f7f Mon Sep 17 00:00:00 2001 From: Eugene Molotov Date: Sun, 11 Nov 2018 16:20:08 +0500 Subject: [PATCH 3/6] [core] coding policy fixes --- index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.php b/index.php index e512ec3bb21..a41c3f7c634 100644 --- a/index.php +++ b/index.php @@ -133,7 +133,7 @@ } else if(IGNORE_CUSTOM_CACHE_TIMEOUT && array_key_exists('_cache_timeout', $params)) { unset($params['_cache_timeout']); - header('Location: '. parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?' . http_build_query($params), true, 301); + header('Location: ' . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?' . http_build_query($params), true, 301); die(); } else { From 7d38b79fe00189bb45f83df8cbc90b151cfee9be Mon Sep 17 00:00:00 2001 From: Eugene Molotov Date: Tue, 13 Nov 2018 09:52:39 +0500 Subject: [PATCH 4/6] Revert "[core] Added IGNORE_CUSTOM_CACHE_TIMEOUT option" This reverts commit 32b9e009b06eb9dbf86e764e9c36d2a67dbb8148. --- config.default.ini.php | 5 ----- index.php | 2 +- lib/BridgeCard.php | 2 +- lib/Configuration.php | 5 ----- 4 files changed, 2 insertions(+), 12 deletions(-) diff --git a/config.default.ini.php b/config.default.ini.php index f51d11bf807..2d6fca12491 100644 --- a/config.default.ini.php +++ b/config.default.ini.php @@ -11,11 +11,6 @@ ; false = disabled (default) custom_timeout = false -; Ignore specified custom timeout for specific requests. -; true = enabled -; false = disabled (default) -ignore_custom_timeout = false - [admin] ; Advertise an email address where people can reach the administrator. ; This address is displayed on the main page, visible to everyone! diff --git a/index.php b/index.php index a41c3f7c634..0034bdc62dd 100644 --- a/index.php +++ b/index.php @@ -123,7 +123,7 @@ // Cache timeout $cache_timeout = -1; - if(!IGNORE_CUSTOM_CACHE_TIMEOUT && array_key_exists('_cache_timeout', $params)) { + if(array_key_exists('_cache_timeout', $params)) { if(!CUSTOM_CACHE_TIMEOUT) { throw new \HttpException('This server doesn\'t support "_cache_timeout"!'); diff --git a/lib/BridgeCard.php b/lib/BridgeCard.php index 71b13b4e201..28e74fe67d6 100644 --- a/lib/BridgeCard.php +++ b/lib/BridgeCard.php @@ -220,7 +220,7 @@ static function displayBridgeCard($bridgeName, $formats, $isActive = true){ ); } - if(CUSTOM_CACHE_TIMEOUT && !IGNORE_CUSTOM_CACHE_TIMEOUT) { + if(CUSTOM_CACHE_TIMEOUT) { $parameters['global']['_cache_timeout'] = array( 'name' => 'Cache timeout in seconds', 'type' => 'number', diff --git a/lib/Configuration.php b/lib/Configuration.php index dd13405e009..e141ce93ea6 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -82,11 +82,6 @@ public static function loadConfiguration() { define('CUSTOM_CACHE_TIMEOUT', self::getConfig('cache', 'custom_timeout')); - if(!is_bool(self::getConfig('cache', 'ignore_custom_timeout'))) - die('Parameter [cache] => "ignore_custom_timeout" is not a valid Boolean! Please check "config.ini.php"!'); - - define('IGNORE_CUSTOM_CACHE_TIMEOUT', self::getConfig('cache', 'ignore_custom_timeout')); - if(!is_bool(self::getConfig('authentication', 'enable'))) die('Parameter [authentication] => "enable" is not a valid Boolean! Please check "config.ini.php"!'); From 1767d1dfb9455063cd6feefc3e5503828b93918c Mon Sep 17 00:00:00 2001 From: Eugene Molotov Date: Tue, 13 Nov 2018 09:57:12 +0500 Subject: [PATCH 5/6] [core] Replace exception throwing with redirect if _cache_timeout is present but CUSTOM_CACHE_TIMEOUT is disabled --- index.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/index.php b/index.php index 0034bdc62dd..1c751a8ba39 100644 --- a/index.php +++ b/index.php @@ -126,16 +126,13 @@ if(array_key_exists('_cache_timeout', $params)) { if(!CUSTOM_CACHE_TIMEOUT) { - throw new \HttpException('This server doesn\'t support "_cache_timeout"!'); + unset($params['_cache_timeout']); + header('Location: ' . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?' . http_build_query($params), true, 301); + die(); } $cache_timeout = filter_var($params['_cache_timeout'], FILTER_VALIDATE_INT); - } else if(IGNORE_CUSTOM_CACHE_TIMEOUT && array_key_exists('_cache_timeout', $params)) { - unset($params['_cache_timeout']); - header('Location: ' . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?' . http_build_query($params), true, 301); - die(); - } else { $cache_timeout = $bridge->getCacheTimeout(); } From 1f1ef8bc9d120eefa3c9c10312be4e004255cdef Mon Sep 17 00:00:00 2001 From: Eugene Molotov Date: Tue, 13 Nov 2018 09:59:06 +0500 Subject: [PATCH 6/6] coding policy fixes --- index.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index 1c751a8ba39..09f42a377f1 100644 --- a/index.php +++ b/index.php @@ -127,7 +127,8 @@ if(!CUSTOM_CACHE_TIMEOUT) { unset($params['_cache_timeout']); - header('Location: ' . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?' . http_build_query($params), true, 301); + $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?' . http_build_query($params); + header('Location: ' . $uri, true, 301); die(); }