Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

ListConfigs.php 4.0KB

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