From b18bc644404e02b57635bfcc8258e85abb141146 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 13:44:46 +0200 Subject: Adding upstream version 1.1.1. Signed-off-by: Daniel Baumann --- application/forms/ApiTransportForm.php | 102 +++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 application/forms/ApiTransportForm.php (limited to 'application/forms/ApiTransportForm.php') diff --git a/application/forms/ApiTransportForm.php b/application/forms/ApiTransportForm.php new file mode 100644 index 0000000..27c147b --- /dev/null +++ b/application/forms/ApiTransportForm.php @@ -0,0 +1,102 @@ +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; + } +} -- cgit v1.2.3