LdapResourceForm: Validate the host field and do not require a port
fixes #7990
This commit is contained in:
parent
f87a43b9d3
commit
a34d6026b3
|
@ -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,18 +42,40 @@ class LdapResourceForm extends Form
|
|||
'required' => true,
|
||||
'label' => $this->translate('Host'),
|
||||
'description' => $this->translate(
|
||||
'The hostname or address of the LDAP server to use for authentication'
|
||||
'The hostname, address or URL of the LDAP server.'
|
||||
),
|
||||
'value' => 'localhost'
|
||||
'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]'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
'number',
|
||||
'port',
|
||||
array(
|
||||
'required' => true,
|
||||
'allowEmpty' => true,
|
||||
'label' => $this->translate('Port'),
|
||||
'description' => $this->translate('The port of the LDAP server to use for authentication'),
|
||||
'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.'
|
||||
),
|
||||
'value' => 389
|
||||
)
|
||||
);
|
||||
|
@ -74,7 +96,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(
|
||||
|
@ -84,7 +106,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.')
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
namespace Icinga\Protocol\Ldap;
|
||||
|
||||
use Exception;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\Protocol\Ldap\Exception as LdapException;
|
||||
use Icinga\Application\Platform;
|
||||
|
@ -76,7 +75,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()
|
||||
|
|
|
@ -132,12 +132,15 @@ class Number extends FormElement
|
|||
*/
|
||||
public function isValid($value, $context = null)
|
||||
{
|
||||
$this->setValue($value);
|
||||
$value = $this->getValue();
|
||||
if (! is_numeric($value)) {
|
||||
$this->addError(sprintf($this->translate('\'%s\' is not a valid number'), $value));
|
||||
if (! parent::isValid($value, $context)) {
|
||||
return false;
|
||||
}
|
||||
return parent::isValid($value, $context);
|
||||
|
||||
if ((! empty($value) || !$this->getAllowEmpty()) && !is_numeric($value)) {
|
||||
$this->addError(sprintf(t('\'%s\' is not a valid number'), $value));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue