diff --git a/core/Command/CommandUnavailableInMaintenanceMode.php b/core/Command/CommandUnavailableInMaintenanceMode.php new file mode 100644 index 0000000000000..f5e857d3d3e67 --- /dev/null +++ b/core/Command/CommandUnavailableInMaintenanceMode.php @@ -0,0 +1,42 @@ + + * @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\Core\Command; + +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +class CommandUnavailableInMaintenanceMode extends Command { + protected function configure(): void { + $this + ->setName('command-unavailable-in-maintenance-mode') + ->setAliases([ + 'user:add', + 'user:delete', + ]) + ->setHidden(true); + } + + protected function execute(InputInterface $input, OutputInterface $output): int { + $output->writeln('The command "' . $input->getArgument('command') . '" is unavailable in maintenance mode.'); + return 1; + } +} diff --git a/core/Command/User/Add.php b/core/Command/User/Add.php index 24d11fbee6eef..b00f211db879d 100644 --- a/core/Command/User/Add.php +++ b/core/Command/User/Add.php @@ -26,6 +26,7 @@ namespace OC\Core\Command\User; use OC\Files\Filesystem; +use OCP\Command\IUnavailableInMaintenanceMode; use OCP\IGroup; use OCP\IGroupManager; use OCP\IUser; @@ -38,7 +39,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\Question; -class Add extends Command { +class Add extends Command implements IUnavailableInMaintenanceMode { protected IUserManager $userManager; protected IGroupManager $groupManager; diff --git a/core/Command/User/Delete.php b/core/Command/User/Delete.php index 9624f04fa18f1..3995ab1185738 100644 --- a/core/Command/User/Delete.php +++ b/core/Command/User/Delete.php @@ -25,6 +25,7 @@ namespace OC\Core\Command\User; use OC\Core\Command\Base; +use OCP\Command\IUnavailableInMaintenanceMode; use OCP\IUser; use OCP\IUserManager; use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; @@ -32,7 +33,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -class Delete extends Base { +class Delete extends Base implements IUnavailableInMaintenanceMode { /** @var IUserManager */ protected $userManager; diff --git a/core/register_command.php b/core/register_command.php index 4aac7fbf8ceb7..033aab5e1b044 100644 --- a/core/register_command.php +++ b/core/register_command.php @@ -48,84 +48,90 @@ * 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 +139,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 +149,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 +157,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 +167,58 @@ ) ); - $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())); + + if (\OC::$server->getConfig()->getSystemValueBool('maintenance')) { + $this->add(new \OC\Core\Command\CommandUnavailableInMaintenanceMode()); + } } 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/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 3e1b9559d5ead..a961bcc5e6a23 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -169,6 +169,7 @@ 'OCP\\Color' => $baseDir . '/lib/public/Color.php', 'OCP\\Command\\IBus' => $baseDir . '/lib/public/Command/IBus.php', 'OCP\\Command\\ICommand' => $baseDir . '/lib/public/Command/ICommand.php', + 'OCP\\Command\\IUnavailableInMaintenanceMode' => $baseDir . '/lib/public/Command/IUnavailableInMaintenanceMode.php', 'OCP\\Comments\\CommentsEntityEvent' => $baseDir . '/lib/public/Comments/CommentsEntityEvent.php', 'OCP\\Comments\\CommentsEvent' => $baseDir . '/lib/public/Comments/CommentsEvent.php', 'OCP\\Comments\\IComment' => $baseDir . '/lib/public/Comments/IComment.php', @@ -910,6 +911,7 @@ 'OC\\Core\\Command\\Base' => $baseDir . '/core/Command/Base.php', 'OC\\Core\\Command\\Broadcast\\Test' => $baseDir . '/core/Command/Broadcast/Test.php', 'OC\\Core\\Command\\Check' => $baseDir . '/core/Command/Check.php', + 'OC\\Core\\Command\\CommandUnavailableInMaintenanceMode' => $baseDir . '/core/Command/CommandUnavailableInMaintenanceMode.php', 'OC\\Core\\Command\\Config\\App\\Base' => $baseDir . '/core/Command/Config/App/Base.php', 'OC\\Core\\Command\\Config\\App\\DeleteConfig' => $baseDir . '/core/Command/Config/App/DeleteConfig.php', 'OC\\Core\\Command\\Config\\App\\GetConfig' => $baseDir . '/core/Command/Config/App/GetConfig.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 1a0d68fd20424..b308e96295809 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -202,6 +202,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OCP\\Color' => __DIR__ . '/../../..' . '/lib/public/Color.php', 'OCP\\Command\\IBus' => __DIR__ . '/../../..' . '/lib/public/Command/IBus.php', 'OCP\\Command\\ICommand' => __DIR__ . '/../../..' . '/lib/public/Command/ICommand.php', + 'OCP\\Command\\IUnavailableInMaintenanceMode' => __DIR__ . '/../../..' . '/lib/public/Command/IUnavailableInMaintenanceMode.php', 'OCP\\Comments\\CommentsEntityEvent' => __DIR__ . '/../../..' . '/lib/public/Comments/CommentsEntityEvent.php', 'OCP\\Comments\\CommentsEvent' => __DIR__ . '/../../..' . '/lib/public/Comments/CommentsEvent.php', 'OCP\\Comments\\IComment' => __DIR__ . '/../../..' . '/lib/public/Comments/IComment.php', @@ -943,6 +944,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OC\\Core\\Command\\Base' => __DIR__ . '/../../..' . '/core/Command/Base.php', 'OC\\Core\\Command\\Broadcast\\Test' => __DIR__ . '/../../..' . '/core/Command/Broadcast/Test.php', 'OC\\Core\\Command\\Check' => __DIR__ . '/../../..' . '/core/Command/Check.php', + 'OC\\Core\\Command\\CommandUnavailableInMaintenanceMode' => __DIR__ . '/../../..' . '/core/Command/CommandUnavailableInMaintenanceMode.php', 'OC\\Core\\Command\\Config\\App\\Base' => __DIR__ . '/../../..' . '/core/Command/Config/App/Base.php', 'OC\\Core\\Command\\Config\\App\\DeleteConfig' => __DIR__ . '/../../..' . '/core/Command/Config/App/DeleteConfig.php', 'OC\\Core\\Command\\Config\\App\\GetConfig' => __DIR__ . '/../../..' . '/core/Command/Config/App/GetConfig.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..dcb4079b644e8 100644 --- a/lib/private/Console/Application.php +++ b/lib/private/Console/Application.php @@ -33,13 +33,15 @@ use OC\MemoryInfo; use OC\NeedsUpdateException; use OC_App; -use OCP\AppFramework\QueryException; use OCP\App\IAppManager; +use OCP\AppFramework\QueryException; +use OCP\Command\IUnavailableInMaintenanceMode; use OCP\Console\ConsoleEvent; use OCP\IConfig; use OCP\IRequest; use Psr\Log\LoggerInterface; 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 +61,8 @@ class Application { /** @var MemoryInfo */ private $memoryInfo; + private bool $maintenanceMode; + public function __construct(IConfig $config, EventDispatcherInterface $dispatcher, IRequest $request, @@ -71,6 +75,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 && $command instanceof IUnavailableInMaintenanceMode) { + return null; + } + return $this->application->add($command); } /** @@ -115,9 +135,7 @@ public function loadCommands( if ($this->config->getSystemValueBool('installed', false)) { if (\OCP\Util::needUpgrade()) { throw new NeedsUpdateException(); - } elseif ($this->config->getSystemValueBool('maintenance')) { - $this->writeMaintenanceModeInfo($input, $output); - } else { + } elseif (!$this->maintenanceMode) { OC_App::loadApps(); $appManager = \OCP\Server::get(IAppManager::class); foreach ($appManager->getInstalledApps() as $app) { @@ -169,29 +187,6 @@ public function loadCommands( } } - /** - * Write a maintenance mode info. - * The commands "_completion" and "maintenance:mode" are excluded. - * - * @param InputInterface $input The input implementation for reading inputs. - * @param ConsoleOutputInterface $output The output implementation - * for writing outputs. - * @return void - */ - private function writeMaintenanceModeInfo( - InputInterface $input, ConsoleOutputInterface $output - ) { - if ($input->getArgument('command') !== '_completion' - && $input->getArgument('command') !== 'maintenance:mode' - && $input->getArgument('command') !== 'status') { - $errOutput = $output->getErrorOutput(); - $errOutput->writeln( - 'Nextcloud is in maintenance mode, hence the database isn\'t accessible.' . PHP_EOL . - 'Cannot perform any command except \'maintenance:mode --off\'' . PHP_EOL - ); - } - } - /** * Sets whether to automatically exit after a command execution or not. * @@ -231,7 +226,7 @@ private function loadCommandsFromInfoXml($commands) { } } - $this->application->add($c); + $this->add($c); } } } diff --git a/lib/public/Command/IUnavailableInMaintenanceMode.php b/lib/public/Command/IUnavailableInMaintenanceMode.php new file mode 100644 index 0000000000000..12c97c062d00f --- /dev/null +++ b/lib/public/Command/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 OCP\Command; + +/** + * Implement if a command is unavailable in maintenance mode. + * + * Use this interface if your command is unavailable during maintenance mode enabled. + * + * @since 27.0.0 + */ +interface IUnavailableInMaintenanceMode { +}