‪TYPO3CMS  9.5
SettingsController.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
20 use TYPO3\CMS\Core\Configuration\ConfigurationManager;
32 use TYPO3\CMS\Core\Package\PackageManager;
39 
45 {
52  public function ‪cardsAction(ServerRequestInterface $request): ResponseInterface
53  {
54  $view = $this->‪initializeStandaloneView($request, 'Settings/Cards.html');
55  return new ‪JsonResponse([
56  'success' => true,
57  'html' => $view->render(),
58  ]);
59  }
60 
67  public function ‪changeInstallToolPasswordGetDataAction(ServerRequestInterface $request): ResponseInterface
68  {
69  $view = $this->‪initializeStandaloneView($request, 'Settings/ChangeInstallToolPassword.html');
70  $formProtection = ‪FormProtectionFactory::get(InstallToolFormProtection::class);
71  $view->assignMultiple([
72  'changeInstallToolPasswordToken' => $formProtection->generateToken('installTool', 'changeInstallToolPassword'),
73  ]);
74  return new ‪JsonResponse([
75  'success' => true,
76  'html' => $view->render(),
77  ]);
78  }
79 
86  public function ‪changeInstallToolPasswordAction(ServerRequestInterface $request): ResponseInterface
87  {
88  $password = $request->getParsedBody()['install']['password'] ?? '';
89  $passwordCheck = $request->getParsedBody()['install']['passwordCheck'];
90  $messageQueue = new ‪FlashMessageQueue('install');
91 
92  if ($password !== $passwordCheck) {
93  $messageQueue->enqueue(new ‪FlashMessage(
94  'Install tool password not changed. Given passwords do not match.',
95  '',
97  ));
98  } elseif (strlen($password) < 8) {
99  $messageQueue->enqueue(new ‪FlashMessage(
100  'Install tool password not changed. Given password must be at least eight characters long.',
101  '',
103  ));
104  } else {
105  $hashInstance = GeneralUtility::makeInstance(PasswordHashFactory::class)->getDefaultHashInstance('BE');
106  $configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
107  $configurationManager->setLocalConfigurationValueByPath(
108  'BE/installToolPassword',
109  $hashInstance->getHashedPassword($password)
110  );
111  $messageQueue->enqueue(new ‪FlashMessage('Install tool password changed'));
112  }
113  return new ‪JsonResponse([
114  'success' => true,
115  'status' => $messageQueue,
116  ]);
117  }
118 
125  public function ‪systemMaintainerGetListAction(ServerRequestInterface $request): ResponseInterface
126  {
127  $view = $this->‪initializeStandaloneView($request, 'Settings/SystemMaintainer.html');
128  $formProtection = ‪FormProtectionFactory::get(InstallToolFormProtection::class);
129  $view->assignMultiple([
130  'systemMaintainerWriteToken' => $formProtection->generateToken('installTool', 'systemMaintainerWrite'),
131  'systemMaintainerIsDevelopmentContext' => GeneralUtility::getApplicationContext()->isDevelopment(),
132  ]);
133 
134  $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
135 
136  // We have to respect the enable fields here by our own because no TCA is loaded
137  $queryBuilder = $connectionPool->getQueryBuilderForTable('be_users');
138  $queryBuilder->getRestrictions()->removeAll();
139  $users = $queryBuilder
140  ->select('uid', 'username', 'disable', 'starttime', 'endtime')
141  ->from('be_users')
142  ->where(
143  $queryBuilder->expr()->andX(
144  $queryBuilder->expr()->eq('deleted', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)),
145  $queryBuilder->expr()->eq('admin', $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT)),
146  $queryBuilder->expr()->neq('username', $queryBuilder->createNamedParameter('_cli_', \PDO::PARAM_STR))
147  )
148  )
149  ->orderBy('uid')
150  ->execute()
151  ->fetchAll();
152 
153  $systemMaintainerList = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['systemMaintainers'] ?? [];
154  $systemMaintainerList = array_map('intval', $systemMaintainerList);
155  $currentTime = time();
156  foreach ($users as &$user) {
157  $user['disable'] = $user['disable'] ||
158  ((int)$user['starttime'] !== 0 && $user['starttime'] > $currentTime) ||
159  ((int)$user['endtime'] !== 0 && $user['endtime'] < $currentTime);
160  $user['isSystemMaintainer'] = in_array((int)$user['uid'], $systemMaintainerList, true);
161  }
162  return new ‪JsonResponse([
163  'success' => true,
164  'status' => [],
165  'users' => $users,
166  'html' => $view->render(),
167  ]);
168  }
169 
176  public function ‪systemMaintainerWriteAction(ServerRequestInterface $request): ResponseInterface
177  {
178  // Sanitize given user list and write out
179  $newUserList = [];
180  $users = $request->getParsedBody()['install']['users'] ?? [];
181  if (is_array($users)) {
182  foreach ($users as $uid) {
184  $newUserList[] = (int)$uid;
185  }
186  }
187  }
188 
189  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('be_users');
190  $queryBuilder->getRestrictions()->removeAll();
191 
192  $validatedUserList = $queryBuilder
193  ->select('uid')
194  ->from('be_users')
195  ->where(
196  $queryBuilder->expr()->andX(
197  $queryBuilder->expr()->eq('deleted', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)),
198  $queryBuilder->expr()->eq('admin', $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT)),
199  $queryBuilder->expr()->in('uid', $queryBuilder->createNamedParameter($newUserList, Connection::PARAM_INT_ARRAY))
200  )
201  )->execute()->fetchAll();
202 
203  $validatedUserList = array_column($validatedUserList, 'uid');
204  $validatedUserList = array_map('intval', $validatedUserList);
205 
206  $configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
207  $configurationManager->setLocalConfigurationValuesByPathValuePairs(
208  ['SYS/systemMaintainers' => $validatedUserList]
209  );
210 
211  $messages = [];
212  if (empty($validatedUserList)) {
213  $messages[] = new ‪FlashMessage(
214  '',
215  'Set system maintainer list to an empty array',
217  );
218  } else {
219  $messages[] = new ‪FlashMessage(
220  implode(', ', $validatedUserList),
221  'New system maintainer uid list',
223  );
224  }
225  return new ‪JsonResponse([
226  'success' => true,
227  'status' => $messages
228  ]);
229  }
230 
237  public function ‪localConfigurationGetContentAction(ServerRequestInterface $request): ResponseInterface
238  {
239  $localConfigurationValueService = new ‪LocalConfigurationValueService();
240  $formProtection = ‪FormProtectionFactory::get(InstallToolFormProtection::class);
241  $view = $this->‪initializeStandaloneView($request, 'Settings/LocalConfigurationGetContent.html');
242  $view->assignMultiple([
243  'localConfigurationWriteToken' => $formProtection->generateToken('installTool', 'localConfigurationWrite'),
244  'localConfigurationData' => $localConfigurationValueService->getCurrentConfigurationData(),
245  ]);
246  return new ‪JsonResponse([
247  'success' => true,
248  'html' => $view->render(),
249  ]);
250  }
251 
259  public function ‪localConfigurationWriteAction(ServerRequestInterface $request): ResponseInterface
260  {
261  $settings = $request->getParsedBody()['install']['configurationValues'];
262  if (!is_array($settings) || empty($settings)) {
263  throw new \RuntimeException(
264  'Expected value array not found',
265  1502282283
266  );
267  }
268  $localConfigurationValueService = new ‪LocalConfigurationValueService();
269  $messageQueue = $localConfigurationValueService->updateLocalConfigurationValues($settings);
270  if (empty($messageQueue)) {
271  $messageQueue->enqueue(new ‪FlashMessage(
272  '',
273  'No values changed',
275  ));
276  }
277  return new ‪JsonResponse([
278  'success' => true,
279  'status' => $messageQueue,
280  ]);
281  }
282 
289  public function ‪presetsGetContentAction(ServerRequestInterface $request): ResponseInterface
290  {
291  $view = $this->‪initializeStandaloneView($request, 'Settings/PresetsGetContent.html');
292  $presetFeatures = GeneralUtility::makeInstance(FeatureManager::class);
293  $presetFeatures = $presetFeatures->getInitializedFeatures($request->getParsedBody()['install']['values'] ?? []);
294  $formProtection = ‪FormProtectionFactory::get(InstallToolFormProtection::class);
295  $view->assignMultiple([
296  'presetsActivateToken' => $formProtection->generateToken('installTool', 'presetsActivate'),
297  // This action is called again from within the card itself if a custom image path is supplied
298  'presetsGetContentToken' => $formProtection->generateToken('installTool', 'presetsGetContent'),
299  'presetFeatures' => $presetFeatures,
300  ]);
301  return new ‪JsonResponse([
302  'success' => true,
303  'html' => $view->render(),
304  ]);
305  }
306 
313  public function ‪presetsActivateAction(ServerRequestInterface $request): ResponseInterface
314  {
315  $messages = new ‪FlashMessageQueue('install');
316  $configurationManager = new ConfigurationManager();
317  $featureManager = new ‪FeatureManager();
318  $configurationValues = $featureManager->getConfigurationForSelectedFeaturePresets($request->getParsedBody()['install']['values'] ?? []);
319  if (!empty($configurationValues)) {
320  $configurationManager->setLocalConfigurationValuesByPathValuePairs($configurationValues);
321  $messageBody = [];
322  foreach ($configurationValues as $configurationKey => $configurationValue) {
323  $messageBody[] = '\'' . $configurationKey . '\' => \'' . $configurationValue . '\'';
324  }
325  $messages->enqueue(new ‪FlashMessage(
326  implode(', ', $messageBody),
327  'Configuration written'
328  ));
329  } else {
330  $messages->enqueue(new ‪FlashMessage(
331  '',
332  'No configuration change selected',
334  ));
335  }
336  return new ‪JsonResponse([
337  'success' => true,
338  'status' => $messages,
339  ]);
340  }
341 
348  public function ‪extensionConfigurationGetContentAction(ServerRequestInterface $request): ResponseInterface
349  {
350  // Extension configuration needs initialized $GLOBALS['LANG']
352  $extensionConfigurationService = new ‪ExtensionConfigurationService();
353  $extensionsWithConfigurations = [];
354  $activePackages = GeneralUtility::makeInstance(PackageManager::class)->getActivePackages();
355  foreach ($activePackages as $extensionKey => $activePackage) {
356  if (@file_exists($activePackage->getPackagePath() . 'ext_conf_template.txt')) {
357  $extensionsWithConfigurations[$extensionKey] = [
358  'packageInfo' => $activePackage,
359  'configuration' => $extensionConfigurationService->getConfigurationPreparedForView($extensionKey),
360  ];
361  }
362  }
363  ksort($extensionsWithConfigurations);
364  $formProtection = ‪FormProtectionFactory::get(InstallToolFormProtection::class);
365  $view = $this->‪initializeStandaloneView($request, 'Settings/ExtensionConfigurationGetContent.html');
366  $view->assignMultiple([
367  'extensionsWithConfigurations' => $extensionsWithConfigurations,
368  'extensionConfigurationWriteToken' => $formProtection->generateToken('installTool', 'extensionConfigurationWrite'),
369  ]);
370  return new ‪JsonResponse([
371  'success' => true,
372  'html' => $view->render(),
373  ]);
374  }
375 
382  public function ‪extensionConfigurationWriteAction(ServerRequestInterface $request): ResponseInterface
383  {
384  $extensionKey = $request->getParsedBody()['install']['extensionKey'];
385  $configuration = $request->getParsedBody()['install']['extensionConfiguration'];
386  $nestedConfiguration = [];
387  foreach ($configuration as $configKey => $value) {
388  $nestedConfiguration = ‪ArrayUtility::setValueByPath($nestedConfiguration, $configKey, $value, '.');
389  }
390  (new ‪ExtensionConfiguration())->set($extensionKey, '', $nestedConfiguration);
391  $messages = [
392  new ‪FlashMessage(
393  'Successfully saved configuration for extension "' . $extensionKey . '"',
394  '',
396  )
397  ];
398  return new ‪JsonResponse([
399  'success' => true,
400  'status' => $messages,
401  ]);
402  }
403 
410  public function ‪featuresGetContentAction(ServerRequestInterface $request): ResponseInterface
411  {
412  $configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
413  $configurationDescription = GeneralUtility::makeInstance(YamlFileLoader::class)
414  ->load($configurationManager->getDefaultConfigurationDescriptionFileLocation());
415  $allFeatures = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['features'] ?? [];
416  $features = [];
417  foreach ($allFeatures as $featureName => $featureValue) {
418  // Only features that have a .yml description will be listed. There is currently no
419  // way for extensions to extend this, so feature toggles of non-core extensions are
420  // not listed here.
421  if (isset($configurationDescription['SYS']['items']['features']['items'][$featureName]['description'])) {
422  $default = $configurationManager->getDefaultConfigurationValueByPath('SYS/features/' . $featureName);
423  $features[] = [
424  'name' => $featureName,
425  'description' => $configurationDescription['SYS']['items']['features']['items'][$featureName]['description'],
426  'default' => $default,
427  'value' => $featureValue,
428  ];
429  }
430  }
431  $formProtection = ‪FormProtectionFactory::get(InstallToolFormProtection::class);
432  $view = $this->‪initializeStandaloneView($request, 'Settings/FeaturesGetContent.html');
433  $view->assignMultiple([
434  'features' => $features,
435  'featuresSaveToken' => $formProtection->generateToken('installTool', 'featuresSave'),
436  ]);
437  return new ‪JsonResponse([
438  'success' => true,
439  'html' => $view->render(),
440  ]);
441  }
442 
449  public function ‪featuresSaveAction(ServerRequestInterface $request): ResponseInterface
450  {
451  $configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
452  $enabledFeaturesFromPost = $request->getParsedBody()['install']['values'] ?? [];
453  $allFeatures = array_keys(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['features'] ?? []);
454  $configurationDescription = GeneralUtility::makeInstance(YamlFileLoader::class)
455  ->load($configurationManager->getDefaultConfigurationDescriptionFileLocation());
456  foreach ($allFeatures as $featureName) {
457  // Only features that have a .yml description will be listed. There is currently no
458  // way for extensions to extend this, so feature toggles of non-core extensions are
459  // not considered.
460  if (isset($configurationDescription['SYS']['items']['features']['items'][$featureName]['description'])) {
461  if (isset($enabledFeaturesFromPost[$featureName])) {
462  $configurationManager->enableFeature($featureName);
463  } else {
464  $configurationManager->disableFeature($featureName);
465  }
466  }
467  }
468  $messages = [
469  new ‪FlashMessage(
470  'Successfully updated feature toggles',
471  '',
473  )
474  ];
475  return new ‪JsonResponse([
476  'success' => true,
477  'status' => $messages,
478  ]);
479  }
480 }
‪TYPO3\CMS\Core\Crypto\PasswordHashing\PasswordHashFactory
Definition: PasswordHashFactory.php:25
‪TYPO3\CMS\Install\Controller\AbstractController\initializeStandaloneView
‪StandaloneView initializeStandaloneView(ServerRequestInterface $request, string $templatePath)
Definition: AbstractController.php:37
‪TYPO3\CMS\Core\FormProtection\FormProtectionFactory\get
‪static TYPO3 CMS Core FormProtection AbstractFormProtection get($classNameOrType='default',... $constructorArguments)
Definition: FormProtectionFactory.php:72
‪TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger
‪static bool canBeInterpretedAsInteger($var)
Definition: MathUtility.php:73
‪TYPO3\CMS\Install\Configuration\FeatureManager
Definition: FeatureManager.php:28
‪TYPO3\CMS\Install\Controller\SettingsController\featuresGetContentAction
‪ResponseInterface featuresGetContentAction(ServerRequestInterface $request)
Definition: SettingsController.php:410
‪TYPO3\CMS\Core\Configuration\ExtensionConfiguration
Definition: ExtensionConfiguration.php:42
‪TYPO3\CMS\Install\Controller\SettingsController\localConfigurationGetContentAction
‪ResponseInterface localConfigurationGetContentAction(ServerRequestInterface $request)
Definition: SettingsController.php:237
‪TYPO3\CMS\Install\Service\ExtensionConfigurationService
Definition: ExtensionConfigurationService.php:36
‪TYPO3\CMS\Install\Controller\SettingsController\systemMaintainerGetListAction
‪ResponseInterface systemMaintainerGetListAction(ServerRequestInterface $request)
Definition: SettingsController.php:125
‪TYPO3\CMS\Install\Controller\SettingsController\presetsGetContentAction
‪ResponseInterface presetsGetContentAction(ServerRequestInterface $request)
Definition: SettingsController.php:289
‪TYPO3\CMS\Core\FormProtection\InstallToolFormProtection
Definition: InstallToolFormProtection.php:60
‪TYPO3\CMS\Core\Messaging\AbstractMessage\WARNING
‪const WARNING
Definition: AbstractMessage.php:28
‪TYPO3\CMS\Install\Controller\SettingsController\extensionConfigurationGetContentAction
‪ResponseInterface extensionConfigurationGetContentAction(ServerRequestInterface $request)
Definition: SettingsController.php:348
‪TYPO3\CMS\Install\Controller\SettingsController\changeInstallToolPasswordGetDataAction
‪ResponseInterface changeInstallToolPasswordGetDataAction(ServerRequestInterface $request)
Definition: SettingsController.php:67
‪TYPO3\CMS\Install\Controller\SettingsController\cardsAction
‪ResponseInterface cardsAction(ServerRequestInterface $request)
Definition: SettingsController.php:52
‪TYPO3\CMS\Install\Controller
Definition: AbstractController.php:3
‪TYPO3\CMS\Install\Controller\SettingsController\changeInstallToolPasswordAction
‪ResponseInterface changeInstallToolPasswordAction(ServerRequestInterface $request)
Definition: SettingsController.php:86
‪TYPO3\CMS\Install\Controller\SettingsController\featuresSaveAction
‪ResponseInterface featuresSaveAction(ServerRequestInterface $request)
Definition: SettingsController.php:449
‪TYPO3\CMS\Install\Controller\SettingsController\localConfigurationWriteAction
‪ResponseInterface localConfigurationWriteAction(ServerRequestInterface $request)
Definition: SettingsController.php:259
‪TYPO3\CMS\Core\Messaging\AbstractMessage\OK
‪const OK
Definition: AbstractMessage.php:27
‪TYPO3\CMS\Core\Utility\ArrayUtility\setValueByPath
‪static array setValueByPath(array $array, $path, $value, $delimiter='/')
Definition: ArrayUtility.php:271
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:31
‪TYPO3\CMS\Core\Configuration\Loader\YamlFileLoader
Definition: YamlFileLoader.php:41
‪TYPO3\CMS\Core\Messaging\AbstractMessage\INFO
‪const INFO
Definition: AbstractMessage.php:26
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:22
‪TYPO3\CMS\Core\FormProtection\FormProtectionFactory
Definition: FormProtectionFactory.php:45
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:23
‪TYPO3\CMS\Core\Http\JsonResponse
Definition: JsonResponse.php:25
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:50
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:21
‪TYPO3\CMS\Install\Controller\AbstractController
Definition: AbstractController.php:28
‪TYPO3\CMS\Install\Controller\SettingsController
Definition: SettingsController.php:45
‪TYPO3\CMS\Install\Service\LocalConfigurationValueService
Definition: LocalConfigurationValueService.php:31
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Install\Controller\SettingsController\systemMaintainerWriteAction
‪ResponseInterface systemMaintainerWriteAction(ServerRequestInterface $request)
Definition: SettingsController.php:176
‪TYPO3\CMS\Core\Messaging\FlashMessageQueue
Definition: FlashMessageQueue.php:25
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:29
‪TYPO3\CMS\Core\Core\Bootstrap\initializeLanguageObject
‪static Bootstrap null initializeLanguageObject()
Definition: Bootstrap.php:986
‪TYPO3\CMS\Install\Controller\SettingsController\presetsActivateAction
‪ResponseInterface presetsActivateAction(ServerRequestInterface $request)
Definition: SettingsController.php:313
‪TYPO3\CMS\Install\Controller\SettingsController\extensionConfigurationWriteAction
‪ResponseInterface extensionConfigurationWriteAction(ServerRequestInterface $request)
Definition: SettingsController.php:382