Add `CheckForExpiredAppEvaluation` middleware
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 20 May 2022 08:01:12 +0000 (10:01 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 20 May 2022 08:02:44 +0000 (10:02 +0200)
wcfsetup/install/files/lib/http/middleware/CheckForExpiredAppEvaluation.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/request/RequestHandler.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 (file)
index 0000000..fb391a7
--- /dev/null
@@ -0,0 +1,59 @@
+<?php
+
+namespace wcf\http\middleware;
+
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\MiddlewareInterface;
+use Psr\Http\Server\RequestHandlerInterface;
+use wcf\system\application\ApplicationHandler;
+use wcf\system\exception\NamedUserException;
+use wcf\system\request\RequestHandler;
+use wcf\system\WCF;
+
+/**
+ * Checks whether the accessed app is an evaluation version that is expired.
+ *
+ * @author  Tim Duesterhus
+ * @copyright   2001-2022 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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);
+    }
+}
index b426b354e80c046b04f7538e3cea127020f46d19..6c57cd2668867c9e3df42e88504e935ca4cf9eda 100644 (file)
@@ -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).
      *