Fixed bug #14989: Use TYPO3_REQUESTTYPE consistently for CLI calls detection
authorFrancois Suter <francois.suter@typo3.org>
Sun, 4 Jul 2010 07:55:53 +0000 (07:55 +0000)
committerFrancois Suter <francois.suter@typo3.org>
Sun, 4 Jul 2010 07:55:53 +0000 (07:55 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@8084 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_beuserauth.php
t3lib/class.t3lib_div.php
t3lib/class.t3lib_userauth.php
typo3/init.php
typo3/sysext/scheduler/class.tx_scheduler_task.php
typo3/sysext/scheduler/cli/scheduler_cli_dispatch.php

index 624518f..653ec16 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2010-07-04 Francois Suter  <francois@typo3.org>
+
+       * Fixed bug #14989: Use TYPO3_REQUESTTYPE consistently for CLI calls detection
+
 2010-07-03 Francois Suter  <francois@typo3.org>
 
        * Cleanup #14987: Spelling mistakes in cli_dispatch.phpsh
index d8d6fd2..874f8c0 100644 (file)
@@ -231,7 +231,7 @@ class t3lib_beUserAuth extends t3lib_userAuthGroup {
         */
        function checkCLIuser() {
                        // First, check if cliMode is enabled:
-               if (defined('TYPO3_cliMode') && TYPO3_cliMode)  {
+               if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI) {
                        if (!$this->user['uid'])        {
                                if (substr($GLOBALS['MCONF']['name'],0,5)=='_CLI_')     {
                                        $userName = strtolower($GLOBALS['MCONF']['name']);
@@ -387,7 +387,7 @@ class t3lib_beUserAuth extends t3lib_userAuthGroup {
                if (!$adminOnlyMode || $this->isAdmin()) {
                        $isUserAllowedToLogin = TRUE;
                        // Backend user is allowed if adminOnly is set to 2 (CLI) and a CLI process is running:
-               } elseif ($adminOnlyMode == 2 && defined('TYPO3_cliMode') && TYPO3_cliMode) {
+               } elseif ($adminOnlyMode == 2 && (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI)) {
                        $isUserAllowedToLogin = TRUE;
                }
 
index 11ca279..252cb84 100644 (file)
@@ -4199,6 +4199,8 @@ final class t3lib_div {
         */
        public static function getHostname($requestHost=TRUE)   {
                $host = '';
+                       // If not called from the command-line, resolve on getIndpEnv()
+                       // Note that TYPO3_REQUESTTYPE is not used here as it may not yet be defined
                if ($requestHost && (!defined('TYPO3_cliMode') || !TYPO3_cliMode))      {
                        $host = self::getIndpEnv('HTTP_HOST');
                }
@@ -5593,6 +5595,7 @@ final class t3lib_div {
                global $TYPO3_CONF_VARS;
 
                        // for CLI logging name is <fqdn-hostname>:<TYPO3-path>
+                       // Note that TYPO3_REQUESTTYPE is not used here as it may not yet be defined
                if (defined('TYPO3_cliMode') && TYPO3_cliMode)  {
                        $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogHost'] = self::getHostname($requestHost=FALSE).':'.PATH_site;
                }
index cb6d7f4..dfbd452 100644 (file)
@@ -497,8 +497,9 @@ class t3lib_userAuth {
                                $this->logoff();
                        }
 
-                               // Refuse login for _CLI users (used by commandline scripts)
-                       if ((strtoupper(substr($loginData['uname'],0,5))=='_CLI_') && (!defined('TYPO3_cliMode') || !TYPO3_cliMode))    {       // although TYPO3_cliMode should never be set when using active login...
+                               // Refuse login for _CLI users, if not processing a CLI request type
+                               // (although we shouldn't be here in case of a CLI request type)
+                       if ((strtoupper(substr($loginData['uname'],0,5)) == '_CLI_') && !(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI)) {
                                throw new RuntimeException(
                                        'TYPO3 Fatal Error: You have tried to login using a CLI user. Access prohibited!',
                                        1270853931
index 6ac65a7..9e795d5 100644 (file)
@@ -233,7 +233,7 @@ if (TYPO3_UseCachingFramework) {
 // *************************
 // CLI dispatch processing
 // *************************
-if (defined('TYPO3_cliMode') && TYPO3_cliMode && basename(PATH_thisScript)=='cli_dispatch.phpsh')      {
+if ((TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI) && basename(PATH_thisScript) == 'cli_dispatch.phpsh') {
                // First, take out the first argument (cli-key)
        $temp_cliScriptPath = array_shift($_SERVER['argv']);
        $temp_cliKey = array_shift($_SERVER['argv']);
@@ -266,7 +266,7 @@ if ($TYPO3_CONF_VARS['BE']['adminOnly'] < 0)        {
        t3lib_BEfunc::typo3printError('Backend locked', 'Backend and Install Tool are locked for maintenance. [BE][adminOnly] is set to "' . intval($TYPO3_CONF_VARS['BE']['adminOnly']) . '".');
        exit;
 }
-if (!(defined('TYPO3_cliMode') && TYPO3_cliMode) && @is_file(PATH_typo3conf.'LOCK_BACKEND'))   {
+if (!(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI) && @is_file(PATH_typo3conf . 'LOCK_BACKEND')) {
        if (TYPO3_PROCEED_IF_NO_USER == 2) {
                // ajax poll for login, let him pass
        } else {
@@ -284,7 +284,7 @@ if (!(defined('TYPO3_cliMode') && TYPO3_cliMode) && @is_file(PATH_typo3conf.'LOC
 // **********************
 // Check IP
 // **********************
-if (trim($TYPO3_CONF_VARS['BE']['IPmaskList']) && !(defined('TYPO3_cliMode') && TYPO3_cliMode))        {
+if (trim($TYPO3_CONF_VARS['BE']['IPmaskList']) && !(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI)) {
        if (!t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $TYPO3_CONF_VARS['BE']['IPmaskList']))      {
                header('Status: 404 Not Found');        // Send Not Found header - if the webserver can make use of it...
                header('Location: http://');    // Just point us away from here...
@@ -296,7 +296,7 @@ if (trim($TYPO3_CONF_VARS['BE']['IPmaskList']) && !(defined('TYPO3_cliMode') &&
 // **********************
 // Check SSL (https)
 // **********************
-if (intval($TYPO3_CONF_VARS['BE']['lockSSL']) && !(defined('TYPO3_cliMode') && TYPO3_cliMode)) {
+if (intval($TYPO3_CONF_VARS['BE']['lockSSL']) && !(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI)) {
        if(intval($TYPO3_CONF_VARS['BE']['lockSSLPort'])) {
                $sslPortSuffix = ':'.intval($TYPO3_CONF_VARS['BE']['lockSSLPort']);
        } else {
@@ -372,7 +372,7 @@ if ($TYPO3_DB->sql_pconnect(TYPO3_db_host, TYPO3_db_username, TYPO3_db_password)
 // *******************************
 // Checks for proper browser
 // *******************************
-if (!$CLIENT['BROWSER'] && !(defined('TYPO3_cliMode') && TYPO3_cliMode))       {
+if (!$CLIENT['BROWSER'] && !(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI)) {
        t3lib_BEfunc::typo3PrintError ('Browser error','Your browser version looks incompatible with this TYPO3 version!',0);
        exit;
 }
@@ -428,7 +428,7 @@ $GLOBALS['LANG']->init($BE_USER->uc['lang']);
 // ****************
 // CLI processing
 // ****************
-if (defined('TYPO3_cliMode') && TYPO3_cliMode) {
+if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI) {
                // Status output:
        if (!strcmp($_SERVER['argv'][1],'status'))      {
                echo "Status of TYPO3 CLI script:\n\n";
index c50156a..2f9d439 100755 (executable)
@@ -325,7 +325,7 @@ abstract class tx_scheduler_Task {
 
                        // Define the context in which the script is running
                $context = 'BE';
-               if (defined('TYPO3_cliMode') && TYPO3_cliMode) {
+               if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI) {
                        $context = 'CLI';
                }
 
index 2de1a7d..f504c1d 100644 (file)
@@ -32,7 +32,7 @@
  *
  * $Id$
  */
-if (defined('TYPO3_cliMode') && TYPO3_cliMode && basename(PATH_thisScript) == 'cli_dispatch.phpsh') {
+if ((TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI) && basename(PATH_thisScript) == 'cli_dispatch.phpsh') {
        $hasTask = true;
                // Create an instance of the scheduler object
                /**