From 4f79d7cf4b97a6c7ef1e2ee6d5670f27420e3f72 Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Sun, 26 Nov 2023 22:22:39 +0100 Subject: [PATCH] check php-extension requirements not only on installation (e.g. when php version was changed) Signed-off-by: Michael Kaufmann --- lib/Froxlor/Install/Install.php | 39 ++++++++----------- lib/Froxlor/Install/Requirements.php | 10 +++++ lib/init.php | 19 +++++++++ .../misc/missingextensionhint.html.twig | 18 +++++++++ 4 files changed, 64 insertions(+), 22 deletions(-) create mode 100644 lib/Froxlor/Install/Requirements.php create mode 100644 templates/Froxlor/misc/missingextensionhint.html.twig diff --git a/lib/Froxlor/Install/Install.php b/lib/Froxlor/Install/Install.php index 190c2eb9..7899f9cf 100644 --- a/lib/Froxlor/Install/Install.php +++ b/lib/Froxlor/Install/Install.php @@ -26,13 +26,13 @@ namespace Froxlor\Install; use Exception; -use PDO; +use Froxlor\Config\ConfigParser; use Froxlor\Install\Install\Core; +use Froxlor\System\IPTools; use Froxlor\UI\Panel\UI; use Froxlor\UI\Request; -use Froxlor\Config\ConfigParser; use Froxlor\Validate\Validate; -use Froxlor\System\IPTools; +use PDO; class Install { @@ -41,9 +41,6 @@ class Install public $maxSteps; public $phpVersion; public $formfield; - public string $requiredVersion = '7.4.0'; - public array $requiredExtensions = ['session', 'ctype', 'xml', 'filter', 'posix', 'mbstring', 'curl', 'gmp', 'json', 'gd']; - public array $suggestedExtensions = ['bcmath', 'zip', 'gnupg']; public array $suggestions = []; public array $criticals = []; public array $loadedExtensions; @@ -99,7 +96,7 @@ class Install } // check for url manipulation or wrong step - if ((isset($_SESSION['installation']['stepCompleted']) && ($this->currentStep + 1) > ($_SESSION['installation']['stepCompleted'] ?? 0)) + if ((isset($_SESSION['installation']['stepCompleted']) && ($this->currentStep + 1) > $_SESSION['installation']['stepCompleted']) || (!isset($_SESSION['installation']['stepCompleted']) && $this->currentStep > 0) ) { $this->currentStep = isset($_SESSION['installation']['stepCompleted']) ? $_SESSION['installation']['stepCompleted'] + 1 : 1; @@ -151,16 +148,14 @@ class Install if ($this->currentStep <= $this->maxSteps) { // Validate user data $validatedData = $this->validateRequest($formfield['sections']['step' . $this->currentStep]['fields']); - // Check database connection ( if ($this->currentStep == 1) { + // Check database connection $this->checkDatabase($validatedData); - } - // Check validity of admin user data - elseif ($this->currentStep == 2) { + } elseif ($this->currentStep == 2) { + // Check validity of admin user data $this->checkAdminUser($validatedData); - } - // Check validity of system data - elseif ($this->currentStep == 3) { + } elseif ($this->currentStep == 3) { + // Check validity of system data $this->checkSystem($validatedData); } $validatedData['stepCompleted'] = ($this->currentStep < $this->maxSteps) ? $this->currentStep : ($this->maxSteps - 1); @@ -192,7 +187,7 @@ class Install private function checkInstallStateFinished(): bool { $core = new Core($_SESSION['installation']); - if (isset($_SESSION['installation']['manual_config']) && (int) $_SESSION['installation']['manual_config'] == 1) { + if (isset($_SESSION['installation']['manual_config']) && (int)$_SESSION['installation']['manual_config'] == 1) { $core->createUserdataConf(); return true; } @@ -200,7 +195,7 @@ class Install $stmt = $pdo->prepare("SELECT `value` FROM `panel_settings` WHERE `settinggroup` = 'panel' AND `varname` = 'is_configured'"); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); - if ($result && (int) $result['value'] == 1) { + if ($result && (int)$result['value'] == 1) { $core->createUserdataConf(); return true; } @@ -223,7 +218,7 @@ class Install } // check for required extensions - foreach ($this->requiredExtensions as $requiredExtension) { + foreach (Requirements::REQUIRED_EXTENSIONS as $requiredExtension) { if (in_array($requiredExtension, $this->loadedExtensions)) { continue; } @@ -231,7 +226,7 @@ class Install } // check for suggested extensions - foreach ($this->suggestedExtensions as $suggestedExtension) { + foreach (Requirements::SUGGESTED_EXTENSIONS as $suggestedExtension) { if (in_array($suggestedExtension, $this->loadedExtensions)) { continue; } @@ -250,11 +245,11 @@ class Install */ private function getInformationText(): string { - if (version_compare($this->requiredVersion, PHP_VERSION, "<")) { + if (version_compare(Requirements::REQUIRED_VERSION, PHP_VERSION, "<")) { $text = lng('install.phpinfosuccess', [$this->phpVersion]); } else { - $text = lng('install.phpinfowarn', [$this->requiredVersion]); - $this->criticals[] = lng('install.phpinfoupdate', [$this->phpVersion, $this->requiredVersion]); + $text = lng('install.phpinfowarn', [Requirements::REQUIRED_VERSION]); + $this->criticals[] = lng('install.phpinfoupdate', [$this->phpVersion, Requirements::REQUIRED_VERSION]); } return $text; } @@ -302,7 +297,7 @@ class Install throw new Exception(lng('install.errors.nov4andnov6ip')); } elseif (!empty($serveripv4) && (!Validate::validate_ip2($serveripv4, true, '', false, true) || IPTools::is_ipv6($serveripv4))) { throw new Exception(lng('error.invalidip', [$serveripv4])); - } elseif (!empty($serveripv6) && (!Validate::validate_ip2($serveripv6, true, '', false, true) || IPTools::is_ipv6($serveripv6) == false)) { + } elseif (!empty($serveripv6) && (!Validate::validate_ip2($serveripv6, true, '', false, true) || !IPTools::is_ipv6($serveripv6))) { throw new Exception(lng('error.invalidip', [$serveripv6])); } elseif (!Validate::validateDomain($servername)) { throw new Exception(lng('install.errors.servernameneedstobevalid')); diff --git a/lib/Froxlor/Install/Requirements.php b/lib/Froxlor/Install/Requirements.php new file mode 100644 index 00000000..6d45b8a3 --- /dev/null +++ b/lib/Froxlor/Install/Requirements.php @@ -0,0 +1,10 @@ +addGlobal('install_mode', '1'); + echo UI::twig()->render($_deftheme . '/misc/missingextensionhint.html.twig', [ + 'phpversion' => phpversion(), + 'missing_extensions' => implode(", ", $missingExtensions), + ]); + die(); +} + // set error-handler @set_error_handler([ '\\Froxlor\\PhpHelper', diff --git a/templates/Froxlor/misc/missingextensionhint.html.twig b/templates/Froxlor/misc/missingextensionhint.html.twig new file mode 100644 index 00000000..6369501a --- /dev/null +++ b/templates/Froxlor/misc/missingextensionhint.html.twig @@ -0,0 +1,18 @@ +{% extends "Froxlor/base.html.twig" %} + +{% block content %} +
+ +
+{% endblock %}