Skip to content

Commit

Permalink
[TASK] Move "pageUnavailable_force" into a PSR-15 middleware
Browse files Browse the repository at this point in the history
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
bmack committed Feb 15, 2018
1 parent 54d3af0 commit b4aa8b7
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 12 deletions.
11 changes: 0 additions & 11 deletions typo3/sysext/frontend/Classes/Http/RequestHandler.php
Expand Up @@ -26,7 +26,6 @@
use TYPO3\CMS\Core\TimeTracker\TimeTracker;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Frontend\Controller\ErrorController;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\CMS\Frontend\Page\PageGenerator;
use TYPO3\CMS\Frontend\Utility\CompressionUtility;
Expand Down Expand Up @@ -101,16 +100,6 @@ public function handle(ServerRequestInterface $request): ResponseInterface
// Fetch the initialized time tracker object
$this->timeTracker = GeneralUtility::makeInstance(TimeTracker::class);
$this->initializeController();

if ($GLOBALS['TYPO3_CONF_VARS']['FE']['pageUnavailable_force']
&& !GeneralUtility::cmpIP(
GeneralUtility::getIndpEnv('REMOTE_ADDR'),
$GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask']
)
) {
return GeneralUtility::makeInstance(ErrorController::class)->unavailableAction('This page is temporarily unavailable.');
}

$this->controller->connectToDB();

// Output compression
Expand Down
55 changes: 55 additions & 0 deletions typo3/sysext/frontend/Classes/Middleware/MaintenanceMode.php
@@ -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);
}
}
9 changes: 8 additions & 1 deletion typo3/sysext/frontend/Configuration/RequestMiddlewares.php
Expand Up @@ -38,10 +38,17 @@
'typo3/cms-frontend/preprocessing'
]
],
'typo3/cms-frontend/maintenance-mode' => [
'target' => \TYPO3\CMS\Frontend\Middleware\MaintenanceMode::class,
'after' => [
'typo3/cms-core/normalized-params-attribute',
'typo3/cms-frontend/eid'
]
],
'typo3/cms-frontend/content-length-headers' => [
'target' => \TYPO3\CMS\Frontend\Middleware\ContentLengthResponseHeader::class,
'after' => [
'typo3/cms-frontend/eid'
'typo3/cms-frontend/maintenance-mode'
]
],
]
Expand Down

0 comments on commit b4aa8b7

Please sign in to comment.