mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-29 16:54:04 +02:00
Monitoring\Object: fix a couple of cv-related issues
* Don't throw exceptions with no config * Provide a secure default if not configured * Improve code readability
This commit is contained in:
parent
bb65fb396a
commit
a8d33d90e2
@ -121,16 +121,22 @@ abstract class AbstractObject
|
|||||||
|
|
||||||
public function fetchCustomvars()
|
public function fetchCustomvars()
|
||||||
{
|
{
|
||||||
$monitoringSecurity = Config::module('monitoring')->get('security')->toArray();
|
$blacklist = array();
|
||||||
$customvars = array();
|
$blacklistPattern = '/^(.*pw.*|.*pass.*|community)$/';
|
||||||
foreach (explode(',', $monitoringSecurity['protected_customvars']) as $customvar) {
|
|
||||||
|
if ($security = Config::module('monitoring')->get('security')) {
|
||||||
|
|
||||||
|
$blacklistConfig = $security->get('protected_customvars', '');
|
||||||
|
|
||||||
|
foreach (explode(',', $blacklistConfig) as $customvar) {
|
||||||
$nonWildcards = array();
|
$nonWildcards = array();
|
||||||
foreach (explode('*', $customvar) as $nonWildcard) {
|
foreach (explode('*', $customvar) as $nonWildcard) {
|
||||||
$nonWildcards[] = preg_quote($nonWildcard, '/');
|
$nonWildcards[] = preg_quote($nonWildcard, '/');
|
||||||
}
|
}
|
||||||
$customvars[] = implode('.*', $nonWildcards);
|
$blacklist[] = implode('.*', $nonWildcards);
|
||||||
|
}
|
||||||
|
$blacklistPattern = '/^(' . implode('|', $blacklist) . ')$/i';
|
||||||
}
|
}
|
||||||
$customvars = '/^(' . implode('|', $customvars) . ')$/i';
|
|
||||||
|
|
||||||
$query = Customvar::fromParams(array('backend' => null), array(
|
$query = Customvar::fromParams(array('backend' => null), array(
|
||||||
'varname',
|
'varname',
|
||||||
@ -147,11 +153,13 @@ abstract class AbstractObject
|
|||||||
->where('service_description', $this->service_description);
|
->where('service_description', $this->service_description);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->customvars = $query->getQuery()->fetchPairs();
|
$customvars = $query->getQuery()->fetchPairs();
|
||||||
foreach ($this->customvars as $name => &$value) {
|
foreach ($customvars as $name => &$value) {
|
||||||
if (preg_match($customvars, ucwords(str_replace('_', ' ', strtolower($name))))) {
|
$name = ucwords(str_replace('_', ' ', strtolower($name)));
|
||||||
|
if ($blacklistPattern && preg_match($blacklistPattern, $name)) {
|
||||||
$value = '***';
|
$value = '***';
|
||||||
}
|
}
|
||||||
|
$this->customvars[$name] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user