mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-25 14:54:24 +02:00
LdapBackendForm: Allow to discover a connection's default settings
refs #9602
This commit is contained in:
parent
f06be5c9bc
commit
760c7e4374
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
namespace Icinga\Forms\Config\UserBackend;
|
namespace Icinga\Forms\Config\UserBackend;
|
||||||
|
|
||||||
|
use Icinga\Data\ResourceFactory;
|
||||||
use Icinga\Web\Form;
|
use Icinga\Web\Form;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -86,6 +87,60 @@ class LdapBackendForm extends Form
|
|||||||
: array()
|
: array()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$baseDn = null;
|
||||||
|
$hasAdOid = false;
|
||||||
|
if (! $isAd && !empty($this->resources)) {
|
||||||
|
$this->addElement(
|
||||||
|
'button',
|
||||||
|
'discovery_btn',
|
||||||
|
array(
|
||||||
|
'type' => 'submit',
|
||||||
|
'value' => 'discovery_btn',
|
||||||
|
'label' => $this->translate('Discover', 'A button to discover LDAP capabilities'),
|
||||||
|
'title' => $this->translate(
|
||||||
|
'Push to fill in the chosen connection\'s default settings.'
|
||||||
|
),
|
||||||
|
'decorators' => array(
|
||||||
|
array('ViewHelper', array('separator' => '')),
|
||||||
|
array('HtmlTag', array('tag' => 'div', 'class' => 'element'))
|
||||||
|
),
|
||||||
|
'formnovalidate' => 'formnovalidate'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->addDisplayGroup(
|
||||||
|
array('resource', 'discovery_btn'),
|
||||||
|
'connection_discovery',
|
||||||
|
array(
|
||||||
|
'decorators' => array(
|
||||||
|
'FormElements',
|
||||||
|
array('HtmlTag', array('tag' => 'div', 'class' => 'control-group'))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($this->getElement('discovery_btn')->isChecked()) {
|
||||||
|
$connection = ResourceFactory::create(
|
||||||
|
isset($formData['resource']) ? $formData['resource'] : reset($this->resources)
|
||||||
|
);
|
||||||
|
$capabilities = $connection->bind()->getCapabilities();
|
||||||
|
$baseDn = $capabilities->getDefaultNamingContext();
|
||||||
|
$hasAdOid = $capabilities->isActiveDirectory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($isAd || $hasAdOid) {
|
||||||
|
// ActiveDirectory defaults
|
||||||
|
$userClass = 'user';
|
||||||
|
$filter = '!(objectClass=computer)';
|
||||||
|
$userNameAttribute = 'sAMAccountName';
|
||||||
|
} else {
|
||||||
|
// OpenLDAP defaults
|
||||||
|
$userClass = 'inetOrgPerson';
|
||||||
|
$filter = null;
|
||||||
|
$userNameAttribute = 'uid';
|
||||||
|
}
|
||||||
|
|
||||||
$this->addElement(
|
$this->addElement(
|
||||||
'text',
|
'text',
|
||||||
'user_class',
|
'user_class',
|
||||||
@ -96,7 +151,7 @@ class LdapBackendForm extends Form
|
|||||||
'disabled' => $isAd ?: null,
|
'disabled' => $isAd ?: null,
|
||||||
'label' => $this->translate('LDAP User Object Class'),
|
'label' => $this->translate('LDAP User Object Class'),
|
||||||
'description' => $this->translate('The object class used for storing users on the LDAP server.'),
|
'description' => $this->translate('The object class used for storing users on the LDAP server.'),
|
||||||
'value' => $isAd ? 'user' : 'inetOrgPerson'
|
'value' => $userClass
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->addElement(
|
$this->addElement(
|
||||||
@ -105,7 +160,7 @@ class LdapBackendForm extends Form
|
|||||||
array(
|
array(
|
||||||
'preserveDefault' => true,
|
'preserveDefault' => true,
|
||||||
'allowEmpty' => true,
|
'allowEmpty' => true,
|
||||||
'value' => $isAd ? '!(objectClass=computer)' : null,
|
'value' => $filter,
|
||||||
'label' => $this->translate('LDAP Filter'),
|
'label' => $this->translate('LDAP Filter'),
|
||||||
'description' => $this->translate(
|
'description' => $this->translate(
|
||||||
'An additional filter to use when looking up users using the specified connection. '
|
'An additional filter to use when looking up users using the specified connection. '
|
||||||
@ -148,7 +203,7 @@ class LdapBackendForm extends Form
|
|||||||
'description' => $this->translate(
|
'description' => $this->translate(
|
||||||
'The attribute name used for storing the user name on the LDAP server.'
|
'The attribute name used for storing the user name on the LDAP server.'
|
||||||
),
|
),
|
||||||
'value' => $isAd ? 'sAMAccountName' : 'uid'
|
'value' => $userNameAttribute
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->addElement(
|
$this->addElement(
|
||||||
@ -163,12 +218,14 @@ class LdapBackendForm extends Form
|
|||||||
'text',
|
'text',
|
||||||
'base_dn',
|
'base_dn',
|
||||||
array(
|
array(
|
||||||
'required' => false,
|
'preserveDefault' => true,
|
||||||
'label' => $this->translate('LDAP Base DN'),
|
'required' => false,
|
||||||
'description' => $this->translate(
|
'label' => $this->translate('LDAP Base DN'),
|
||||||
|
'description' => $this->translate(
|
||||||
'The path where users can be found on the LDAP server. Leave ' .
|
'The path where users can be found on the LDAP server. Leave ' .
|
||||||
'empty to select all users available using the specified connection.'
|
'empty to select all users available using the specified connection.'
|
||||||
)
|
),
|
||||||
|
'value' => $baseDn
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user