diff --git a/modules/monitoring/application/controllers/ConfigController.php b/modules/monitoring/application/controllers/ConfigController.php index ce22d73df..a1bed1a4e 100644 --- a/modules/monitoring/application/controllers/ConfigController.php +++ b/modules/monitoring/application/controllers/ConfigController.php @@ -8,7 +8,7 @@ use Icinga\Web\Notification; use Icinga\Form\ConfirmRemovalForm; use Icinga\Module\Monitoring\Form\Config\BackendForm; use Icinga\Module\Monitoring\Form\Config\InstanceForm; -use Icinga\Module\Monitoring\Form\Config\SecurityForm; +use Icinga\Module\Monitoring\Form\Config\SecurityConfigForm; use Icinga\Exception\NotReadableError; /** @@ -254,26 +254,11 @@ class Monitoring_ConfigController extends ModuleActionController */ public function securityAction() { - $this->view->tabs = $this->Module()->getConfigTabs()->activate('security'); - - $form = new SecurityForm(); - $request = $this->getRequest(); - $config = $this->Config()->toArray(); - if ($request->isPost()) { - if ($form->isValid($request->getPost())) { - $config['security'] = $form->getValues(); - if ($this->writeConfiguration(new Zend_Config($config))) { - Notification::success('Configuration modified successfully'); - $this->redirectNow('monitoring/config/security'); - } else { - $this->render('show-configuration'); - return; - } - } - } elseif (isset($config['security'])) { - $form->populate($config['security']); - } + $form = new SecurityConfigForm(); + $form->setConfig($this->Config()); + $form->handleRequest(); $this->view->form = $form; + $this->view->tabs = $this->Module()->getConfigTabs()->activate('security'); } } diff --git a/modules/monitoring/application/forms/Config/SecurityConfigForm.php b/modules/monitoring/application/forms/Config/SecurityConfigForm.php new file mode 100644 index 000000000..33a03328e --- /dev/null +++ b/modules/monitoring/application/forms/Config/SecurityConfigForm.php @@ -0,0 +1,68 @@ +setName('form_config_monitoring_security'); + $this->setSubmitLabel(t('Save Changes')); + } + + /** + * @see Form::onSuccess() + */ + public function onSuccess(Request $request) + { + $this->config->security = $this->getValues(); + + if ($this->save()) { + Notification::success(t('New security configuration has successfully been stored')); + } else { + return false; + } + } + + /** + * @see Form::onRequest() + */ + public function onRequest(Request $request) + { + if (isset($this->config->security)) { + $this->populate($this->config->security->toArray()); + } + } + + /** + * @see Form::createElements() + */ + public function createElements(array $formData) + { + $this->addElement( + 'text', + 'protected_customvars', + array( + 'required' => true, + 'label' => 'Protected Custom Variables', + 'description' => 'Comma separated case insensitive list of protected custom variables.' + . ' Use * as a placeholder for zero or more wildcard characters.' + . ' Existance of those custom variables will be shown, but their values will be masked.' + ) + ); + + return $this; + } +} diff --git a/modules/monitoring/application/forms/Config/SecurityForm.php b/modules/monitoring/application/forms/Config/SecurityForm.php deleted file mode 100644 index 48368d0f1..000000000 --- a/modules/monitoring/application/forms/Config/SecurityForm.php +++ /dev/null @@ -1,42 +0,0 @@ -setName('form_config_monitoring_security'); - $this->setSubmitLabel(t('Save Changes')); - } - - /** - * @see Form::createElements() - */ - public function createElements(array $formData) - { - return array( - $this->createElement( - 'text', - 'protected_customvars', - array( - 'label' => 'Protected Custom Variables', - 'required' => true, - 'helptext' => 'Comma separated case insensitive list of protected custom variables.' - . ' Use * as a placeholder for zero or more wildcard characters.' - . ' Existance of those custom variables will be shown, but their values will be masked.' - ) - ) - ); - } -}