Fixed path info check in WCF/WCFACP
authorAlexander Ebert <ebert@woltlab.com>
Sat, 1 Jun 2013 14:43:43 +0000 (16:43 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 1 Jun 2013 14:43:43 +0000 (16:43 +0200)
wcfsetup/install/files/lib/system/WCF.class.php
wcfsetup/install/files/lib/system/WCFACP.class.php
wcfsetup/install/files/lib/system/request/RouteHandler.class.php

index 0d403c5a595f66853b82c383d16d10ce492e7ed7..8cd63a2f368f92d0f018b9b31972a679d7474cee 100644 (file)
@@ -15,6 +15,7 @@ use wcf\system\exception\PermissionDeniedException;
 use wcf\system\exception\SystemException;
 use wcf\system\language\LanguageFactory;
 use wcf\system\package\PackageInstallationDispatcher;
+use wcf\system\request\RouteHandler;
 use wcf\system\session\SessionFactory;
 use wcf\system\session\SessionHandler;
 use wcf\system\style\StyleHandler;
@@ -691,7 +692,8 @@ class WCF {
        public static function getRequestURI() {
                // resolve path and query components
                $scriptName = $_SERVER['SCRIPT_NAME'];
-               if (empty($_SERVER['PATH_INFO'])) {
+               $pathInfo = RouteHandler::getPathInfo();
+               if (empty($pathInfo)) {
                        // bug fix if URL omits script name and path
                        $scriptName = substr($scriptName, 0, strrpos($scriptName, '/'));
                }
index 15d0207e7e9bbd7b74fa14671f44244573cca767..81fdfde8a3ec3c3a0b22a59305a9f76221ff3bd5 100644 (file)
@@ -60,7 +60,7 @@ class WCFACP extends WCF {
        protected function initAuth() {
                // this is a work-around since neither RequestHandler
                // nor RouteHandler are populated right now
-               $pathInfo = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : '';
+               $pathInfo = RouteHandler::getPathInfo();
                if (empty($pathInfo) || !preg_match('~^/(ACPCaptcha|Login|Logout)/~', $pathInfo)) {
                        if (WCF::getUser()->userID == 0) {
                                // build redirect path
index 176b0e3ea345694ab3ce885c6a6e91ace2ec4170..8eaa4898f24f6c47019f98e7398365b1ff23d73c 100644 (file)
@@ -31,6 +31,12 @@ class RouteHandler extends SingletonFactory {
         */
        protected static $path = '';
        
+       /**
+        * current path info component
+        * @var string
+        */
+       protected static $pathInfo = '';
+       
        /**
         * HTTP protocol, either 'http://' or 'https://'
         * @var string
@@ -105,36 +111,12 @@ class RouteHandler extends SingletonFactory {
         * @return      boolean
         */
        public function matches() {
-               $pathInfo = '';
-               if (isset($_SERVER['ORIG_PATH_INFO'])) {
-                       $pathInfo = $_SERVER['ORIG_PATH_INFO'];
-                       
-                       // in some configurations ORIG_PATH_INFO contains the path to the file
-                       // if the intended PATH_INFO component is empty
-                       if (!empty($pathInfo)) {
-                               if (isset($_SERVER['SCRIPT_NAME']) && ($pathInfo == $_SERVER['SCRIPT_NAME'])) {
-                                       $pathInfo = '';
-                               }
-                               
-                               if (isset($_SERVER['PHP_SELF']) && ($pathInfo == $_SERVER['PHP_SELF'])) {
-                                       $pathInfo = '';
-                               }
-                               
-                               if (isset($_SERVER['SCRIPT_URL']) && ($pathInfo == $_SERVER['SCRIPT_URL'])) {
-                                       $pathInfo = '';
-                               }
-                       }
-               }
-               else if (isset($_SERVER['PATH_INFO'])) {
-                       $pathInfo = $_SERVER['PATH_INFO'];
-               }
-               
                foreach ($this->routes as $route) {
                        if (RequestHandler::getInstance()->isACPRequest() != $route->isACP()) {
                                continue;
                        }
                        
-                       if ($route->matches($pathInfo)) {
+                       if ($route->matches(self::getPathInfo())) {
                                $this->routeData = $route->getRouteData();
                                
                                $this->isDefaultController = $this->routeData['isDefaultController'];
@@ -271,4 +253,38 @@ class RouteHandler extends SingletonFactory {
                
                return self::$path;
        }
+       
+       /**
+        * Returns current path info component.
+        * 
+        * @return      string
+        */
+       public static function getPathInfo() {
+               if (empty(self::$pathInfo)) {
+                       if (isset($_SERVER['ORIG_PATH_INFO'])) {
+                               self::$pathInfo = $_SERVER['ORIG_PATH_INFO'];
+                                       
+                               // in some configurations ORIG_PATH_INFO contains the path to the file
+                               // if the intended PATH_INFO component is empty
+                               if (!empty(self::$pathInfo)) {
+                                       if (isset($_SERVER['SCRIPT_NAME']) && (self::$pathInfo == $_SERVER['SCRIPT_NAME'])) {
+                                               self::$pathInfo = '';
+                                       }
+                       
+                                       if (isset($_SERVER['PHP_SELF']) && (self::$pathInfo == $_SERVER['PHP_SELF'])) {
+                                               self::$pathInfo = '';
+                                       }
+                       
+                                       if (isset($_SERVER['SCRIPT_URL']) && (self::$pathInfo == $_SERVER['SCRIPT_URL'])) {
+                                               self::$pathInfo = '';
+                                       }
+                               }
+                       }
+                       else if (isset($_SERVER['PATH_INFO'])) {
+                               self::$pathInfo = $_SERVER['PATH_INFO'];
+                       }
+               }
+               
+               return self::$pathInfo;
+       }
 }