mirror of
https://github.com/Icinga/icingadb-web.git
synced 2026-05-28 04:36:06 -04:00
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.
102 lines
3.1 KiB
PHP
102 lines
3.1 KiB
PHP
<?php
|
|
|
|
/* Icinga DB Web | (c) 2021 Icinga GmbH | GPLv2+ */
|
|
|
|
namespace Icinga\Module\Icingadb\Forms;
|
|
|
|
use Icinga\Data\ConfigObject;
|
|
use Icinga\Module\Icingadb\Command\Transport\CommandTransport;
|
|
use Icinga\Module\Icingadb\Command\Transport\CommandTransportException;
|
|
use Icinga\Web\Session;
|
|
use ipl\Web\Common\CsrfCounterMeasure;
|
|
use ipl\Web\Compat\CompatForm;
|
|
|
|
class ApiTransportForm extends CompatForm
|
|
{
|
|
use CsrfCounterMeasure;
|
|
|
|
protected function assemble()
|
|
{
|
|
// TODO: Use a validator to check if a name is not already in use
|
|
$this->addElement('text', 'name', [
|
|
'required' => true,
|
|
'label' => t('Transport Name')
|
|
]);
|
|
|
|
$this->addElement('hidden', 'transport', [
|
|
'value' => 'api'
|
|
]);
|
|
|
|
$this->addElement('text', 'host', [
|
|
'required' => true,
|
|
'id' => 'api_transport_host',
|
|
'label' => t('Host'),
|
|
'description' => t('Hostname or address of the Icinga master')
|
|
]);
|
|
|
|
// TODO: Don't rely only on browser validation
|
|
$this->addElement('number', 'port', [
|
|
'required' => true,
|
|
'label' => t('Port'),
|
|
'value' => 5665,
|
|
'min' => 1,
|
|
'max' => 65536
|
|
]);
|
|
|
|
$this->addElement('text', 'username', [
|
|
'required' => true,
|
|
'label' => t('API Username'),
|
|
'description' => t('User to authenticate with using HTTP Basic Auth')
|
|
]);
|
|
|
|
$this->addElement('password', 'password', [
|
|
'required' => true,
|
|
'autocomplete' => 'new-password',
|
|
'label' => t('API Password')
|
|
]);
|
|
|
|
$this->addElement('submit', 'btn_submit', [
|
|
'label' => t('Save')
|
|
]);
|
|
|
|
$this->addElement($this->createCsrfCounterMeasure(Session::getSession()->getId()));
|
|
}
|
|
|
|
public function validate()
|
|
{
|
|
parent::validate();
|
|
if (! $this->isValid) {
|
|
return $this;
|
|
}
|
|
|
|
if ($this->getPopulatedValue('force_creation') === 'y') {
|
|
return $this;
|
|
}
|
|
|
|
try {
|
|
CommandTransport::createTransport(new ConfigObject($this->getValues()))->probe();
|
|
} catch (CommandTransportException $e) {
|
|
$this->addMessage(
|
|
sprintf(t('Failed to successfully validate the configuration: %s'), $e->getMessage())
|
|
);
|
|
|
|
$forceCheckbox = $this->createElement(
|
|
'checkbox',
|
|
'force_creation',
|
|
[
|
|
'ignore' => true,
|
|
'label' => t('Force Changes'),
|
|
'description' => t('Check this box to enforce changes without connectivity validation')
|
|
]
|
|
);
|
|
|
|
$this->registerElement($forceCheckbox);
|
|
$this->decorate($forceCheckbox);
|
|
$this->prepend($forceCheckbox);
|
|
|
|
$this->isValid = false;
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
}
|