Create the ServerConfigurationChecking middleware

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
Maurício Meneghini Fauth 2023-08-15 13:50:24 -03:00
parent 5b5e444adf
commit eebbd6b3f1
No known key found for this signature in database
GPG Key ID: 6A16FD38AFC89CC8
2 changed files with 56 additions and 23 deletions

View File

@ -25,6 +25,7 @@ use PhpMyAdmin\Identifiers\TableName;
use PhpMyAdmin\Middleware\ErrorHandling;
use PhpMyAdmin\Middleware\OutputBuffering;
use PhpMyAdmin\Middleware\PhpExtensionsChecking;
use PhpMyAdmin\Middleware\ServerConfigurationChecking;
use PhpMyAdmin\Plugins\AuthenticationPlugin;
use PhpMyAdmin\Plugins\AuthenticationPluginFactory;
use PhpMyAdmin\Routing\Routing;
@ -79,10 +80,13 @@ class Application
public function run(bool $isSetupPage = false): void
{
$GLOBALS['errorHandler'] = $this->errorHandler;
$requestHandler = new QueueRequestHandler(new ApplicationHandler($this));
$requestHandler->add(new ErrorHandling($this->errorHandler));
$requestHandler->add(new OutputBuffering());
$requestHandler->add(new PhpExtensionsChecking($this, $this->template, $this->responseFactory));
$requestHandler->add(new ServerConfigurationChecking($this->template, $this->responseFactory));
$runner = new RequestHandlerRunner(
$requestHandler,
@ -105,13 +109,6 @@ class Application
{
$isSetupPage = (bool) $request->getAttribute('isSetupPage');
$GLOBALS['errorHandler'] = $this->errorHandler;
$resultOfServerConfigurationCheck = $this->checkServerConfiguration();
if ($resultOfServerConfigurationCheck !== null) {
return $this->getGenericErrorResponse($resultOfServerConfigurationCheck);
}
$this->configurePhpSettings();
try {
@ -500,22 +497,6 @@ class Application
$container->setParameter('url_params', $GLOBALS['urlParams']);
}
/**
* Check whether PHP configuration matches our needs.
*/
private function checkServerConfiguration(): string|null
{
/**
* The ini_set and ini_get functions can be disabled using
* disable_functions but we're relying quite a lot of them.
*/
if (function_exists('ini_get') && function_exists('ini_set')) {
return null;
}
return __('The ini_get and/or ini_set functions are disabled in php.ini. phpMyAdmin requires these functions!');
}
/**
* Checks request and fails with fatal error if something problematic is found
*/

View File

@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Middleware;
use Fig\Http\Message\StatusCodeInterface;
use PhpMyAdmin\Http\Factory\ResponseFactory;
use PhpMyAdmin\Template;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use function __;
use function function_exists;
/**
* Check whether PHP configuration matches our needs.
*/
final class ServerConfigurationChecking implements MiddlewareInterface
{
public function __construct(
private readonly Template $template,
private readonly ResponseFactory $responseFactory,
) {
}
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
/**
* The ini_set and ini_get functions can be disabled using
* disable_functions, but we're relying on them quite a lot.
*/
if (function_exists('ini_get') && function_exists('ini_set')) {
return $handler->handle($request);
}
// Disables template caching because the cache directory is not known yet.
$this->template->disableCache();
$message = __(
'The ini_get and/or ini_set functions are disabled in php.ini. phpMyAdmin requires these functions!',
);
$response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR);
return $response->write($this->template->render('error/generic', [
'lang' => 'en',
'dir' => 'ltr',
'error_message' => $message,
]));
}
}