2014-10-09 04:20:07 -04:00
|
|
|
<?php
|
2026-03-26 12:46:27 -04:00
|
|
|
|
|
|
|
|
// SPDX-FileCopyrightText: 2018 Icinga GmbH <https://icinga.com>
|
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
2014-10-09 04:20:07 -04:00
|
|
|
|
2014-11-14 05:01:16 -05:00
|
|
|
namespace Icinga\Module\Setup\Forms;
|
2014-10-09 04:20:07 -04:00
|
|
|
|
2015-03-10 08:24:54 -04:00
|
|
|
use Exception;
|
2015-03-02 12:19:41 -05:00
|
|
|
use Zend_Validate_NotEmpty;
|
2016-02-12 08:18:40 -05:00
|
|
|
use Icinga\Exception\IcingaException;
|
2014-10-09 04:20:07 -04:00
|
|
|
use Icinga\Web\Form;
|
2015-03-02 12:19:41 -05:00
|
|
|
use Icinga\Web\Form\ErrorLabeller;
|
2014-11-14 04:57:14 -05:00
|
|
|
use Icinga\Forms\LdapDiscoveryForm;
|
2014-11-18 03:45:54 -05:00
|
|
|
use Icinga\Protocol\Ldap\Discovery;
|
|
|
|
|
use Icinga\Module\Setup\Forms\LdapDiscoveryConfirmPage;
|
2014-10-09 04:20:07 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Wizard page to define the connection details for a LDAP resource
|
|
|
|
|
*/
|
|
|
|
|
class LdapDiscoveryPage extends Form
|
|
|
|
|
{
|
|
|
|
|
/**
|
2014-11-18 03:45:54 -05:00
|
|
|
* @var Discovery
|
2014-10-09 04:20:07 -04:00
|
|
|
*/
|
2014-11-18 03:45:54 -05:00
|
|
|
private $discovery;
|
2014-10-09 04:20:07 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initialize this page
|
|
|
|
|
*/
|
|
|
|
|
public function init()
|
|
|
|
|
{
|
|
|
|
|
$this->setName('setup_ldap_discovery');
|
2015-03-02 12:36:04 -05:00
|
|
|
$this->setTitle($this->translate('LDAP Discovery', 'setup.page.title'));
|
|
|
|
|
$this->addDescription($this->translate(
|
|
|
|
|
'You can use this page to discover LDAP or ActiveDirectory servers ' .
|
2017-07-28 16:02:23 -04:00
|
|
|
' for authentication. If you don\'t want to execute a discovery, just skip this step.'
|
2015-03-02 12:36:04 -05:00
|
|
|
));
|
2014-10-09 04:20:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @see Form::createElements()
|
|
|
|
|
*/
|
|
|
|
|
public function createElements(array $formData)
|
|
|
|
|
{
|
2014-11-18 03:45:54 -05:00
|
|
|
$discoveryForm = new LdapDiscoveryForm();
|
|
|
|
|
$this->addElements($discoveryForm->createElements($formData)->getElements());
|
2014-10-09 04:20:07 -04:00
|
|
|
|
|
|
|
|
$this->addElement(
|
|
|
|
|
'checkbox',
|
|
|
|
|
'skip_validation',
|
|
|
|
|
array(
|
2015-01-19 05:07:39 -05:00
|
|
|
'label' => $this->translate('Skip'),
|
|
|
|
|
'description' => $this->translate('Do not discover LDAP servers and enter all settings manually.')
|
2014-10-09 04:20:07 -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;
|
|
|
|
|
}
|
2015-03-02 12:19:41 -05:00
|
|
|
if (isset($data['skip_validation']) && $data['skip_validation']) {
|
2014-11-18 03:45:54 -05:00
|
|
|
return true;
|
2014-10-09 04:20:07 -04:00
|
|
|
}
|
2014-10-17 10:00:52 -04:00
|
|
|
|
2015-03-02 12:19:41 -05:00
|
|
|
if (isset($data['domain']) && $data['domain']) {
|
2015-03-10 08:24:54 -04:00
|
|
|
try {
|
|
|
|
|
$this->discovery = Discovery::discoverDomain($data['domain']);
|
|
|
|
|
if ($this->discovery->isSuccess()) {
|
|
|
|
|
return true;
|
2017-10-26 04:25:37 -04:00
|
|
|
} else {
|
|
|
|
|
$this->error($this->discovery->getError()->getMessage());
|
2015-03-10 08:24:54 -04:00
|
|
|
}
|
|
|
|
|
} catch (Exception $e) {
|
2016-02-12 08:18:40 -05:00
|
|
|
$this->error(sprintf(
|
|
|
|
|
$this->translate('Could not find any LDAP servers on the domain "%s". An error occurred: %s'),
|
|
|
|
|
$data['domain'],
|
|
|
|
|
IcingaException::describe($e)
|
|
|
|
|
));
|
2014-11-18 03:45:54 -05:00
|
|
|
}
|
2015-03-02 12:19:41 -05:00
|
|
|
} else {
|
|
|
|
|
$labeller = new ErrorLabeller(array('element' => $this->getElement('domain')));
|
|
|
|
|
$this->getElement('domain')->addError($labeller->translate(Zend_Validate_NotEmpty::IS_EMPTY));
|
2014-11-18 03:45:54 -05:00
|
|
|
}
|
2015-03-02 12:19:41 -05:00
|
|
|
|
2014-11-18 03:45:54 -05:00
|
|
|
return false;
|
2014-10-09 04:20:07 -04:00
|
|
|
}
|
|
|
|
|
|
2014-11-18 03:45:54 -05:00
|
|
|
/**
|
|
|
|
|
* Suggest settings based on the underlying discovery
|
|
|
|
|
*
|
|
|
|
|
* @param bool $suppressArrayNotation
|
|
|
|
|
*
|
2021-11-16 07:33:45 -05:00
|
|
|
* @return array
|
2014-11-18 03:45:54 -05:00
|
|
|
*/
|
2014-10-09 04:20:07 -04:00
|
|
|
public function getValues($suppressArrayNotation = false)
|
|
|
|
|
{
|
2014-11-18 03:45:54 -05:00
|
|
|
if (! isset($this->discovery) || ! $this->discovery->isSuccess()) {
|
2021-11-16 07:33:45 -05:00
|
|
|
return [];
|
2014-10-09 04:20:07 -04:00
|
|
|
}
|
2014-11-18 03:45:54 -05:00
|
|
|
$disc = $this->discovery;
|
2014-10-09 04:20:07 -04:00
|
|
|
return array(
|
|
|
|
|
'domain' => $this->getValue('domain'),
|
2014-11-18 03:45:54 -05:00
|
|
|
'type' => $disc->isAd() ? LdapDiscoveryConfirmPage::TYPE_AD : LdapDiscoveryConfirmPage::TYPE_MISC,
|
|
|
|
|
'resource' => $disc->suggestResourceSettings(),
|
|
|
|
|
'backend' => $disc->suggestBackendSettings()
|
2014-10-09 04:20:07 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|