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