From c329938304c48adc73d6ea3637b288d2ced93ec7 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sat, 18 May 2013 14:59:11 +0200 Subject: [PATCH] Added rescue mode Fixes #1126 --- .../install/files/lib/system/WCFACP.class.php | 11 +++++++- .../lib/system/request/LinkHandler.class.php | 25 +++++++++++------ .../system/request/RequestHandler.class.php | 28 +++++++++++++++++++ 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/wcfsetup/install/files/lib/system/WCFACP.class.php b/wcfsetup/install/files/lib/system/WCFACP.class.php index e52542ee60..15d0207e7e 100644 --- a/wcfsetup/install/files/lib/system/WCFACP.class.php +++ b/wcfsetup/install/files/lib/system/WCFACP.class.php @@ -65,7 +65,16 @@ class WCFACP extends WCF { if (WCF::getUser()->userID == 0) { // build redirect path $application = ApplicationHandler::getInstance()->getActiveApplication(); - $path = $application->getPageURL() . 'acp/index.php/Login/' . SID_ARG_1ST . '&url=' . rawurlencode(WCF::getSession()->requestURI); + + // fallback for unknown host (rescue mode) + if ($application->domainName != $_SERVER['HTTP_HOST']) { + $pageURL = RouteHandler::getProtocol() . $_SERVER['HTTP_HOST'] . RouteHandler::getPath(array('acp')); + } + else { + $pageURL = $application->getPageURL(); + } + + $path = $pageURL . 'acp/index.php/Login/' . SID_ARG_1ST . '&url=' . rawurlencode(WCF::getSession()->requestURI); HeaderUtil::redirect($path); exit; diff --git a/wcfsetup/install/files/lib/system/request/LinkHandler.class.php b/wcfsetup/install/files/lib/system/request/LinkHandler.class.php index c85cbac3a9..e1a1c5dcae 100644 --- a/wcfsetup/install/files/lib/system/request/LinkHandler.class.php +++ b/wcfsetup/install/files/lib/system/request/LinkHandler.class.php @@ -144,18 +144,25 @@ class LinkHandler extends SingletonFactory { $url = RouteHandler::getHost() . RouteHandler::getPath(array('acp')) . ($isACP ? 'acp/' : '') . $url; } else { - // try to resolve abbreviation - $application = null; - if ($abbreviation != 'wcf') { - $application = ApplicationHandler::getInstance()->getApplication($abbreviation); + if (RequestHandler::getInstance()->inRescueMode()) { + $pageURL = RouteHandler::getHost() . RouteHandler::getPath(array('acp')); } - - // fallback to primary application if abbreviation is 'wcf' or unknown - if ($application === null) { - $application = ApplicationHandler::getInstance()->getPrimaryApplication(); + else { + // try to resolve abbreviation + $application = null; + if ($abbreviation != 'wcf') { + $application = ApplicationHandler::getInstance()->getApplication($abbreviation); + } + + // fallback to primary application if abbreviation is 'wcf' or unknown + if ($application === null) { + $application = ApplicationHandler::getInstance()->getPrimaryApplication(); + } + + $pageURL = $application->getPageURL(); } - $url = $application->getPageURL() . ($isACP ? 'acp/' : '') . $url; + $url = $pageURL . ($isACP ? 'acp/' : '') . $url; } // append previously removed anchor diff --git a/wcfsetup/install/files/lib/system/request/RequestHandler.class.php b/wcfsetup/install/files/lib/system/request/RequestHandler.class.php index 68a11ceec7..ef43988a38 100644 --- a/wcfsetup/install/files/lib/system/request/RequestHandler.class.php +++ b/wcfsetup/install/files/lib/system/request/RequestHandler.class.php @@ -1,5 +1,6 @@ getApplications() as $application) { + if ($application->domainName == $_SERVER['HTTP_HOST']) { + $this->inRescueMode = false; + break; + } + } + } + /** * Handles a http request. * @@ -171,4 +190,13 @@ class RequestHandler extends SingletonFactory { public function isACPRequest() { return $this->isACPRequest; } + + /** + * Returns true, if current host mismatches any known domain. + * + * @return boolean + */ + public function inRescueMode() { + return $this->inRescueMode; + } } -- 2.20.1