[icinga-checkins] icinga.org: icingaweb2/master: Improve element handling in the resource config forms

git at icinga.org git at icinga.org
Mon Dec 12 10:53:11 CET 2016


Module: icingaweb2
Branch: master
Commit: b44c932de833e498585b735bcf11c9896a6c31fe
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=b44c932de833e498585b735bcf11c9896a6c31fe

Author: Alexander A. Klimov <alexander.klimov at icinga.com>
Date:   Wed Dec  7 15:40:18 2016 +0100

Improve element handling in the resource config forms

Signed-off-by: Eric Lippmann <eric.lippmann at icinga.com>

---

 application/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 bbf54cb..818f749 100644
--- a/application/forms/Config/ResourceConfigForm.php
+++ b/application/forms/Config/ResourceConfigForm.php
@@ -23,6 +23,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
      *
      * @var Config|null
@@ -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);
+                }
+            }
         }
     }
 
@@ -396,6 +407,32 @@ class ResourceConfigForm extends ConfigForm
     }
 
     /**
+     * {@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}
      */
     protected function writeConfig(Config $config)



More information about the icinga-checkins mailing list