From 2cf09ebc48159b1b85f46444fd83373dff3ef52a Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 11 Mar 2015 08:00:20 +0100 Subject: [PATCH] Revert "LdapResourceForm: Validate the host field and do not require a port" This reverts commit a34d6026b31a112922508e01f8aad46df47fd162. refs #7990 --- .../Config/Resource/LdapResourceForm.php | 36 ++++--------------- library/Icinga/Protocol/Ldap/Connection.php | 3 +- library/Icinga/Web/Form/Element/Number.php | 13 +++---- 3 files changed, 14 insertions(+), 38 deletions(-) diff --git a/application/forms/Config/Resource/LdapResourceForm.php b/application/forms/Config/Resource/LdapResourceForm.php index 90cc17939..499d39941 100644 --- a/application/forms/Config/Resource/LdapResourceForm.php +++ b/application/forms/Config/Resource/LdapResourceForm.php @@ -32,7 +32,7 @@ class LdapResourceForm extends Form array( 'required' => true, 'label' => $this->translate('Resource Name'), - 'description' => $this->translate('The unique name of this resource.') + 'description' => $this->translate('The unique name of this resource') ) ); $this->addElement( @@ -42,40 +42,18 @@ class LdapResourceForm extends Form 'required' => true, 'label' => $this->translate('Host'), 'description' => $this->translate( - 'The hostname, address or URL of the LDAP server.' + 'The hostname or address of the LDAP server to use for authentication' ), - 'value' => 'localhost', - 'validators' => array( - array( - 'Callback', - false, - array( - 'callback' => function ($v) { - return strpos($v, '?') === false; - }, - 'messages' => array( - 'callbackValue' => $this->translate( - 'The URL pointing to the LDAP server must not contain any filter attributes.' - ) - ) - ) - ) - ), - 'requirement' => $this->translate( - 'The LDAP server\'s URL must have the following format: [ldap[s]://]host[:port]' - ) + 'value' => 'localhost' ) ); $this->addElement( 'number', 'port', array( - 'allowEmpty' => true, + 'required' => true, 'label' => $this->translate('Port'), - 'description' => $this->translate( - 'The port of the LDAP server. Leave empty if you\'ll set this as part of the URL above.' - . ' If not set the default port (389) is being used.' - ), + 'description' => $this->translate('The port of the LDAP server to use for authentication'), 'value' => 389 ) ); @@ -96,7 +74,7 @@ class LdapResourceForm extends Form array( 'required' => true, 'label' => $this->translate('Bind DN'), - 'description' => $this->translate('The user dn to use for querying the ldap server.') + 'description' => $this->translate('The user dn to use for querying the ldap server') ) ); $this->addElement( @@ -106,7 +84,7 @@ class LdapResourceForm extends Form 'required' => true, 'renderPassword' => true, 'label' => $this->translate('Bind Password'), - 'description' => $this->translate('The password to use for querying the ldap server.') + 'description' => $this->translate('The password to use for querying the ldap server') ) ); diff --git a/library/Icinga/Protocol/Ldap/Connection.php b/library/Icinga/Protocol/Ldap/Connection.php index e705c19b8..053c6c908 100644 --- a/library/Icinga/Protocol/Ldap/Connection.php +++ b/library/Icinga/Protocol/Ldap/Connection.php @@ -3,6 +3,7 @@ namespace Icinga\Protocol\Ldap; +use Exception; use Icinga\Exception\ProgrammingError; use Icinga\Protocol\Ldap\Exception as LdapException; use Icinga\Application\Platform; @@ -75,7 +76,7 @@ class Connection $this->bind_dn = $config->bind_dn; $this->bind_pw = $config->bind_pw; $this->root_dn = $config->root_dn; - $this->port = $config->get('port') ?: $this->port; + $this->port = $config->get('port', $this->port); } public function getHostname() diff --git a/library/Icinga/Web/Form/Element/Number.php b/library/Icinga/Web/Form/Element/Number.php index 95640c5ca..8a1217363 100644 --- a/library/Icinga/Web/Form/Element/Number.php +++ b/library/Icinga/Web/Form/Element/Number.php @@ -132,15 +132,12 @@ class Number extends FormElement */ public function isValid($value, $context = null) { - if (! parent::isValid($value, $context)) { + $this->setValue($value); + $value = $this->getValue(); + if (! is_numeric($value)) { + $this->addError(sprintf($this->translate('\'%s\' is not a valid number'), $value)); return false; } - - if ((! empty($value) || !$this->getAllowEmpty()) && !is_numeric($value)) { - $this->addError(sprintf(t('\'%s\' is not a valid number'), $value)); - return false; - } - - return true; + return parent::isValid($value, $context); } }