‪TYPO3CMS  9.5
LockedBackendGuard.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 Psr\Http\Server\MiddlewareInterface;
21 use Psr\Http\Server\RequestHandlerInterface;
27 
36 class ‪LockedBackendGuard implements MiddlewareInterface
37 {
45  public function ‪process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
46  {
47  try {
48  $redirectToUri = $this->‪checkLockedBackend();
49  if (!empty($redirectToUri)) {
50  return new ‪RedirectResponse($redirectToUri, 302);
51  }
52  } catch (‪BackendLockedException $e) {
53  // Looks like an AJAX request that can handle JSON, (usually from the timeout functionality)
54  // So, let's form a request that fits
55  if (strpos($request->getHeaderLine('Accept'), 'application/json') !== false) {
56  $session = [
57  'timed_out' => false,
58  'will_time_out' => false,
59  'locked' => true,
60  'message' => $e->getMessage()
61  ];
62  return new ‪JsonResponse(['login' => $session]);
63  }
64  throw $e;
65  }
67  $request->getAttribute('normalizedParams')->getRemoteAddress(),
68  trim((string)‪$GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'])
69  );
70 
71  return $handler->handle($request);
72  }
73 
80  protected function ‪checkLockedBackend()
81  {
82  if (‪$GLOBALS['TYPO3_CONF_VARS']['BE']['adminOnly'] < 0) {
83  throw new ‪BackendLockedException('TYPO3 Backend locked: Backend and Install Tool are locked for maintenance. [BE][adminOnly] is set to "' . (int)‪$GLOBALS['TYPO3_CONF_VARS']['BE']['adminOnly'] . '".', 1517949794);
84  }
85  if (@is_file(‪Environment::getLegacyConfigPath() . '/LOCK_BACKEND')) {
86  $fileContent = file_get_contents(‪Environment::getLegacyConfigPath() . '/LOCK_BACKEND');
87  if ($fileContent) {
88  return $fileContent;
89  }
90  throw new ‪BackendLockedException('TYPO3 Backend locked: Browser backend is locked for maintenance. Remove lock by removing the file "typo3conf/LOCK_BACKEND" or use CLI-scripts.', 1517949793);
91  }
92  }
93 
101  protected function ‪validateVisitorsIpAgainstIpMaskList(string $ipAddress, string $ipMaskList = '')
102  {
103  if ($ipMaskList !== '' && !GeneralUtility::cmpIP($ipAddress, $ipMaskList)) {
104  throw new \RuntimeException('TYPO3 Backend access denied: The IP address of your client does not match the list of allowed IP addresses.', 1517949792);
105  }
106  }
107 }
‪TYPO3\CMS\Backend\Middleware
Definition: AdditionalResponseHeaders.php:3
‪TYPO3\CMS\Backend\Middleware\LockedBackendGuard
Definition: LockedBackendGuard.php:37
‪TYPO3\CMS\Backend\Middleware\LockedBackendGuard\validateVisitorsIpAgainstIpMaskList
‪validateVisitorsIpAgainstIpMaskList(string $ipAddress, string $ipMaskList='')
Definition: LockedBackendGuard.php:101
‪TYPO3\CMS\Backend\Exception\BackendLockedException
Definition: BackendLockedException.php:21
‪TYPO3\CMS\Backend\Middleware\LockedBackendGuard\checkLockedBackend
‪string null checkLockedBackend()
Definition: LockedBackendGuard.php:80
‪TYPO3\CMS\Core\Http\RedirectResponse
Definition: RedirectResponse.php:27
‪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\Environment
Definition: Environment.php:39
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Core\Environment\getLegacyConfigPath
‪static string getLegacyConfigPath()
Definition: Environment.php:256
‪TYPO3\CMS\Backend\Middleware\LockedBackendGuard\process
‪ResponseInterface process(ServerRequestInterface $request, RequestHandlerInterface $handler)
Definition: LockedBackendGuard.php:45