From 1c480f55a28eefd0f7b161e321f654a9f7fa9352 Mon Sep 17 00:00:00 2001 From: skjnldsv Date: Tue, 19 Nov 2024 12:41:53 +0100 Subject: [PATCH 1/2] feat(settings): add big file upload setup checks Signed-off-by: skjnldsv --- .../composer/composer/autoload_classmap.php | 1 + .../composer/composer/autoload_static.php | 1 + apps/settings/lib/AppInfo/Application.php | 2 + .../lib/SetupChecks/PhpMaxFileSize.php | 80 +++++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 apps/settings/lib/SetupChecks/PhpMaxFileSize.php diff --git a/apps/settings/composer/composer/autoload_classmap.php b/apps/settings/composer/composer/autoload_classmap.php index 599e601e7fa75..c2a883f706b83 100644 --- a/apps/settings/composer/composer/autoload_classmap.php +++ b/apps/settings/composer/composer/autoload_classmap.php @@ -103,6 +103,7 @@ 'OCA\\Settings\\SetupChecks\\PhpDisabledFunctions' => $baseDir . '/../lib/SetupChecks/PhpDisabledFunctions.php', 'OCA\\Settings\\SetupChecks\\PhpFreetypeSupport' => $baseDir . '/../lib/SetupChecks/PhpFreetypeSupport.php', 'OCA\\Settings\\SetupChecks\\PhpGetEnv' => $baseDir . '/../lib/SetupChecks/PhpGetEnv.php', + 'OCA\\Settings\\SetupChecks\\PhpMaxFileSize' => $baseDir . '/../lib/SetupChecks/PhpMaxFileSize.php', 'OCA\\Settings\\SetupChecks\\PhpMemoryLimit' => $baseDir . '/../lib/SetupChecks/PhpMemoryLimit.php', 'OCA\\Settings\\SetupChecks\\PhpModules' => $baseDir . '/../lib/SetupChecks/PhpModules.php', 'OCA\\Settings\\SetupChecks\\PhpOpcacheSetup' => $baseDir . '/../lib/SetupChecks/PhpOpcacheSetup.php', diff --git a/apps/settings/composer/composer/autoload_static.php b/apps/settings/composer/composer/autoload_static.php index 32a323a7863bf..b86200b491ee4 100644 --- a/apps/settings/composer/composer/autoload_static.php +++ b/apps/settings/composer/composer/autoload_static.php @@ -118,6 +118,7 @@ class ComposerStaticInitSettings 'OCA\\Settings\\SetupChecks\\PhpDisabledFunctions' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpDisabledFunctions.php', 'OCA\\Settings\\SetupChecks\\PhpFreetypeSupport' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpFreetypeSupport.php', 'OCA\\Settings\\SetupChecks\\PhpGetEnv' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpGetEnv.php', + 'OCA\\Settings\\SetupChecks\\PhpMaxFileSize' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpMaxFileSize.php', 'OCA\\Settings\\SetupChecks\\PhpMemoryLimit' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpMemoryLimit.php', 'OCA\\Settings\\SetupChecks\\PhpModules' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpModules.php', 'OCA\\Settings\\SetupChecks\\PhpOpcacheSetup' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpOpcacheSetup.php', diff --git a/apps/settings/lib/AppInfo/Application.php b/apps/settings/lib/AppInfo/Application.php index ac553ddca9e37..9a1f11ae9df9b 100644 --- a/apps/settings/lib/AppInfo/Application.php +++ b/apps/settings/lib/AppInfo/Application.php @@ -75,6 +75,7 @@ use OCA\Settings\SetupChecks\PhpDisabledFunctions; use OCA\Settings\SetupChecks\PhpFreetypeSupport; use OCA\Settings\SetupChecks\PhpGetEnv; +use OCA\Settings\SetupChecks\PhpMaxFileSize; use OCA\Settings\SetupChecks\PhpMemoryLimit; use OCA\Settings\SetupChecks\PhpModules; use OCA\Settings\SetupChecks\PhpOpcacheSetup; @@ -200,6 +201,7 @@ public function register(IRegistrationContext $context): void { $context->registerSetupCheck(PhpDisabledFunctions::class); $context->registerSetupCheck(PhpFreetypeSupport::class); $context->registerSetupCheck(PhpGetEnv::class); + $context->registerSetupCheck(PhpMaxFileSize::class); $context->registerSetupCheck(PhpMemoryLimit::class); $context->registerSetupCheck(PhpModules::class); $context->registerSetupCheck(PhpOpcacheSetup::class); diff --git a/apps/settings/lib/SetupChecks/PhpMaxFileSize.php b/apps/settings/lib/SetupChecks/PhpMaxFileSize.php new file mode 100644 index 0000000000000..942a8408e8181 --- /dev/null +++ b/apps/settings/lib/SetupChecks/PhpMaxFileSize.php @@ -0,0 +1,80 @@ +l10n->t('PHP file size upload limit'); + } + + public function run(): SetupResult { + $upload_max_filesize = Util::computerFileSize((string)$this->iniGetWrapper->getString('upload_max_filesize')); + $post_max_size = Util::computerFileSize((string)$this->iniGetWrapper->getString('post_max_size')); + $max_input_time = (int)$this->iniGetWrapper->getString('max_input_time'); + $max_execution_time = (int)$this->iniGetWrapper->getString('max_execution_time'); + + $warnings = []; + $recommendedSize = 16 * 1024 * 1024 * 1024; + $recommendedTime = 3600; + + // Check if the PHP upload limit is too low + if ($upload_max_filesize < $recommendedSize) { + $warnings[] = $this->l10n->t('The PHP upload_max_filesize is too low. A size of at least %1$s is recommended. Current value: %2$s.', [ + Util::humanFileSize($recommendedSize), + Util::humanFileSize($upload_max_filesize), + ]); + } + if ($post_max_size < $recommendedSize) { + $warnings[] = $this->l10n->t('The PHP post_max_size is too low. A size of at least %1$s is recommended. Current value: %2$s.', [ + Util::humanFileSize($recommendedSize), + Util::humanFileSize($post_max_size), + ]); + } + + // Check if the PHP execution time is too low + if ($max_input_time < $recommendedTime && $max_input_time !== -1) { + $warnings[] = $this->l10n->t('The PHP max_input_time is too low. A time of at least %1$s is recommended. Current value: %2$s.', [ + $recommendedTime, + $max_input_time, + ]); + } + + if ($max_execution_time < $recommendedTime && $max_execution_time !== -1) { + $warnings[] = $this->l10n->t('The PHP max_execution_time is too low. A time of at least %1$s is recommended. Current value: %2$s.', [ + $recommendedTime, + $max_execution_time, + ]); + } + + if (!empty($warnings)) { + return SetupResult::warning(join(' ', $warnings), $this->urlGenerator->linkToDocs('admin-big-file-upload')); + } + + return SetupResult::success(); + } +} From 6b3c02746ba19d3b12d21955fbfe64255d117548 Mon Sep 17 00:00:00 2001 From: skjnldsv Date: Tue, 19 Nov 2024 19:05:35 +0100 Subject: [PATCH 2/2] fix(settings): psalm PhpMaxFileSize setup check warning Signed-off-by: skjnldsv --- apps/settings/lib/SetupChecks/PhpMaxFileSize.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/settings/lib/SetupChecks/PhpMaxFileSize.php b/apps/settings/lib/SetupChecks/PhpMaxFileSize.php index 942a8408e8181..d81cbe6d45c18 100644 --- a/apps/settings/lib/SetupChecks/PhpMaxFileSize.php +++ b/apps/settings/lib/SetupChecks/PhpMaxFileSize.php @@ -33,8 +33,8 @@ public function getName(): string { } public function run(): SetupResult { - $upload_max_filesize = Util::computerFileSize((string)$this->iniGetWrapper->getString('upload_max_filesize')); - $post_max_size = Util::computerFileSize((string)$this->iniGetWrapper->getString('post_max_size')); + $upload_max_filesize = (string)$this->iniGetWrapper->getString('upload_max_filesize'); + $post_max_size = (string)$this->iniGetWrapper->getString('post_max_size'); $max_input_time = (int)$this->iniGetWrapper->getString('max_input_time'); $max_execution_time = (int)$this->iniGetWrapper->getString('max_execution_time'); @@ -43,16 +43,16 @@ public function run(): SetupResult { $recommendedTime = 3600; // Check if the PHP upload limit is too low - if ($upload_max_filesize < $recommendedSize) { + if (Util::computerFileSize($upload_max_filesize) < $recommendedSize) { $warnings[] = $this->l10n->t('The PHP upload_max_filesize is too low. A size of at least %1$s is recommended. Current value: %2$s.', [ Util::humanFileSize($recommendedSize), - Util::humanFileSize($upload_max_filesize), + $upload_max_filesize, ]); } - if ($post_max_size < $recommendedSize) { + if (Util::computerFileSize($post_max_size) < $recommendedSize) { $warnings[] = $this->l10n->t('The PHP post_max_size is too low. A size of at least %1$s is recommended. Current value: %2$s.', [ Util::humanFileSize($recommendedSize), - Util::humanFileSize($post_max_size), + $post_max_size, ]); }