[BUGFIX] Unlock Install Tool only after acknowledgement
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / mod / index.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2011 Steffen Gebert <steffen.gebert@typo3.org>
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 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 // This checks permissions and exits if the users has no permission for entry.
26 $BE_USER->modAccess($MCONF, TRUE);
27
28
29 /**
30 * Backend module of the 'install' extension, which automatically enables the
31 * Install Tool, if it's accessed by an authenticated Backend user.
32 *
33 * @author Steffen Gebert <steffen.gebert@typo3.org>
34 * @package TYPO3
35 * @subpackage install
36 */
37 class tx_install_mod1 extends t3lib_SCbase {
38
39 /**
40 * Entry point for the backend module
41 *
42 * @return void
43 */
44 public function main() {
45 /** @var $installToolService Tx_Install_Service_BasicService */
46 $installToolService = t3lib_div::makeInstance('Tx_Install_Service_BasicService');
47
48 if ($installToolService->checkInstallToolEnableFile()) {
49 // Install Tool is already enabled
50 t3lib_utility_Http::redirect('install/');
51 } elseif ($this->isValidEnableRequest()) {
52 // Install Tool should be enabled
53 $installToolService->createInstallToolEnableFile();
54 t3lib_utility_Http::redirect('install/');
55 } else {
56 // ask the user to enable the Install Tool
57 $this->showInstallToolEnableRequest();
58 }
59 }
60
61
62 /**
63 * Checks if enabling install tool is requested and form token is correct
64 *
65 * @return bool
66 */
67 protected function isValidEnableRequest() {
68 return t3lib_div::_POST('enableInstallTool') &&
69 t3lib_formprotection_Factory::get()
70 ->validateToken(t3lib_div::_POST('formToken'), 'installToolEnableToken');
71 }
72
73 /**
74 * Shows warning message about ENABLE_INSTALL_TOOL file and a button to create this file
75 *
76 * @return void
77 */
78 protected function showInstallToolEnableRequest() {
79 // Create instance of object for output of data
80 $this->doc = t3lib_div::makeInstance('template');
81 $this->doc->setModuleTemplate(
82 t3lib_extMgm::extPath('install') . 'mod/mod_template.html'
83 );
84 $this->doc->form = '<form method="post" id="t3-install-form-unlock" action="">';
85 $this->doc->addStyleSheet(
86 'install',
87 'stylesheets/install/install.css'
88 );
89 $this->doc->addStyleSheet(
90 'mod-install',
91 t3lib_extMgm::extRelPath('install') . 'mod/mod_styles.css'
92 );
93
94 $markers = $buttons = array();
95 $markers['CONTENT'] = $this->renderMessage();
96 $content = $this->doc->moduleBody('', $buttons, $markers);
97 $this->doc->postCode = '<input type="hidden" name="enableInstallTool" value="1" />' .
98 t3lib_TCEforms::getHiddenTokenField('installToolEnableToken');
99 echo $this->doc->render('', $content);
100 }
101
102 /**
103 * Renders the message and the activation button
104 *
105 * @return string
106 */
107 protected function renderMessage() {
108 /** @var $message t3lib_message_ErrorpageMessage */
109 $message = t3lib_div::makeInstance('t3lib_message_ErrorPageMessage');
110
111 $message->setTitle($GLOBALS['LANG']->sL('LLL:EXT:install/mod/locallang_mod.xlf:confirmUnlockInstallToolTitle'));
112 $message->setSeverity(t3lib_message_ErrorPageMessage::WARNING);
113 $message->setHtmlTemplate('/typo3/templates/install.html');
114
115 $content = $GLOBALS['LANG']->sL('LLL:EXT:install/mod/locallang_mod.xlf:confirmUnlockInstallToolMessage') .
116 '<button type="submit">' .
117 $GLOBALS['LANG']->sL('LLL:EXT:install/mod/locallang_mod.xlf:confirmUnlockInstallToolButton') .
118 '<span class="t3-install-form-button-icon-positive">&nbsp;</span></button>';
119
120 $messageMarkers = array();
121 $messageMarkers['###CONTENT###'] = $content;
122 $message->setMarkers($messageMarkers);
123
124 return $message->render();
125 }
126 }
127
128
129 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/install/mod/index.php'])) {
130 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/install/mod/index.php']);
131 }
132
133 /** @var $SOBE tx_install_mod1 */
134 $SOBE = t3lib_div::makeInstance('tx_install_mod1');
135 $SOBE->init();
136
137 $SOBE->main();
138
139 ?>