From 8ca6cc32b2c789a3149861159ad258f2cb9491e3 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:39:39 +0200 Subject: Adding upstream version 2.11.4. Signed-off-by: Daniel Baumann --- .../application/controllers/ConfigController.php | 298 +++++++++++++++++++++ 1 file changed, 298 insertions(+) create mode 100644 modules/monitoring/application/controllers/ConfigController.php (limited to 'modules/monitoring/application/controllers/ConfigController.php') diff --git a/modules/monitoring/application/controllers/ConfigController.php b/modules/monitoring/application/controllers/ConfigController.php new file mode 100644 index 0000000..b8ca0a1 --- /dev/null +++ b/modules/monitoring/application/controllers/ConfigController.php @@ -0,0 +1,298 @@ +assertPermission('config/modules'); + $this->view->title = $this->translate('Backends'); + $this->view->defaultTitle = 'monitoring :: ' . $this->view->defaultTitle; + parent::init(); + } + + /** + * Display a list of available backends and command transports + */ + public function indexAction() + { + $this->view->commandTransportReorderForm = $form = new TransportReorderForm(); + $form->handleRequest(); + + $this->view->backendsConfig = $this->Config('backends'); + $this->view->tabs = $this->Module()->getConfigTabs()->activate('backends'); + } + + /** + * Edit a monitoring backend + */ + public function editbackendAction() + { + $backendName = $this->params->getRequired('backend-name'); + + $form = new BackendConfigForm(); + $form->setRedirectUrl('monitoring/config'); + $form->setTitle(sprintf($this->translate('Edit Monitoring Backend %s'), $backendName)); + $form->setIniConfig($this->Config('backends')); + $form->setResourceConfig(ResourceFactory::getResourceConfigs()); + $form->setOnSuccess(function (BackendConfigForm $form) use ($backendName) { + try { + $form->edit($backendName, array_map( + function ($v) { + return $v !== '' ? $v : null; + }, + $form->getValues() + )); + } catch (Exception $e) { + $form->error($e->getMessage()); + return false; + } + + if ($form->save()) { + Notification::success(sprintf(t('Monitoring backend "%s" successfully updated'), $backendName)); + return true; + } + + return false; + }); + + try { + $form->load($backendName); + $form->handleRequest(); + } catch (NotFoundError $_) { + $this->httpNotFound(sprintf($this->translate('Monitoring backend "%s" not found'), $backendName)); + } + + $this->view->form = $form; + $this->render('form'); + } + + /** + * Create a new monitoring backend + */ + public function createbackendAction() + { + $form = new BackendConfigForm(); + $form->setRedirectUrl('monitoring/config'); + $form->setTitle($this->translate('Create New Monitoring Backend')); + $form->setIniConfig($this->Config('backends')); + + try { + $form->setResourceConfig(ResourceFactory::getResourceConfigs()); + } catch (ConfigurationError $e) { + if ($this->hasPermission('config/resources')) { + Notification::error($e->getMessage()); + $this->redirectNow('config/createresource'); + } + + throw $e; // No permission for resource configuration, show the error + } + + $form->setOnSuccess(function (BackendConfigForm $form) { + try { + $form->add($form::transformEmptyValuesToNull($form->getValues())); + } catch (Exception $e) { + $form->error($e->getMessage()); + return false; + } + + if ($form->save()) { + Notification::success(t('Monitoring backend successfully created')); + return true; + } + + return false; + }); + $form->handleRequest(); + + $this->view->form = $form; + $this->render('form'); + } + + /** + * Display a confirmation form to remove the backend identified by the 'backend' parameter + */ + public function removebackendAction() + { + $backendName = $this->params->getRequired('backend-name'); + + $backendForm = new BackendConfigForm(); + $backendForm->setIniConfig($this->Config('backends')); + $form = new ConfirmRemovalForm(); + $form->setRedirectUrl('monitoring/config'); + $form->setTitle(sprintf($this->translate('Remove Monitoring Backend %s'), $backendName)); + $form->setOnSuccess(function (ConfirmRemovalForm $form) use ($backendName, $backendForm) { + try { + $backendForm->delete($backendName); + } catch (Exception $e) { + $form->error($e->getMessage()); + return false; + } + + if ($backendForm->save()) { + Notification::success(sprintf(t('Monitoring backend "%s" successfully removed'), $backendName)); + return true; + } + + return false; + }); + $form->handleRequest(); + + $this->view->form = $form; + $this->render('form'); + } + + /** + * Remove a command transport + */ + public function removetransportAction() + { + $transportName = $this->params->getRequired('transport'); + + $transportForm = new TransportConfigForm(); + $transportForm->setIniConfig($this->Config('commandtransports')); + $form = new ConfirmRemovalForm(); + $form->setRedirectUrl('monitoring/config'); + $form->setTitle(sprintf($this->translate('Remove Command Transport %s'), $transportName)); + $form->info( + $this->translate( + 'If you still have any environments or views referring to this transport, ' + . 'you won\'t be able to send commands anymore after deletion.' + ), + false + ); + $form->setOnSuccess(function (ConfirmRemovalForm $form) use ($transportName, $transportForm) { + try { + $transportForm->delete($transportName); + } catch (Exception $e) { + $form->error($e->getMessage()); + return false; + } + + if ($transportForm->save()) { + Notification::success(sprintf(t('Command transport "%s" successfully removed'), $transportName)); + return true; + } + + return false; + }); + $form->handleRequest(); + + $this->view->form = $form; + $this->render('form'); + } + + /** + * Edit a command transport + */ + public function edittransportAction() + { + $transportName = $this->params->getRequired('transport'); + + $form = new TransportConfigForm(); + $form->setRedirectUrl('monitoring/config'); + $form->setTitle(sprintf($this->translate('Edit Command Transport %s'), $transportName)); + $form->setIniConfig($this->Config('commandtransports')); + $form->setInstanceNames( + MonitoringBackend::instance()->select()->from('instance', array('instance_name'))->fetchColumn() + ); + $form->setOnSuccess(function (TransportConfigForm $form) use ($transportName) { + try { + $form->edit($transportName, array_map( + function ($v) { + return $v !== '' ? $v : null; + }, + $form->getValues() + )); + } catch (Exception $e) { + $form->error($e->getMessage()); + return false; + } + + if ($form->save()) { + Notification::success(sprintf(t('Command transport "%s" successfully updated'), $transportName)); + return true; + } + + return false; + }); + + try { + $form->load($transportName); + $form->handleRequest(); + } catch (NotFoundError $_) { + $this->httpNotFound(sprintf($this->translate('Command transport "%s" not found'), $transportName)); + } + + $this->view->form = $form; + $this->render('form'); + } + + /** + * Create a new command transport + */ + public function createtransportAction() + { + $form = new TransportConfigForm(); + $form->setRedirectUrl('monitoring/config'); + $form->setTitle($this->translate('Create New Command Transport')); + $form->setIniConfig($this->Config('commandtransports')); + $form->setInstanceNames( + MonitoringBackend::instance()->select()->from('instance', array('instance_name'))->fetchColumn() + ); + $form->setOnSuccess(function (TransportConfigForm $form) { + try { + $form->add($form::transformEmptyValuesToNull($form->getValues())); + } catch (Exception $e) { + $form->error($e->getMessage()); + return false; + } + + if ($form->save()) { + Notification::success(t('Command transport successfully created')); + return true; + } + + return false; + }); + $form->handleRequest(); + + $this->view->form = $form; + $this->render('form'); + } + + /** + * Display a form to adjust security relevant settings + */ + public function securityAction() + { + $form = new SecurityConfigForm(); + $form->setIniConfig($this->Config()); + $form->handleRequest(); + + $this->view->form = $form; + $this->view->title = $this->translate('Security'); + $this->view->tabs = $this->Module()->getConfigTabs()->activate('security'); + } +} -- cgit v1.2.3