icingadb-web/application/forms/Command/Object/ScheduleHostDowntimeForm.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

86 lines
2.8 KiB
PHP

<?php
/* Icinga DB Web | (c) 2021 Icinga GmbH | GPLv2+ */
namespace Icinga\Module\Icingadb\Forms\Command\Object;
use DateInterval;
use DateTime;
use Icinga\Application\Config;
use Icinga\Web\Notification;
use ipl\Web\FormDecorator\IcingaFormDecorator;
use Iterator;
use Traversable;
class ScheduleHostDowntimeForm extends ScheduleServiceDowntimeForm
{
/** @var bool */
protected $hostDowntimeAllServices;
public function __construct()
{
$this->start = new DateTime();
$config = Config::module('icingadb');
$this->commentText = $config->get('settings', 'hostdowntime_comment_text');
$this->hostDowntimeAllServices = (bool) $config->get('settings', 'hostdowntime_all_services', false);
$fixedEnd = clone $this->start;
$fixed = $config->get('settings', 'hostdowntime_end_fixed', 'PT1H');
$this->fixedEnd = $fixedEnd->add(new DateInterval($fixed));
$flexibleEnd = clone $this->start;
$flexible = $config->get('settings', 'hostdowntime_end_flexible', 'PT2H');
$this->flexibleEnd = $flexibleEnd->add(new DateInterval($flexible));
$flexibleDuration = $config->get('settings', 'hostdowntime_flexible_duration', 'PT2H');
$this->flexibleDuration = new DateInterval($flexibleDuration);
$this->on(self::ON_SUCCESS, function () {
if ($this->errorOccurred) {
return;
}
$countObjects = count($this->getObjects());
Notification::success(sprintf(
tp('Scheduled downtime successfully', 'Scheduled downtime for %d hosts successfully', $countObjects),
$countObjects
));
});
}
protected function assembleElements()
{
parent::assembleElements();
$decorator = new IcingaFormDecorator();
$allServices = $this->createElement(
'checkbox',
'all_services',
[
'label' => t('All Services'),
'description' => t(
'Sets downtime for all services for the matched host objects. If child options are set,'
. ' all child hosts and their services will schedule a downtime too.'
),
'value' => $this->hostDowntimeAllServices
]
);
$this->insertBefore($allServices, $this->getElement('child_options'));
$this->registerElement($allServices);
$decorator->decorate($allServices);
}
protected function getCommands(Iterator $objects): Traversable
{
if (! $this->getElement('all_services')->isChecked()) {
yield from parent::getCommands($objects);
} else {
foreach (parent::getCommands($objects) as $command) {
yield $command->setForAllServices();
}
}
}
}