[TASK] Release installation procedure from LocalConfiguration file
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / InstallBootstrap.php
1 <?php
2 namespace TYPO3\CMS\Install;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012-2013 Christian Kuhn <lolli@schwarzbu.ch>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 /**
30 * Encapsulate install tool specific bootstrap methods.
31 *
32 * This script is internal code and subject to change.
33 * DO NOT use it in own code, or be prepared your code might
34 * break in future core versions.
35 *
36 * @author Christian Kuhn <lolli@schwarzbu.ch>
37 */
38 class InstallBootstrap {
39
40 /**
41 * During first install, typo3conf/LocalConfiguration.php does not
42 * exist. It is created now based on factory configuration as a
43 * first action in the install process.
44 *
45 * @return void
46 * @internal This is not a public API method, do not use in own extensions
47 */
48 static public function createLocalConfigurationIfNotExists() {
49 /** @var $configurationManager \TYPO3\CMS\Core\Configuration\ConfigurationManager */
50 $configurationManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
51 if (
52 !file_exists($configurationManager->getLocalConfigurationFileLocation())
53 && !file_exists($configurationManager->getLocalconfFileLocation())
54 ) {
55 $configurationManager->createLocalConfigurationFromFactoryConfiguration();
56 }
57 }
58
59 /**
60 * Check ENABLE_INSTALL_TOOL and FIRST_INSTALL file in typo3conf
61 * or exit the script if conditions to access the install tool are not met.
62 *
63 * @return void
64 * @internal This is not a public API method, do not use in own extensions
65 */
66 static public function checkEnabledInstallToolOrDie() {
67 $quickstartFile = PATH_site . 'typo3conf/FIRST_INSTALL';
68 $enableInstallToolFile = PATH_site . 'typo3conf/ENABLE_INSTALL_TOOL';
69 // If typo3conf/FIRST_INSTALL is present and can be deleted, automatically create typo3conf/ENABLE_INSTALL_TOOL
70 if (is_file($quickstartFile) && is_writeable($quickstartFile) && unlink($quickstartFile)) {
71 touch($enableInstallToolFile);
72 }
73 // Additional security measure if ENABLE_INSTALL_TOOL file cannot, but
74 // should be deleted (in case it is write-protected, for example).
75 $removeInstallToolFileFailed = FALSE;
76 // Only allow Install Tool access if the file "typo3conf/ENABLE_INSTALL_TOOL" is found
77 if (is_file($enableInstallToolFile) && time() - filemtime($enableInstallToolFile) > 3600) {
78 $content = file_get_contents($enableInstallToolFile);
79 $verifyString = 'KEEP_FILE';
80 if (trim($content) !== $verifyString) {
81 // Delete the file if it is older than 3600s (1 hour)
82 if (!@unlink($enableInstallToolFile)) {
83 $removeInstallToolFileFailed = TRUE;
84 }
85 }
86 }
87 if (!is_file($enableInstallToolFile) || $removeInstallToolFileFailed) {
88 self::dieWithLockedInstallToolMessage();
89 }
90 }
91
92 /**
93 * Exit the script with a message that the install tool is locked.
94 *
95 * @return void
96 */
97 static protected function dieWithLockedInstallToolMessage() {
98 require_once PATH_site . 't3lib/class.t3lib_parsehtml.php';
99 // Define the stylesheet
100 $stylesheet = '<link rel="stylesheet" type="text/css" href="' . '../stylesheets/install/install.css" />';
101 $javascript = '<script type="text/javascript" src="' . '../contrib/prototype/prototype.js"></script>';
102 $javascript .= '<script type="text/javascript" src="' . '../sysext/install/Resources/Public/Javascript/install.js"></script>';
103 // Get the template file
104 $template = @file_get_contents((PATH_site . 'typo3/templates/install.html'));
105 // Define the markers content
106 $markers = array(
107 'styleSheet' => $stylesheet,
108 'javascript' => $javascript,
109 'title' => 'The Install Tool is locked',
110 'content' => '
111 <p>
112 To enable the Install Tool, the file ENABLE_INSTALL_TOOL must be created.
113 </p>
114 <ul>
115 <li>
116 In the typo3conf/ folder, create a file named ENABLE_INSTALL_TOOL. The file name is
117 case sensitive, but the file itself can simply be an empty file.
118 </li>
119 <li class="t3-install-locked-user-settings">
120 Alternatively, in the Backend, go to <a href="javascript:top.goToModule(\'tools_install\',1);">Admin tools &gt; Install</a>
121 and let TYPO3 create this file for you.<br />
122 You are recommended to log out from the Install Tool after finishing your work.
123 The file will then automatically be deleted.
124 </li>
125 </ul>
126 <p>
127 For security reasons, it is highly recommended that you either rename or delete the file after the operation is finished.
128 </p>
129 <p>
130 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.
131 </p>
132 '
133 );
134 // Fill the markers
135 $content = \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($template, $markers, '###|###', 1, 1);
136 // Output the warning message and exit
137 header('Content-Type: text/html; charset=utf-8');
138 header('Cache-Control: no-cache, must-revalidate');
139 header('Pragma: no-cache');
140 echo $content;
141 die;
142 }
143
144 }
145
146
147 ?>