Skip to content

Commit

Permalink
Monitoring/Object: filter protected customvars
Browse files Browse the repository at this point in the history
Move the responsibility from the viewscript to Monitoring/Object

refs #6641
  • Loading branch information
Al2Klimov committed Aug 19, 2014
1 parent ea0248e commit 0719379
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
@@ -1,12 +1,5 @@
<?php

if (! $object->customvars) { return; }

foreach ($object->customvars as $name => $value) {
$name = ucwords(str_replace('_', ' ', strtolower($name)));
if (preg_match('~(?:pw|pass|community)~', strtolower($name))) {
$value = '***';
}
printf(
"<tr><th>%s</th><td>%s</td></tr>\n",
$this->escape($name),
Expand Down
18 changes: 18 additions & 0 deletions modules/monitoring/library/Monitoring/Object/AbstractObject.php
Expand Up @@ -20,6 +20,7 @@
use Icinga\Module\Monitoring\DataView\Servicegroup;
use Icinga\Module\Monitoring\DataView\Customvar;
use Icinga\Web\UrlParams;
use Icinga\Application\Config;


abstract class AbstractObject
Expand Down Expand Up @@ -120,6 +121,17 @@ public function fetchHostgroups()

public function fetchCustomvars()
{
$monitoringSecurity = Config::module('monitoring')->get('security')->toArray();
$customvars = array();
foreach (explode(',', $monitoringSecurity['protected_customvars']) as $customvar) {
$nonWildcards = array();
foreach (explode('*', $customvar) as $nonWildcard) {
$nonWildcards[] = preg_quote($nonWildcard, '/');
}
$customvars[] = implode('.*', $nonWildcards);
}
$customvars = '/^(' . implode('|', $customvars) . ')$/i';

$query = Customvar::fromParams(array('backend' => null), array(
'varname',
'varvalue'
Expand All @@ -136,6 +148,12 @@ public function fetchCustomvars()
}

$this->customvars = $query->getQuery()->fetchPairs();
foreach ($this->customvars as $name => &$value) {
if (preg_match($customvars, ucwords(str_replace('_', ' ', strtolower($name))))) {
$value = '***';
}
}

return $this;
}

Expand Down

0 comments on commit 0719379

Please sign in to comment.