2014-09-29 06:27:58 -04:00
|
|
|
<?php
|
2015-02-04 04:46:36 -05:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
2014-09-29 06:27:58 -04:00
|
|
|
|
2014-11-14 05:01:16 -05:00
|
|
|
namespace Icinga\Module\Setup\Forms;
|
2014-09-29 06:27:58 -04:00
|
|
|
|
|
|
|
|
use Icinga\Web\Form;
|
2014-11-14 04:57:14 -05:00
|
|
|
use Icinga\Forms\Config\Resource\LdapResourceForm;
|
2014-09-29 06:27:58 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Wizard page to define the connection details for a LDAP resource
|
|
|
|
|
*/
|
|
|
|
|
class LdapResourcePage extends Form
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Initialize this page
|
|
|
|
|
*/
|
|
|
|
|
public function init()
|
|
|
|
|
{
|
|
|
|
|
$this->setName('setup_ldap_resource');
|
2015-03-02 12:36:04 -05:00
|
|
|
$this->setTitle($this->translate('LDAP Resource', 'setup.page.title'));
|
|
|
|
|
$this->addDescription($this->translate(
|
|
|
|
|
'Now please configure your AD/LDAP resource. This will later '
|
|
|
|
|
. 'be used to authenticate users logging in to Icinga Web 2.'
|
|
|
|
|
));
|
2014-09-29 06:27:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @see Form::createElements()
|
|
|
|
|
*/
|
|
|
|
|
public function createElements(array $formData)
|
|
|
|
|
{
|
|
|
|
|
$this->addElement(
|
|
|
|
|
'hidden',
|
|
|
|
|
'type',
|
|
|
|
|
array(
|
|
|
|
|
'required' => true,
|
|
|
|
|
'value' => 'ldap'
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (isset($formData['skip_validation']) && $formData['skip_validation']) {
|
|
|
|
|
$this->addSkipValidationCheckbox();
|
|
|
|
|
} else {
|
|
|
|
|
$this->addElement(
|
|
|
|
|
'hidden',
|
|
|
|
|
'skip_validation',
|
|
|
|
|
array(
|
|
|
|
|
'required' => true,
|
|
|
|
|
'value' => 0
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$resourceForm = new LdapResourceForm();
|
|
|
|
|
$this->addElements($resourceForm->createElements($formData)->getElements());
|
2014-11-11 06:41:02 -05:00
|
|
|
$this->getElement('name')->setValue('icingaweb_ldap');
|
2014-09-29 06:27:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Validate the given form data and check whether a BIND-request is successful
|
|
|
|
|
*
|
|
|
|
|
* @param array $data The data to validate
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function isValid($data)
|
|
|
|
|
{
|
|
|
|
|
if (false === parent::isValid($data)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (false === isset($data['skip_validation']) || $data['skip_validation'] == 0) {
|
|
|
|
|
if (false === LdapResourceForm::isValidResource($this)) {
|
|
|
|
|
$this->addSkipValidationCheckbox();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a checkbox to the form by which the user can skip the connection validation
|
|
|
|
|
*/
|
|
|
|
|
protected function addSkipValidationCheckbox()
|
|
|
|
|
{
|
|
|
|
|
$this->addElement(
|
|
|
|
|
'checkbox',
|
|
|
|
|
'skip_validation',
|
|
|
|
|
array(
|
|
|
|
|
'required' => true,
|
2015-01-19 05:07:39 -05:00
|
|
|
'label' => $this->translate('Skip Validation'),
|
|
|
|
|
'description' => $this->translate(
|
2014-11-11 03:24:53 -05:00
|
|
|
'Check this to not to validate connectivity with the given directory service'
|
|
|
|
|
)
|
2014-09-29 06:27:58 -04:00
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|