|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors |
| 7 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 8 | + */ |
| 9 | + |
| 10 | +namespace OCA\Settings\SetupChecks; |
| 11 | + |
| 12 | +use bantu\IniGetWrapper\IniGetWrapper; |
| 13 | +use OCP\IL10N; |
| 14 | +use OCP\IURLGenerator; |
| 15 | +use OCP\SetupCheck\ISetupCheck; |
| 16 | +use OCP\SetupCheck\SetupResult; |
| 17 | +use OCP\Util; |
| 18 | + |
| 19 | +class PhpMaxFileSize implements ISetupCheck { |
| 20 | + public function __construct( |
| 21 | + private IL10N $l10n, |
| 22 | + private IURLGenerator $urlGenerator, |
| 23 | + private IniGetWrapper $iniGetWrapper, |
| 24 | + ) { |
| 25 | + } |
| 26 | + |
| 27 | + public function getCategory(): string { |
| 28 | + return 'php'; |
| 29 | + } |
| 30 | + |
| 31 | + public function getName(): string { |
| 32 | + return $this->l10n->t('PHP file size upload limit'); |
| 33 | + } |
| 34 | + |
| 35 | + public function run(): SetupResult { |
| 36 | + $upload_max_filesize = Util::computerFileSize((string)$this->iniGetWrapper->getString('upload_max_filesize')); |
| 37 | + $post_max_size = Util::computerFileSize((string)$this->iniGetWrapper->getString('post_max_size')); |
| 38 | + $max_input_time = (int)$this->iniGetWrapper->getString('max_input_time'); |
| 39 | + $max_execution_time = (int)$this->iniGetWrapper->getString('max_execution_time'); |
| 40 | + |
| 41 | + $warnings = []; |
| 42 | + $recommendedSize = 16 * 1024 * 1024 * 1024; |
| 43 | + $recommendedTime = 3600; |
| 44 | + |
| 45 | + // Check if the PHP upload limit is too low |
| 46 | + if ($upload_max_filesize < $recommendedSize) { |
| 47 | + $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.', [ |
| 48 | + Util::humanFileSize($recommendedSize), |
| 49 | + Util::humanFileSize($upload_max_filesize), |
| 50 | + ]); |
| 51 | + } |
| 52 | + if ($post_max_size < $recommendedSize) { |
| 53 | + $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.', [ |
| 54 | + Util::humanFileSize($recommendedSize), |
| 55 | + Util::humanFileSize($post_max_size), |
| 56 | + ]); |
| 57 | + } |
| 58 | + |
| 59 | + // Check if the PHP execution time is too low |
| 60 | + if ($max_input_time < $recommendedTime && $max_input_time !== -1) { |
| 61 | + $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.', [ |
| 62 | + $recommendedTime, |
| 63 | + $max_input_time, |
| 64 | + ]); |
| 65 | + } |
| 66 | + |
| 67 | + if ($max_execution_time < $recommendedTime && $max_execution_time !== -1) { |
| 68 | + $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.', [ |
| 69 | + $recommendedTime, |
| 70 | + $max_execution_time, |
| 71 | + ]); |
| 72 | + } |
| 73 | + |
| 74 | + if (!empty($warnings)) { |
| 75 | + return SetupResult::warning(join(' ', $warnings), $this->urlGenerator->linkToDocs('admin-big-file-upload')); |
| 76 | + } |
| 77 | + |
| 78 | + return SetupResult::success(); |
| 79 | + } |
| 80 | +} |
0 commit comments