2014-09-02 15:39:21 +02:00
|
|
|
<?php
|
2016-02-08 15:41:00 +01:00
|
|
|
/* Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */
|
2014-09-02 15:39:21 +02:00
|
|
|
|
2014-11-14 10:57:14 +01:00
|
|
|
namespace Icinga\Forms\Config\Resource;
|
2014-09-02 15:39:21 +02:00
|
|
|
|
|
|
|
use Icinga\Web\Form;
|
2017-02-02 11:08:07 +01:00
|
|
|
use Icinga\Web\Url;
|
2015-06-24 09:05:29 +02:00
|
|
|
use Icinga\Protocol\Ldap\LdapConnection;
|
2014-09-02 15:39:21 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Form class for adding/modifying ldap resources
|
|
|
|
*/
|
|
|
|
class LdapResourceForm extends Form
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Initialize this form
|
|
|
|
*/
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$this->setName('form_config_resource_ldap');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-02-02 11:08:07 +01:00
|
|
|
* {@inheritdoc}
|
2014-09-02 15:39:21 +02:00
|
|
|
*/
|
|
|
|
public function createElements(array $formData)
|
|
|
|
{
|
2015-06-24 09:05:29 +02:00
|
|
|
$defaultPort = ! array_key_exists('encryption', $formData) || $formData['encryption'] !== LdapConnection::LDAPS
|
2015-04-07 15:06:32 +02:00
|
|
|
? 389
|
|
|
|
: 636;
|
|
|
|
|
2014-09-29 11:20:39 +02:00
|
|
|
$this->addElement(
|
|
|
|
'text',
|
|
|
|
'name',
|
|
|
|
array(
|
|
|
|
'required' => true,
|
2015-01-19 11:26:23 +01:00
|
|
|
'label' => $this->translate('Resource Name'),
|
2015-03-11 08:00:20 +01:00
|
|
|
'description' => $this->translate('The unique name of this resource')
|
2014-09-29 11:20:39 +02:00
|
|
|
)
|
|
|
|
);
|
2014-09-03 12:21:31 +02:00
|
|
|
$this->addElement(
|
|
|
|
'text',
|
|
|
|
'hostname',
|
|
|
|
array(
|
|
|
|
'required' => true,
|
2015-01-19 11:26:23 +01:00
|
|
|
'label' => $this->translate('Host'),
|
|
|
|
'description' => $this->translate(
|
2016-12-12 16:42:56 +01:00
|
|
|
'The hostname or address of the LDAP server to use for authentication.'
|
|
|
|
. ' You can also provide multiple hosts separated by a space'
|
2015-01-19 11:26:23 +01:00
|
|
|
),
|
2019-04-23 10:56:05 +02:00
|
|
|
'value' => 'localhost'
|
2014-09-03 12:21:31 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->addElement(
|
2014-11-14 10:15:11 +01:00
|
|
|
'number',
|
|
|
|
'port',
|
|
|
|
array(
|
2015-04-07 15:06:32 +02:00
|
|
|
'required' => true,
|
|
|
|
'preserveDefault' => true,
|
|
|
|
'label' => $this->translate('Port'),
|
|
|
|
'description' => $this->translate('The port of the LDAP server to use for authentication'),
|
|
|
|
'value' => $defaultPort
|
2014-09-02 15:39:21 +02:00
|
|
|
)
|
|
|
|
);
|
2015-03-12 15:17:19 +01:00
|
|
|
$this->addElement(
|
|
|
|
'select',
|
2015-03-13 00:02:18 +01:00
|
|
|
'encryption',
|
2015-03-12 15:17:19 +01:00
|
|
|
array(
|
|
|
|
'required' => true,
|
|
|
|
'autosubmit' => true,
|
2015-03-13 00:02:18 +01:00
|
|
|
'label' => $this->translate('Encryption'),
|
2015-03-12 15:17:19 +01:00
|
|
|
'description' => $this->translate(
|
2015-03-13 00:00:21 +01:00
|
|
|
'Whether to encrypt communication. Choose STARTTLS or LDAPS for encrypted communication or'
|
2015-03-13 00:47:23 +01:00
|
|
|
. ' none for unencrypted communication'
|
2015-03-12 15:17:19 +01:00
|
|
|
),
|
|
|
|
'multiOptions' => array(
|
2015-06-24 09:05:29 +02:00
|
|
|
'none' => $this->translate('None', 'resource.ldap.encryption'),
|
|
|
|
LdapConnection::STARTTLS => 'STARTTLS',
|
|
|
|
LdapConnection::LDAPS => 'LDAPS'
|
2015-03-12 15:17:19 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2014-09-03 12:21:31 +02:00
|
|
|
$this->addElement(
|
|
|
|
'text',
|
|
|
|
'root_dn',
|
|
|
|
array(
|
|
|
|
'required' => true,
|
2015-01-19 11:26:23 +01:00
|
|
|
'label' => $this->translate('Root DN'),
|
|
|
|
'description' => $this->translate(
|
|
|
|
'Only the root and its child nodes will be accessible on this resource.'
|
|
|
|
)
|
2014-09-03 12:21:31 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->addElement(
|
|
|
|
'text',
|
|
|
|
'bind_dn',
|
|
|
|
array(
|
2015-01-19 11:26:23 +01:00
|
|
|
'label' => $this->translate('Bind DN'),
|
2015-05-22 14:15:59 +02:00
|
|
|
'description' => $this->translate(
|
|
|
|
'The user dn to use for querying the ldap server. Leave the dn and password empty for attempting'
|
|
|
|
. ' an anonymous bind'
|
|
|
|
)
|
2014-09-03 12:21:31 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->addElement(
|
|
|
|
'password',
|
|
|
|
'bind_pw',
|
|
|
|
array(
|
|
|
|
'renderPassword' => true,
|
2015-01-19 11:26:23 +01:00
|
|
|
'label' => $this->translate('Bind Password'),
|
2015-03-11 08:00:20 +01:00
|
|
|
'description' => $this->translate('The password to use for querying the ldap server')
|
2014-09-03 12:21:31 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2018-10-16 14:35:50 +02:00
|
|
|
$this->addElement(
|
|
|
|
'number',
|
|
|
|
'timeout',
|
|
|
|
array(
|
|
|
|
'preserveDefault' => true,
|
|
|
|
'label' => $this->translate('Timeout'),
|
|
|
|
'description' => $this->translate('Connection timeout for every LDAP connection'),
|
|
|
|
'value' => 5 // see LdapConnection::__construct()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2014-09-03 12:21:31 +02:00
|
|
|
return $this;
|
2014-09-02 15:39:21 +02:00
|
|
|
}
|
|
|
|
}
|