1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Joas Schilling <[email protected]> |
4
|
|
|
* @author Jonathan Kawohl <[email protected]> |
5
|
|
|
* @author Lukas Reschke <[email protected]> |
6
|
|
|
* @author Morris Jobke <[email protected]> |
7
|
|
|
* @author Roeland Jago Douma <[email protected]> |
8
|
|
|
* |
9
|
|
|
* @copyright Copyright (c) 2018, ownCloud GmbH |
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
|
|
|
|
26
|
|
|
namespace OC; |
27
|
|
|
|
28
|
|
|
use OCP\IConfig; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Class which provides access to the system config values stored in config.php |
32
|
|
|
* Internal class for bootstrap only. |
33
|
|
|
* fixes cyclic DI: AllConfig needs AppConfig needs Database needs AllConfig |
34
|
|
|
*/ |
35
|
|
|
class SystemConfig { |
36
|
|
|
|
37
|
|
|
/** @var array */ |
38
|
|
|
protected $sensitiveValues = [ |
39
|
|
|
'dbpassword' => true, |
40
|
|
|
'dbuser' => true, |
41
|
|
|
'mail_smtpname' => true, |
42
|
|
|
'mail_smtppassword' => true, |
43
|
|
|
'mail_from_address' => true, |
44
|
|
|
'mail_domain' => true, |
45
|
|
|
'mail_smtphost' => true, |
46
|
|
|
'passwordsalt' => true, |
47
|
|
|
'secret' => true, |
48
|
|
|
'updater.secret' => true, |
49
|
|
|
'ldap_agent_password' => true, |
50
|
|
|
'proxyuserpwd' => true, |
51
|
|
|
'marketplace.key' => true, |
52
|
|
|
'log.condition' => [ |
53
|
|
|
[ |
54
|
|
|
'shared_secret' => true, |
55
|
|
|
] |
56
|
|
|
], |
57
|
|
|
'log.conditions' => [ |
58
|
|
|
[ |
59
|
|
|
'shared_secret' => true, |
60
|
|
|
] |
61
|
|
|
], |
62
|
|
|
'license-key' => true, |
63
|
|
|
'redis' => [ |
64
|
|
|
'password' => true, |
65
|
|
|
], |
66
|
|
|
'objectstore' => [ |
67
|
|
|
'arguments' => [ |
68
|
|
|
'password' => true, |
69
|
|
|
'options' => [ |
70
|
|
|
'credentials' =>[ |
71
|
|
|
'key' => true, |
72
|
|
|
'secret' => true, |
73
|
|
|
], |
74
|
|
|
], |
75
|
|
|
], |
76
|
|
|
], |
77
|
|
|
]; |
78
|
|
|
/** @var Config */ |
79
|
|
|
private $config; |
80
|
|
|
|
81
|
|
|
public function __construct(Config $config) { |
82
|
|
|
$this->config = $config; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Lists all available config keys |
87
|
|
|
* @return array an array of key names |
88
|
|
|
*/ |
89
|
|
|
public function getKeys() { |
90
|
|
|
return $this->config->getKeys(); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Sets a new system wide value |
95
|
|
|
* |
96
|
|
|
* @param string $key the key of the value, under which will be saved |
97
|
|
|
* @param mixed $value the value that should be stored |
98
|
|
|
*/ |
99
|
|
|
public function setValue($key, $value) { |
100
|
|
|
$this->config->setValue($key, $value); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Sets and deletes values and writes the config.php |
105
|
|
|
* |
106
|
|
|
* @param array $configs Associative array with `key => value` pairs |
107
|
|
|
* If value is null, the config key will be deleted |
108
|
|
|
*/ |
109
|
|
|
public function setValues(array $configs) { |
110
|
|
|
$this->config->setValues($configs); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Looks up a system wide defined value |
115
|
|
|
* |
116
|
|
|
* @param string $key the key of the value, under which it was saved |
117
|
|
|
* @param mixed $default the default value to be returned if the value isn't set |
118
|
|
|
* @return mixed the value or $default |
119
|
|
|
*/ |
120
|
|
|
public function getValue($key, $default = '') { |
121
|
|
|
return $this->config->getValue($key, $default); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Looks up a system wide defined value and filters out sensitive data |
126
|
|
|
* |
127
|
|
|
* @param string $key the key of the value, under which it was saved |
128
|
|
|
* @param mixed $default the default value to be returned if the value isn't set |
129
|
|
|
* @return mixed the value or $default |
130
|
|
|
*/ |
131
|
|
|
public function getFilteredValue($key, $default = '') { |
132
|
|
|
$value = $this->getValue($key, $default); |
133
|
|
|
|
134
|
|
|
if (isset($this->sensitiveValues[$key])) { |
135
|
|
|
$value = $this->removeSensitiveValue($this->sensitiveValues[$key], $value); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
return $value; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Delete a system wide defined value |
143
|
|
|
* |
144
|
|
|
* @param string $key the key of the value, under which it was saved |
145
|
|
|
*/ |
146
|
|
|
public function deleteValue($key) { |
147
|
|
|
$this->config->deleteKey($key); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @param bool|array $keysToRemove |
152
|
|
|
* @param mixed $value |
153
|
|
|
* @return mixed |
154
|
|
|
*/ |
155
|
|
|
protected function removeSensitiveValue($keysToRemove, $value) { |
156
|
|
|
if ($keysToRemove === true) { |
157
|
|
|
return IConfig::SENSITIVE_VALUE; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
if (\is_array($value)) { |
161
|
|
|
foreach ($keysToRemove as $keyToRemove => $valueToRemove) { |
|
|
|
|
162
|
|
|
if ($keyToRemove === 0) { |
163
|
|
|
/* |
164
|
|
|
* The 0 key in keysToRemove indicates a possibly repeating |
165
|
|
|
* array of actual entries 0,1,2,3... |
166
|
|
|
* Remove any sensitive values from all actual entries. |
167
|
|
|
*/ |
168
|
|
|
foreach ($value as $valueKey => $valueData) { |
169
|
|
|
if (\is_int($valueKey) && ($valueKey >= 0)) { |
170
|
|
|
$value[$valueKey] = $this->removeSensitiveValue($valueToRemove, $value[$valueKey]); |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
} else { |
174
|
|
|
if (isset($value[$keyToRemove])) { |
175
|
|
|
$value[$keyToRemove] = $this->removeSensitiveValue($valueToRemove, $value[$keyToRemove]); |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
return $value; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
public function isReadOnly() { |
185
|
|
|
return $this->config->isReadOnly(); |
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.