[TASK] Fix broken references to exceptions in global namespace
[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 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 * @author Christian Kuhn <lolli@schwarzbu.ch>
33 * @package TYPO3
34 * @subpackage core
35 */
36 class InstallBootstrap {
37
38 /**
39 * Check ENABLE_INSTALL_TOOL and FIRST_INSTALL file in typo3conf
40 * or exit the script if conditions to access the install tool are not met.
41 *
42 * @return void
43 */
44 static public function checkEnabledInstallToolOrDie() {
45 $quickstartFile = PATH_site . 'typo3conf/FIRST_INSTALL';
46 $enableInstallToolFile = PATH_site . 'typo3conf/ENABLE_INSTALL_TOOL';
47 // If typo3conf/FIRST_INSTALL is present and can be deleted, automatically create typo3conf/ENABLE_INSTALL_TOOL
48 if ((is_file($quickstartFile) && is_writeable($quickstartFile)) && unlink($quickstartFile)) {
49 touch($enableInstallToolFile);
50 }
51 // Additional security measure if ENABLE_INSTALL_TOOL file cannot, but
52 // should be deleted (in case it is write-protected, for example).
53 $removeInstallToolFileFailed = FALSE;
54 // Only allow Install Tool access if the file "typo3conf/ENABLE_INSTALL_TOOL" is found
55 if (is_file($enableInstallToolFile) && time() - filemtime($enableInstallToolFile) > 3600) {
56 $content = file_get_contents($enableInstallToolFile);
57 $verifyString = 'KEEP_FILE';
58 if (trim($content) !== $verifyString) {
59 // Delete the file if it is older than 3600s (1 hour)
60 if (!@unlink($enableInstallToolFile)) {
61 $removeInstallToolFileFailed = TRUE;
62 }
63 }
64 }
65 if (!is_file($enableInstallToolFile) || $removeInstallToolFileFailed) {
66 self::dieWithLockedInstallToolMessage();
67 }
68 }
69
70 /**
71 * Exit the script with a message that the install tool is locked.
72 *
73 * @return void
74 */
75 static protected function dieWithLockedInstallToolMessage() {
76 require_once PATH_site . 't3lib/class.t3lib_parsehtml.php';
77 // Define the stylesheet
78 $stylesheet = '<link rel="stylesheet" type="text/css" href="' . '../stylesheets/install/install.css" />';
79 $javascript = '<script type="text/javascript" src="' . '../contrib/prototype/prototype.js"></script>';
80 $javascript .= '<script type="text/javascript" src="' . '../sysext/install/Resources/Public/Javascript/install.js"></script>';
81 // Get the template file
82 $template = @file_get_contents((PATH_site . 'typo3/templates/install.html'));
83 // Define the markers content
84 $markers = array(
85 'styleSheet' => $stylesheet,
86 'javascript' => $javascript,
87 'title' => 'The Install Tool is locked',
88 'content' => '
89 <p>
90 To enable the Install Tool, the file ENABLE_INSTALL_TOOL must be created.
91 </p>
92 <ul>
93 <li>
94 In the typo3conf/ folder, create a file named ENABLE_INSTALL_TOOL. The file name is
95 case sensitive, but the file itself can simply be an empty file.
96 </li>
97 <li class="t3-install-locked-user-settings">
98 Alternatively, in the Backend, go to <a href="javascript:top.goToModule(\'tools_install\',1);">Admin tools &gt; Install</a>
99 and let TYPO3 create this file for you.<br />
100 You are recommended to log out from the Install Tool after finishing your work.
101 The file will then automatically be deleted.
102 </li>
103 </ul>
104 <p>
105 For security reasons, it is highly recommended that you either rename or delete the file after the operation is finished.
106 </p>
107 <p>
108 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.
109 </p>
110 '
111 );
112 // Fill the markers
113 $content = \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($template, $markers, '###|###', 1, 1);
114 // Output the warning message and exit
115 header('Content-Type: text/html; charset=utf-8');
116 header('Cache-Control: no-cache, must-revalidate');
117 header('Pragma: no-cache');
118 echo $content;
119 die;
120 }
121
122 }
123
124
125 ?>