From b44c932de833e498585b735bcf11c9896a6c31fe Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 7 Dec 2016 15:40:18 +0100 Subject: [PATCH] Improve element handling in the resource config forms Signed-off-by: Eric Lippmann --- .../forms/Config/ResourceConfigForm.php | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/application/forms/Config/ResourceConfigForm.php b/application/forms/Config/ResourceConfigForm.php index bbf54cb19..818f74948 100644 --- a/application/forms/Config/ResourceConfigForm.php +++ b/application/forms/Config/ResourceConfigForm.php @@ -22,6 +22,13 @@ use Icinga\Web\Notification; class ResourceConfigForm extends ConfigForm { + /** + * Bogus password when inspecting password elements + * + * @var string + */ + protected static $dummyPassword = '_web_form_5847ed1b5b8ca'; + /** * If the global config must be updated because a resource has been changed, this is the updated global config * @@ -215,10 +222,14 @@ class ResourceConfigForm extends ConfigForm } elseif (! $this->config->hasSection($resource)) { throw new ConfigurationError($this->translate('Unknown resource provided')); } - $configValues = $this->config->getSection($resource)->toArray(); $configValues['name'] = $resource; $this->populate($configValues); + foreach ($this->getElements() as $element) { + if ($element->getType() === 'Zend_Form_Element_Password' && strlen($element->getValue())) { + $element->setValue(static::$dummyPassword); + } + } } } @@ -395,6 +406,32 @@ class ResourceConfigForm extends ConfigForm return $this; } + /** + * {@inheritdoc} + */ + public function getValues($suppressArrayNotation = false) + { + $values = parent::getValues($suppressArrayNotation); + $resource = $this->request->getQuery('resource'); + if ($resource !== null && $this->config->hasSection($resource)) { + $resourceConfig = $this->config->getSection($resource)->toArray(); + foreach ($this->getElements() as $element) { + if ($element->getType() === 'Zend_Form_Element_Password') { + $name = $element->getName(); + if (isset($values[$name]) && $values[$name] === static::$dummyPassword) { + if (isset($resourceConfig[$name])) { + $values[$name] = $resourceConfig[$name]; + } else { + unset($values[$name]); + } + } + } + } + } + + return $values; + } + /** * {@inheritDoc} */