diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:36:40 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:36:40 +0000 |
commit | a0901c4b7f2db488cb4fb3be2dd921a0308f4659 (patch) | |
tree | fafb393cf330a60df129ff10d0059eb7b14052a7 /library/Icingadb/ProvidedHook/X509/Sni.php | |
parent | Initial commit. (diff) | |
download | icingadb-web-upstream.tar.xz icingadb-web-upstream.zip |
Adding upstream version 1.0.2.upstream/1.0.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Icingadb/ProvidedHook/X509/Sni.php')
-rw-r--r-- | library/Icingadb/ProvidedHook/X509/Sni.php | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/library/Icingadb/ProvidedHook/X509/Sni.php b/library/Icingadb/ProvidedHook/X509/Sni.php new file mode 100644 index 0000000..d6e1415 --- /dev/null +++ b/library/Icingadb/ProvidedHook/X509/Sni.php @@ -0,0 +1,57 @@ +<?php + +/* Icinga DB Web | (c) 2021 Icinga GmbH | GPLv2 */ + +namespace Icinga\Module\Icingadb\ProvidedHook\X509; + +use Generator; +use Icinga\Data\Filter\Filter; +use Icinga\Module\Icingadb\Common\Auth; +use Icinga\Module\Icingadb\Common\Database; +use Icinga\Module\Icingadb\Model\Host; +use Icinga\Module\X509\Hook\SniHook; +use ipl\Web\Filter\QueryString; + +class Sni extends SniHook +{ + use Auth; + use Database; + + /** + * @inheritDoc + */ + public function getHosts(Filter $filter = null): Generator + { + $queryHost = Host::on($this->getDb()); + + $queryHost->getSelectBase(); + + $hostStatusCols = [ + 'host_name' => 'name', + 'host_address' => 'address', + 'host_address6' => 'address6' + ]; + + $queryHost = $queryHost->columns($hostStatusCols); + + $this->applyRestrictions($queryHost); + + if ($filter !== null) { + $queryString = $filter->toQueryString(); + $filterCondition = QueryString::parse($queryString); + $queryHost->filter($filterCondition); + } + + $hosts = $this->getdb()->select($queryHost->assembleSelect()); + + foreach ($hosts as $host) { + if (! empty($host->host_address)) { + yield $host->host_address => $host->host_name; + } + + if (! empty($host->host_address6)) { + yield $host->host_address6 => $host->host_name; + } + } + } +} |