2013-08-16 16:24:12 +02:00
|
|
|
<?php
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
/**
|
|
|
|
* This file is part of Icinga 2 Web.
|
2013-08-21 11:02:53 +02:00
|
|
|
*
|
2013-08-16 16:24:12 +02:00
|
|
|
* Icinga 2 Web - Head for multiple monitoring backends.
|
|
|
|
* Copyright (C) 2013 Icinga Development Team
|
2013-08-21 11:02:53 +02:00
|
|
|
*
|
2013-08-16 16:24:12 +02:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2013-08-21 11:02:53 +02:00
|
|
|
*
|
2013-08-16 16:24:12 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2013-08-21 11:02:53 +02:00
|
|
|
*
|
2013-08-16 16:24:12 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2013-08-21 11:02:53 +02:00
|
|
|
*
|
2013-08-16 16:24:12 +02:00
|
|
|
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
|
|
|
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
|
|
|
* @author Icinga Development Team <info@icinga.org>
|
|
|
|
*/
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
|
|
|
namespace Icinga\Form\Config\Authentication;
|
|
|
|
|
2013-08-26 16:56:23 +02:00
|
|
|
use \Icinga\Authentication\Backend\LdapUserBackend;
|
|
|
|
use \Exception;
|
2013-08-21 11:02:53 +02:00
|
|
|
use \Zend_Config;
|
2013-08-16 16:24:12 +02:00
|
|
|
use \Icinga\Web\Form;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Form for adding or modifying LDAP authentication backends
|
|
|
|
*/
|
|
|
|
class LdapBackendForm extends BaseBackendForm
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Create this form and add all required elements
|
|
|
|
*
|
|
|
|
* @see Form::create()
|
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
2013-08-28 10:12:27 +02:00
|
|
|
$this->setName('form_modify_backend');
|
2013-08-16 16:24:12 +02:00
|
|
|
$name = $this->filterName($this->getBackendName());
|
|
|
|
$backend = $this->getBackend();
|
|
|
|
|
|
|
|
$this->addElement(
|
|
|
|
'text',
|
|
|
|
'backend_'.$name.'_name',
|
|
|
|
array(
|
2013-08-21 11:02:53 +02:00
|
|
|
'required' => true,
|
|
|
|
'allowEmpty' => false,
|
|
|
|
'label' => 'Backend Name',
|
|
|
|
'helptext' => 'The name of this authentication backend',
|
|
|
|
'value' => $this->getBackendName()
|
2013-08-16 16:24:12 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->addElement(
|
|
|
|
'text',
|
|
|
|
'backend_' . $name . '_hostname',
|
|
|
|
array(
|
2013-08-20 17:30:28 +02:00
|
|
|
'label' => 'LDAP Server Host',
|
2013-08-16 16:24:12 +02:00
|
|
|
'allowEmpty' => false,
|
2013-08-19 18:25:20 +02:00
|
|
|
'value' => $backend->get('hostname', 'localhost'),
|
|
|
|
'helptext' => 'The hostname or address of the LDAP server to use for authentication',
|
|
|
|
'required' => true
|
2013-08-16 16:24:12 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->addElement(
|
|
|
|
'text',
|
|
|
|
'backend_' . $name . '_root_dn',
|
|
|
|
array(
|
2013-08-20 17:30:28 +02:00
|
|
|
'label' => 'LDAP Root DN',
|
2013-08-19 18:25:20 +02:00
|
|
|
'value' => $backend->get('root_dn', 'ou=people,dc=icinga,dc=org'),
|
2013-08-21 11:02:53 +02:00
|
|
|
'helptext' => 'The path where users can be found on the ldap server',
|
2013-08-16 16:24:12 +02:00
|
|
|
'required' => true
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->addElement(
|
|
|
|
'text',
|
|
|
|
'backend_' . $name . '_bind_dn',
|
|
|
|
array(
|
2013-08-20 17:30:28 +02:00
|
|
|
'label' => 'LDAP Bind DN',
|
2013-08-16 16:24:12 +02:00
|
|
|
'value' => $backend->get('bind_dn', 'cn=admin,cn=config'),
|
2013-08-21 11:02:53 +02:00
|
|
|
'helptext' => 'The user dn to use for querying the ldap server',
|
2013-08-16 16:24:12 +02:00
|
|
|
'required' => true
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->addElement(
|
|
|
|
'password',
|
|
|
|
'backend_' . $name . '_bind_pw',
|
|
|
|
array(
|
2013-08-21 11:02:53 +02:00
|
|
|
'label' => 'LDAP Bind Password',
|
|
|
|
'renderPassword' => true,
|
|
|
|
'value' => $backend->get('bind_pw', 'admin'),
|
|
|
|
'helptext' => 'The password to use for querying the ldap server',
|
|
|
|
'required' => true
|
2013-08-16 16:24:12 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->addElement(
|
|
|
|
'text',
|
2013-08-19 18:25:20 +02:00
|
|
|
'backend_' . $name . '_user_class',
|
2013-08-16 16:24:12 +02:00
|
|
|
array(
|
2013-08-20 17:30:28 +02:00
|
|
|
'label' => 'LDAP User Object Class',
|
2013-08-16 16:24:12 +02:00
|
|
|
'value' => $backend->get('user_class', 'inetOrgPerson'),
|
2013-08-19 18:25:20 +02:00
|
|
|
'helptext' => 'The object class used for storing users on the ldap server',
|
2013-08-16 16:24:12 +02:00
|
|
|
'required' => true
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->addElement(
|
|
|
|
'text',
|
2013-08-19 18:25:20 +02:00
|
|
|
'backend_' . $name . '_user_name_attribute',
|
2013-08-16 16:24:12 +02:00
|
|
|
array(
|
2013-08-20 17:30:28 +02:00
|
|
|
'label' => 'LDAP User Name Attribute',
|
2013-08-16 16:24:12 +02:00
|
|
|
'value' => $backend->get('user_name_attribute', 'uid'),
|
2013-08-19 18:25:20 +02:00
|
|
|
'helptext' => 'The attribute name used for storing the user name on the ldap server',
|
2013-08-16 16:24:12 +02:00
|
|
|
'required' => true
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2013-08-22 17:27:11 +02:00
|
|
|
$this->setSubmitLabel('{{SAVE_ICON}} Save Backend');
|
2013-08-16 16:24:12 +02:00
|
|
|
}
|
|
|
|
|
2013-08-26 16:56:23 +02:00
|
|
|
|
2013-08-16 16:24:12 +02:00
|
|
|
/**
|
|
|
|
* Return the ldap authentication backend configuration for this form
|
|
|
|
*
|
2013-08-21 11:02:53 +02:00
|
|
|
* @return array
|
|
|
|
*
|
|
|
|
* @see BaseBackendForm::getConfig()
|
2013-08-16 16:24:12 +02:00
|
|
|
*/
|
|
|
|
public function getConfig()
|
|
|
|
{
|
|
|
|
$name = $this->getBackendName();
|
|
|
|
$prefix = 'backend_' . $this->filterName($name) . '_';
|
|
|
|
|
|
|
|
$section = $this->getValue($prefix . 'name');
|
|
|
|
$cfg = array(
|
2013-08-21 11:02:53 +02:00
|
|
|
'backend' => 'ldap',
|
|
|
|
'target' => 'user',
|
|
|
|
'hostname' => $this->getValue($prefix . 'hostname'),
|
|
|
|
'root_dn' => $this->getValue($prefix . 'root_dn'),
|
|
|
|
'bind_dn' => $this->getValue($prefix . 'bind_dn'),
|
|
|
|
'bind_pw' => $this->getValue($prefix . 'bind_pw'),
|
|
|
|
'user_class' => $this->getValue($prefix . 'user_class'),
|
|
|
|
'user_name_attribute' => $this->getValue($prefix . 'user_name_attribute')
|
2013-08-16 16:24:12 +02:00
|
|
|
);
|
|
|
|
return array(
|
|
|
|
$section => $cfg
|
|
|
|
);
|
|
|
|
}
|
2013-08-26 16:56:23 +02:00
|
|
|
|
2013-08-27 14:37:22 +02:00
|
|
|
/**
|
|
|
|
* Validate the current configuration by creating a backend and requesting the user count
|
|
|
|
*
|
|
|
|
* @return bool True when the backend is valid, false otherwise
|
|
|
|
* @see BaseBackendForm::isValidAuthenticationBacken
|
|
|
|
*/
|
|
|
|
public function isValidAuthenticationBackend()
|
2013-08-26 16:56:23 +02:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
$cfg = $this->getConfig();
|
2013-08-27 14:37:22 +02:00
|
|
|
$backendName = 'backend_' . $this->filterName($this->getBackendName()) . '_name';
|
2013-08-26 16:56:23 +02:00
|
|
|
$testConn = new LdapUserBackend(
|
2013-08-27 14:37:22 +02:00
|
|
|
new Zend_Config($cfg[$this->getValue($backendName)])
|
2013-08-26 16:56:23 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
if ($testConn->getUserCount() === 0) {
|
|
|
|
throw new Exception('No Users Found On Directory Server');
|
|
|
|
}
|
2013-08-27 14:37:22 +02:00
|
|
|
} catch (Exception $exc) {
|
2013-08-26 16:56:23 +02:00
|
|
|
|
|
|
|
$this->addErrorMessage(
|
|
|
|
'Connection Validation Failed:'.
|
|
|
|
$exc->getMessage()
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2013-08-16 16:24:12 +02:00
|
|
|
}
|