From 62fd5375dca4c10b35f40c995b06c3e4ad62fc0f Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sat, 4 May 2019 13:42:26 +0200 Subject: [PATCH 1/2] Move mod/maintenance to src/Module/Maintenance --- mod/maintenance.php | 29 ----------------------------- src/App.php | 8 ++++---- src/App/Router.php | 1 + src/Core/System.php | 3 +++ src/Module/Maintenance.php | 37 +++++++++++++++++++++++++++++++++++++ 5 files changed, 45 insertions(+), 33 deletions(-) delete mode 100644 mod/maintenance.php create mode 100644 src/Module/Maintenance.php diff --git a/mod/maintenance.php b/mod/maintenance.php deleted file mode 100644 index 8e0197b868..0000000000 --- a/mod/maintenance.php +++ /dev/null @@ -1,29 +0,0 @@ - L10n::t('System down for maintenance'), - '$reason' => $reason - ]); -} diff --git a/src/App.php b/src/App.php index 017661c4ca..32e9fa8763 100644 --- a/src/App.php +++ b/src/App.php @@ -1077,10 +1077,10 @@ class App // in install mode, any url loads install module // but we need "view" module for stylesheet - if ($this->getMode()->isInstall() && $this->module != 'view') { - $this->module = 'install'; - } elseif (!$this->getMode()->has(App\Mode::MAINTENANCEDISABLED) && $this->module != 'view') { - $this->module = 'maintenance'; + if ($this->getMode()->isInstall() && $this->module !== 'install') { + $this->internalRedirect('install'); + } elseif (!$this->getMode()->has(App\Mode::MAINTENANCEDISABLED) && $this->module !== 'maintenance') { + $this->internalRedirect('maintenance'); } else { $this->checkURL(); Core\Update::check($this->getBasePath(), false, $this->getMode()); diff --git a/src/App/Router.php b/src/App/Router.php index b94c0bb58d..ac701a0786 100644 --- a/src/App/Router.php +++ b/src/App/Router.php @@ -138,6 +138,7 @@ class Router $this->routeCollector->addRoute(['GET', 'POST'], '/login', Module\Login::class); $this->routeCollector->addRoute(['GET', 'POST'], '/logout', Module\Logout::class); $this->routeCollector->addRoute(['GET'], '/magic', Module\Magic::class); + $this->routeCollector->addRoute(['GET'], '/maintenance', Module\Maintenance::class); $this->routeCollector->addRoute(['GET'], '/manifest', Module\Manifest::class); $this->routeCollector->addRoute(['GET'], '/nodeinfo/1.0', Module\NodeInfo::class); $this->routeCollector->addRoute(['GET'], '/nogroup', Module\Group::class); diff --git a/src/Core/System.php b/src/Core/System.php index 31934af5a7..42587577da 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -242,6 +242,9 @@ class System extends BaseObject case 301: header('HTTP/1.1 301 Moved Permanently'); break; + case 307: + header('HTTP/1.1 307 Temporary Redirect'); + break; } header("Location: $url"); diff --git a/src/Module/Maintenance.php b/src/Module/Maintenance.php new file mode 100644 index 0000000000..e7dc5a075d --- /dev/null +++ b/src/Module/Maintenance.php @@ -0,0 +1,37 @@ +getConfig(); + + $reason = $config->get('system', 'maintenance_reason'); + + if ((substr(Strings::normaliseLink($reason), 0, 7) === 'http://') || + (substr(Strings::normaliseLink($reason), 0, 8) === 'https://')) { + System::externalRedirect($reason, 307); + } + + header('HTTP/1.1 503 Service Temporarily Unavailable'); + header('Status: 503 Service Temporarily Unavailable'); + header('Retry-After: 600'); + + return Renderer::replaceMacros(Renderer::getMarkupTemplate('maintenance.tpl'), [ + '$sysdown' => L10n::t('System down for maintenance'), + '$reason' => $reason + ]); + } +} From 9fb111bca2cc7ab0817d4ddcb294faa9c144c650 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sat, 4 May 2019 16:22:47 +0200 Subject: [PATCH 2/2] Rename ServiceUnavailableException & alter maintenance --- src/App.php | 2 +- src/Module/Maintenance.php | 13 ++++--------- ...xception.php => ServiceUnavailableException.php} | 2 +- 3 files changed, 6 insertions(+), 11 deletions(-) rename src/Network/HTTPException/{ServiceUnavaiableException.php => ServiceUnavailableException.php} (67%) diff --git a/src/App.php b/src/App.php index 32e9fa8763..0f0c0537e4 100644 --- a/src/App.php +++ b/src/App.php @@ -988,7 +988,7 @@ class App header('Refresh: 120; url=' . $this->getBaseURL() . "/" . $this->query_string); Module\Special\HTTPException::rawContent( - new HTTPException\ServiceUnavaiableException('The node is currently overloaded. Please try again later.') + new HTTPException\ServiceUnavailableException('The node is currently overloaded. Please try again later.') ); } diff --git a/src/Module/Maintenance.php b/src/Module/Maintenance.php index e7dc5a075d..24140bb351 100644 --- a/src/Module/Maintenance.php +++ b/src/Module/Maintenance.php @@ -4,8 +4,8 @@ namespace Friendica\Module; use Friendica\BaseModule; use Friendica\Core\L10n; -use Friendica\Core\Renderer; use Friendica\Core\System; +use Friendica\Network\HTTPException; use Friendica\Util\Strings; /** @@ -25,13 +25,8 @@ class Maintenance extends BaseModule System::externalRedirect($reason, 307); } - header('HTTP/1.1 503 Service Temporarily Unavailable'); - header('Status: 503 Service Temporarily Unavailable'); - header('Retry-After: 600'); - - return Renderer::replaceMacros(Renderer::getMarkupTemplate('maintenance.tpl'), [ - '$sysdown' => L10n::t('System down for maintenance'), - '$reason' => $reason - ]); + $exception = new HTTPException\ServiceUnavailableException($reason); + $exception->httpdesc = L10n::t('System down for maintenance'); + throw $exception; } } diff --git a/src/Network/HTTPException/ServiceUnavaiableException.php b/src/Network/HTTPException/ServiceUnavailableException.php similarity index 67% rename from src/Network/HTTPException/ServiceUnavaiableException.php rename to src/Network/HTTPException/ServiceUnavailableException.php index 6c0e6595d8..257b8c8585 100644 --- a/src/Network/HTTPException/ServiceUnavaiableException.php +++ b/src/Network/HTTPException/ServiceUnavailableException.php @@ -4,7 +4,7 @@ namespace Friendica\Network\HTTPException; use Friendica\Network\HTTPException; -class ServiceUnavaiableException extends HTTPException +class ServiceUnavailableException extends HTTPException { protected $code = 503; }