Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Move "pageUnavailable_force" into a PSR-15 middleware
The check if the frontend is in "maintenance mode", set by $GLOBALS['TYPO3_CONF_VARS']['FE']['pageUnavailable_force'], is moved into a custom PSR-15 based middleware, effectively decoupling this logic from TSFE object. Resolves: #83917 Releases: master Change-Id: I38c42069b82ca2403df9aa4b0e66410a3dfe6404 Reviewed-on: https://review.typo3.org/55721 Tested-by: TYPO3com <no-reply@typo3.com> Reviewed-by: Susanne Moog <susanne.moog@typo3.org> Tested-by: Susanne Moog <susanne.moog@typo3.org> Reviewed-by: Mathias Schreiber <mathias.schreiber@typo3.com> Tested-by: Mathias Schreiber <mathias.schreiber@typo3.com> Reviewed-by: Benni Mack <benni@typo3.org> Tested-by: Benni Mack <benni@typo3.org>
- Loading branch information
Showing
3 changed files
with
63 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
typo3/sysext/frontend/Classes/Middleware/MaintenanceMode.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
namespace TYPO3\CMS\Frontend\Middleware; | ||
|
||
/* | ||
* This file is part of the TYPO3 CMS project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Psr\Http\Server\MiddlewareInterface; | ||
use Psr\Http\Server\RequestHandlerInterface; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Frontend\Controller\ErrorController; | ||
|
||
/** | ||
* Checks whether the whole Frontend should be put into "Page unavailable mode" | ||
* unless the devIPMask matches the current visitor's IP. | ||
* | ||
* The global setting $GLOBALS['TYPO3_CONF_VARS']['FE']['pageUnavailable_force'] | ||
* is used for turning on the maintenance mode. | ||
*/ | ||
class MaintenanceMode implements MiddlewareInterface | ||
{ | ||
/** | ||
* Calls the "unavailableAction" of the error controller if the system is in maintenance mode. | ||
* This only applies if the REMOTE_ADDR does not match the devIpMask | ||
* | ||
* @param ServerRequestInterface $request | ||
* @param RequestHandlerInterface $handler | ||
* @return ResponseInterface | ||
*/ | ||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface | ||
{ | ||
if ($GLOBALS['TYPO3_CONF_VARS']['FE']['pageUnavailable_force'] | ||
&& !GeneralUtility::cmpIP( | ||
$request->getAttribute('normalizedParams')->getRemoteAddress(), | ||
$GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'] | ||
) | ||
) { | ||
return GeneralUtility::makeInstance(ErrorController::class)->unavailableAction('This page is temporarily unavailable.'); | ||
} | ||
// Continue the regular stack if no maintenance mode is active | ||
return $handler->handle($request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters