[BUGFIX] Properly detect HHVM with fastcgi 35/29335/7
authorKevin Häfeli <khaefeli@snowflake.ch>
Thu, 10 Apr 2014 11:40:00 +0000 (13:40 +0200)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Sat, 12 Apr 2014 19:35:57 +0000 (21:35 +0200)
Extend the PHP_SAPI check with "srv" to match the interface between
the webserver and PHP also for Facebook's HHVM and set the paths
correctly for HHVM hostings.

Resolves: #57785
Releases: 6.2
Change-Id: Ie9e302f9ce606158f5e70af1930eda778a8a5a34
Reviewed-on: https://review.typo3.org/29335
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
typo3/sysext/core/Classes/Core/SystemEnvironmentBuilder.php
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/install/Classes/Controller/Action/Tool/ImportantActions.php

index 896809e..060c545 100644 (file)
@@ -49,6 +49,21 @@ namespace TYPO3\CMS\Core\Core;
 class SystemEnvironmentBuilder {
 
        /**
+        * A list of supported CGI server APIs
+        * NOTICE: This is a duplicate of the SAME array in GeneralUtility!
+        *         It is duplicated here as this information is needed early in bootstrap
+        *         and GeneralUtility is not available yet.
+        * @var array
+        */
+       static protected $supportedCgiServerApis = array(
+               'fpm-fcgi',
+               'cgi',
+               'isapi',
+               'cgi-fcgi',
+               'srv', // HHVM with fastcgi
+       );
+
+       /**
         * Run base setup.
         * This entry method is used in all scopes (FE, BE, eid, ajax, ...)
         *
@@ -343,7 +358,7 @@ class SystemEnvironmentBuilder {
                } elseif (isset($_SERVER['PATH_TRANSLATED'])) {
                        $cgiPath = $_SERVER['PATH_TRANSLATED'];
                }
-               if ($cgiPath && (PHP_SAPI === 'fpm-fcgi' || PHP_SAPI === 'cgi' || PHP_SAPI === 'isapi' || PHP_SAPI === 'cgi-fcgi')) {
+               if ($cgiPath && in_array(PHP_SAPI, self::$supportedCgiServerApis, TRUE)) {
                        $scriptPath = $cgiPath;
                } else {
                        if (isset($_SERVER['ORIG_SCRIPT_FILENAME'])) {
@@ -488,5 +503,4 @@ class SystemEnvironmentBuilder {
                }
                return $directory . '/';
        }
-
 }
index 94d98cd..2d2a364 100644 (file)
@@ -26,6 +26,7 @@ namespace TYPO3\CMS\Core\Utility;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+
 /**
  * The legendary "t3lib_div" class - Miscellaneous functions for general purpose.
  * Most of the functions do not relate specifically to TYPO3
@@ -91,6 +92,19 @@ class GeneralUtility {
         */
        static protected $idnaConverter = NULL;
 
+       /**
+        * A list of supported CGI server APIs
+        * NOTICE: This is a duplicate of the SAME array in SystemEnvironmentBuilder
+        * @var array
+        */
+       static protected $supportedCgiServerApis = array(
+               'fpm-fcgi',
+               'cgi',
+               'isapi',
+               'cgi-fcgi',
+               'srv', // HHVM with fastcgi
+       );
+
        /*************************
         *
         * GET/POST Variables
@@ -3292,7 +3306,10 @@ Connection: close
                $retVal = '';
                switch ((string) $getEnvName) {
                        case 'SCRIPT_NAME':
-                               $retVal = (PHP_SAPI == 'fpm-fcgi' || PHP_SAPI == 'cgi' || PHP_SAPI == 'cgi-fcgi') && ($_SERVER['ORIG_PATH_INFO'] ? $_SERVER['ORIG_PATH_INFO'] : $_SERVER['PATH_INFO']) ? ($_SERVER['ORIG_PATH_INFO'] ? $_SERVER['ORIG_PATH_INFO'] : $_SERVER['PATH_INFO']) : ($_SERVER['ORIG_SCRIPT_NAME'] ? $_SERVER['ORIG_SCRIPT_NAME'] : $_SERVER['SCRIPT_NAME']);
+                               $retVal = self::isRunningOnCgiServerApi()
+                                       && ($_SERVER['ORIG_PATH_INFO'] ?: $_SERVER['PATH_INFO'])
+                                               ? ($_SERVER['ORIG_PATH_INFO'] ?: $_SERVER['PATH_INFO'])
+                                               : ($_SERVER['ORIG_SCRIPT_NAME'] ?: $_SERVER['SCRIPT_NAME']);
                                // Add a prefix if TYPO3 is behind a proxy: ext-domain.com => int-server.com/prefix
                                if (self::cmpIP($_SERVER['REMOTE_ADDR'], $GLOBALS['TYPO3_CONF_VARS']['SYS']['reverseProxyIP'])) {
                                        if (self::getIndpEnv('TYPO3_SSL') && $GLOBALS['TYPO3_CONF_VARS']['SYS']['reverseProxyPrefixSSL']) {
@@ -3327,10 +3344,15 @@ Connection: close
                                }
                                break;
                        case 'PATH_INFO':
-                               // $_SERVER['PATH_INFO']!=$_SERVER['SCRIPT_NAME'] is necessary because some servers (Windows/CGI) are seen to set PATH_INFO equal to script_name
+                               // $_SERVER['PATH_INFO'] != $_SERVER['SCRIPT_NAME'] is necessary because some servers (Windows/CGI)
+                               // are seen to set PATH_INFO equal to script_name
                                // Further, there must be at least one '/' in the path - else the PATH_INFO value does not make sense.
-                               // IF 'PATH_INFO' never works for our purpose in TYPO3 with CGI-servers, then 'PHP_SAPI=='cgi'' might be a better check. Right now strcmp($_SERVER['PATH_INFO'],\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('SCRIPT_NAME')) will always return FALSE for CGI-versions, but that is only as long as SCRIPT_NAME is set equal to PATH_INFO because of PHP_SAPI=='cgi' (see above)
-                               if (PHP_SAPI != 'cgi' && PHP_SAPI != 'cgi-fcgi' && PHP_SAPI != 'fpm-fcgi') {
+                               // IF 'PATH_INFO' never works for our purpose in TYPO3 with CGI-servers,
+                               // then 'PHP_SAPI=='cgi'' might be a better check.
+                               // Right now strcmp($_SERVER['PATH_INFO'], GeneralUtility::getIndpEnv('SCRIPT_NAME')) will always
+                               // return FALSE for CGI-versions, but that is only as long as SCRIPT_NAME is set equal to PATH_INFO
+                               // because of PHP_SAPI=='cgi' (see above)
+                               if (!self::isRunningOnCgiServerApi()) {
                                        $retVal = $_SERVER['PATH_INFO'];
                                }
                                break;
@@ -5228,4 +5250,12 @@ Connection: close
        static public function getApplicationContext() {
                return static::$applicationContext;
        }
+
+       /**
+        * Check if the current request is running on a CGI server API
+        * @return bool
+        */
+       static public function isRunningOnCgiServerApi() {
+               return in_array(PHP_SAPI, self::$supportedCgiServerApis, TRUE);
+       }
 }
