Merge branch 'bugfix/passwords-not-hidden-by-icinga-web-2-10640'

fixes #10640
This commit is contained in:
Eric Lippmann 2016-02-23 15:40:27 +01:00
commit bb8478a219
1 changed files with 25 additions and 8 deletions

View File

@ -3,6 +3,7 @@
namespace Icinga\Module\Monitoring\Object;
use stdClass;
use InvalidArgumentException;
use Icinga\Application\Config;
use Icinga\Data\Filter\Filter;
@ -456,18 +457,34 @@ abstract class MonitoredObject implements Filterable
$customvars = $this->hostVariables;
}
$this->customvars = array();
foreach ($customvars as $name => $value) {
if ($blacklistPattern && preg_match($blacklistPattern, $name)) {
$this->customvars[$name] = '***';
} else {
$this->customvars[$name] = $value;
}
}
$this->customvars = $this->obfuscateCustomVars($customvars, $blacklistPattern);
return $this;
}
/**
* Obfuscate custom variables recursively
*
* @param stdClass|array $customvars The custom variables to obfuscate
* @param string $blacklistPattern Which custom variables to obfuscate
*
* @return stdClass|array The obfuscated custom variables
*/
protected function obfuscateCustomVars($customvars, $blacklistPattern)
{
$obfuscatedCustomVars = array();
foreach ($customvars as $name => $value) {
if ($blacklistPattern && preg_match($blacklistPattern, $name)) {
$obfuscatedCustomVars[$name] = '***';
} else {
$obfuscatedCustomVars[$name] = $value instanceof stdClass || is_array($value)
? $this->obfuscateCustomVars($value, $blacklistPattern)
: $value;
}
}
return $customvars instanceof stdClass ? (object) $obfuscatedCustomVars : $obfuscatedCustomVars;
}
/**
* Fetch the host custom variables related to this object
*