icingaweb2/modules/setup/application/forms/LdapDiscoveryPage.php

107 lines
3.0 KiB
PHP
Raw Normal View History

2014-10-09 10:20:07 +02:00
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Setup\Form;
2014-10-09 10:20:07 +02:00
use Icinga\Web\Form;
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(
'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(
'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,
'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;
}
if (! $data['skip_validation'] && false === $this->discoveryForm->isValid($data)) {
2014-10-09 10:20:07 +02:00
return false;
}
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()
);
}
}