Adjust ..\Monitoring\Form\Config\SecurityForm to use handleRequest()

refs #5525
This commit is contained in:
Johannes Meyer 2014-09-03 15:08:37 +02:00
parent 54a834266c
commit 49562e75d7
3 changed files with 73 additions and 62 deletions

View File

@ -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');
}
}

View File

@ -0,0 +1,68 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Form\Config;
use Icinga\Web\Request;
use Icinga\Web\Notification;
use Icinga\Form\ConfigForm;
/**
* Form for modifying security relevant settings
*/
class SecurityConfigForm extends ConfigForm
{
/**
* Initialize this form
*/
public function init()
{
$this->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;
}
}

View File

@ -1,42 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Form\Config;
use Icinga\Web\Form;
/**
* Form for modifying security relevant settings
*/
class SecurityForm extends Form
{
/**
* Initialize this form
*/
public function init()
{
$this->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.'
)
)
);
}
}