diff --git a/library/Director/CustomVariable/CustomVariableString.php b/library/Director/CustomVariable/CustomVariableString.php index 2d509681c..ea1a0ca6c 100644 --- a/library/Director/CustomVariable/CustomVariableString.php +++ b/library/Director/CustomVariable/CustomVariableString.php @@ -46,7 +46,7 @@ public function flatten(array &$flat, $prefix) public function toConfigString($renderExpressions = false) { if ($renderExpressions) { - return c::renderStringWithVariables($this->getValue(), ['config']); + return c::renderStringWithVariables($this->getValue(), ['config'], true); } else { return c::renderString($this->getValue()); } diff --git a/library/Director/IcingaConfig/IcingaConfigHelper.php b/library/Director/IcingaConfig/IcingaConfigHelper.php index 634337f04..7cdd18578 100644 --- a/library/Director/IcingaConfig/IcingaConfigHelper.php +++ b/library/Director/IcingaConfig/IcingaConfigHelper.php @@ -381,7 +381,7 @@ public static function isValidMacroName($name) && ! preg_match('/\.$/', $name); } - public static function renderStringWithVariables($string, array $whiteList = null) + public static function renderStringWithVariables($string, array $whiteList = null, bool $matchRegex = false) { $len = strlen($string); $start = false; @@ -400,7 +400,20 @@ public static function renderStringWithVariables($string, array $whiteList = nul // We got a macro $macroName = substr($string, $start + 1, $i - $start - 1); if (static::isValidMacroName($macroName)) { - if ($whiteList === null || in_array($macroName, $whiteList)) { + $whiteListMatch = false; + // If matchRegex, match macro with parameter + if ($whiteList !== null || $matchRegex) { + foreach ($whiteList as $entry) { + $pattern = "/^(" . $entry . "|" . $entry . "\..*)$/i"; + if (preg_match($pattern, $macroName)) { + $whiteListMatch = true; + } + } + // Otherwise simply match against array entries + } elseif ($whiteList !== null) { + $whiteListMatch = in_array($macroName, $whiteList); + } + if ($whiteList === null || $whiteListMatch) { if ($start > $offset) { $parts[] = static::renderString( substr($string, $offset, $start - $offset)