2014-11-27 18:40:12 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 18:07:57 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2016-07-21 18:07:57 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2014-11-27 18:40:12 +03:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2014-11-27 18:40:12 +03:00
|
|
|
*
|
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
2014-11-27 18:40:12 +03:00
|
|
|
namespace OC;
|
|
|
|
|
2015-09-25 14:17:23 +03:00
|
|
|
|
|
|
|
use OCP\IConfig;
|
|
|
|
|
2014-11-27 18:40:12 +03:00
|
|
|
/**
|
|
|
|
* 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 {
|
2015-09-25 12:08:33 +03:00
|
|
|
|
|
|
|
/** @var array */
|
|
|
|
protected $sensitiveValues = [
|
2017-10-30 01:37:29 +03:00
|
|
|
'instanceid' => true,
|
|
|
|
'trusted_domains' => true,
|
|
|
|
'datadirectory' => true,
|
|
|
|
'overwrite.cli.url' => true,
|
2017-07-07 10:53:55 +03:00
|
|
|
'dbname' => true,
|
2017-10-30 01:37:29 +03:00
|
|
|
'dbhost' => true,
|
2015-09-25 12:08:33 +03:00
|
|
|
'dbpassword' => true,
|
|
|
|
'dbuser' => true,
|
2017-07-07 10:53:55 +03:00
|
|
|
'mail_from_address' => true,
|
|
|
|
'mail_domain' => true,
|
2017-10-30 01:37:29 +03:00
|
|
|
'mail_smtphost' => true,
|
2015-09-25 12:08:33 +03:00
|
|
|
'mail_smtpname' => true,
|
|
|
|
'mail_smtppassword' => true,
|
|
|
|
'passwordsalt' => true,
|
|
|
|
'secret' => true,
|
2016-02-09 22:41:55 +03:00
|
|
|
'updater.secret' => true,
|
2017-10-30 01:37:29 +03:00
|
|
|
'trusted_proxies' => true,
|
2016-04-01 14:03:34 +03:00
|
|
|
'proxyuserpwd' => true,
|
|
|
|
'log.condition' => [
|
|
|
|
'shared_secret' => true,
|
|
|
|
],
|
|
|
|
'license-key' => true,
|
|
|
|
'redis' => [
|
2017-10-30 01:37:29 +03:00
|
|
|
'host' => true,
|
2016-04-01 14:03:34 +03:00
|
|
|
'password' => true,
|
|
|
|
],
|
|
|
|
'objectstore' => [
|
|
|
|
'arguments' => [
|
|
|
|
'password' => true,
|
2016-07-08 15:13:16 +03:00
|
|
|
'options' => [
|
|
|
|
'credentials' => [
|
|
|
|
'key' => true,
|
|
|
|
'secret' => true,
|
|
|
|
]
|
|
|
|
]
|
2016-04-01 14:03:34 +03:00
|
|
|
],
|
|
|
|
],
|
2015-09-25 12:08:33 +03:00
|
|
|
];
|
|
|
|
|
2015-12-18 13:24:15 +03:00
|
|
|
/** @var Config */
|
|
|
|
private $config;
|
|
|
|
|
|
|
|
public function __construct(Config $config) {
|
|
|
|
$this->config = $config;
|
|
|
|
}
|
|
|
|
|
2015-04-30 16:48:31 +03:00
|
|
|
/**
|
|
|
|
* Lists all available config keys
|
|
|
|
* @return array an array of key names
|
|
|
|
*/
|
|
|
|
public function getKeys() {
|
2015-12-18 13:24:15 +03:00
|
|
|
return $this->config->getKeys();
|
2015-04-30 16:48:31 +03:00
|
|
|
}
|
|
|
|
|
2014-11-27 18:40:12 +03:00
|
|
|
/**
|
|
|
|
* Sets a new system wide value
|
|
|
|
*
|
|
|
|
* @param string $key the key of the value, under which will be saved
|
|
|
|
* @param mixed $value the value that should be stored
|
|
|
|
*/
|
|
|
|
public function setValue($key, $value) {
|
2015-12-18 13:24:15 +03:00
|
|
|
$this->config->setValue($key, $value);
|
2014-11-27 18:40:12 +03:00
|
|
|
}
|
|
|
|
|
2015-01-23 12:50:25 +03:00
|
|
|
/**
|
|
|
|
* Sets and deletes values and writes the config.php
|
|
|
|
*
|
|
|
|
* @param array $configs Associative array with `key => value` pairs
|
|
|
|
* If value is null, the config key will be deleted
|
|
|
|
*/
|
|
|
|
public function setValues(array $configs) {
|
2015-12-18 13:24:15 +03:00
|
|
|
$this->config->setValues($configs);
|
2015-01-23 12:50:25 +03:00
|
|
|
}
|
|
|
|
|
2014-11-27 18:40:12 +03:00
|
|
|
/**
|
|
|
|
* Looks up a system wide defined value
|
|
|
|
*
|
|
|
|
* @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 getValue($key, $default = '') {
|
2015-12-18 13:24:15 +03:00
|
|
|
return $this->config->getValue($key, $default);
|
2014-11-27 18:40:12 +03:00
|
|
|
}
|
|
|
|
|
2015-09-25 12:08:33 +03:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2014-11-27 18:40:12 +03:00
|
|
|
/**
|
|
|
|
* Delete a system wide defined value
|
|
|
|
*
|
|
|
|
* @param string $key the key of the value, under which it was saved
|
|
|
|
*/
|
|
|
|
public function deleteValue($key) {
|
2015-12-18 13:24:15 +03:00
|
|
|
$this->config->deleteKey($key);
|
2014-11-27 18:40:12 +03:00
|
|
|
}
|
2015-09-25 12:08:33 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param bool|array $keysToRemove
|
|
|
|
* @param mixed $value
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
protected function removeSensitiveValue($keysToRemove, $value) {
|
|
|
|
if ($keysToRemove === true) {
|
2015-09-25 14:17:23 +03:00
|
|
|
return IConfig::SENSITIVE_VALUE;
|
2015-09-25 12:08:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (is_array($value)) {
|
|
|
|
foreach ($keysToRemove as $keyToRemove => $valueToRemove) {
|
|
|
|
if (isset($value[$keyToRemove])) {
|
|
|
|
$value[$keyToRemove] = $this->removeSensitiveValue($valueToRemove, $value[$keyToRemove]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $value;
|
|
|
|
}
|
2014-11-27 18:40:12 +03:00
|
|
|
}
|