[TASK] Introduce jQuery in the Install Tool
[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 /**
31 * Encapsulate install tool specific bootstrap methods.
32 *
33 * This script is internal code and subject to change.
34 * DO NOT use it in own code, or be prepared your code might
35 * break in future core versions.
36 *
37 * @author Christian Kuhn <lolli@schwarzbu.ch>
38 */
39 class InstallBootstrap {
40
41 /**
42 * During first install, typo3conf/LocalConfiguration.php does not
43 * exist. It is created now based on factory configuration as a
44 * first action in the install process.
45 *
46 * @return void
47 * @internal This is not a public API method, do not use in own extensions
48 */
49 static public function createLocalConfigurationIfNotExists() {
50 /** @var $configurationManager \TYPO3\CMS\Core\Configuration\ConfigurationManager */
51 $configurationManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
52 if (
53 !file_exists($configurationManager->getLocalConfigurationFileLocation())
54 && !file_exists($configurationManager->getLocalconfFileLocation())
55 ) {
56 $configurationManager->createLocalConfigurationFromFactoryConfiguration();
57 }
58 }
59
60 /**
61 * Check ENABLE_INSTALL_TOOL and FIRST_INSTALL file in typo3conf
62 * or exit the script if conditions to access the install tool are not met.
63 *
64 * @return void
65 * @internal This is not a public API method, do not use in own extensions
66 */
67 static public function checkEnabledInstallToolOrDie() {
68 $quickstartFile = PATH_site . 'typo3conf/FIRST_INSTALL';
69 $enableInstallToolFile = PATH_site . 'typo3conf/ENABLE_INSTALL_TOOL';
70 // If typo3conf/FIRST_INSTALL is present and can be deleted, automatically create typo3conf/ENABLE_INSTALL_TOOL
71 if (is_file($quickstartFile) && is_writeable($quickstartFile) && unlink($quickstartFile)) {
72 touch($enableInstallToolFile);
73 }
74 // Additional security measure if ENABLE_INSTALL_TOOL file cannot, but
75 // should be deleted (in case it is write-protected, for example).
76 $removeInstallToolFileFailed = FALSE;
77 // Only allow Install Tool access if the file "typo3conf/ENABLE_INSTALL_TOOL" is found
78 if (is_file($enableInstallToolFile) && time() - filemtime($enableInstallToolFile) > 3600) {
79 $content = file_get_contents($enableInstallToolFile);
80 $verifyString = 'KEEP_FILE';
81 if (trim($content) !== $verifyString) {
82 // Delete the file if it is older than 3600s (1 hour)
83 if (!@unlink($enableInstallToolFile)) {
84 $removeInstallToolFileFailed = TRUE;
85 }
86 }
87 }
88 if (!is_file($enableInstallToolFile) || $removeInstallToolFileFailed) {
89 self::dieWithLockedInstallToolMessage();
90 }
91 }
92
93 /**
94 * Exit the script with a message that the install tool is locked.
95 *
96 * @return void
97 */
98 static protected function dieWithLockedInstallToolMessage() {
99 require_once PATH_site . 'typo3/sysext/core/Classes/Html/HtmlParser.php';
100 // Define the stylesheet
101 $stylesheet = '<link rel="stylesheet" type="text/css" href="' . '../stylesheets/install/install.css" />';
102 $javascript = '<script type="text/javascript" src="' . '../contrib/jquery/jquery-1.9.1.min.js"></script>';
103 $javascript .= '<script type="text/javascript" src="' . '../sysext/install/Resources/Public/Javascript/install.js"></script>';
104 // Get the template file
105 $template = @file_get_contents(PATH_site . 'typo3/sysext/install/Resources/Private/Templates/Notice.html');
106 // Define the markers content
107 $markers = array(
108 'styleSheet' => $stylesheet,
109 'javascript' => $javascript,
110 'title' => 'The Install Tool is locked',
111 'content' => '
112 <p>
113 To enable the Install Tool, the file ENABLE_INSTALL_TOOL must be created.
114 </p>
115 <ul>
116 <li>
117 In the typo3conf/ folder, create a file named ENABLE_INSTALL_TOOL. The file name is
118 case sensitive, but the file itself can simply be an empty file.
119 </li>
120 <li class="t3-install-locked-user-settings">
121 Alternatively, in the Backend, go to <a href="javascript:top.goToModule(\'tools_install\',1);">Admin tools &gt; Install</a>
122 and let TYPO3 create this file for you.<br />
123 You are recommended to log out from the Install Tool after finishing your work.
124 The file will then automatically be deleted.
125 </li>
126 </ul>
127 <p>
128 For security reasons, it is highly recommended that you either rename or delete the file after the operation is finished.
129 </p>
130 <p>
131 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.
132 </p>
133 '
134 );
135 // Fill the markers
136 $content = \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($template, $markers, '###|###', 1, 1);
137 // Output the warning message and exit
138 header('Content-Type: text/html; charset=utf-8');
139 header('Cache-Control: no-cache, must-revalidate');
140 header('Pragma: no-cache');
141 echo $content;
142 die;
143 }
144
145 }
146
147
148 ?>