From 7b7023bc0e6c31f9032df1974a17d49801ad9bb3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Fri, 20 May 2022 10:01:12 +0200 Subject: [PATCH] Add `CheckForExpiredAppEvaluation` middleware --- .../CheckForExpiredAppEvaluation.class.php | 59 +++++++++++++++++++ .../system/request/RequestHandler.class.php | 35 +---------- 2 files changed, 61 insertions(+), 33 deletions(-) create mode 100644 wcfsetup/install/files/lib/http/middleware/CheckForExpiredAppEvaluation.class.php diff --git a/wcfsetup/install/files/lib/http/middleware/CheckForExpiredAppEvaluation.class.php b/wcfsetup/install/files/lib/http/middleware/CheckForExpiredAppEvaluation.class.php new file mode 100644 index 0000000000..fb391a735e --- /dev/null +++ b/wcfsetup/install/files/lib/http/middleware/CheckForExpiredAppEvaluation.class.php @@ -0,0 +1,59 @@ + + * @package WoltLabSuite\Core\Http\Middleware + * @since 5.6 + */ +final class CheckForExpiredAppEvaluation implements MiddlewareInterface +{ + /** + * @inheritDoc + */ + public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface + { + [$abbreviation] = \explode('\\', RequestHandler::getInstance()->getActiveRequest()->getClassName(), 2); + + if ($abbreviation !== 'wcf') { + $application = ApplicationHandler::getInstance()->getApplication($abbreviation); + $applicationObject = WCF::getApplicationObject($application); + $endDate = $applicationObject->getEvaluationEndDate(); + + if ($endDate && $endDate < TIME_NOW) { + $package = $application->getPackage(); + + $pluginStoreFileID = $applicationObject->getEvaluationPluginStoreID(); + $isWoltLab = false; + if ($pluginStoreFileID === 0 && \str_starts_with($package->package, 'com.woltlab.')) { + $isWoltLab = true; + } + + throw new NamedUserException(WCF::getLanguage()->getDynamicVariable( + 'wcf.acp.package.evaluation.expired', + [ + 'packageName' => $package->getName(), + 'pluginStoreFileID' => $pluginStoreFileID, + 'isWoltLab' => $isWoltLab, + ] + )); + } + } + + return $handler->handle($request); + } +} diff --git a/wcfsetup/install/files/lib/system/request/RequestHandler.class.php b/wcfsetup/install/files/lib/system/request/RequestHandler.class.php index b426b354e8..6c57cd2668 100644 --- a/wcfsetup/install/files/lib/system/request/RequestHandler.class.php +++ b/wcfsetup/install/files/lib/system/request/RequestHandler.class.php @@ -6,6 +6,7 @@ use Laminas\Diactoros\ServerRequestFactory; use Laminas\HttpHandlerRunner\Emitter\SapiEmitter; use wcf\http\LegacyPlaceholderResponse; use wcf\http\middleware\AddAcpSecurityHeaders; +use wcf\http\middleware\CheckForExpiredAppEvaluation; use wcf\http\middleware\CheckForOfflineMode; use wcf\http\middleware\EnforceCacheControlPrivate; use wcf\http\middleware\EnforceFrameOptions; @@ -94,12 +95,11 @@ class RequestHandler extends SingletonFactory throw new IllegalLinkException(); } - $this->checkAppEvaluation(); - $pipeline = new Pipeline([ new AddAcpSecurityHeaders(), new EnforceCacheControlPrivate(), new EnforceFrameOptions(), + new CheckForExpiredAppEvaluation(), new CheckForOfflineMode(), ]); @@ -249,37 +249,6 @@ class RequestHandler extends SingletonFactory } } - /** - * @since 5.5 - */ - private function checkAppEvaluation() - { - // check if the controller matches an app that has an expired evaluation date - [$abbreviation] = \explode('\\', $this->getActiveRequest()->getClassName(), 2); - if ($abbreviation !== 'wcf') { - $applicationObject = ApplicationHandler::getInstance()->getApplication($abbreviation); - $endDate = WCF::getApplicationObject($applicationObject)->getEvaluationEndDate(); - if ($endDate && $endDate < TIME_NOW) { - $package = $applicationObject->getPackage(); - - $pluginStoreFileID = WCF::getApplicationObject($applicationObject)->getEvaluationPluginStoreID(); - $isWoltLab = false; - if ($pluginStoreFileID === 0 && \strpos($package->package, 'com.woltlab.') === 0) { - $isWoltLab = true; - } - - throw new NamedUserException(WCF::getLanguage()->getDynamicVariable( - 'wcf.acp.package.evaluation.expired', - [ - 'packageName' => $package->getName(), - 'pluginStoreFileID' => $pluginStoreFileID, - 'isWoltLab' => $isWoltLab, - ] - )); - } - } - } - /** * Redirects to the actual URL, e.g. controller has been aliased or mistyped (boardlist instead of board-list). * -- 2.20.1