diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:45:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:45:29 +0000 |
commit | 0fa6f7723cca9bf7edc8af84112e8429e82dea84 (patch) | |
tree | 52c73718c9e2b6e4aa3f997791786aa2ee6ebcc9 /library/Nagvis/RestrictionHelper.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-nagvis-0fa6f7723cca9bf7edc8af84112e8429e82dea84.tar.xz icingaweb2-module-nagvis-0fa6f7723cca9bf7edc8af84112e8429e82dea84.zip |
Adding upstream version 1.1.1.upstream/1.1.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Nagvis/RestrictionHelper.php')
-rw-r--r-- | library/Nagvis/RestrictionHelper.php | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/library/Nagvis/RestrictionHelper.php b/library/Nagvis/RestrictionHelper.php new file mode 100644 index 0000000..a757b9d --- /dev/null +++ b/library/Nagvis/RestrictionHelper.php @@ -0,0 +1,41 @@ +<?php + +namespace Icinga\Module\Nagvis; + +use Icinga\Authentication\Auth; + +/** + * NagVis restriction helper + */ +class RestrictionHelper +{ + /** + * Get the regular expression for validating map names + * + * @return string|null + */ + public static function getRegex() + { + $mapFilters = array(); + foreach (Auth::getInstance()->getRestrictions('nagvis/map/filter') as $mapFilter) { + if ($mapFilter !== '') { + $mapFilters = array_merge($mapFilters, array_map('trim', explode(',', $mapFilter))); + } + } + + if (! empty($mapFilters)) { + $mapRegexParts = array(); + foreach (array_unique($mapFilters) as $mapFilter) { + $nonWildcards = array(); + foreach (explode('*', $mapFilter) as $nonWildcard) { + $nonWildcards[] = preg_quote($nonWildcard, '/'); + } + $mapRegexParts[] = implode('.*', $nonWildcards); + } + + return '/^(?:' . implode('|', $mapRegexParts) . ')$/i'; + } + + return null; + } +} |