2014-10-09 10:20:07 +02:00
|
|
|
<?php
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
2014-11-10 16:31:40 +01:00
|
|
|
namespace Icinga\Module\Setup\Form;
|
2014-10-09 10:20:07 +02:00
|
|
|
|
|
|
|
use Icinga\Web\Form;
|
2014-11-14 10:57:14 +01:00
|
|
|
use Icinga\Forms\LdapDiscoveryForm;
|
2014-10-09 10:20:07 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Wizard page to define the connection details for a LDAP resource
|
|
|
|
*/
|
|
|
|
class LdapDiscoveryPage extends Form
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var LdapDiscoveryForm
|
|
|
|
*/
|
|
|
|
private $discoveryForm;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize this page
|
|
|
|
*/
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$this->setName('setup_ldap_discovery');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see Form::createElements()
|
|
|
|
*/
|
|
|
|
public function createElements(array $formData)
|
|
|
|
{
|
2014-11-11 15:27:14 +01:00
|
|
|
$this->addElement(
|
2014-11-14 10:15:11 +01:00
|
|
|
'note',
|
|
|
|
'title',
|
|
|
|
array(
|
|
|
|
'value' => mt('setup', 'LDAP Discovery', 'setup.page.title'),
|
|
|
|
'decorators' => array(
|
|
|
|
'ViewHelper',
|
|
|
|
array('HtmlTag', array('tag' => 'h2'))
|
2014-11-11 15:27:14 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2014-10-09 10:20:07 +02:00
|
|
|
$this->addElement(
|
2014-11-14 10:15:11 +01:00
|
|
|
'note',
|
|
|
|
'description',
|
|
|
|
array(
|
|
|
|
'value' => mt(
|
|
|
|
'setup',
|
|
|
|
'You can use this page to discover LDAP or ActiveDirectory servers ' .
|
|
|
|
' for authentication. If you don\' want to execute a discovery, just skip this step.'
|
2014-10-09 10:20:07 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->discoveryForm = new LdapDiscoveryForm();
|
|
|
|
$this->addElements($this->discoveryForm->createElements($formData)->getElements());
|
2014-11-11 15:27:14 +01:00
|
|
|
$this->getElement('domain')->setRequired(
|
|
|
|
isset($formData['skip_validation']) === false || ! $formData['skip_validation']
|
|
|
|
);
|
2014-10-09 10:20:07 +02:00
|
|
|
|
|
|
|
$this->addElement(
|
|
|
|
'checkbox',
|
|
|
|
'skip_validation',
|
|
|
|
array(
|
|
|
|
'required' => true,
|
2014-11-11 09:24:53 +01:00
|
|
|
'label' => mt('setup', 'Skip'),
|
|
|
|
'description' => mt('setup', 'Do not discover LDAP servers and enter all settings manually.')
|
2014-10-09 10:20:07 +02: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;
|
|
|
|
}
|
2014-10-17 16:00:52 +02:00
|
|
|
|
|
|
|
if (! $data['skip_validation'] && false === $this->discoveryForm->isValid($data)) {
|
2014-10-09 10:20:07 +02:00
|
|
|
return false;
|
|
|
|
}
|
2014-10-17 16:00:52 +02:00
|
|
|
|
2014-10-09 10:20:07 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getValues($suppressArrayNotation = false)
|
|
|
|
{
|
|
|
|
if (! isset($this->discoveryForm) || ! $this->discoveryForm->hasSuggestion()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return array(
|
|
|
|
'domain' => $this->getValue('domain'),
|
|
|
|
'type' => $this->discoveryForm->isAd() ?
|
|
|
|
LdapDiscoveryConfirmPage::TYPE_AD : LdapDiscoveryConfirmPage::TYPE_MISC,
|
|
|
|
'resource' => $this->discoveryForm->suggestResourceSettings(),
|
|
|
|
'backend' => $this->discoveryForm->suggestBackendSettings()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|