From 2f653320146ebdd840176c74d9ffdaaf435e1f2f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 30 Apr 2015 16:14:10 +0200 Subject: [PATCH] Add an option to exclude sensitive values (e.g. for reports) --- core/command/config/listconfigs.php | 38 ++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/core/command/config/listconfigs.php b/core/command/config/listconfigs.php index d25495a55d..5b9bca20f0 100644 --- a/core/command/config/listconfigs.php +++ b/core/command/config/listconfigs.php @@ -26,9 +26,20 @@ use OC\SystemConfig; use OCP\IAppConfig; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class ListConfigs extends Base { + /** @var array */ + protected $sensitiveValues = [ + 'dbpassword', + 'dbuser', + 'mail_smtpname', + 'mail_smtppassword', + 'passwordsalt', + 'secret', + ]; + /** * @var SystemConfig */ protected $systemConfig; @@ -55,16 +66,29 @@ class ListConfigs extends Base { 'app', InputArgument::OPTIONAL, 'Name of the app ("system" to get the config.php values, "all" for all apps and system)', - 'system' + 'all' + ) + ->addOption( + 'public', + null, + InputOption::VALUE_NONE, + 'Use this option when you want to exclude sensitive configs like passwords, salts, ...' ) ; } protected function execute(InputInterface $input, OutputInterface $output) { $app = $input->getArgument('app'); + $noSensitiveValues = $input->getOption('public'); + + if ($noSensitiveValues && !$input->hasParameterOption('--output')) { + // If you post this publicly we prefer the json format + $input->setOption('output', 'json_pretty'); + } + switch ($app) { case 'system': - $configs = $this->getSystemConfigs(); + $configs = $this->getSystemConfigs($noSensitiveValues); break; case 'all': @@ -73,7 +97,7 @@ class ListConfigs extends Base { foreach ($apps as $appName) { $configs[$appName] = $this->appConfig->getValues($appName, false); } - $configs['system'] = $this->getSystemConfigs(); + $configs['system'] = $this->getSystemConfigs($noSensitiveValues); break; default: @@ -85,13 +109,19 @@ class ListConfigs extends Base { /** * Get the system configs + * + * @param bool $noSensitiveValues * @return array */ - protected function getSystemConfigs() { + protected function getSystemConfigs($noSensitiveValues) { $keys = $this->systemConfig->getKeys(); $configs = []; foreach ($keys as $key) { + if ($noSensitiveValues && in_array($key, $this->sensitiveValues)) { + continue; + } + $value = $this->systemConfig->getValue($key, new \Exception('Not set')); if (!($value instanceof \Exception)) { $configs[$key] = $value;