You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SystemConfig.php 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OC;
  26. use OCP\IConfig;
  27. /**
  28. * Class which provides access to the system config values stored in config.php
  29. * Internal class for bootstrap only.
  30. * fixes cyclic DI: AllConfig needs AppConfig needs Database needs AllConfig
  31. */
  32. class SystemConfig {
  33. /** @var array */
  34. protected $sensitiveValues = [
  35. 'dbpassword' => true,
  36. 'dbuser' => true,
  37. 'mail_smtpname' => true,
  38. 'mail_smtppassword' => true,
  39. 'passwordsalt' => true,
  40. 'secret' => true,
  41. 'updater.secret' => true,
  42. 'ldap_agent_password' => true,
  43. 'proxyuserpwd' => true,
  44. 'log.condition' => [
  45. 'shared_secret' => true,
  46. ],
  47. 'license-key' => true,
  48. 'redis' => [
  49. 'password' => true,
  50. ],
  51. 'objectstore' => [
  52. 'arguments' => [
  53. 'password' => true,
  54. 'options' => [
  55. 'credentials' => [
  56. 'key' => true,
  57. 'secret' => true,
  58. ]
  59. ]
  60. ],
  61. ],
  62. ];
  63. /** @var Config */
  64. private $config;
  65. public function __construct(Config $config) {
  66. $this->config = $config;
  67. }
  68. /**
  69. * Lists all available config keys
  70. * @return array an array of key names
  71. */
  72. public function getKeys() {
  73. return $this->config->getKeys();
  74. }
  75. /**
  76. * Sets a new system wide value
  77. *
  78. * @param string $key the key of the value, under which will be saved
  79. * @param mixed $value the value that should be stored
  80. */
  81. public function setValue($key, $value) {
  82. $this->config->setValue($key, $value);
  83. }
  84. /**
  85. * Sets and deletes values and writes the config.php
  86. *
  87. * @param array $configs Associative array with `key => value` pairs
  88. * If value is null, the config key will be deleted
  89. */
  90. public function setValues(array $configs) {
  91. $this->config->setValues($configs);
  92. }
  93. /**
  94. * Looks up a system wide defined value
  95. *
  96. * @param string $key the key of the value, under which it was saved
  97. * @param mixed $default the default value to be returned if the value isn't set
  98. * @return mixed the value or $default
  99. */
  100. public function getValue($key, $default = '') {
  101. return $this->config->getValue($key, $default);
  102. }
  103. /**
  104. * Looks up a system wide defined value and filters out sensitive data
  105. *
  106. * @param string $key the key of the value, under which it was saved
  107. * @param mixed $default the default value to be returned if the value isn't set
  108. * @return mixed the value or $default
  109. */
  110. public function getFilteredValue($key, $default = '') {
  111. $value = $this->getValue($key, $default);
  112. if (isset($this->sensitiveValues[$key])) {
  113. $value = $this->removeSensitiveValue($this->sensitiveValues[$key], $value);
  114. }
  115. return $value;
  116. }
  117. /**
  118. * Delete a system wide defined value
  119. *
  120. * @param string $key the key of the value, under which it was saved
  121. */
  122. public function deleteValue($key) {
  123. $this->config->deleteKey($key);
  124. }
  125. /**
  126. * @param bool|array $keysToRemove
  127. * @param mixed $value
  128. * @return mixed
  129. */
  130. protected function removeSensitiveValue($keysToRemove, $value) {
  131. if ($keysToRemove === true) {
  132. return IConfig::SENSITIVE_VALUE;
  133. }
  134. if (is_array($value)) {
  135. foreach ($keysToRemove as $keyToRemove => $valueToRemove) {
  136. if (isset($value[$keyToRemove])) {
  137. $value[$keyToRemove] = $this->removeSensitiveValue($valueToRemove, $value[$keyToRemove]);
  138. }
  139. }
  140. }
  141. return $value;
  142. }
  143. }