2 namespace TYPO3\CMS\Install\Controller
;
4 /***************************************************************
7 * (c) 2013 Susanne Moog <typo3@susannemoog.de>
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.
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.
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.
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
31 * Install tool ajax controller, handles ajax requests
34 class AjaxController
extends AbstractController
{
39 protected $unauthorized = 'unauthorized';
42 * @var array List of valid action names that need authentication
44 protected $authenticationActions = array(
45 'extensionCompatibilityTester',
55 public function execute() {
56 $this->loadBaseExtensions();
57 $this->initializeObjectManager();
58 // Warning: Order of these methods is security relevant and interferes with different access
59 // conditions (new/existing installation). See the single method comments for details.
60 $this->checkInstallToolEnabled();
61 $this->checkInstallToolPasswordNotSet();
62 $this->initializeSession();
63 $this->checkSessionToken();
64 $this->checkSessionLifetime();
66 $this->dispatchAuthenticationActions();
70 * Check whether the install tool is enabled
74 protected function checkInstallToolEnabled() {
75 if (is_dir(PATH_typo3conf
)) {
76 /** @var \TYPO3\CMS\Install\Service\EnableFileService $installToolEnableService */
77 $installToolEnableService = $this->objectManager
->get('TYPO3\\CMS\\Install\\Service\\EnableFileService');
78 if (!$installToolEnableService->checkInstallToolEnableFile()) {
79 $this->output($this->unauthorized
);
85 * Check if the install tool password is set
89 protected function checkInstallToolPasswordNotSet() {
90 if (empty($GLOBALS['TYPO3_CONF_VARS']['BE']['installToolPassword'])) {
91 $this->output($this->unauthorized
);
100 protected function checkLogin() {
101 if (!$this->session
->isAuthorized()) {
102 $this->output($this->unauthorized
);
104 $this->session
->refreshSession();
109 * Overwrites abstract method
110 * In contrast to abstract method, a response "you are not authorized is outputted"
112 * @param boolean $tokenOk
115 protected function handleSessionTokenCheck($tokenOk) {
117 $this->output($this->unauthorized
);
122 * Overwrites abstract method
123 * In contrast to abstract method, a response "you are not authorized is outputted"
127 protected function handleSessionLifeTimeExpired() {
128 $this->output($this->unauthorized
);
132 * Call an action that needs authentication
135 * @return string Rendered content
137 protected function dispatchAuthenticationActions() {
138 $action = $this->getAction();
139 if ($action === '') {
140 $this->output('noAction');
142 $this->validateAuthenticationAction($action);
143 $actionClass = ucfirst($action);
144 /** @var \TYPO3\CMS\Install\Controller\Action\ActionInterface $toolAction */
145 $toolAction = $this->objectManager
->get('TYPO3\\CMS\\Install\\Controller\\Action\\Ajax\\' . $actionClass);
146 if (!($toolAction instanceof \TYPO3\CMS\Install\Controller\Action\ActionInterface
)) {
148 $action . ' does not implement ActionInterface',
152 $toolAction->setController('ajax');
153 $toolAction->setAction($action);
154 $toolAction->setToken($this->generateTokenForAction($action));
155 $toolAction->setPostValues($this->getPostValues());
156 $this->output($toolAction->handle());
161 * WARNING: This exits the script execution!
163 * @param string $content Content to output
165 protected function output($content = '') {
166 header('Content-Type: text/html; charset=utf-8');
167 header('Cache-Control: no-cache, must-revalidate');
168 header('Pragma: no-cache');