aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/systemconfig.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/systemconfig.php')
-rw-r--r--lib/private/systemconfig.php54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/private/systemconfig.php b/lib/private/systemconfig.php
index 13b0959768a..94b815aebd7 100644
--- a/lib/private/systemconfig.php
+++ b/lib/private/systemconfig.php
@@ -22,12 +22,28 @@
namespace OC;
+
+use OCP\IConfig;
+
/**
* Class which provides access to the system config values stored in config.php
* Internal class for bootstrap only.
* fixes cyclic DI: AllConfig needs AppConfig needs Database needs AllConfig
*/
class SystemConfig {
+
+ /** @var array */
+ protected $sensitiveValues = [
+ 'dbpassword' => true,
+ 'dbuser' => true,
+ 'mail_smtpname' => true,
+ 'mail_smtppassword' => true,
+ 'passwordsalt' => true,
+ 'secret' => true,
+ 'ldap_agent_password' => true,
+ 'objectstore' => ['arguments' => ['password' => true]],
+ ];
+
/**
* Lists all available config keys
* @return array an array of key names
@@ -68,6 +84,23 @@ class SystemConfig {
}
/**
+ * Looks up a system wide defined value and filters out sensitive data
+ *
+ * @param string $key the key of the value, under which it was saved
+ * @param mixed $default the default value to be returned if the value isn't set
+ * @return mixed the value or $default
+ */
+ public function getFilteredValue($key, $default = '') {
+ $value = $this->getValue($key, $default);
+
+ if (isset($this->sensitiveValues[$key])) {
+ $value = $this->removeSensitiveValue($this->sensitiveValues[$key], $value);
+ }
+
+ return $value;
+ }
+
+ /**
* Delete a system wide defined value
*
* @param string $key the key of the value, under which it was saved
@@ -75,4 +108,25 @@ class SystemConfig {
public function deleteValue($key) {
\OC_Config::deleteKey($key);
}
+
+ /**
+ * @param bool|array $keysToRemove
+ * @param mixed $value
+ * @return mixed
+ */
+ protected function removeSensitiveValue($keysToRemove, $value) {
+ if ($keysToRemove === true) {
+ return IConfig::SENSITIVE_VALUE;
+ }
+
+ if (is_array($value)) {
+ foreach ($keysToRemove as $keyToRemove => $valueToRemove) {
+ if (isset($value[$keyToRemove])) {
+ $value[$keyToRemove] = $this->removeSensitiveValue($valueToRemove, $value[$keyToRemove]);
+ }
+ }
+ }
+
+ return $value;
+ }
}