icingadb-web/application/controllers/HostgroupsController.php
Alexander A. Klimov 3c8ed68cc6 Upgrade license from GPLv2 to GPLv2+
This was easy because only README.md and doc/01-About.md were redacted manually, everything else via:
git ls-files -z |xargs -0 perl -pi -e 's/Icinga GmbH \| GPLv2/Icinga GmbH | GPLv2+/'

This is legal because we have only merged PRs with label:cla/signed or made by Icinga staff:
https://github.com/Icinga/icingadb-web/pulls?page=1&q=is%3Apr+is%3Aclosed+-label%3Acla%2Fsigned+-author%3Anilmerg

This has no risk for us in people distributing their own version under GPLv3 only.
After all, we won't take their patches anyway, unless they sign our CLA.

This is the cleanest solution for having e.g. these in one address space:

* Icinga Web, GPLv2+
* K8s Web, AGPLv3
* Thirdparty, some LGPLv3 and Apache-2.0

Apropos, K8s Web is even v3-licensed on purpose, to have a stronger protection against cloud ops.
2025-11-21 13:31:24 +01:00

149 lines
4.8 KiB
PHP

<?php
/* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2+ */
namespace Icinga\Module\Icingadb\Controllers;
use GuzzleHttp\Psr7\ServerRequest;
use Icinga\Module\Icingadb\Model\Hostgroup;
use Icinga\Module\Icingadb\Model\Hostgroupsummary;
use Icinga\Module\Icingadb\View\HostgroupGridRenderer;
use Icinga\Module\Icingadb\View\HostgroupRenderer;
use Icinga\Module\Icingadb\Web\Control\SearchBar\ObjectSuggestions;
use Icinga\Module\Icingadb\Web\Controller;
use Icinga\Module\Icingadb\Web\Control\ViewModeSwitcher;
use Icinga\Module\Icingadb\Widget\ItemTable\ObjectGrid;
use Icinga\Module\Icingadb\Widget\ItemTable\ObjectTable;
use Icinga\Module\Icingadb\Widget\ShowMore;
use ipl\Web\Control\LimitControl;
use ipl\Web\Control\SortControl;
use ipl\Web\Url;
class HostgroupsController extends Controller
{
public function init()
{
parent::init();
$this->assertRouteAccess();
}
public function indexAction()
{
$this->addTitleTab(t('Host Groups'));
$compact = $this->view->compact;
$db = $this->getDb();
$hostgroups = Hostgroupsummary::on($db);
$this->handleSearchRequest($hostgroups);
$limitControl = $this->createLimitControl();
$paginationControl = $this->createPaginationControl($hostgroups);
$viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl);
if ($viewModeSwitcher->getViewMode() === 'grid') {
$hostgroups->without([
'services_critical_handled',
'services_critical_unhandled',
'services_ok',
'services_pending',
'services_total',
'services_unknown_handled',
'services_unknown_unhandled',
'services_warning_handled',
'services_warning_unhandled',
]);
}
$sortControl = $this->createSortControl(
$hostgroups,
[
'display_name' => t('Name'),
'hosts_severity desc, display_name' => t('Severity'),
'hosts_total desc' => t('Total Hosts'),
],
['hosts_severity DESC', 'display_name']
);
$searchBar = $this->createSearchBar($hostgroups, [
$limitControl->getLimitParam(),
$sortControl->getSortParam(),
$viewModeSwitcher->getViewModeParam()
]);
if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
if ($searchBar->hasBeenSubmitted()) {
$filter = $this->getFilter();
} else {
$this->addControl($searchBar);
$this->sendMultipartUpdate();
return;
}
} else {
$filter = $searchBar->getFilter();
}
$this->filter($hostgroups, $filter);
$hostgroups->peekAhead($compact);
yield $this->export($hostgroups);
$this->addControl($paginationControl);
$this->addControl($sortControl);
$this->addControl($limitControl);
$this->addControl($viewModeSwitcher);
$this->addControl($searchBar);
$results = $hostgroups->execute();
if ($viewModeSwitcher->getViewMode() === 'grid') {
$content = new ObjectGrid($results, (new HostgroupGridRenderer())->setBaseFilter($filter));
} else {
$content = new ObjectTable($results, (new HostgroupRenderer())->setBaseFilter($filter));
}
$content->setEmptyStateMessage($paginationControl->getEmptyStateMessage());
$this->addContent($content);
if ($compact) {
$this->addContent(
(new ShowMore($results, Url::fromRequest()->without(['showCompact', 'limit', 'view'])))
->setBaseTarget('_next')
->setAttribute('title', sprintf(
t('Show all %d hostgroups'),
$hostgroups->count()
))
);
}
if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) {
$this->sendMultipartUpdate();
}
$this->setAutorefreshInterval(30);
}
public function completeAction()
{
$suggestions = new ObjectSuggestions();
$suggestions->setModel(Hostgroup::class);
$suggestions->forRequest(ServerRequest::fromGlobals());
$this->getDocument()->add($suggestions);
}
public function searchEditorAction()
{
$editor = $this->createSearchEditor(Hostgroupsummary::on($this->getDb()), [
LimitControl::DEFAULT_LIMIT_PARAM,
SortControl::DEFAULT_SORT_PARAM,
ViewModeSwitcher::DEFAULT_VIEW_MODE_PARAM
]);
$this->getDocument()->add($editor);
$this->setTitle(t('Adjust Filter'));
}
}