Added rescue mode
authorAlexander Ebert <ebert@woltlab.com>
Sat, 18 May 2013 12:59:11 +0000 (14:59 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 18 May 2013 12:59:11 +0000 (14:59 +0200)
Fixes #1126

wcfsetup/install/files/lib/system/WCFACP.class.php
wcfsetup/install/files/lib/system/request/LinkHandler.class.php
wcfsetup/install/files/lib/system/request/RequestHandler.class.php

index e52542ee6039e4077b7fb95e1285954cd5c41ec3..15d0207e7e9bbd7b74fa14671f44244573cca767 100644 (file)
@@ -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;
index c85cbac3a9e35026b2daf9e8d4532b99d9dca13e..e1a1c5dcaec4ac2580146b0c1d11703f85ab75cc 100644 (file)
@@ -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
index 68a11ceec72e3a30f559ef606b6efcb3b09dae7a..ef43988a386eaeccc0537d1c0e29d28f43397800 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\system\request;
+use wcf\system\application\ApplicationHandler;
 use wcf\system\exception\AJAXException;
 use wcf\system\exception\IllegalLinkException;
 use wcf\system\exception\SystemException;
@@ -26,12 +27,30 @@ class RequestHandler extends SingletonFactory {
         */
        protected $activeRequest = null;
        
+       /**
+        * true, if current domain mismatch any known domain
+        * @var boolean
+        */
+       protected $inRescueMode = true;
+       
        /**
         * indicates if the request is an acp request
         * @var boolean
         */
        protected $isACPRequest = false;
        
+       /**
+        * @see wcf\system\SingletonFactory::init()
+        */
+       protected function init() {
+               foreach (ApplicationHandler::getInstance()->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;
+       }
 }