icingadb-web/application/controllers/CommandTransportController.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

154 lines
4.9 KiB
PHP

<?php
/* Icinga DB Web | (c) 2021 Icinga GmbH | GPLv2+ */
namespace Icinga\Module\Icingadb\Controllers;
use GuzzleHttp\Psr7\ServerRequest;
use Icinga\Application\Config;
use Icinga\Data\Filter\Filter;
use Icinga\Forms\ConfirmRemovalForm;
use Icinga\Module\Icingadb\Command\Transport\CommandTransportConfig;
use Icinga\Module\Icingadb\Forms\ApiTransportForm;
use Icinga\Module\Icingadb\Widget\ItemList\CommandTransportList;
use Icinga\Web\Notification;
use ipl\Html\HtmlString;
use ipl\Web\Widget\ButtonLink;
class CommandTransportController extends ConfigController
{
public function init()
{
$this->assertPermission('config/modules');
}
public function indexAction()
{
$list = new CommandTransportList((new CommandTransportConfig())->select());
$this->addControl(
(new ButtonLink(
t('Create Command Transport'),
'icingadb/command-transport/add',
'plus'
))->setBaseTarget('_next')
);
$this->addContent($list);
$this->mergeTabs($this->Module()->getConfigTabs());
$this->getTabs()->disableLegacyExtensions();
$this->setTitle($this->getTabs()
->activate('command-transports')
->getActiveTab()
->getLabel());
}
public function showAction()
{
$transportName = $this->params->getRequired('name');
$transportConfig = (new CommandTransportConfig())
->select()
->where('name', $transportName)
->fetchRow();
if ($transportConfig === false) {
$this->httpNotFound(t('Unknown transport'));
}
$form = new ApiTransportForm();
$form->populate((array) $transportConfig);
$form->on(ApiTransportForm::ON_SUCCESS, function (ApiTransportForm $form) use ($transportName) {
(new CommandTransportConfig())->update(
'transport',
$form->getValues(),
Filter::where('name', $transportName)
);
Notification::success(sprintf(t('Updated command transport "%s" successfully'), $transportName));
$this->redirectNow('icingadb/command-transport');
});
$form->handleRequest(ServerRequest::fromGlobals());
$this->addContent($form);
$this->addTitleTab($this->translate('Command Transport: %s'), $transportName);
$this->getTabs()->disableLegacyExtensions();
}
public function addAction()
{
$form = new ApiTransportForm();
$form->on(ApiTransportForm::ON_SUCCESS, function (ApiTransportForm $form) {
(new CommandTransportConfig())->insert('transport', $form->getValues());
Notification::success(t('Created command transport successfully'));
$this->redirectNow('icingadb/command-transport');
});
$form->handleRequest(ServerRequest::fromGlobals());
$this->addContent($form);
$this->addTitleTab($this->translate('Add Command Transport'));
$this->getTabs()->disableLegacyExtensions();
}
public function removeAction()
{
$transportName = $this->params->getRequired('name');
$form = new ConfirmRemovalForm();
$form->setOnSuccess(function () use ($transportName) {
(new CommandTransportConfig())->delete(
'transport',
Filter::where('name', $transportName)
);
Notification::success(sprintf(t('Removed command transport "%s" successfully'), $transportName));
$this->redirectNow('icingadb/command-transport');
});
$form->handleRequest();
$this->addContent(HtmlString::create($form->render()));
$this->setTitle($this->translate('Remove Command Transport: %s'), $transportName);
$this->getTabs()->disableLegacyExtensions();
}
public function sortAction()
{
$transportName = $this->params->getRequired('name');
$newPosition = (int) $this->params->getRequired('pos');
$config = $this->Config('commandtransports');
if (! $config->hasSection($transportName)) {
$this->httpNotFound(t('Unknown transport'));
}
if ($newPosition < 0 || $newPosition > $config->count()) {
$this->httpBadRequest(t('Position out of bounds'));
}
$transports = $config->getConfigObject()->toArray();
$transportNames = array_keys($transports);
array_splice($transportNames, array_search($transportName, $transportNames, true), 1);
array_splice($transportNames, $newPosition, 0, [$transportName]);
$sortedTransports = [];
foreach ($transportNames as $name) {
$sortedTransports[$name] = $transports[$name];
}
$newConfig = Config::fromArray($sortedTransports);
$newConfig->saveIni($config->getConfigFile());
$this->redirectNow('icingadb/command-transport');
}
}