From b5eeaa90d7fd417a10e6c5096ee9643548e8a4d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 24 Oct 2023 10:42:26 +0200 Subject: [PATCH 1/5] Add a command to run the setup checks from CLI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- core/Command/SetupChecks.php | 88 +++++++++++++++++++++ core/register_command.php | 1 + lib/composer/composer/autoload_classmap.php | 1 + lib/composer/composer/autoload_static.php | 1 + 4 files changed, 91 insertions(+) create mode 100644 core/Command/SetupChecks.php diff --git a/core/Command/SetupChecks.php b/core/Command/SetupChecks.php new file mode 100644 index 00000000000..d43b5a07592 --- /dev/null +++ b/core/Command/SetupChecks.php @@ -0,0 +1,88 @@ + + * + * @author Côme Chilliet + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace OC\Core\Command; + +use OCP\SetupCheck\ISetupCheckManager; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +class SetupChecks extends Base { + public function __construct( + private ISetupCheckManager $setupCheckManager, + ) { + parent::__construct(); + } + + protected function configure(): void { + parent::configure(); + + $this + ->setName('setupchecks') + ->setDescription('Run setup checks and output the results') + ; + } + + protected function execute(InputInterface $input, OutputInterface $output): int { + $results = $this->setupCheckManager->runAll(); + switch ($input->getOption('output')) { + case self::OUTPUT_FORMAT_JSON: + case self::OUTPUT_FORMAT_JSON_PRETTY: + $this->writeArrayInOutputFormat($input, $output, $results); + break; + default: + foreach ($results as $category => $checks) { + $output->writeln("\t{$category}:"); + foreach ($checks as $title => $check) { + $styleTag = match ($check->getSeverity()) { + 'success' => 'info', + 'error' => 'error', + default => 'comment', + }; + $emoji = match ($check->getSeverity()) { + 'success' => '✓', + 'error' => '❌', + default => 'ℹ', + }; + $output->writeln( + "\t\t<{$styleTag}>". + "{$emoji} ". + $title. + ($check->getDescription() !== null ? ': '.$check->getDescription() : ''). + "" + ); + } + } + } + foreach ($results as $category => $checks) { + foreach ($checks as $title => $check) { + if ($check->getSeverity() !== 'success') { + return 1; + } + } + } + return 0; + } +} diff --git a/core/register_command.php b/core/register_command.php index d9e5dfcd775..975dcf6c05f 100644 --- a/core/register_command.php +++ b/core/register_command.php @@ -214,6 +214,7 @@ if (\OC::$server->getConfig()->getSystemValue('installed', false)) { $application->add(new OC\Core\Command\Security\RemoveCertificate(\OC::$server->getCertificateManager())); $application->add(\OC::$server->get(\OC\Core\Command\Security\BruteforceAttempts::class)); $application->add(\OC::$server->get(\OC\Core\Command\Security\BruteforceResetAttempts::class)); + $application->add(\OC::$server->get(\OC\Core\Command\SetupChecks::class)); } else { $application->add(\OC::$server->get(\OC\Core\Command\Maintenance\Install::class)); } diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index b2d0b225574..0aebab5d181 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -1059,6 +1059,7 @@ return array( 'OC\\Core\\Command\\Security\\ImportCertificate' => $baseDir . '/core/Command/Security/ImportCertificate.php', 'OC\\Core\\Command\\Security\\ListCertificates' => $baseDir . '/core/Command/Security/ListCertificates.php', 'OC\\Core\\Command\\Security\\RemoveCertificate' => $baseDir . '/core/Command/Security/RemoveCertificate.php', + 'OC\\Core\\Command\\SetupChecks' => $baseDir . '/core/Command/SetupChecks.php', 'OC\\Core\\Command\\Status' => $baseDir . '/core/Command/Status.php', 'OC\\Core\\Command\\SystemTag\\Add' => $baseDir . '/core/Command/SystemTag/Add.php', 'OC\\Core\\Command\\SystemTag\\Delete' => $baseDir . '/core/Command/SystemTag/Delete.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 7e73255b29b..ac6207eeb07 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -1092,6 +1092,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OC\\Core\\Command\\Security\\ImportCertificate' => __DIR__ . '/../../..' . '/core/Command/Security/ImportCertificate.php', 'OC\\Core\\Command\\Security\\ListCertificates' => __DIR__ . '/../../..' . '/core/Command/Security/ListCertificates.php', 'OC\\Core\\Command\\Security\\RemoveCertificate' => __DIR__ . '/../../..' . '/core/Command/Security/RemoveCertificate.php', + 'OC\\Core\\Command\\SetupChecks' => __DIR__ . '/../../..' . '/core/Command/SetupChecks.php', 'OC\\Core\\Command\\Status' => __DIR__ . '/../../..' . '/core/Command/Status.php', 'OC\\Core\\Command\\SystemTag\\Add' => __DIR__ . '/../../..' . '/core/Command/SystemTag/Add.php', 'OC\\Core\\Command\\SystemTag\\Delete' => __DIR__ . '/../../..' . '/core/Command/SystemTag/Delete.php', From a1a7774374c46dd3e904035237e02cb20b37f0e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 24 Oct 2023 16:55:45 +0200 Subject: [PATCH 2/5] Use constants for SUCCESS/FAILURE and show errors even on quiet level MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- core/Command/SetupChecks.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/core/Command/SetupChecks.php b/core/Command/SetupChecks.php index d43b5a07592..f31acba63e3 100644 --- a/core/Command/SetupChecks.php +++ b/core/Command/SetupChecks.php @@ -66,12 +66,15 @@ class SetupChecks extends Base { 'error' => '❌', default => 'ℹ', }; + $verbosity = ($check->getSeverity() === 'error' ? OutputInterface::VERBOSITY_QUIET : OutputInterface::VERBOSITY_NORMAL); + $description = $check->getDescription(); $output->writeln( "\t\t<{$styleTag}>". "{$emoji} ". $title. - ($check->getDescription() !== null ? ': '.$check->getDescription() : ''). - "" + ($description !== null ? ': '.$description : ''). + "", + $verbosity ); } } @@ -79,10 +82,10 @@ class SetupChecks extends Base { foreach ($results as $category => $checks) { foreach ($checks as $title => $check) { if ($check->getSeverity() !== 'success') { - return 1; + return self::FAILURE; } } } - return 0; + return self::SUCCESS; } } From 802da2b801c6b3c02bfcbb816316cf39e556911b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Thu, 26 Oct 2023 12:01:52 +0200 Subject: [PATCH 3/5] Add an emoji for warnings as well MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- core/Command/SetupChecks.php | 1 + 1 file changed, 1 insertion(+) diff --git a/core/Command/SetupChecks.php b/core/Command/SetupChecks.php index f31acba63e3..e64f7a5058e 100644 --- a/core/Command/SetupChecks.php +++ b/core/Command/SetupChecks.php @@ -64,6 +64,7 @@ class SetupChecks extends Base { $emoji = match ($check->getSeverity()) { 'success' => '✓', 'error' => '❌', + 'warning' => '⚠', default => 'ℹ', }; $verbosity = ($check->getSeverity() === 'error' ? OutputInterface::VERBOSITY_QUIET : OutputInterface::VERBOSITY_NORMAL); From 2aab6bd2096fc83912182704ad70c25954396457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Thu, 26 Oct 2023 16:10:49 +0200 Subject: [PATCH 4/5] Fix icon for errors to be consistent with the others MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- core/Command/SetupChecks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Command/SetupChecks.php b/core/Command/SetupChecks.php index e64f7a5058e..d266b62a0f2 100644 --- a/core/Command/SetupChecks.php +++ b/core/Command/SetupChecks.php @@ -63,7 +63,7 @@ class SetupChecks extends Base { }; $emoji = match ($check->getSeverity()) { 'success' => '✓', - 'error' => '❌', + 'error' => '✗', 'warning' => '⚠', default => 'ℹ', }; From 3cdb059dcfa8dc441221dfb2eefacc863b864854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 6 Nov 2023 15:28:51 +0100 Subject: [PATCH 5/5] Use no style for info to make it different from warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- core/Command/SetupChecks.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/Command/SetupChecks.php b/core/Command/SetupChecks.php index d266b62a0f2..ed0d22bdfc0 100644 --- a/core/Command/SetupChecks.php +++ b/core/Command/SetupChecks.php @@ -59,7 +59,8 @@ class SetupChecks extends Base { $styleTag = match ($check->getSeverity()) { 'success' => 'info', 'error' => 'error', - default => 'comment', + 'warning' => 'comment', + default => null, }; $emoji = match ($check->getSeverity()) { 'success' => '✓', @@ -70,11 +71,12 @@ class SetupChecks extends Base { $verbosity = ($check->getSeverity() === 'error' ? OutputInterface::VERBOSITY_QUIET : OutputInterface::VERBOSITY_NORMAL); $description = $check->getDescription(); $output->writeln( - "\t\t<{$styleTag}>". + "\t\t". + ($styleTag !== null ? "<{$styleTag}>" : ''). "{$emoji} ". $title. ($description !== null ? ': '.$description : ''). - "", + ($styleTag !== null ? "" : ''), $verbosity ); }