blob: d6e1415bf2967cdd49fd084aba03713c0f5fd7f9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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;
}
}
}
}
|