Skip to content

Commit

Permalink
Merge pull request #2711 from Icinga/bugfix/improve-error-handling-an…
Browse files Browse the repository at this point in the history
…d-validation-of-multiple-ldap-uris-2645

fixes #2645
  • Loading branch information
nilmerg authored Feb 2, 2017
2 parents 35ba15a + 8d3e8b8 commit 5b4de83
Show file tree
Hide file tree
Showing 5 changed files with 985 additions and 906 deletions.
38 changes: 34 additions & 4 deletions application/forms/Config/Resource/LdapResourceForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Icinga\Forms\Config\Resource;

use Icinga\Web\Form;
use Icinga\Web\Url;
use Icinga\Protocol\Ldap\LdapConnection;

/**
Expand All @@ -20,9 +21,7 @@ public function init()
}

/**
* Create and add elements to this form
*
* @param array $formData The data sent by the user
* {@inheritdoc}
*/
public function createElements(array $formData)
{
Expand All @@ -49,7 +48,38 @@ public function createElements(array $formData)
'The hostname or address of the LDAP server to use for authentication.'
. ' You can also provide multiple hosts separated by a space'
),
'value' => 'localhost'
'value' => 'localhost',
'validators' => array(
array(
'Callback',
false,
array(
'callback' => function ($v) {
$withoutScheme = $withScheme = false;
foreach (explode(' ', $v) as $uri) {
if (preg_match('~^(?<!://)[^:]+:\d+$~', $uri)) {
return false;
}

$url = Url::fromPath($uri);
if ($url->getScheme()) {
$withScheme = true;
} else {
$withoutScheme = true;
}
}

return $withScheme ^ $withoutScheme;
},
'messages' => array(
'callbackValue' => $this->translate(
'A protocol scheme such as ldap:// or ldaps:// is mandatory for URIs with a given'
. ' port and for all other URIs as well once a scheme is given for a single one.'
)
)
)
)
)
)
);
$this->addElement(
Expand Down
Binary file modified application/locale/de_DE/LC_MESSAGES/icinga.mo
Binary file not shown.
Loading

0 comments on commit 5b4de83

Please sign in to comment.