@@ -35,129 +35,129 @@ |
||
| 35 | 35 | */ |
| 36 | 36 | class SystemConfig { |
| 37 | 37 | |
| 38 | - /** @var array */ |
|
| 39 | - protected $sensitiveValues = [ |
|
| 40 | - 'dbname' => true, |
|
| 41 | - 'dbpassword' => true, |
|
| 42 | - 'dbuser' => true, |
|
| 43 | - 'mail_from_address' => true, |
|
| 44 | - 'mail_domain' => true, |
|
| 45 | - 'mail_smtpname' => true, |
|
| 46 | - 'mail_smtppassword' => true, |
|
| 47 | - 'passwordsalt' => true, |
|
| 48 | - 'secret' => true, |
|
| 49 | - 'updater.secret' => true, |
|
| 50 | - 'proxyuserpwd' => true, |
|
| 51 | - 'log.condition' => [ |
|
| 52 | - 'shared_secret' => true, |
|
| 53 | - ], |
|
| 54 | - 'license-key' => true, |
|
| 55 | - 'redis' => [ |
|
| 56 | - 'password' => true, |
|
| 57 | - ], |
|
| 58 | - 'objectstore' => [ |
|
| 59 | - 'arguments' => [ |
|
| 60 | - 'password' => true, |
|
| 61 | - 'options' => [ |
|
| 62 | - 'credentials' => [ |
|
| 63 | - 'key' => true, |
|
| 64 | - 'secret' => true, |
|
| 65 | - ] |
|
| 66 | - ] |
|
| 67 | - ], |
|
| 68 | - ], |
|
| 69 | - ]; |
|
| 70 | - |
|
| 71 | - /** @var Config */ |
|
| 72 | - private $config; |
|
| 73 | - |
|
| 74 | - public function __construct(Config $config) { |
|
| 75 | - $this->config = $config; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Lists all available config keys |
|
| 80 | - * @return array an array of key names |
|
| 81 | - */ |
|
| 82 | - public function getKeys() { |
|
| 83 | - return $this->config->getKeys(); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Sets a new system wide value |
|
| 88 | - * |
|
| 89 | - * @param string $key the key of the value, under which will be saved |
|
| 90 | - * @param mixed $value the value that should be stored |
|
| 91 | - */ |
|
| 92 | - public function setValue($key, $value) { |
|
| 93 | - $this->config->setValue($key, $value); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Sets and deletes values and writes the config.php |
|
| 98 | - * |
|
| 99 | - * @param array $configs Associative array with `key => value` pairs |
|
| 100 | - * If value is null, the config key will be deleted |
|
| 101 | - */ |
|
| 102 | - public function setValues(array $configs) { |
|
| 103 | - $this->config->setValues($configs); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Looks up a system wide defined value |
|
| 108 | - * |
|
| 109 | - * @param string $key the key of the value, under which it was saved |
|
| 110 | - * @param mixed $default the default value to be returned if the value isn't set |
|
| 111 | - * @return mixed the value or $default |
|
| 112 | - */ |
|
| 113 | - public function getValue($key, $default = '') { |
|
| 114 | - return $this->config->getValue($key, $default); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Looks up a system wide defined value and filters out sensitive data |
|
| 119 | - * |
|
| 120 | - * @param string $key the key of the value, under which it was saved |
|
| 121 | - * @param mixed $default the default value to be returned if the value isn't set |
|
| 122 | - * @return mixed the value or $default |
|
| 123 | - */ |
|
| 124 | - public function getFilteredValue($key, $default = '') { |
|
| 125 | - $value = $this->getValue($key, $default); |
|
| 126 | - |
|
| 127 | - if (isset($this->sensitiveValues[$key])) { |
|
| 128 | - $value = $this->removeSensitiveValue($this->sensitiveValues[$key], $value); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - return $value; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Delete a system wide defined value |
|
| 136 | - * |
|
| 137 | - * @param string $key the key of the value, under which it was saved |
|
| 138 | - */ |
|
| 139 | - public function deleteValue($key) { |
|
| 140 | - $this->config->deleteKey($key); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * @param bool|array $keysToRemove |
|
| 145 | - * @param mixed $value |
|
| 146 | - * @return mixed |
|
| 147 | - */ |
|
| 148 | - protected function removeSensitiveValue($keysToRemove, $value) { |
|
| 149 | - if ($keysToRemove === true) { |
|
| 150 | - return IConfig::SENSITIVE_VALUE; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - if (is_array($value)) { |
|
| 154 | - foreach ($keysToRemove as $keyToRemove => $valueToRemove) { |
|
| 155 | - if (isset($value[$keyToRemove])) { |
|
| 156 | - $value[$keyToRemove] = $this->removeSensitiveValue($valueToRemove, $value[$keyToRemove]); |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - return $value; |
|
| 162 | - } |
|
| 38 | + /** @var array */ |
|
| 39 | + protected $sensitiveValues = [ |
|
| 40 | + 'dbname' => true, |
|
| 41 | + 'dbpassword' => true, |
|
| 42 | + 'dbuser' => true, |
|
| 43 | + 'mail_from_address' => true, |
|
| 44 | + 'mail_domain' => true, |
|
| 45 | + 'mail_smtpname' => true, |
|
| 46 | + 'mail_smtppassword' => true, |
|
| 47 | + 'passwordsalt' => true, |
|
| 48 | + 'secret' => true, |
|
| 49 | + 'updater.secret' => true, |
|
| 50 | + 'proxyuserpwd' => true, |
|
| 51 | + 'log.condition' => [ |
|
| 52 | + 'shared_secret' => true, |
|
| 53 | + ], |
|
| 54 | + 'license-key' => true, |
|
| 55 | + 'redis' => [ |
|
| 56 | + 'password' => true, |
|
| 57 | + ], |
|
| 58 | + 'objectstore' => [ |
|
| 59 | + 'arguments' => [ |
|
| 60 | + 'password' => true, |
|
| 61 | + 'options' => [ |
|
| 62 | + 'credentials' => [ |
|
| 63 | + 'key' => true, |
|
| 64 | + 'secret' => true, |
|
| 65 | + ] |
|
| 66 | + ] |
|
| 67 | + ], |
|
| 68 | + ], |
|
| 69 | + ]; |
|
| 70 | + |
|
| 71 | + /** @var Config */ |
|
| 72 | + private $config; |
|
| 73 | + |
|
| 74 | + public function __construct(Config $config) { |
|
| 75 | + $this->config = $config; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Lists all available config keys |
|
| 80 | + * @return array an array of key names |
|
| 81 | + */ |
|
| 82 | + public function getKeys() { |
|
| 83 | + return $this->config->getKeys(); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Sets a new system wide value |
|
| 88 | + * |
|
| 89 | + * @param string $key the key of the value, under which will be saved |
|
| 90 | + * @param mixed $value the value that should be stored |
|
| 91 | + */ |
|
| 92 | + public function setValue($key, $value) { |
|
| 93 | + $this->config->setValue($key, $value); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Sets and deletes values and writes the config.php |
|
| 98 | + * |
|
| 99 | + * @param array $configs Associative array with `key => value` pairs |
|
| 100 | + * If value is null, the config key will be deleted |
|
| 101 | + */ |
|
| 102 | + public function setValues(array $configs) { |
|
| 103 | + $this->config->setValues($configs); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Looks up a system wide defined value |
|
| 108 | + * |
|
| 109 | + * @param string $key the key of the value, under which it was saved |
|
| 110 | + * @param mixed $default the default value to be returned if the value isn't set |
|
| 111 | + * @return mixed the value or $default |
|
| 112 | + */ |
|
| 113 | + public function getValue($key, $default = '') { |
|
| 114 | + return $this->config->getValue($key, $default); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Looks up a system wide defined value and filters out sensitive data |
|
| 119 | + * |
|
| 120 | + * @param string $key the key of the value, under which it was saved |
|
| 121 | + * @param mixed $default the default value to be returned if the value isn't set |
|
| 122 | + * @return mixed the value or $default |
|
| 123 | + */ |
|
| 124 | + public function getFilteredValue($key, $default = '') { |
|
| 125 | + $value = $this->getValue($key, $default); |
|
| 126 | + |
|
| 127 | + if (isset($this->sensitiveValues[$key])) { |
|
| 128 | + $value = $this->removeSensitiveValue($this->sensitiveValues[$key], $value); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + return $value; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Delete a system wide defined value |
|
| 136 | + * |
|
| 137 | + * @param string $key the key of the value, under which it was saved |
|
| 138 | + */ |
|
| 139 | + public function deleteValue($key) { |
|
| 140 | + $this->config->deleteKey($key); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * @param bool|array $keysToRemove |
|
| 145 | + * @param mixed $value |
|
| 146 | + * @return mixed |
|
| 147 | + */ |
|
| 148 | + protected function removeSensitiveValue($keysToRemove, $value) { |
|
| 149 | + if ($keysToRemove === true) { |
|
| 150 | + return IConfig::SENSITIVE_VALUE; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + if (is_array($value)) { |
|
| 154 | + foreach ($keysToRemove as $keyToRemove => $valueToRemove) { |
|
| 155 | + if (isset($value[$keyToRemove])) { |
|
| 156 | + $value[$keyToRemove] = $this->removeSensitiveValue($valueToRemove, $value[$keyToRemove]); |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + return $value; |
|
| 162 | + } |
|
| 163 | 163 | } |