[!!!][TASK] Rewrite install tool
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Controller / ToolController.php
1 <?php
2 namespace TYPO3\CMS\Install\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 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 * Install tool controller, dispatcher class of the install tool.
32 *
33 * Handles install tool session, login and login form rendering,
34 * calls actions that need authentication and handles form tokens.
35 */
36 class ToolController extends AbstractController {
37
38 /**
39 * @var array List of valid action names that need authentication
40 */
41 protected $authenticationActions = array(
42 'welcome',
43 'importantActions',
44 'systemEnvironment',
45 'folderStructure',
46 'testSetup',
47 'updateWizard',
48 'allConfiguration',
49 'cleanUp',
50 );
51
52 /**
53 * Main dispatch method
54 *
55 * @return void
56 */
57 public function execute() {
58 $this->loadBaseExtensions();
59 $this->initializeObjectManager();
60
61 // Warning: Order of this methods is security relevant and interferes with different access
62 // conditions (new/existing installation). See the single method comments for details.
63 $this->outputInstallToolNotEnabledMessageIfNeeded();
64 $this->outputInstallToolPasswordNotSetMessageIfNeeded();
65 $this->initializeSession();
66 $this->checkSessionToken();
67 $this->checkSessionLifetime();
68 $this->logoutIfRequested();
69 $this->loginIfRequested();
70 $this->outputLoginFormIfNotAuthorized();
71 $this->dispatchAuthenticationActions();
72 }
73
74 /**
75 * Logout user if requested
76 *
77 * @return void
78 */
79 protected function logoutIfRequested() {
80 $action = $this->getAction();
81 if ($action === 'logout') {
82 // @TODO: This and similar code in step action DefaultConfiguration should be moved to enable install file service
83 $enableInstallToolFile = PATH_typo3conf . 'ENABLE_INSTALL_TOOL';
84 if (is_file($enableInstallToolFile) && trim(file_get_contents($enableInstallToolFile)) !== 'KEEP_FILE') {
85 unlink($enableInstallToolFile);
86 }
87
88 /** @var $formProtection \TYPO3\CMS\Core\FormProtection\InstallToolFormProtection */
89 $formProtection = \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get(
90 'TYPO3\\CMS\\Core\\FormProtection\\InstallToolFormProtection'
91 );
92 $formProtection->clean();
93 $this->session->destroySession();
94 $this->redirect();
95 }
96 }
97
98 /**
99 * Call an action that needs authentication
100 *
101 * @throws Exception
102 * @return string Rendered content
103 */
104 protected function dispatchAuthenticationActions() {
105 $action = $this->getAction();
106 if ($action === '') {
107 $action = 'welcome';
108 }
109 $this->validateAuthenticationAction($action);
110 $actionClass = ucfirst($action);
111 /** @var \TYPO3\CMS\Install\Controller\Action\ActionInterface $toolAction */
112 $toolAction = $this->objectManager->get('TYPO3\\CMS\\Install\\Controller\\Action\\Tool\\' . $actionClass);
113 if (!($toolAction instanceof \TYPO3\CMS\Install\Controller\Action\ActionInterface)) {
114 throw new Exception(
115 $action . ' does non implement ActionInterface',
116 1369474308
117 );
118 }
119 $toolAction->setController('tool');
120 $toolAction->setAction($action);
121 $toolAction->setToken($this->generateTokenForAction($action));
122 $toolAction->setPostValues($this->getPostValues());
123 $this->output($toolAction->handle());
124 }
125 }
126
127 ?>