[TASK] Bootstrap: Disentangle cli and install from init.php
authorChristian Kuhn <lolli@schwarzbu.ch>
Wed, 9 May 2012 19:27:53 +0000 (21:27 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Wed, 16 May 2012 17:58:21 +0000 (19:58 +0200)
Extract code from init.php and put it to methods in Bootstrap.php.
Additionally, cli_dispatch and install/index.php do not require
init.php anymore and have a uncoupled bootstrap now.

There is still room for improvement,
this patch is just another intermediate step.

Change-Id: I5c6d84b8acb7760c8a77f192b2b5ba063b417b0d
Resolves: #37130
Releases: 6.0
Reviewed-on: http://review.typo3.org/11153
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
Reviewed-by: Philipp Gampe
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
index.php
t3lib/class.t3lib_spritemanager.php
t3lib/config_default.php
typo3/Bootstrap.php
typo3/Bootstrap_Cli.php [new file with mode: 0644]
typo3/Bootstrap_Install.php [new file with mode: 0644]
typo3/ajax.php
typo3/cli_dispatch.phpsh
typo3/init.php
typo3/install/index.php
typo3/sysext/cms/tslib/index_ts.php

index b74cccc..569bd65 100644 (file)
--- a/index.php
+++ b/index.php
  * @subpackage tslib
  */
 
-// *******************************
-// Set error reporting
-// *******************************
-error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
-
 require('typo3/Bootstrap.php');
+Typo3_Bootstrap::checkEnvironmentOrDie();
 Typo3_Bootstrap::defineBaseConstants();
 Typo3_Bootstrap::defineAndCheckPaths('');
+Typo3_Bootstrap::requireBaseClasses();
+Typo3_Bootstrap::setUpEnvironment();
 
 // ******************
 // include TSFE
 // ******************
-require (PATH_tslib.'index_ts.php');
+require (PATH_tslib . 'index_ts.php');
 ?>
\ No newline at end of file
index d544938..a4e7801 100644 (file)
@@ -62,8 +62,7 @@ class t3lib_SpriteManager {
        /**
         * Check if the icon cache has to be rebuild, instantiate and call the handler class if so.
         *
-        * @param boolean Suppress regeneration if FALSE (useful for feediting)
-        * @return void
+        * @param boolean $allowRegeneration Suppress regeneration if FALSE (useful for feediting)
         */
        function __construct($allowRegeneration = TRUE) {
                        // Create temp directory if missing
index 7c715bb..d34484f 100644 (file)
@@ -1059,6 +1059,18 @@ if(count($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']) > 0) {
        t3lib_div::deprecationLog('This installation runs with extensions that use XCLASSing by setting the XCLASS path in ext_localconf.php. This is deprecated and will be removed in TYPO3 6.2 and later. It is preferred to define XCLASSes in ext_autoload.php instead. See http://wiki.typo3.org/Autoload for more information.');
 }
 
+
+       // Error & Exception handling
+if ($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionHandler'] !== '') {
+       if ($TYPO3_CONF_VARS['SYS']['errorHandler'] !== '') {
+                       //      Register an error handler for the given errorHandlerErrors
+               $errorHandler = t3lib_div::makeInstance($TYPO3_CONF_VARS['SYS']['errorHandler'], $TYPO3_CONF_VARS['SYS']['errorHandlerErrors']);
+                       // Set errors which will be converted in an exception
+               $errorHandler->setExceptionalErrors($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionalErrors']);
+       }
+       $exceptionHandler = t3lib_div::makeInstance($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionHandler']);
+}
+
        // Extensions may register new caches, so we set the
        // global cache array to the manager again at this point
 $GLOBALS['typo3CacheManager']->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
index 6b562eb..9a6d2cc 100644 (file)
  * It is required directly as the very first thing in entry scripts and
  * used to define all base things like constants and pathes and so on.
  *
+ * Most methods in this class have dependencies to each other. They can
+ * not be called in arbitrary order. The methods are ordered top down, so
+ * a method at the beginning has lower dependencies than a method further
+ * down. Do not fiddle with the load order in own scripts except you know
+ * exactly what you are doing!
+ *
  * @author Christian Kuhn <lolli@schwarzbu.ch>
  * @package TYPO3
  * @subpackage core
 class Typo3_Bootstrap {
 
        /**
+        * Check several a priori conditions like the current
+        * php version or exit the script with an error.
+        *
+        * @return void
+        */
+       public static function checkEnvironmentOrDie() {
+               self::checkPhpVersionOrDie();
+               self::checkGlobalsAreNotSetViaPostOrGet();
+       }
+
+       /**
         * Define all simple base constants
         *
         * @return void
@@ -132,6 +149,247 @@ class Typo3_Bootstrap {
        }
 
        /**
+        * Load several base classes during bootstrap
+        *
+        * @return void
+        */
+       public static function requireBaseClasses() {
+               require_once(PATH_t3lib . 'class.t3lib_div.php');
+               require_once(PATH_t3lib . 'class.t3lib_extmgm.php');
+       }
+
+       /**
+        * Set up php error reporting and various things like time tracking
+        *
+        * @return void
+        */
+       public static function setUpEnvironment() {
+                       // Core should be notice free at least until this point ...
+                       // @TODO: Move further down / get rid of it until errorHandler is initialized
+               error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
+
+                       // Unset variable(s) in global scope (security issue #13959)
+               unset($GLOBALS['error']);
+
+                       // Include information about the browser/user-agent
+               $GLOBALS['CLIENT'] = t3lib_div::clientInfo();
+
+                       // Is set to the system time in milliseconds.
+                       // This could be used to output script parsetime in the end of the script
+               $GLOBALS['PARSETIME_START'] = t3lib_div::milliseconds();
+               $GLOBALS['TYPO3_MISC'] = array();
+               $GLOBALS['TYPO3_MISC']['microtime_start'] = microtime(TRUE);
+
+                       // Compatibility layer for magic quotes
+               if (!get_magic_quotes_gpc()) {
+                       t3lib_div::addSlashesOnArray($_GET);
+                       t3lib_div::addSlashesOnArray($_POST);
+                       $GLOBALS['HTTP_GET_VARS'] = $_GET;
+                       $GLOBALS['HTTP_POST_VARS'] = $_POST;
+               }
+       }
+
+       /**
+        * Initialize t3lib_db in $GLOBALS and connect if requested
+        *
+        * @param bool $connect Whether or not the db should be connected already
+        * @return void
+        */
+       public static function initializeTypo3DbGlobal($connect = TRUE) {
+                       /** @var TYPO3_DB t3lib_db */
+               $GLOBALS['TYPO3_DB'] = t3lib_div::makeInstance('t3lib_DB');
+               $GLOBALS['TYPO3_DB']->debugOutput = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sqlDebug'];
+               if ($connect) {
+                       $GLOBALS['TYPO3_DB']->connectDB();
+               }
+       }
+
+       /**
+        * Check adminOnly configuration variable and redirects
+        * to an URL in file typo3conf/LOCK_BACKEND or exit the script
+        *
+        * @throws RuntimeException
+        * @return void
+        */
+       public static function checkLockedBackendAndRedirectOrDie() {
+               if ($GLOBALS['TYPO3_CONF_VARS']['BE']['adminOnly'] < 0) {
+                       throw new RuntimeException(
+                               'TYPO3 Backend locked: Backend and Install Tool are locked for maintenance. [BE][adminOnly] is set to "' . intval($GLOBALS['TYPO3_CONF_VARS']['BE']['adminOnly']) . '".',
+                               1294586847
+                       );
+               }
+               if (@is_file(PATH_typo3conf . 'LOCK_BACKEND')) {
+                       if (TYPO3_PROCEED_IF_NO_USER === 2) {
+                               // Ajax poll for login, let it pass
+                       } else {
+                               $fileContent = t3lib_div::getUrl(PATH_typo3conf.'LOCK_BACKEND');
+                               if ($fileContent)       {
+                                       header('Location: ' . $fileContent);
+                               } else {
+                                       throw new RuntimeException(
+                                               'TYPO3 Backend locked: Browser backend is locked for maintenance. Remove lock by removing the file "typo3conf/LOCK_BACKEND" or use CLI-scripts.',
+                                               1294586848
+                                       );
+                               }
+                               exit;
+                       }
+               }
+       }
+
+       /**
+        * Compare client IP with IPmaskList and exit the script run
+        * if the client is not allowed to access the backend
+        *
+        * @return void
+        */
+       public static function checkBackendIpOrDie() {
+               if (trim($GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'])) {
+                       if (!t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'])) {
+                                       // Send Not Found header - if the webserver can make use of it
+                               header('Status: 404 Not Found');
+                                       // Just point us away from here...
+                               header('Location: http://');
+                                       // ... and exit good!
+                               exit;
+                       }
+               }
+       }
+
+       /**
+        * Check lockSSL configuration variable and redirect
+        * to https version of the backend if needed
+        *
+        * @return void
+        */
+       public static function checkSslBackendAndRedirectIfNeeded() {
+               if (intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL'])) {
+                       if(intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSLPort'])) {
+                               $sslPortSuffix = ':' . intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSLPort']);
+                       } else {
+                               $sslPortSuffix = '';
+                       }
+                       if ($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL'] == 3) {
+                               $requestStr = substr(t3lib_div::getIndpEnv('TYPO3_REQUEST_SCRIPT'), strlen(t3lib_div::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir));
+                               if($requestStr == 'index.php' && !t3lib_div::getIndpEnv('TYPO3_SSL')) {
+                                       list(,$url) = explode('://', t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'), 2);
+                                       list($server, $address) = explode('/', $url, 2);
+                                       header('Location: https://' . $server . $sslPortSuffix . '/' . $address);
+                                       exit;
+                               }
+                       } elseif (!t3lib_div::getIndpEnv('TYPO3_SSL') ) {
+                               if ($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL'] == 2) {
+                                       list(,$url) = explode('://', t3lib_div::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir, 2);
+                                       list($server, $address) = explode('/', $url, 2);
+                                       header('Location: https://'.$server . $sslPortSuffix . '/' . $address);
+                               } else {
+                                               // Send Not Found header - if the webserver can make use of it...
+                                       header('Status: 404 Not Found');
+                                               // Just point us away from here...
+                                       header('Location: http://');
+                               }
+                                       // ... and exit good!
+                               exit;
+                       }
+               }
+       }
+
+       /**
+        * Check for registered ext tables hooks and run them
+        *
+        * @throws UnexpectedValueException
+        * @return void
+        */
+       public static function runExtTablesPostProcessingHooks() {
+               if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'])) {
+                       foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'] as $classReference) {
+                                       /** @var $hookObject t3lib_extTables_PostProcessingHook */
+                               $hookObject = t3lib_div::getUserObj($classReference);
+                               if (!$hookObject instanceof t3lib_extTables_PostProcessingHook) {
+                                       throw new UnexpectedValueException('$hookObject must implement interface t3lib_extTables_PostProcessingHook', 1320585902);
+                               }
+                               $hookObject->processData();
+                       }
+               }
+       }
+
+       /**
+        * Initialize sprite manager global
+        *
+        * @param bool $allowRegeneration
+        * @return void
+        */
+       public static function initializeSpriteManager($allowRegeneration = TRUE) {
+                       /** @var $spriteManager t3lib_SpriteManager */
+               $GLOBALS['spriteManager'] = t3lib_div::makeInstance('t3lib_SpriteManager', $allowRegeneration);
+               $GLOBALS['spriteManager']->loadCacheFile();
+       }
+
+       /**
+        * Initialize backend user object in globals
+        *
+        * @return void
+        */
+       public static function initializeBackendUser() {
+                       /** @var $backendUser t3lib_beUserAuth */
+               $backendUser = t3lib_div::makeInstance('t3lib_beUserAuth');
+               $backendUser->warningEmail = $GLOBALS['TYPO3_CONF_VARS']['BE']['warning_email_addr'];
+               $backendUser->lockIP = $GLOBALS['TYPO3_CONF_VARS']['BE']['lockIP'];
+               $backendUser->auth_timeout_field = intval($GLOBALS['TYPO3_CONF_VARS']['BE']['sessionTimeout']);
+               $backendUser->OS = TYPO3_OS;
+               if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI) {
+                       $backendUser->dontSetCookie = TRUE;
+               }
+               $backendUser->start();
+               $backendUser->checkCLIuser();
+               $backendUser->backendCheckLogin();
+               $GLOBALS['BE_USER'] = $backendUser;
+       }
+
+       /**
+        * Initialize backend user mount points
+        *
+        * @return void
+        */
+       public static function initializeBackendUserMounts() {
+                       // ! WILL INCLUDE deleted mount pages as well!
+               $GLOBALS['WEBMOUNTS'] = $GLOBALS['BE_USER']->returnWebmounts();
+               $GLOBALS['FILEMOUNTS'] = $GLOBALS['BE_USER']->returnFilemounts();
+       }
+
+       /**
+        * Initialize language object
+        *
+        * @return void
+        */
+       public static function initializeLanguageObject() {
+                       /** @var $GLOBALS['LANG'] language */
+               $GLOBALS['LANG'] = t3lib_div::makeInstance('language');
+               $GLOBALS['LANG']->init($GLOBALS['BE_USER']->uc['lang']);
+       }
+
+       /**
+        * Check php version requirement or exit script
+        *
+        * @return void
+        */
+       protected static function checkPhpVersionOrDie() {
+               if (version_compare(phpversion(), '5.3', '<')) {
+                       die ('TYPO3 requires PHP 5.3.0 or higher.');
+               }
+       }
+
+       /**
+        * Exit script if globals are set via post or get
+        *
+        * @return void
+        */
+       protected static function checkGlobalsAreNotSetViaPostOrGet() {
+               if (isset($_POST['GLOBALS']) || isset($_GET['GLOBALS'])) {
+                       die('You cannot set the GLOBALS array from outside the script.');
+               }
+       }
+
+       /**
         * Determine the operating system TYPO3 is running on.
         *
         * @return string Either 'WIN' if running on Windows, else empty string
@@ -174,15 +432,16 @@ class Typo3_Bootstrap {
         * @return string Absolute path to entry script
         */
        protected static function getPathThisScriptNonCli() {
-               if ($_SERVER['ORIG_PATH_TRANSLATED']) {
+               $cgiPath = '';
+               if (isset($_SERVER['ORIG_PATH_TRANSLATED'])) {
                        $cgiPath = $_SERVER['ORIG_PATH_TRANSLATED'];
-               } else {
+               } 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')) {
                        $scriptPath = $cgiPath;
                } else {
-                       if ($_SERVER['ORIG_SCRIPT_FILENAME']) {
+                       if (isset($_SERVER['ORIG_SCRIPT_FILENAME'])) {
                                $scriptPath = $_SERVER['ORIG_SCRIPT_FILENAME'];
                        } else {
                                $scriptPath = $_SERVER['SCRIPT_FILENAME'];
diff --git a/typo3/Bootstrap_Cli.php b/typo3/Bootstrap_Cli.php
new file mode 100644 (file)
index 0000000..81f1b42
--- /dev/null
@@ -0,0 +1,108 @@
+<?php
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2012 Christian Kuhn <lolli@schwarzbu.ch>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * This class encapsulates cli specific bootstrap methods.
+ *
+ * @author Christian Kuhn <lolli@schwarzbu.ch>
+ * @package TYPO3
+ * @subpackage core
+ */
+class Typo3_Bootstrap_Cli {
+
+       /**
+        * Check the script is called from a cli environment.
+        *
+        * @return void
+        */
+       public static function checkEnvironmentOrDie() {
+               if (substr(php_sapi_name(), 0, 3) === 'cgi') {
+                       self::initializeCgiCompatibilityLayerOrDie();
+               } elseif (php_sapi_name() !== 'cli') {
+                       die('Not called from a command line interface (e.g. a shell or scheduler).' . chr(10));
+               }
+       }
+
+       /**
+        * Check and define cli parameters
+        *
+        * @return void
+        */
+       public static function initializeCliKeyOrDie() {
+               if (!isset($_SERVER['argv'][1])) {
+                       fwrite(STDERR, 'The first argument must be a valid key.' . chr(10));
+                       exit(1);
+               }
+
+                       // First argument is a key that points to the script configuration
+               define('TYPO3_cliKey', $_SERVER['argv'][1]);
+
+               if (!is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['cliKeys'][TYPO3_cliKey])) {
+                       $message = "The supplied 'cliKey' was not valid. Please use one of the available from this list:\n\n";
+                       $message .= var_export(array_keys($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['cliKeys']), TRUE);
+                       fwrite(STDERR, $message . LF);
+                       exit(1);
+               }
+
+               define('TYPO3_cliInclude', t3lib_div::getFileAbsFileName($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['cliKeys'][TYPO3_cliKey][0]));
+               $GLOBALS['MCONF']['name'] = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['cliKeys'][TYPO3_cliKey][1];
+
+                       // This is a compatibility layer: Some cli scripts rely on this, like ext:phpunit cli
+               $GLOBALS['temp_cliScriptPath'] = array_shift($_SERVER['argv']);
+               $GLOBALS['temp_cliKey'] = array_shift($_SERVER['argv']);
+               array_unshift($_SERVER['argv'],$GLOBALS['temp_cliScriptPath']);
+       }
+
+       /**
+        * Set up cgi sapi as de facto cli, but check no HTTP
+        * environment variables are set.
+        *
+        * @return void
+        */
+       protected static function initializeCgiCompatibilityLayerOrDie() {
+                       // Sanity check: Ensure we're running in a shell or cronjob (and NOT via HTTP)
+               $checkEnvVars = array('HTTP_USER_AGENT', 'HTTP_HOST', 'SERVER_NAME', 'REMOTE_ADDR', 'REMOTE_PORT', 'SERVER_PROTOCOL');
+               foreach ($checkEnvVars as $var) {
+                       if (array_key_exists($var, $_SERVER)) {
+                               echo 'SECURITY CHECK FAILED! This script cannot be used within your browser!' . chr(10);
+                               echo 'If you are sure that we run in a shell or cronjob, please unset' . chr(10);
+                               echo 'environment variable ' . $var . ' (usually using \'unset ' . $var . '\')' . chr(10);
+                               echo 'before starting this script.' . chr(10);
+                               exit;
+                       }
+               }
+
+                       // Mimic CLI API in CGI API (you must use the -C/-no-chdir and the -q/--no-header switches!)
+               ini_set('html_errors', 0);
+               ini_set('implicit_flush', 1);
+               ini_set('max_execution_time', 0);
+               define(STDIN, fopen('php://stdin', 'r'));
+               define(STDOUT, fopen('php://stdout', 'w'));
+               define(STDERR, fopen('php://stderr', 'w'));
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/Bootstrap_Install.php b/typo3/Bootstrap_Install.php
new file mode 100644 (file)
index 0000000..a53252d
--- /dev/null
@@ -0,0 +1,137 @@
+<?php
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2012 Christian Kuhn <lolli@schwarzbu.ch>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Encapsulate install tool specific bootstrap methods.
+ *
+ * @author Christian Kuhn <lolli@schwarzbu.ch>
+ * @package TYPO3
+ * @subpackage core
+ */
+class Typo3_Bootstrap_Install {
+
+       /**
+        * Check ENABLE_INSTALL_TOOL and FIRST_INSTALL file in typo3conf
+        * or exit the scipt if conditions to access the install tool are not met.
+        *
+        * @return void
+        */
+       public static function checkEnabledInstallToolOrDie() {
+               $quickstartFile = PATH_site . 'typo3conf/FIRST_INSTALL';
+               $enableInstallToolFile = PATH_site . 'typo3conf/ENABLE_INSTALL_TOOL';
+
+                       // If typo3conf/FIRST_INSTALL is present and can be deleted, automatically create typo3conf/ENABLE_INSTALL_TOOL
+               if (is_file($quickstartFile) && is_writeable($quickstartFile) && unlink($quickstartFile)) {
+                       touch($enableInstallToolFile);
+               }
+
+                       // Additional security measure if ENABLE_INSTALL_TOOL file cannot, but
+                       // should be deleted (in case it is write-protected, for example).
+               $removeInstallToolFileFailed = FALSE;
+
+                       // Only allow Install Tool access if the file "typo3conf/ENABLE_INSTALL_TOOL" is found
+               if (is_file($enableInstallToolFile) && (time() - filemtime($enableInstallToolFile) > 3600)) {
+                       $content = file_get_contents($enableInstallToolFile);
+                       $verifyString = 'KEEP_FILE';
+
+                       if (trim($content) !== $verifyString) {
+                                       // Delete the file if it is older than 3600s (1 hour)
+                               if (!@unlink($enableInstallToolFile)) {
+                                       $removeInstallToolFileFailed = TRUE;
+                               }
+                       }
+               }
+
+               if (!is_file($enableInstallToolFile) || $removeInstallToolFileFailed) {
+                       self::dieWithLockedInstallToolMessage();
+               }
+       }
+
+       /**
+        * Exit the script with a message that the install tool is locked.
+        *
+        * @return void
+        */
+       protected static function dieWithLockedInstallToolMessage() {
+               require_once(PATH_site . 't3lib/class.t3lib_parsehtml.php');
+
+                       // Define the stylesheet
+               $stylesheet = '<link rel="stylesheet" type="text/css" href="' .
+                       '../stylesheets/install/install.css" />';
+               $javascript = '<script type="text/javascript" src="' .
+                       '../contrib/prototype/prototype.js"></script>';
+               $javascript .= '<script type="text/javascript" src="' .
+                       '../sysext/install/Resources/Public/Javascript/install.js"></script>';
+
+                       // Get the template file
+               $template = @file_get_contents(PATH_site . 'typo3/templates/install.html');
+                       // Define the markers content
+               $markers = array(
+                       'styleSheet' => $stylesheet,
+                       'javascript' => $javascript,
+                       'title' => 'The Install Tool is locked',
+                       'content' => '
+                               <p>
+                                       To enable the Install Tool, the file ENABLE_INSTALL_TOOL must be created.
+                               </p>
+                               <ul>
+                                       <li>
+                                               In the typo3conf/ folder, create a file named ENABLE_INSTALL_TOOL. The file name is
+                                               case sensitive, but the file itself can simply be an empty file.
+                                       </li>
+                                       <li class="t3-install-locked-user-settings">
+                                               Alternatively, in the Backend, go to <a href="javascript:top.goToModule(\'tools_install\',1);">Admin tools &gt; Install</a>
+                                               and let TYPO3 create this file for you.<br />
+                                               You are recommended to log out from the Install Tool after finishing your work.
+                                               The file will then automatically be deleted.
+                                       </li>
+                               </ul>
+                               <p>
+                                       For security reasons, it is highly recommended that you either rename or delete the file after the operation is finished.
+                               </p>
+                               <p>
+                                       As an additional security measure, if the file is older than one hour, TYPO3 will automatically delete it. The file must be writable by the web server user.
+                               </p>
+                       '
+               );
+                       // Fill the markers
+               $content = t3lib_parsehtml::substituteMarkerArray(
+                       $template,
+                       $markers,
+                       '###|###',
+                       1,
+                       1
+               );
+                       // Output the warning message and exit
+               header('Content-Type: text/html; charset=utf-8');
+               header('Cache-Control: no-cache, must-revalidate');
+               header('Pragma: no-cache');
+               echo $content;
+               exit();
+       }
+}
+?>
\ No newline at end of file
index 03afe6f..9ff2189 100644 (file)
 ***************************************************************/
 /**
  * AJAX dispatcher
- * @author     Benjamin Mack <mack@xnos.org>
- * @package    TYPO3
+ *
+ * @author Benjamin Mack <mack@xnos.org>
+ * @package TYPO3
+ * @subpackage core
  */
 
 $TYPO3_AJAX = TRUE;
@@ -35,6 +37,7 @@ $TYPO3_AJAX = TRUE;
 // include t3lib_div at this time to get the GET/POST methods it provides
 require_once(dirname(__FILE__) . '/../t3lib/class.t3lib_div.php');
 
+
 // first get the ajaxID
 $ajaxID = (string)t3lib_div::_GP('ajaxID');
 
@@ -60,7 +63,7 @@ $ajaxScript = $TYPO3_CONF_VARS['BE']['AJAX'][$ajaxID];
 
 
        // instantiating the AJAX object
-$ajaxObj    = t3lib_div::makeInstance('TYPO3AJAX', $ajaxID);
+$ajaxObj = t3lib_div::makeInstance('TYPO3AJAX', $ajaxID);
 $ajaxParams = array();
 
 
index a768609..31aacf0 100755 (executable)
@@ -3,7 +3,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 2005-2008 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  (c) 2005-2012 Kasper Skaarhoj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 /**
  * Command Line Interface module dispatcher
  *
- * @author      Kasper Skaarhoj <kasperYYYY@typo3.com>
- *
- * This script takes a "cliKey" as first argument and uses that to look up the path of the script to include in the end.
- * See configuration of this feature in $TYPO3_CONF_VARS['SC_OPTIONS']['GLOBAL']['cliKeys'].
- * The point is to have only ONE script dealing with the environment initialization while the actual processing is all a developer should care for.
+ * This script takes a "cliKey" as first argument and uses that to dispatch
+ * the call to a registered script with that key.
+ * Valid cliKeys must be registered in
+ * $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['cliKeys'].
  *
+ * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
  */
 
-if (substr(php_sapi_name(), 0, 3) == 'cgi') {
-        // sanity check: ensure that we're running in a shell or cronjob (and NOT via HTTP)
-        $checkEnvVars = array('HTTP_USER_AGENT', 'HTTP_HOST', 'SERVER_NAME', 'REMOTE_ADDR', 'REMOTE_PORT', 'SERVER_PROTOCOL');
-        foreach ($checkEnvVars as $var) {
-                if (array_key_exists($var, $_SERVER)) {
-                        echo 'SECURITY CHECK FAILED! This script cannot be used within your browser!' . chr(10);
-                        echo 'If you are sure that we run in a shell or cronjob, please unset' . chr(10);
-                        echo 'environment variable ' . $var . ' (usually using \'unset ' . $var . '\')' . chr(10);
-                        echo 'before starting this script.' . chr(10);
-                        exit;
-                }
-        }
-        unset($checkEnvVars);
+define('TYPO3_MODE','BE');
+define('TYPO3_cliMode', TRUE);
 
-       // mimic CLI API in CGI API (you must use the -C/-no-chdir and the -q/--no-header switches!)
-       ini_set('html_errors', 0);
-       ini_set('implicit_flush', 1);
-       ini_set('max_execution_time', 0);
-       if (!ini_get('register_argc_argv')) {
-               $argv = $_SERVER['argv'];
-               $argc = $_SERVER['argc'];
-       }
-       define(STDIN, fopen('php://stdin', 'r'));
-       define(STDOUT, fopen('php://stdout', 'w'));
-       define(STDERR, fopen('php://stderr', 'w'));
-} elseif (php_sapi_name() != 'cli') {
-       die('Not called from a command line interface (e.g. a shell or scheduler).' . chr(10));
-}
+require('Bootstrap_Cli.php');
+Typo3_Bootstrap_Cli::checkEnvironmentOrDie();
 
-       // Defining circumstances for CLI mode:
-define('TYPO3_cliMode', TRUE);
+require('Bootstrap.php');
+Typo3_Bootstrap::checkEnvironmentOrDie();
+Typo3_Bootstrap::defineBaseConstants();
+Typo3_Bootstrap::defineAndCheckPaths('typo3/');
+Typo3_Bootstrap::requireBaseClasses();
+Typo3_Bootstrap::setUpEnvironment();
+
+       /** @define "PATH_t3lib" "../t3lib/" */
+require(PATH_t3lib . 'config_default.php');
 
+Typo3_Bootstrap::initializeTypo3DbGlobal(TRUE);
 
+Typo3_Bootstrap_Cli::initializeCliKeyOrDie();
 
-if (!isset($_SERVER['argv'][1]))       {
-       fwrite(STDERR, 'The first argument must be a valid key.' . chr(10));
-       exit(1);
+       // Include standard tables.php or own file
+if (TYPO3_tables_script) {
+       include(PATH_typo3conf . TYPO3_tables_script);
+} else {
+       include(PATH_t3lib . 'stddb/tables.php');
 }
+       // Load temp_CACHED file of ext_tables or each ext_tables.php of loaded extensions
+if ($TYPO3_LOADED_EXT['_CACHEFILE']) {
+       include(PATH_typo3conf . $TYPO3_LOADED_EXT['_CACHEFILE'] . '_ext_tables.php');
+} else {
+       include(PATH_t3lib . 'stddb/load_ext_tables.php');
+}
+       // Load additional ext tables script
+if (TYPO3_extTableDef_script) {
+       include(PATH_typo3conf . TYPO3_extTableDef_script);
+}
+Typo3_Bootstrap::runExtTablesPostProcessingHooks();
 
-       // First argument is a key that points to the script configuration
-define('TYPO3_cliKey', $_SERVER['argv'][1]);
+// TODO: Check if we really need the sprite manager on the command line
+Typo3_Bootstrap::initializeSpriteManager(TRUE);
 
-       // Include init file:
-require(dirname(__FILE__) . '/init.php');
+Typo3_Bootstrap::initializeBackendUser();
+Typo3_Bootstrap::initializeBackendUserMounts();
 
-       // Make sure output is not buffered,
-       // so that command-line output and interaction can take place
+Typo3_Bootstrap::initializeLanguageObject();
+
+       // Make sure output is not buffered, so command-line output and interaction can take place
 t3lib_div::flushOutputBuffers();
 
-if (defined('TYPO3_cliInclude')) {
-       try {
-               include(TYPO3_cliInclude);
-       } catch (Exception $e) {
-               fwrite(STDERR, $e->getMessage() . LF);
-               exit(99);
-       }
-} else {
-       fwrite(STDERR,  'No include file configured for key "'.TYPO3_cliKey.'".' . LF);
-       exit(1);
+try {
+       include(TYPO3_cliInclude);
+} catch (Exception $e) {
+       fwrite(STDERR, $e->getMessage() . LF);
+       exit(99);
 }
-
-?>
+?>
\ No newline at end of file
index e01cdb1..c51aa29 100644 (file)
  * For a detailed description of this script, the scope of constants and variables in it,
  * please refer to the document "Inside TYPO3"
  *
- * Revised for TYPO3 3.6 2/2003 by Kasper Skårhøj
- *
- * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
+ * @author Kasper Skårhøj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage core
  */
 
 // *******************************
-// Checking PHP version
-// *******************************
-if (version_compare(phpversion(), '5.3', '<')) die ('TYPO3 requires PHP 5.3.0 or higher.');
-
-
-// *******************************
-// Set error reporting
-// *******************************
-error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
-
-// *******************************
 // Prevent any unwanted output that may corrupt AJAX/compression. Note: this does
 // not interfeer with "die()" or "echo"+"exit()" messages!
 // *******************************
@@ -78,175 +65,20 @@ ob_start();
 // *******************************
 define('TYPO3_MODE','BE');
 
-require_once('Bootstrap.php');
+require('Bootstrap.php');
+Typo3_Bootstrap::checkEnvironmentOrDie();
 Typo3_Bootstrap::defineBaseConstants();
 Typo3_Bootstrap::defineAndCheckPaths('typo3/');
+Typo3_Bootstrap::requireBaseClasses();
+Typo3_Bootstrap::setUpEnvironment();
 
 
+require(PATH_t3lib . 'config_default.php');
 
-// *********************
-// Unset variable(s) in global scope (fixes #13959)
-// *********************
-unset($error);
-
-// *************************************************
-// t3lib_div + extention management class included
-// *************************************************
-require_once(PATH_t3lib.'class.t3lib_div.php');                // The standard-library is included
-require_once(PATH_t3lib.'class.t3lib_extmgm.php');     // Extension API Management library included
-
-// ****************************************************
-// Include configuration (localconf + ext_localconf)
-// ****************************************************
-require(PATH_t3lib.'config_default.php');
-if (!defined ('TYPO3_db'))     die ('The configuration file was not included.');
-
-
-
-
-// *********************
-// Error & Exception handling
-// *********************
-if ($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionHandler'] !== '') {
-       if ($TYPO3_CONF_VARS['SYS']['errorHandler'] !== '') {
-                       //      register an error handler for the given errorHandlerErrors
-               $errorHandler = t3lib_div::makeInstance($TYPO3_CONF_VARS['SYS']['errorHandler'], $TYPO3_CONF_VARS['SYS']['errorHandlerErrors']);
-                       // set errors which will be converted in an exception
-               $errorHandler->setExceptionalErrors($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionalErrors']);
-       }
-       $exceptionHandler = t3lib_div::makeInstance($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionHandler']);
-}
-
-/** @var TYPO3_DB t3lib_db */
-$TYPO3_DB = t3lib_div::makeInstance('t3lib_DB');
-$TYPO3_DB->debugOutput = $TYPO3_CONF_VARS['SYS']['sqlDebug'];
-
-$CLIENT = t3lib_div::clientInfo();                                     // $CLIENT includes information about the browser/user-agent
-$PARSETIME_START = t3lib_div::milliseconds();          // Is set to the system time in milliseconds. This could be used to output script parsetime in the end of the script
-
-
-// *************************
-// CLI dispatch processing
-// *************************
-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']);
-       array_unshift($_SERVER['argv'],$temp_cliScriptPath);
-
-               // If cli_key was found in configuration, then set up the cliInclude path and module name:
-       if ($temp_cliKey)       {
-               if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['GLOBAL']['cliKeys'][$temp_cliKey]))        {
-                       define('TYPO3_cliInclude', t3lib_div::getFileAbsFileName($TYPO3_CONF_VARS['SC_OPTIONS']['GLOBAL']['cliKeys'][$temp_cliKey][0]));
-                       $MCONF['name'] = $TYPO3_CONF_VARS['SC_OPTIONS']['GLOBAL']['cliKeys'][$temp_cliKey][1];
-               } else {
-                       $message = "The supplied 'cliKey' was not valid. Please use one of the available from this list:\n\n";
-                       $message .= var_export(array_keys($TYPO3_CONF_VARS['SC_OPTIONS']['GLOBAL']['cliKeys']), TRUE);
-                       fwrite(STDERR, $message . LF);
-                       exit(2);
-               }
-       } else {
-               $message = "Please supply a 'cliKey' as first argument. The following are available:\n\n";
-               $message .= var_export(array_keys($TYPO3_CONF_VARS['SC_OPTIONS']['GLOBAL']['cliKeys']), TRUE);
-               fwrite(STDERR, $message . LF);
-               exit(2);
-       }
-}
-
-
-// **********************
-// Check Hardcoded lock on BE:
-// **********************
-if ($TYPO3_CONF_VARS['BE']['adminOnly'] < 0) {
-       throw new RuntimeException('TYPO3 Backend locked: Backend and Install Tool are locked for maintenance. [BE][adminOnly] is set to "' . intval($TYPO3_CONF_VARS['BE']['adminOnly']) . '".', 1294586847);
-}
-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 {
-               $fContent = t3lib_div::getUrl(PATH_typo3conf.'LOCK_BACKEND');
-               if ($fContent)  {
-                       header('Location: '.$fContent); // Redirect
-               } else {
-                       throw new RuntimeException('TYPO3 Backend locked: Browser backend is locked for maintenance. Remove lock by removing the file "typo3conf/LOCK_BACKEND" or use CLI-scripts.', 1294586848);
-               }
-               exit;
-       }
-
-}
-
-// **********************
-// Check IP
-// **********************
-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...
-               exit;   // ... and exit good!
-       }
-}
-
-
-// **********************
-// Check SSL (https)
-// **********************
-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 {
-               $sslPortSuffix = '';
-       }
-       if ($TYPO3_CONF_VARS['BE']['lockSSL'] == 3)     {
-               $requestStr = substr(t3lib_div::getIndpEnv('TYPO3_REQUEST_SCRIPT'), strlen(t3lib_div::getIndpEnv('TYPO3_SITE_URL').TYPO3_mainDir));
-               if($requestStr == 'index.php' && !t3lib_div::getIndpEnv('TYPO3_SSL'))   {
-                       list(,$url) = explode('://',t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'),2);
-                       list($server,$address) = explode('/',$url,2);
-                       header('Location: https://'.$server.$sslPortSuffix.'/'.$address);
-                       exit;
-               }
-       } elseif (!t3lib_div::getIndpEnv('TYPO3_SSL') ) {
-               if ($TYPO3_CONF_VARS['BE']['lockSSL'] == 2)     {
-                       list(,$url) = explode('://',t3lib_div::getIndpEnv('TYPO3_SITE_URL').TYPO3_mainDir,2);
-                       list($server,$address) = explode('/',$url,2);
-                       header('Location: https://'.$server.$sslPortSuffix.'/'.$address);
-               } else {
-                       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...
-               }
-               exit;   // ... and exit good!
-       }
-}
-
-
-// *******************************
-// Checking environment
-// *******************************
-if (isset($_POST['GLOBALS']) || isset($_GET['GLOBALS'])) {
-       die('You cannot set the GLOBALS-array from outside the script.');
-}
-if (!get_magic_quotes_gpc()) {
-       t3lib_div::addSlashesOnArray($_GET);
-       t3lib_div::addSlashesOnArray($_POST);
-       $HTTP_GET_VARS = $_GET;
-       $HTTP_POST_VARS = $_POST;
-}
-
-
-// ********************************************
-// Check if the install script should be run:
-// ********************************************
-if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_INSTALL) {
-       if(!t3lib_extMgm::isLoaded('install')) {
-               die('Install Tool is not loaded as an extension.<br />You must add the key "install" to the list of installed extensions in typo3conf/localconf.php, $TYPO3_CONF_VARS[\'EXT\'][\'extList\'].');
-       }
-
-       require_once(t3lib_extMgm::extPath('install').'mod/class.tx_install.php');
-       $install_check = t3lib_div::makeInstance('tx_install');
-       $install_check->allowUpdateLocalConf = 1;
-       $install_check->init();
-       exit;
-}
-
+Typo3_Bootstrap::initializeTypo3DbGlobal(FALSE);
+Typo3_Bootstrap::checkLockedBackendAndRedirectOrDie();
+Typo3_Bootstrap::checkBackendIpOrDie();
+Typo3_Bootstrap::checkSslBackendAndRedirectIfNeeded();
 
 // *************************
 // Connect to the database
@@ -262,79 +94,36 @@ if (!TYPO3_db_host && !TYPO3_db) {
 // *******************************
 // Checks for proper browser
 // *******************************
-if (!$CLIENT['BROWSER'] && !(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI)) {
+if (!$CLIENT['BROWSER']) {
        throw new RuntimeException('Browser Error: Your browser version looks incompatible with this TYPO3 version!', 1294587023);
 }
 
-
-// ****************************************************
-// Include tables customization (tables + ext_tables)
-// ****************************************************
-include (TYPO3_tables_script ? PATH_typo3conf.TYPO3_tables_script : PATH_t3lib.'stddb/tables.php');
-       // Extension additions
-if ($TYPO3_LOADED_EXT['_CACHEFILE'])   {
-       include (PATH_typo3conf.$TYPO3_LOADED_EXT['_CACHEFILE'].'_ext_tables.php');
+       // Include standard tables.php or own file
+if (TYPO3_tables_script) {
+       include(PATH_typo3conf . TYPO3_tables_script);
 } else {
-       include (PATH_t3lib.'stddb/load_ext_tables.php');
+       include(PATH_t3lib . 'stddb/tables.php');
 }
-       // extScript
-if (TYPO3_extTableDef_script)  {
-       include (PATH_typo3conf.TYPO3_extTableDef_script);
-}
-
-       // Hook for postprocessing values set in extTables.php
-if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'])) {
-       foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'] as $_classRef) {
-               $hookObject = t3lib_div::getUserObj($_classRef);
-               if (!$hookObject instanceof t3lib_extTables_PostProcessingHook) {
-                       throw new UnexpectedValueException('$hookObject must implement interface t3lib_extTables_PostProcessingHook', 1320585902);
-               }
-               $hookObject->processData();
-       }
+       // Load temp_CACHED file of ext_tables or each ext_tables.php of loaded extensions
+if ($TYPO3_LOADED_EXT['_CACHEFILE']) {
+       include(PATH_typo3conf . $TYPO3_LOADED_EXT['_CACHEFILE'] . '_ext_tables.php');
+} else {
+       include(PATH_t3lib . 'stddb/load_ext_tables.php');
 }
-
-
-       // load TYPO3 SpriteGenerating API
-$spriteManager = t3lib_div::makeInstance('t3lib_SpriteManager', TRUE);
-$spriteManager->loadCacheFile();
-
-
-// *******************************
-// BackEnd User authentication
-// *******************************
-/*
-       NOTICE:
-       if constant TYPO3_PROCEED_IF_NO_USER is defined TRUE (in the mainscript), this script will return even though a user did not log in!
-*/
-$BE_USER = t3lib_div::makeInstance('t3lib_beUserAuth');        // New backend user object
-$BE_USER->warningEmail = $TYPO3_CONF_VARS['BE']['warning_email_addr'];
-$BE_USER->lockIP = $TYPO3_CONF_VARS['BE']['lockIP'];
-$BE_USER->auth_timeout_field = intval($TYPO3_CONF_VARS['BE']['sessionTimeout']);
-$BE_USER->OS = TYPO3_OS;
-if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI) {
-       $BE_USER->dontSetCookie = TRUE;
+       // Load additional ext tables script
+if (TYPO3_extTableDef_script) {
+       include(PATH_typo3conf . TYPO3_extTableDef_script);
 }
-$BE_USER->start();                     // Object is initialized
-$BE_USER->checkCLIuser();
-$BE_USER->backendCheckLogin(); // Checking if there's a user logged in
-
-       // Setting the web- and filemount global vars:
-$WEBMOUNTS = $BE_USER->returnWebmounts();              // ! WILL INCLUDE deleted mount pages as well!
-$FILEMOUNTS = $BE_USER->returnFilemounts();
-
-// *******************************
-// $GLOBALS['LANG'] initialisation
-// *******************************
-// $GLOBALS needed here ?? we still are in the global scope.
 
-$GLOBALS['LANG'] = t3lib_div::makeInstance('language');
-$GLOBALS['LANG']->init($BE_USER->uc['lang']);
+Typo3_Bootstrap::runExtTablesPostProcessingHooks();
+Typo3_Bootstrap::initializeSpriteManager(TRUE);
+Typo3_Bootstrap::initializeBackendUser();
+Typo3_Bootstrap::initializeBackendUserMounts();
+Typo3_Bootstrap::initializeLanguageObject();
 
-// ****************
-// compression
-// ****************
+       // Compression
 ob_clean();
-if (extension_loaded('zlib') && $TYPO3_CONF_VARS['BE']['compressionLevel'])    {
+if (extension_loaded('zlib') && $TYPO3_CONF_VARS['BE']['compressionLevel']) {
        if (t3lib_utility_Math::canBeInterpretedAsInteger($TYPO3_CONF_VARS['BE']['compressionLevel'])) {
                @ini_set('zlib.output_compression_level', $TYPO3_CONF_VARS['BE']['compressionLevel']);
        }
index 74fb45a..ca79a9a 100755 (executable)
  * @subpackage core
  */
 
+ob_start();
 
+define('TYPO3_MODE','BE');
+define('TYPO3_enterInstallScript', '1');
 
-// **************************************************************************
-// Insert some security here, if you don't trust the Install Tool Password:
-// **************************************************************************
-
-error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
-
-$PATH_thisScript = str_replace('//', '/', str_replace('\\', '/',
-       (PHP_SAPI == 'fpm-fcgi' || PHP_SAPI == 'cgi' || PHP_SAPI == 'isapi' || PHP_SAPI == 'cgi-fcgi') &&
-       ($_SERVER['ORIG_PATH_TRANSLATED'] ? $_SERVER['ORIG_PATH_TRANSLATED'] : $_SERVER['PATH_TRANSLATED']) ?
-       ($_SERVER['ORIG_PATH_TRANSLATED'] ? $_SERVER['ORIG_PATH_TRANSLATED'] : $_SERVER['PATH_TRANSLATED']) :
-       ($_SERVER['ORIG_SCRIPT_FILENAME'] ? $_SERVER['ORIG_SCRIPT_FILENAME'] : $_SERVER['SCRIPT_FILENAME'])));
-
-$PATH_site = dirname(dirname(dirname($PATH_thisScript)));
-
-$quickstartFile = $PATH_site . '/typo3conf/FIRST_INSTALL';
-$enableInstallToolFile = $PATH_site . '/typo3conf/ENABLE_INSTALL_TOOL';
+require('../Bootstrap.php');
+Typo3_Bootstrap::checkEnvironmentOrDie();
+Typo3_Bootstrap::defineBaseConstants();
+Typo3_Bootstrap::defineAndCheckPaths('typo3/install/');
+Typo3_Bootstrap::requireBaseClasses();
+Typo3_Bootstrap::setUpEnvironment();
 
-       // If typo3conf/FIRST_INSTALL is present and can be deleted, automatically create typo3conf/ENABLE_INSTALL_TOOL
-if (is_file($quickstartFile) && is_writeable($quickstartFile) && unlink($quickstartFile)) {
-       touch($enableInstallToolFile);
-}
+require('../Bootstrap_Install.php');
+Typo3_Bootstrap_Install::checkEnabledInstallToolOrDie();
 
-       // Additional security measure if ENABLE_INSTALL_TOOL file cannot, but
-       // should be deleted (in case it is write-protected, for example).
-$removeInstallToolFileFailed = FALSE;
+require(PATH_t3lib . 'config_default.php');
 
-       // Only allow Install Tool access if the file "typo3conf/ENABLE_INSTALL_TOOL" is found
-if (is_file($enableInstallToolFile) && (time() - filemtime($enableInstallToolFile) > 3600)) {
-       $content = file_get_contents($enableInstallToolFile);
-       $verifyString = 'KEEP_FILE';
+Typo3_Bootstrap::initializeTypo3DbGlobal(FALSE);
 
-       if (trim($content) !== $verifyString) {
-                       // Delete the file if it is older than 3600s (1 hour)
-               if (!@unlink($enableInstallToolFile)) {
-                       $removeInstallToolFileFailed = TRUE;
-               }
-       }
-}
+Typo3_Bootstrap::checkLockedBackendAndRedirectOrDie();
 
-       // Change 1==2 to 1==1 if you want to lock the Install Tool regardless of the file ENABLE_INSTALL_TOOL
-if (1==2 || !is_file($enableInstallToolFile) || $removeInstallToolFileFailed) {
-               // Include t3lib_div and t3lib_parsehtml for templating
-       require_once($PATH_site . '/t3lib/class.t3lib_div.php');
-       require_once($PATH_site . '/t3lib/class.t3lib_parsehtml.php');
+Typo3_Bootstrap::checkBackendIpOrDie();
 
-               // Define the stylesheet
-       $stylesheet = '<link rel="stylesheet" type="text/css" href="' .
-               '../stylesheets/install/install.css" />';
-       $javascript = '<script type="text/javascript" src="' .
-               '../contrib/prototype/prototype.js"></script>';
-       $javascript .= '<script type="text/javascript" src="' .
-               '../sysext/install/Resources/Public/Javascript/install.js"></script>';
+Typo3_Bootstrap::checkSslBackendAndRedirectIfNeeded();
 
-               // Get the template file
-       $template = @file_get_contents($PATH_site . '/typo3/templates/install.html');
-               // Define the markers content
-       $markers = array(
-               'styleSheet' => $stylesheet,
-               'javascript' => $javascript,
-               'title' => 'The Install Tool is locked',
-               'content' => '
-                       <p>
-                               To enable the Install Tool, the file ENABLE_INSTALL_TOOL must be created.
-                       </p>
-                       <ul>
-                               <li>
-                                       In the typo3conf/ folder, create a file named ENABLE_INSTALL_TOOL. The file name is
-                                       case sensitive, but the file itself can simply be an empty file.
-                               </li>
-                               <li class="t3-install-locked-user-settings">
-                                       Alternatively, in the Backend, go to <a href="javascript:top.goToModule(\'tools_install\',1);">Admin tools &gt; Install</a>
-                                       and let TYPO3 create this file for you.<br />
-                                       You are recommended to log out from the Install Tool after finishing your work.
-                                       The file will then automatically be deleted.
-                               </li>
-                       </ul>
-                       <p>
-                               For security reasons, it is highly recommended that you either rename or delete the file after the operation is finished.
-                       </p>
-                       <p>
-                               As an additional security measure, if the file is older than one hour, TYPO3 will automatically delete it. The file must be writable by the web server user.
-                       </p>
-               '
-       );
-               // Fill the markers
-       $content = t3lib_parsehtml::substituteMarkerArray(
-               $template,
-               $markers,
-               '###|###',
-               1,
-               1
-       );
-               // Output the warning message and exit
-       header('Content-Type: text/html; charset=utf-8');
-       header('Cache-Control: no-cache, must-revalidate');
-       header('Pragma: no-cache');
-       echo $content;
-       exit();
+       // Run install script
+if(!t3lib_extMgm::isLoaded('install')) {
+       die('Install Tool is not loaded as an extension.<br />You must add the key "install" to the list of installed extensions in typo3conf/localconf.php, $TYPO3_CONF_VARS[\'EXT\'][\'extList\'].');
 }
 
-
-
-// *****************************************************************************
-// Defining constants necessary for the install-script to invoke the installer
-// *****************************************************************************
-define('TYPO3_MOD_PATH', 'install/');
-$BACK_PATH='../';
-
-       // Defining this variable and setting it non-false will invoke the install-screen called from init.php
-define('TYPO3_enterInstallScript', '1');
-require ('../init.php');
-
+require_once(t3lib_extMgm::extPath('install') . 'mod/class.tx_install.php');
+$install_check = t3lib_div::makeInstance('tx_install');
+$install_check->allowUpdateLocalConf = 1;
+$install_check->init();
 ?>
\ No newline at end of file
index ac78e7d..ec70e02 100644 (file)
  * @subpackage tslib
  */
 
-// *******************************
-// Checking PHP version
-// *******************************
-if (version_compare(phpversion(), '5.3', '<')) die ('TYPO3 requires PHP 5.3.0 or higher.');
-
-
 // ******************
 // Constants defined
 // ******************
-$TYPO3_MISC['microtime_start'] = microtime(TRUE);
 define('TYPO3_MODE','FE');
 
 // *********************
-// Unset variable(s) in global scope (fixes #13959)
-// *********************
-unset($error);
-
-// *********************
 // Prevent any output until AJAX/compression is initialized to stop
 // AJAX/compression data corruption
 // *********************
 ob_start();
 
 
-// *********************
-// Mandatory libraries included
-// *********************
-require_once(PATH_t3lib . 'class.t3lib_div.php');
-require_once(PATH_t3lib . 'class.t3lib_extmgm.php');
-
 
 // **********************
 // Include configuration
 // **********************
 require(PATH_t3lib.'config_default.php');
-if (!defined ('TYPO3_db'))     die ('The configuration file was not included.');       // the name of the TYPO3 database is stored in this constant. Here the inclusion of the config-file is verified by checking if this var is set.
-if (!t3lib_extMgm::isLoaded('cms'))    die('<strong>Error:</strong> The main frontend extension "cms" was not loaded. Enable it in the extension manager in the backend.');
+if (!t3lib_extMgm::isLoaded('cms')) {
+       die('<strong>Error:</strong> The main frontend extension "cms" was not loaded. Enable it in the extension manager in the backend.');
+}
 
 
 // *********************
@@ -87,43 +70,9 @@ if ($_COOKIE[t3lib_beUserAuth::getCookieName()]) {
        $TT = new t3lib_timeTrackNull();
 }
 $TT->start();
-$TT->push('', 'Script start');
-
-// *********************
-// Error & Exception handling
-// *********************
-if ($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionHandler'] !== '') {
-       $TT->push('Register Exceptionhandler', '');
-       if ($TYPO3_CONF_VARS['SYS']['errorHandler'] !== '') {
-                       // register an error handler for the given errorHandlerErrors
-               $errorHandler = t3lib_div::makeInstance($TYPO3_CONF_VARS['SYS']['errorHandler'], $TYPO3_CONF_VARS['SYS']['errorHandlerErrors']);
-                       // set errors which will be converted in an exception
-               $errorHandler->setExceptionalErrors($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionalErrors']);
-       }
-       $exceptionHandler = t3lib_div::makeInstance($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionHandler']);
-       $TT->pull();
-}
-
-$TYPO3_DB = t3lib_div::makeInstance('t3lib_DB');
-$TYPO3_DB->debugOutput = $TYPO3_CONF_VARS['SYS']['sqlDebug'];
 
-$CLIENT = t3lib_div::clientInfo();                             // Set to the browser: net / msie if 4+ browsers
-$TT->pull();
+Typo3_Bootstrap::initializeTypo3DbGlobal(FALSE);
 
-// *******************************
-// Checking environment
-// *******************************
-if (isset($_POST['GLOBALS']) || isset($_GET['GLOBALS'])) {
-       throw new Exception('You cannot set the GLOBALS-array from outside the script.', 1294585200);
-}
-if (!get_magic_quotes_gpc())   {
-       $TT->push('Add slashes to GET/POST arrays','');
-       t3lib_div::addSlashesOnArray($_GET);
-       t3lib_div::addSlashesOnArray($_POST);
-       $HTTP_GET_VARS = $_GET;
-       $HTTP_POST_VARS = $_POST;
-       $TT->pull();
-}
 
 
 // Hook to preprocess the current request:
@@ -240,14 +189,11 @@ $TT->pull();
 // Admin Panel & Frontend editing
 // *****************************************
 if ($TSFE->isBackendUserLoggedIn()) {
-               // if a BE User is present load, the sprite manager for frontend-editing
-       $spriteManager = t3lib_div::makeInstance('t3lib_SpriteManager', FALSE);
-       $spriteManager->loadCacheFile();
+       Typo3_Bootstrap::initializeSpriteManager(FALSE);
 
        $BE_USER->initializeFrontendEdit();
        if ($BE_USER->adminPanel instanceof tslib_AdminPanel) {
-               $LANG = t3lib_div::makeInstance('language');
-               $LANG->init($BE_USER->uc['lang']);
+               Typo3_Bootstrap::initializeLanguageObject();
        }
        if ($BE_USER->frontendEdit instanceof t3lib_frontendedit) {
                $BE_USER->frontendEdit->initConfigOptions();