index 2cafae6..5ca922f 100644 (file)
@@ -76,16 +76,13 @@ class ImportantActions extends Action\AbstractAction {
                $this->view->assign('actionMessages', $actionMessages);
 
                $operatingSystem = TYPO3_OS === 'WIN' ? 'Windows' : 'Unix';
-               $cgiDetected = (PHP_SAPI == 'fpm-fcgi' || PHP_SAPI == 'cgi' || PHP_SAPI == 'isapi' || PHP_SAPI == 'cgi-fcgi')
-                       ? TRUE
-                       : FALSE;
 
                /** @var \TYPO3\CMS\Install\Service\CoreUpdateService $coreUpdateService */
                $coreUpdateService = $this->objectManager->get('TYPO3\\CMS\\Install\\Service\\CoreUpdateService');
                $this->view
                        ->assign('enableCoreUpdate', $coreUpdateService->isCoreUpdateEnabled())
                        ->assign('operatingSystem', $operatingSystem)
-                       ->assign('cgiDetected', $cgiDetected)
+                       ->assign('cgiDetected', GeneralUtility::isRunningOnCgiServerApi())
                        ->assign('databaseName', $GLOBALS['TYPO3_CONF_VARS']['DB']['database'])
                        ->assign('databaseUsername', $GLOBALS['TYPO3_CONF_VARS']['DB']['username'])
                        ->assign('databaseHost', $GLOBALS['TYPO3_CONF_VARS']['DB']['host'])