ListConfigs.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * @author Joas Schilling <nickvergessen@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2016, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace OC\Core\Command\Config;
  22. use OC\Core\Command\Base;
  23. use OC\SystemConfig;
  24. use OCP\IAppConfig;
  25. use Symfony\Component\Console\Input\InputArgument;
  26. use Symfony\Component\Console\Input\InputInterface;
  27. use Symfony\Component\Console\Input\InputOption;
  28. use Symfony\Component\Console\Output\OutputInterface;
  29. class ListConfigs extends Base {
  30. protected $defaultOutputFormat = self::OUTPUT_FORMAT_JSON_PRETTY;
  31. /** * @var SystemConfig */
  32. protected $systemConfig;
  33. /** @var IAppConfig */
  34. protected $appConfig;
  35. /**
  36. * @param SystemConfig $systemConfig
  37. * @param IAppConfig $appConfig
  38. */
  39. public function __construct(SystemConfig $systemConfig, IAppConfig $appConfig) {
  40. parent::__construct();
  41. $this->systemConfig = $systemConfig;
  42. $this->appConfig = $appConfig;
  43. }
  44. protected function configure() {
  45. parent::configure();
  46. $this
  47. ->setName('config:list')
  48. ->setDescription('List all configs')
  49. ->addArgument(
  50. 'app',
  51. InputArgument::OPTIONAL,
  52. 'Name of the app ("system" to get the config.php values, "all" for all apps and system)',
  53. 'all'
  54. )
  55. ->addOption(
  56. 'private',
  57. null,
  58. InputOption::VALUE_NONE,
  59. 'Use this option when you want to include sensitive configs like passwords, salts, ...'
  60. )
  61. ;
  62. }
  63. protected function execute(InputInterface $input, OutputInterface $output) {
  64. $app = $input->getArgument('app');
  65. $noSensitiveValues = !$input->getOption('private');
  66. switch ($app) {
  67. case 'system':
  68. $configs = [
  69. 'system' => $this->getSystemConfigs($noSensitiveValues),
  70. ];
  71. break;
  72. case 'all':
  73. $apps = $this->appConfig->getApps();
  74. $configs = [
  75. 'system' => $this->getSystemConfigs($noSensitiveValues),
  76. 'apps' => [],
  77. ];
  78. foreach ($apps as $appName) {
  79. $configs['apps'][$appName] = $this->appConfig->getValues($appName, false);
  80. }
  81. break;
  82. default:
  83. $configs = [
  84. 'apps' => [
  85. $app => $this->appConfig->getValues($app, false),
  86. ],
  87. ];
  88. }
  89. $this->writeArrayInOutputFormat($input, $output, $configs);
  90. }
  91. /**
  92. * Get the system configs
  93. *
  94. * @param bool $noSensitiveValues
  95. * @return array
  96. */
  97. protected function getSystemConfigs($noSensitiveValues) {
  98. $keys = $this->systemConfig->getKeys();
  99. $configs = [];
  100. foreach ($keys as $key) {
  101. if ($noSensitiveValues) {
  102. $value = $this->systemConfig->getFilteredValue($key, serialize(null));
  103. } else {
  104. $value = $this->systemConfig->getValue($key, serialize(null));
  105. }
  106. if ($value !== 'N;') {
  107. $configs[$key] = $value;
  108. }
  109. }
  110. return $configs;
  111. }
  112. }