From 22c6c28b81488959c37adced4d632b82653162ed Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Fri, 10 Mar 2023 23:17:59 +0100 Subject: [PATCH] feat: only load available commands in maintenance mode Signed-off-by: Daniel Kesselberg --- core/Command/Log/File.php | 1 - core/Command/Maintenance/Mode.php | 1 - core/register_command.php | 217 +++++++++--------- lib/composer/composer/ClassLoader.php | 12 +- lib/composer/composer/autoload_classmap.php | 1 + lib/composer/composer/autoload_real.php | 6 +- lib/composer/composer/autoload_static.php | 1 + lib/composer/composer/installed.php | 14 +- lib/private/Console/Application.php | 25 +- .../Console/IUnavailableInMaintenanceMode.php | 33 +++ 10 files changed, 183 insertions(+), 128 deletions(-) create mode 100644 lib/private/Console/IUnavailableInMaintenanceMode.php diff --git a/core/Command/Log/File.php b/core/Command/Log/File.php index 6d6e530fe9aed..fb1aaecc1139f 100644 --- a/core/Command/Log/File.php +++ b/core/Command/Log/File.php @@ -26,7 +26,6 @@ namespace OC\Core\Command\Log; use OCP\IConfig; - use Stecman\Component\Symfony\Console\BashCompletion\Completion; use Stecman\Component\Symfony\Console\BashCompletion\Completion\ShellPathCompletion; use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; diff --git a/core/Command/Maintenance/Mode.php b/core/Command/Maintenance/Mode.php index c2af33aa4edbf..cedbc00949874 100644 --- a/core/Command/Maintenance/Mode.php +++ b/core/Command/Maintenance/Mode.php @@ -26,7 +26,6 @@ namespace OC\Core\Command\Maintenance; use OCP\IConfig; - use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; diff --git a/core/register_command.php b/core/register_command.php index 4aac7fbf8ceb7..d1d25eb1b27ca 100644 --- a/core/register_command.php +++ b/core/register_command.php @@ -48,84 +48,89 @@ * along with this program. If not, see * */ +use OC\Console\Application; use Psr\Log\LoggerInterface; -$application->add(new \Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand()); -$application->add(new OC\Core\Command\Status(\OC::$server->get(\OCP\IConfig::class), \OC::$server->get(\OCP\Defaults::class))); -$application->add(new OC\Core\Command\Check(\OC::$server->getSystemConfig())); -$application->add(new OC\Core\Command\L10n\CreateJs()); -$application->add(new \OC\Core\Command\Integrity\SignApp( +/** + * @var Application $this + */ + +$this->add(new \Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand()); +$this->add(new OC\Core\Command\Status(\OC::$server->get(\OCP\IConfig::class), \OC::$server->get(\OCP\Defaults::class))); +$this->add(new OC\Core\Command\Check(\OC::$server->getSystemConfig())); +$this->add(new OC\Core\Command\L10n\CreateJs()); +$this->add(new \OC\Core\Command\Integrity\SignApp( \OC::$server->getIntegrityCodeChecker(), new \OC\IntegrityCheck\Helpers\FileAccessHelper(), \OC::$server->getURLGenerator() )); -$application->add(new \OC\Core\Command\Integrity\SignCore( +$this->add(new \OC\Core\Command\Integrity\SignCore( \OC::$server->getIntegrityCodeChecker(), new \OC\IntegrityCheck\Helpers\FileAccessHelper() )); -$application->add(new \OC\Core\Command\Integrity\CheckApp( +$this->add(new \OC\Core\Command\Integrity\CheckApp( \OC::$server->getIntegrityCodeChecker() )); -$application->add(new \OC\Core\Command\Integrity\CheckCore( +$this->add(new \OC\Core\Command\Integrity\CheckCore( \OC::$server->getIntegrityCodeChecker() )); if (\OC::$server->getConfig()->getSystemValue('installed', false)) { - $application->add(new OC\Core\Command\App\Disable(\OC::$server->getAppManager())); - $application->add(new OC\Core\Command\App\Enable(\OC::$server->getAppManager(), \OC::$server->getGroupManager())); - $application->add(new OC\Core\Command\App\Install()); - $application->add(new OC\Core\Command\App\GetPath()); - $application->add(new OC\Core\Command\App\ListApps(\OC::$server->getAppManager())); - $application->add(new OC\Core\Command\App\Remove(\OC::$server->getAppManager(), \OC::$server->query(\OC\Installer::class), \OC::$server->get(LoggerInterface::class))); - $application->add(\OC::$server->query(\OC\Core\Command\App\Update::class)); - - $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Cleanup::class)); - $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Enforce::class)); - $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Enable::class)); - $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Disable::class)); - $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\State::class)); - - $application->add(new OC\Core\Command\Background\Cron(\OC::$server->getConfig())); - $application->add(new OC\Core\Command\Background\WebCron(\OC::$server->getConfig())); - $application->add(new OC\Core\Command\Background\Ajax(\OC::$server->getConfig())); - $application->add(new OC\Core\Command\Background\Job(\OC::$server->getJobList(), \OC::$server->getLogger())); - $application->add(new OC\Core\Command\Background\ListCommand(\OC::$server->getJobList())); - - $application->add(\OC::$server->query(\OC\Core\Command\Broadcast\Test::class)); - - $application->add(new OC\Core\Command\Config\App\DeleteConfig(\OC::$server->getConfig())); - $application->add(new OC\Core\Command\Config\App\GetConfig(\OC::$server->getConfig())); - $application->add(new OC\Core\Command\Config\App\SetConfig(\OC::$server->getConfig())); - $application->add(new OC\Core\Command\Config\Import(\OC::$server->getConfig())); - $application->add(new OC\Core\Command\Config\ListConfigs(\OC::$server->getSystemConfig(), \OC::$server->getAppConfig())); - $application->add(new OC\Core\Command\Config\System\DeleteConfig(\OC::$server->getSystemConfig())); - $application->add(new OC\Core\Command\Config\System\GetConfig(\OC::$server->getSystemConfig())); - $application->add(new OC\Core\Command\Config\System\SetConfig(\OC::$server->getSystemConfig())); - - $application->add(\OC::$server->get(OC\Core\Command\Info\File::class)); - - $application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig()))); - $application->add(new OC\Core\Command\Db\ConvertMysqlToMB4(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection(), \OC::$server->getURLGenerator(), \OC::$server->get(LoggerInterface::class))); - $application->add(new OC\Core\Command\Db\ConvertFilecacheBigInt(\OC::$server->get(\OC\DB\Connection::class))); - $application->add(new OC\Core\Command\Db\AddMissingIndices(\OC::$server->get(\OC\DB\Connection::class), \OC::$server->getEventDispatcher())); - $application->add(new OC\Core\Command\Db\AddMissingColumns(\OC::$server->get(\OC\DB\Connection::class), \OC::$server->getEventDispatcher())); - $application->add(new OC\Core\Command\Db\AddMissingPrimaryKeys(\OC::$server->get(\OC\DB\Connection::class), \OC::$server->getEventDispatcher())); + $this->add(new OC\Core\Command\App\Disable(\OC::$server->getAppManager())); + $this->add(new OC\Core\Command\App\Enable(\OC::$server->getAppManager(), \OC::$server->getGroupManager())); + $this->add(new OC\Core\Command\App\Install()); + $this->add(new OC\Core\Command\App\GetPath()); + $this->add(new OC\Core\Command\App\ListApps(\OC::$server->getAppManager())); + $this->add(new OC\Core\Command\App\Remove(\OC::$server->getAppManager(), \OC::$server->query(\OC\Installer::class), \OC::$server->get(LoggerInterface::class))); + $this->add(\OC::$server->query(\OC\Core\Command\App\Update::class)); + + $this->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Cleanup::class)); + $this->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Enforce::class)); + $this->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Enable::class)); + $this->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Disable::class)); + $this->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\State::class)); + + $this->add(new OC\Core\Command\Background\Cron(\OC::$server->getConfig())); + $this->add(new OC\Core\Command\Background\WebCron(\OC::$server->getConfig())); + $this->add(new OC\Core\Command\Background\Ajax(\OC::$server->getConfig())); + $this->add(new OC\Core\Command\Background\Job(\OC::$server->getJobList(), \OC::$server->getLogger())); + $this->add(new OC\Core\Command\Background\ListCommand(\OC::$server->getJobList())); + + $this->add(\OC::$server->query(\OC\Core\Command\Broadcast\Test::class)); + + $this->add(new OC\Core\Command\Config\App\DeleteConfig(\OC::$server->getConfig())); + $this->add(new OC\Core\Command\Config\App\GetConfig(\OC::$server->getConfig())); + $this->add(new OC\Core\Command\Config\App\SetConfig(\OC::$server->getConfig())); + $this->add(new OC\Core\Command\Config\Import(\OC::$server->getConfig())); + $this->add(new OC\Core\Command\Config\ListConfigs(\OC::$server->getSystemConfig(), \OC::$server->getAppConfig())); + $this->add(new OC\Core\Command\Config\System\DeleteConfig(\OC::$server->getSystemConfig())); + $this->add(new OC\Core\Command\Config\System\GetConfig(\OC::$server->getSystemConfig())); + $this->add(new OC\Core\Command\Config\System\SetConfig(\OC::$server->getSystemConfig())); + + $this->add(\OC::$server->get(OC\Core\Command\Info\File::class)); + + $this->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig()))); + $this->add(new OC\Core\Command\Db\ConvertMysqlToMB4(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection(), \OC::$server->getURLGenerator(), \OC::$server->get(LoggerInterface::class))); + $this->add(new OC\Core\Command\Db\ConvertFilecacheBigInt(\OC::$server->get(\OC\DB\Connection::class))); + $this->add(new OC\Core\Command\Db\AddMissingIndices(\OC::$server->get(\OC\DB\Connection::class), \OC::$server->getEventDispatcher())); + $this->add(new OC\Core\Command\Db\AddMissingColumns(\OC::$server->get(\OC\DB\Connection::class), \OC::$server->getEventDispatcher())); + $this->add(new OC\Core\Command\Db\AddMissingPrimaryKeys(\OC::$server->get(\OC\DB\Connection::class), \OC::$server->getEventDispatcher())); if (\OC::$server->getConfig()->getSystemValueBool('debug', false)) { - $application->add(new OC\Core\Command\Db\Migrations\StatusCommand(\OC::$server->get(\OC\DB\Connection::class))); - $application->add(new OC\Core\Command\Db\Migrations\MigrateCommand(\OC::$server->get(\OC\DB\Connection::class))); - $application->add(new OC\Core\Command\Db\Migrations\GenerateCommand(\OC::$server->get(\OC\DB\Connection::class), \OC::$server->getAppManager())); - $application->add(new OC\Core\Command\Db\Migrations\ExecuteCommand(\OC::$server->get(\OC\DB\Connection::class), \OC::$server->getConfig())); + $this->add(new OC\Core\Command\Db\Migrations\StatusCommand(\OC::$server->get(\OC\DB\Connection::class))); + $this->add(new OC\Core\Command\Db\Migrations\MigrateCommand(\OC::$server->get(\OC\DB\Connection::class))); + $this->add(new OC\Core\Command\Db\Migrations\GenerateCommand(\OC::$server->get(\OC\DB\Connection::class), \OC::$server->getAppManager())); + $this->add(new OC\Core\Command\Db\Migrations\ExecuteCommand(\OC::$server->get(\OC\DB\Connection::class), \OC::$server->getConfig())); } - $application->add(new OC\Core\Command\Encryption\Disable(\OC::$server->getConfig())); - $application->add(new OC\Core\Command\Encryption\Enable(\OC::$server->getConfig(), \OC::$server->getEncryptionManager())); - $application->add(new OC\Core\Command\Encryption\ListModules(\OC::$server->getEncryptionManager(), \OC::$server->getConfig())); - $application->add(new OC\Core\Command\Encryption\SetDefaultModule(\OC::$server->getEncryptionManager(), \OC::$server->getConfig())); - $application->add(new OC\Core\Command\Encryption\Status(\OC::$server->getEncryptionManager())); - $application->add(new OC\Core\Command\Encryption\EncryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getAppManager(), \OC::$server->getConfig(), new \Symfony\Component\Console\Helper\QuestionHelper())); - $application->add(new OC\Core\Command\Encryption\DecryptAll( + $this->add(new OC\Core\Command\Encryption\Disable(\OC::$server->getConfig())); + $this->add(new OC\Core\Command\Encryption\Enable(\OC::$server->getConfig(), \OC::$server->getEncryptionManager())); + $this->add(new OC\Core\Command\Encryption\ListModules(\OC::$server->getEncryptionManager(), \OC::$server->getConfig())); + $this->add(new OC\Core\Command\Encryption\SetDefaultModule(\OC::$server->getEncryptionManager(), \OC::$server->getConfig())); + $this->add(new OC\Core\Command\Encryption\Status(\OC::$server->getEncryptionManager())); + $this->add(new OC\Core\Command\Encryption\EncryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getAppManager(), \OC::$server->getConfig(), new \Symfony\Component\Console\Helper\QuestionHelper())); + $this->add(new OC\Core\Command\Encryption\DecryptAll( \OC::$server->getEncryptionManager(), \OC::$server->getAppManager(), \OC::$server->getConfig(), @@ -133,8 +138,8 @@ new \Symfony\Component\Console\Helper\QuestionHelper()) ); - $application->add(new OC\Core\Command\Log\Manage(\OC::$server->getConfig())); - $application->add(new OC\Core\Command\Log\File(\OC::$server->getConfig())); + $this->add(new OC\Core\Command\Log\Manage(\OC::$server->getConfig())); + $this->add(new OC\Core\Command\Log\File(\OC::$server->getConfig())); $view = new \OC\Files\View(); $util = new \OC\Encryption\Util( @@ -143,7 +148,7 @@ \OC::$server->getGroupManager(), \OC::$server->getConfig() ); - $application->add(new OC\Core\Command\Encryption\ChangeKeyStorageRoot( + $this->add(new OC\Core\Command\Encryption\ChangeKeyStorageRoot( $view, \OC::$server->getUserManager(), \OC::$server->getConfig(), @@ -151,8 +156,8 @@ new \Symfony\Component\Console\Helper\QuestionHelper() ) ); - $application->add(new OC\Core\Command\Encryption\ShowKeyStorageRoot($util)); - $application->add(new OC\Core\Command\Encryption\MigrateKeyStorage( + $this->add(new OC\Core\Command\Encryption\ShowKeyStorageRoot($util)); + $this->add(new OC\Core\Command\Encryption\MigrateKeyStorage( $view, \OC::$server->getUserManager(), \OC::$server->getConfig(), @@ -161,54 +166,54 @@ ) ); - $application->add(new OC\Core\Command\Maintenance\DataFingerprint(\OC::$server->getConfig(), new \OC\AppFramework\Utility\TimeFactory())); - $application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateDB(\OC::$server->getMimeTypeDetector(), \OC::$server->getMimeTypeLoader())); - $application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateJS(\OC::$server->getMimeTypeDetector())); - $application->add(new OC\Core\Command\Maintenance\Mode(\OC::$server->getConfig())); - $application->add(new OC\Core\Command\Maintenance\UpdateHtaccess()); - $application->add(new OC\Core\Command\Maintenance\UpdateTheme(\OC::$server->getMimeTypeDetector(), \OC::$server->getMemCacheFactory())); + $this->add(new OC\Core\Command\Maintenance\DataFingerprint(\OC::$server->getConfig(), new \OC\AppFramework\Utility\TimeFactory())); + $this->add(new OC\Core\Command\Maintenance\Mimetype\UpdateDB(\OC::$server->getMimeTypeDetector(), \OC::$server->getMimeTypeLoader())); + $this->add(new OC\Core\Command\Maintenance\Mimetype\UpdateJS(\OC::$server->getMimeTypeDetector())); + $this->add(new OC\Core\Command\Maintenance\Mode(\OC::$server->getConfig())); + $this->add(new OC\Core\Command\Maintenance\UpdateHtaccess()); + $this->add(new OC\Core\Command\Maintenance\UpdateTheme(\OC::$server->getMimeTypeDetector(), \OC::$server->getMemCacheFactory())); - $application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), \OC::$server->query(\OC\Installer::class))); - $application->add(new OC\Core\Command\Maintenance\Repair( + $this->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), \OC::$server->query(\OC\Installer::class))); + $this->add(new OC\Core\Command\Maintenance\Repair( new \OC\Repair([], \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class), \OC::$server->get(LoggerInterface::class)), \OC::$server->getConfig(), \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class), \OC::$server->getAppManager() )); - $application->add(\OC::$server->query(OC\Core\Command\Maintenance\RepairShareOwnership::class)); - - $application->add(\OC::$server->get(\OC\Core\Command\Preview\Generate::class)); - $application->add(\OC::$server->query(\OC\Core\Command\Preview\Repair::class)); - $application->add(\OC::$server->query(\OC\Core\Command\Preview\ResetRenderedTexts::class)); - - $application->add(new OC\Core\Command\User\Add(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); - $application->add(new OC\Core\Command\User\Delete(\OC::$server->getUserManager())); - $application->add(new OC\Core\Command\User\Disable(\OC::$server->getUserManager())); - $application->add(new OC\Core\Command\User\Enable(\OC::$server->getUserManager())); - $application->add(new OC\Core\Command\User\LastSeen(\OC::$server->getUserManager())); - $application->add(\OC::$server->get(\OC\Core\Command\User\Report::class)); - $application->add(new OC\Core\Command\User\ResetPassword(\OC::$server->getUserManager(), \OC::$server->getAppManager())); - $application->add(new OC\Core\Command\User\Setting(\OC::$server->getUserManager(), \OC::$server->getConfig())); - $application->add(new OC\Core\Command\User\ListCommand(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); - $application->add(new OC\Core\Command\User\Info(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); - $application->add(new OC\Core\Command\User\AddAppPassword(\OC::$server->get(\OCP\IUserManager::class), \OC::$server->get(\OC\Authentication\Token\IProvider::class), \OC::$server->get(\OCP\Security\ISecureRandom::class), \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class))); - - $application->add(new OC\Core\Command\Group\Add(\OC::$server->getGroupManager())); - $application->add(new OC\Core\Command\Group\Delete(\OC::$server->getGroupManager())); - $application->add(new OC\Core\Command\Group\ListCommand(\OC::$server->getGroupManager())); - $application->add(new OC\Core\Command\Group\AddUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); - $application->add(new OC\Core\Command\Group\RemoveUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); - $application->add(new OC\Core\Command\Group\Info(\OC::$server->get(\OCP\IGroupManager::class))); - - $application->add(new OC\Core\Command\SystemTag\ListCommand(\OC::$server->get(\OCP\SystemTag\ISystemTagManager::class))); - $application->add(new OC\Core\Command\SystemTag\Delete(\OC::$server->get(\OCP\SystemTag\ISystemTagManager::class))); - $application->add(new OC\Core\Command\SystemTag\Add(\OC::$server->get(\OCP\SystemTag\ISystemTagManager::class))); - $application->add(new OC\Core\Command\SystemTag\Edit(\OC::$server->get(\OCP\SystemTag\ISystemTagManager::class))); - - $application->add(new OC\Core\Command\Security\ListCertificates(\OC::$server->getCertificateManager(), \OC::$server->getL10N('core'))); - $application->add(new OC\Core\Command\Security\ImportCertificate(\OC::$server->getCertificateManager())); - $application->add(new OC\Core\Command\Security\RemoveCertificate(\OC::$server->getCertificateManager())); - $application->add(new OC\Core\Command\Security\ResetBruteforceAttempts(\OC::$server->getBruteForceThrottler())); + $this->add(\OC::$server->query(OC\Core\Command\Maintenance\RepairShareOwnership::class)); + + $this->add(\OC::$server->get(\OC\Core\Command\Preview\Generate::class)); + $this->add(\OC::$server->query(\OC\Core\Command\Preview\Repair::class)); + $this->add(\OC::$server->query(\OC\Core\Command\Preview\ResetRenderedTexts::class)); + + $this->add(new OC\Core\Command\User\Add(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); + $this->add(new OC\Core\Command\User\Delete(\OC::$server->getUserManager())); + $this->add(new OC\Core\Command\User\Disable(\OC::$server->getUserManager())); + $this->add(new OC\Core\Command\User\Enable(\OC::$server->getUserManager())); + $this->add(new OC\Core\Command\User\LastSeen(\OC::$server->getUserManager())); + $this->add(\OC::$server->get(\OC\Core\Command\User\Report::class)); + $this->add(new OC\Core\Command\User\ResetPassword(\OC::$server->getUserManager(), \OC::$server->getAppManager())); + $this->add(new OC\Core\Command\User\Setting(\OC::$server->getUserManager(), \OC::$server->getConfig())); + $this->add(new OC\Core\Command\User\ListCommand(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); + $this->add(new OC\Core\Command\User\Info(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); + $this->add(new OC\Core\Command\User\AddAppPassword(\OC::$server->get(\OCP\IUserManager::class), \OC::$server->get(\OC\Authentication\Token\IProvider::class), \OC::$server->get(\OCP\Security\ISecureRandom::class), \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class))); + + $this->add(new OC\Core\Command\Group\Add(\OC::$server->getGroupManager())); + $this->add(new OC\Core\Command\Group\Delete(\OC::$server->getGroupManager())); + $this->add(new OC\Core\Command\Group\ListCommand(\OC::$server->getGroupManager())); + $this->add(new OC\Core\Command\Group\AddUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); + $this->add(new OC\Core\Command\Group\RemoveUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); + $this->add(new OC\Core\Command\Group\Info(\OC::$server->get(\OCP\IGroupManager::class))); + + $this->add(new OC\Core\Command\SystemTag\ListCommand(\OC::$server->get(\OCP\SystemTag\ISystemTagManager::class))); + $this->add(new OC\Core\Command\SystemTag\Delete(\OC::$server->get(\OCP\SystemTag\ISystemTagManager::class))); + $this->add(new OC\Core\Command\SystemTag\Add(\OC::$server->get(\OCP\SystemTag\ISystemTagManager::class))); + $this->add(new OC\Core\Command\SystemTag\Edit(\OC::$server->get(\OCP\SystemTag\ISystemTagManager::class))); + + $this->add(new OC\Core\Command\Security\ListCertificates(\OC::$server->getCertificateManager(), \OC::$server->getL10N('core'))); + $this->add(new OC\Core\Command\Security\ImportCertificate(\OC::$server->getCertificateManager())); + $this->add(new OC\Core\Command\Security\RemoveCertificate(\OC::$server->getCertificateManager())); + $this->add(new OC\Core\Command\Security\ResetBruteforceAttempts(\OC::$server->getBruteForceThrottler())); } else { - $application->add(\OC::$server->get(\OC\Core\Command\Maintenance\Install::class)); + $this->add(\OC::$server->get(\OC\Core\Command\Maintenance\Install::class)); } diff --git a/lib/composer/composer/ClassLoader.php b/lib/composer/composer/ClassLoader.php index a72151c77c8eb..fd56bd7d8405f 100644 --- a/lib/composer/composer/ClassLoader.php +++ b/lib/composer/composer/ClassLoader.php @@ -429,8 +429,7 @@ public function unregister() public function loadClass($class) { if ($file = $this->findFile($class)) { - $includeFile = self::$includeFile; - $includeFile($file); + (self::$includeFile)($file); return true; } @@ -561,10 +560,7 @@ private function findFileWithExtension($class, $ext) return false; } - /** - * @return void - */ - private static function initializeIncludeClosure() + private static function initializeIncludeClosure(): void { if (self::$includeFile !== null) { return; @@ -578,8 +574,8 @@ private static function initializeIncludeClosure() * @param string $file * @return void */ - self::$includeFile = \Closure::bind(static function($file) { + self::$includeFile = static function($file) { include $file; - }, null, null); + }; } } diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 3e1b9559d5ead..a3b7296d0fe17 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -878,6 +878,7 @@ 'OC\\Comments\\ManagerFactory' => $baseDir . '/lib/private/Comments/ManagerFactory.php', 'OC\\Config' => $baseDir . '/lib/private/Config.php', 'OC\\Console\\Application' => $baseDir . '/lib/private/Console/Application.php', + 'OC\\Console\\IUnavailableInMaintenanceMode' => $baseDir . '/lib/private/Console/IUnavailableInMaintenanceMode.php', 'OC\\Console\\TimestampFormatter' => $baseDir . '/lib/private/Console/TimestampFormatter.php', 'OC\\ContactsManager' => $baseDir . '/lib/private/ContactsManager.php', 'OC\\Contacts\\ContactsMenu\\ActionFactory' => $baseDir . '/lib/private/Contacts/ContactsMenu/ActionFactory.php', diff --git a/lib/composer/composer/autoload_real.php b/lib/composer/composer/autoload_real.php index ca3361d7202e4..9e054bba0be48 100644 --- a/lib/composer/composer/autoload_real.php +++ b/lib/composer/composer/autoload_real.php @@ -34,15 +34,15 @@ public static function getLoader() $loader->register(true); $filesToLoad = \Composer\Autoload\ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2::$files; - $requireFile = \Closure::bind(static function ($fileIdentifier, $file) { + $requireFile = static function ($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; require $file; } - }, null, null); + }; foreach ($filesToLoad as $fileIdentifier => $file) { - $requireFile($fileIdentifier, $file); + ($requireFile)($fileIdentifier, $file); } return $loader; diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 1a0d68fd20424..485c3ab648151 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -911,6 +911,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OC\\Comments\\ManagerFactory' => __DIR__ . '/../../..' . '/lib/private/Comments/ManagerFactory.php', 'OC\\Config' => __DIR__ . '/../../..' . '/lib/private/Config.php', 'OC\\Console\\Application' => __DIR__ . '/../../..' . '/lib/private/Console/Application.php', + 'OC\\Console\\IUnavailableInMaintenanceMode' => __DIR__ . '/../../..' . '/lib/private/Console/IUnavailableInMaintenanceMode.php', 'OC\\Console\\TimestampFormatter' => __DIR__ . '/../../..' . '/lib/private/Console/TimestampFormatter.php', 'OC\\ContactsManager' => __DIR__ . '/../../..' . '/lib/private/ContactsManager.php', 'OC\\Contacts\\ContactsMenu\\ActionFactory' => __DIR__ . '/../../..' . '/lib/private/Contacts/ContactsMenu/ActionFactory.php', diff --git a/lib/composer/composer/installed.php b/lib/composer/composer/installed.php index 1f382499aeb21..3fab34d1bd402 100644 --- a/lib/composer/composer/installed.php +++ b/lib/composer/composer/installed.php @@ -1,22 +1,22 @@ array( - 'pretty_version' => '1.0.0+no-version-set', - 'version' => '1.0.0.0', + 'name' => '__root__', + 'pretty_version' => 'dev-master', + 'version' => 'dev-master', + 'reference' => 'f5e7a1fbc40d93be93c9f4891a90fdcd3a1eedd4', 'type' => 'library', 'install_path' => __DIR__ . '/../../../', 'aliases' => array(), - 'reference' => NULL, - 'name' => '__root__', 'dev' => false, ), 'versions' => array( '__root__' => array( - 'pretty_version' => '1.0.0+no-version-set', - 'version' => '1.0.0.0', + 'pretty_version' => 'dev-master', + 'version' => 'dev-master', + 'reference' => 'f5e7a1fbc40d93be93c9f4891a90fdcd3a1eedd4', 'type' => 'library', 'install_path' => __DIR__ . '/../../../', 'aliases' => array(), - 'reference' => NULL, 'dev_requirement' => false, ), ), diff --git a/lib/private/Console/Application.php b/lib/private/Console/Application.php index 0ed436fb0e6cc..9c1a921df525c 100644 --- a/lib/private/Console/Application.php +++ b/lib/private/Console/Application.php @@ -33,13 +33,16 @@ use OC\MemoryInfo; use OC\NeedsUpdateException; use OC_App; -use OCP\AppFramework\QueryException; use OCP\App\IAppManager; +use OCP\AppFramework\QueryException; use OCP\Console\ConsoleEvent; use OCP\IConfig; use OCP\IRequest; use Psr\Log\LoggerInterface; +use Stecman\Component\Symfony\Console\BashCompletion\Completion; +use Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand; use Symfony\Component\Console\Application as SymfonyApplication; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\ConsoleOutputInterface; @@ -59,6 +62,8 @@ class Application { /** @var MemoryInfo */ private $memoryInfo; + private bool $maintenanceMode; + public function __construct(IConfig $config, EventDispatcherInterface $dispatcher, IRequest $request, @@ -71,6 +76,22 @@ public function __construct(IConfig $config, $this->request = $request; $this->logger = $logger; $this->memoryInfo = $memoryInfo; + $this->maintenanceMode = $this->config->getSystemValueBool('maintenance'); + } + + /** + * Adds a command object. + * + * If a command with the same name already exists, it will be overridden. + * If the command is not enabled it will not be added. + * + * @return Command|null The registered command if enabled or null + */ + public function add(Command $command) { + if ($this->maintenanceMode && in_array(IUnavailableInMaintenanceMode::class, class_implements($command, false))) { + return null; + } + return $this->application->add($command); } /** @@ -231,7 +252,7 @@ private function loadCommandsFromInfoXml($commands) { } } - $this->application->add($c); + $this->add($c); } } } diff --git a/lib/private/Console/IUnavailableInMaintenanceMode.php b/lib/private/Console/IUnavailableInMaintenanceMode.php new file mode 100644 index 0000000000000..c4b6c306d56b9 --- /dev/null +++ b/lib/private/Console/IUnavailableInMaintenanceMode.php @@ -0,0 +1,33 @@ + + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * 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 + * along with this program. If not, see . + * + */ + +namespace OC\Console; + +/** + * Implement if a command is unavailable in maintenance mode. + * + * A core command is a command registered in core/register_command.php. + * + * @since 27.0.0 + */ +interface IUnavailableInMaintenanceMode { +}