Implement Authentication form
- Allow creation of authentication providers - Allow modification of authentication providers - Allow reordering of authentication providers refs #3777
This commit is contained in:
parent
5a768ccaa9
commit
c705f5d475
|
@ -33,6 +33,8 @@ use \Icinga\Web\Hook\Configuration\ConfigurationTabBuilder;
|
|||
use \Icinga\Application\Icinga;
|
||||
use \Icinga\Form\Config\GeneralForm;
|
||||
use \Icinga\Form\Config\AuthenticationForm;
|
||||
use \Icinga\Form\Config\Authentication\LdapBackendForm;
|
||||
use \Icinga\Form\Config\Authentication\DbBackendForm;
|
||||
use \Icinga\Form\Config\LoggingForm;
|
||||
use \Icinga\Config\PreservingIniWriter;
|
||||
|
||||
|
@ -106,14 +108,7 @@ class ConfigController extends BaseConfigController
|
|||
$this->view->form = $form;
|
||||
}
|
||||
|
||||
public function authenticationAction()
|
||||
{
|
||||
$form = new AuthenticationForm();
|
||||
$form->setConfiguration(IcingaConfig::app('authentication'));
|
||||
$form->setRequest($this->_request);
|
||||
$form->isSubmittedAndValid();
|
||||
$this->view->form = $form;
|
||||
}
|
||||
|
||||
|
||||
public function loggingAction()
|
||||
{
|
||||
|
@ -156,6 +151,66 @@ class ConfigController extends BaseConfigController
|
|||
$this->redirectNow('config/moduleoverview?_render=body');
|
||||
}
|
||||
|
||||
private function writeAuthenticationFile(array $config)
|
||||
{
|
||||
$cfg = new Zend_Config($config);
|
||||
$writer = new Zend_Config_Writer_Ini(
|
||||
array(
|
||||
'config' => $cfg,
|
||||
'filename' => IcingaConfig::app('authentication')->getConfigFile()
|
||||
)
|
||||
);
|
||||
try {
|
||||
$writer->write();
|
||||
} catch (Exception $exc) {
|
||||
$this->view->exceptionMessage = $exc->getMessage();
|
||||
$this->view->iniConfigurationString = $writer->render();
|
||||
$this->render('authentication/show-configuration');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action for creating a new authentication backend
|
||||
*
|
||||
*/
|
||||
public function authenticationAction()
|
||||
{
|
||||
$form = new AuthenticationForm();
|
||||
$config = IcingaConfig::app('authentication');
|
||||
$form->setConfiguration($config);
|
||||
$form->setRequest($this->_request);
|
||||
|
||||
if ($form->isSubmittedAndValid()) {
|
||||
$this->writeAuthenticationFile($form->getConfig());
|
||||
}
|
||||
$this->view->form = $form;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Action for creating a new authentication backend
|
||||
*
|
||||
*/
|
||||
public function createauthenticationbackendAction()
|
||||
{
|
||||
if ($this->getRequest()->getParam('type') === 'ldap') {
|
||||
$form = new LdapBackendForm();
|
||||
} else {
|
||||
$form = new DbBackendForm();
|
||||
}
|
||||
$form->setRequest($this->getRequest());
|
||||
if ($form->isSubmittedAndValid()) {
|
||||
$backendCfg = IcingaConfig::app('authentication')->toArray();
|
||||
|
||||
foreach ($form->getConfig() as $backendName => $settings) {
|
||||
$backendCfg[$backendName] = $settings;
|
||||
}
|
||||
|
||||
$this->writeAuthenticationFile($backendCfg);
|
||||
}
|
||||
$this->view->form = $form;
|
||||
$this->render('authentication/modify');
|
||||
}
|
||||
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
|
|
@ -0,0 +1,140 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga 2 Web.
|
||||
*
|
||||
* Icinga 2 Web - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @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;
|
||||
|
||||
use \Icinga\Application\Config as IcingaConfig;
|
||||
use \Icinga\Application\Icinga;
|
||||
use \Icinga\Application\Logger;
|
||||
use \Icinga\Application\DbAdapterFactory;
|
||||
use \Icinga\Web\Form;
|
||||
use \Zend_Config;
|
||||
|
||||
/**
|
||||
* Base form for authentication backend forms
|
||||
*
|
||||
*/
|
||||
abstract class BaseBackendForm extends Form
|
||||
{
|
||||
/**
|
||||
* The name of the backend currently displayed in this form
|
||||
*
|
||||
* Will be the section in the authentication.ini file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $backendName = "";
|
||||
|
||||
/**
|
||||
* The backend configuration as a Zend_Config object
|
||||
*
|
||||
* @var Zend_Config
|
||||
*/
|
||||
private $backend = null;
|
||||
|
||||
/**
|
||||
* The resources to use instead of the factory provided ones (use for testing)
|
||||
*
|
||||
* @var Zend_Config
|
||||
*/
|
||||
private $resources = null;
|
||||
|
||||
/**
|
||||
* Set the name of the currently displayed backend
|
||||
*
|
||||
* @param string $name The name to be stored as the section when persisting
|
||||
*/
|
||||
public function setBackendName($name)
|
||||
{
|
||||
$this->backendName = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the backend name of this form
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBackendName()
|
||||
{
|
||||
return $this->backendName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the backend configuration or a empty Zend_Config object if none is given
|
||||
*
|
||||
* @return Zend_Config
|
||||
*/
|
||||
public function getBackend()
|
||||
{
|
||||
return ($this->backend !== null) ? $this->backend : new Zend_Config(array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the backend configuration for initial population
|
||||
*
|
||||
* @param Zend_Config $backend The backend to display in this form
|
||||
*/
|
||||
public function setBackend(Zend_Config $backend)
|
||||
{
|
||||
$this->backend = $backend;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an alternative array of resources that should be used instead of the DBFactory resource set
|
||||
* (used for testing)
|
||||
*
|
||||
* @param array $resources The resources to use for populating the db selection field
|
||||
*/
|
||||
public function setResources(array $resources)
|
||||
{
|
||||
$this->resources = $resources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return content of the resources.ini or previously set resources for displaying in the database selection field
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getResources()
|
||||
{
|
||||
if ($this->resources === null) {
|
||||
return DbAdapterFactory::getResources();
|
||||
} else {
|
||||
return $this->resources;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array containing all sections defined by this form as the key and all settings
|
||||
* as an keyvalue subarray
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function getConfig();
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga 2 Web.
|
||||
*
|
||||
* Icinga 2 Web - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @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;
|
||||
|
||||
|
||||
use \Icinga\Application\Config as IcingaConfig;
|
||||
use \Icinga\Application\Icinga;
|
||||
use \Icinga\Application\Logger;
|
||||
use \Icinga\Application\DbAdapterFactory;
|
||||
|
||||
use \Icinga\Web\Form;
|
||||
use \Zend_Config;
|
||||
|
||||
/**
|
||||
* Form class for adding/modifying database authentication backends
|
||||
*
|
||||
*/
|
||||
class DbBackendForm extends BaseBackendForm
|
||||
{
|
||||
|
||||
/**
|
||||
* Return a list of all database resource ready to be used as the multiOptions
|
||||
* attribute in a Zend_Form_Element_Select object
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getDatabaseResources()
|
||||
{
|
||||
$backends = array();
|
||||
foreach ($this->getResources() as $resname => $resource) {
|
||||
if ($resource['type'] !== 'db') {
|
||||
continue;
|
||||
}
|
||||
$backends[$resname] = $resname;
|
||||
}
|
||||
return $backends;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create this form and add all required elements
|
||||
*
|
||||
* @see Form::create()
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$name = $this->filterName($this->getBackendName());
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'backend_' . $name . '_name',
|
||||
array(
|
||||
'required' => true,
|
||||
'allowEmpty' => false,
|
||||
'label' => 'Backend name',
|
||||
'value' => $this->getBackendName()
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'select',
|
||||
'backend_' . $name . '_resource',
|
||||
array(
|
||||
'label' => 'Database connection',
|
||||
'required' => true,
|
||||
'allowEmpty' => false,
|
||||
'value' => $this->getBackend()->get('resource'),
|
||||
'multiOptions' => $this->getDatabaseResources()
|
||||
)
|
||||
);
|
||||
|
||||
$this->setSubmitLabel('Save backend');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the datatbase authentication backend configuration for this form
|
||||
*
|
||||
* @return array
|
||||
* @see BaseBackendForm::getConfig
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
$name = $this->getBackendName();
|
||||
$prefix = 'backend_' . $this->filterName($name) . '_';
|
||||
|
||||
$section = $this->getValue($prefix . 'name');
|
||||
$cfg = array(
|
||||
'backend' => 'db',
|
||||
'target' => 'user',
|
||||
'resource' => $this->getValue($prefix . 'resource'),
|
||||
);
|
||||
return array(
|
||||
$section => $cfg
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,157 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga 2 Web.
|
||||
*
|
||||
* Icinga 2 Web - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @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;
|
||||
|
||||
use \Icinga\Application\Config as IcingaConfig;
|
||||
use \Icinga\Application\Icinga;
|
||||
use \Icinga\Application\Logger;
|
||||
use \Icinga\Application\DbAdapterFactory;
|
||||
|
||||
use \Icinga\Web\Form;
|
||||
use \Zend_Config;
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
$name = $this->filterName($this->getBackendName());
|
||||
$backend = $this->getBackend();
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'backend_'.$name.'_name',
|
||||
array(
|
||||
'required' => true,
|
||||
'allowEmpty' => false,
|
||||
'label' => 'Backend name',
|
||||
'value' => $this->getBackendName()
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'backend_' . $name . '_hostname',
|
||||
array(
|
||||
'label' => 'LDAP server host',
|
||||
'allowEmpty' => false,
|
||||
'value' => $backend->get('hostname', 'localhost'),
|
||||
'required' => true
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'backend_' . $name . '_root_dn',
|
||||
array(
|
||||
'label' => 'LDAP root dn',
|
||||
'value' => $backend->get('hostname', 'ou=people,dc=icinga,dc=org'),
|
||||
'required' => true
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'backend_' . $name . '_bind_dn',
|
||||
array(
|
||||
'label' => 'LDAP bind dn',
|
||||
'value' => $backend->get('bind_dn', 'cn=admin,cn=config'),
|
||||
'required' => true
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'password',
|
||||
'backend_' . $name . '_bind_pw',
|
||||
array(
|
||||
'label' => 'LDAP bind password',
|
||||
'renderPassword' => true,
|
||||
'value' => $backend->get('bind_pw', 'admin'),
|
||||
'required' => true
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'backend_' . $name . '_bind_user_class',
|
||||
array(
|
||||
'label' => 'LDAP user object class',
|
||||
'value' => $backend->get('user_class', 'inetOrgPerson'),
|
||||
'required' => true
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'backend_' . $name . '_bind_user_name_attribute',
|
||||
array(
|
||||
'label' => 'LDAP user name attribute',
|
||||
'value' => $backend->get('user_name_attribute', 'uid'),
|
||||
'required' => true
|
||||
)
|
||||
);
|
||||
|
||||
$this->setSubmitLabel('Save backend');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the ldap authentication backend configuration for this form
|
||||
*
|
||||
* @return array
|
||||
* @see BaseBackendForm::getConfig
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
$name = $this->getBackendName();
|
||||
$prefix = 'backend_' . $this->filterName($name) . '_';
|
||||
|
||||
$section = $this->getValue($prefix . 'name');
|
||||
$cfg = array(
|
||||
'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'),
|
||||
'bind_user_class' => $this->getValue($prefix . 'bind_user_class'),
|
||||
'bind_user_name_attribute' => $this->getValue($prefix . 'bind_user_name_attribute')
|
||||
);
|
||||
return array(
|
||||
$section => $cfg
|
||||
);
|
||||
}
|
||||
}
|
|
@ -32,6 +32,8 @@ use \Icinga\Application\Config as IcingaConfig;
|
|||
use \Icinga\Application\Icinga;
|
||||
use \Icinga\Application\Logger;
|
||||
use \Icinga\Application\DbAdapterFactory;
|
||||
use \Icinga\Form\Config\Authentication\DbBackendForm;
|
||||
use \Icinga\Form\Config\Authentication\LdapBackendForm;
|
||||
|
||||
use \Icinga\Web\Form;
|
||||
use \Icinga\Web\Form\Element\Note;
|
||||
|
@ -39,6 +41,7 @@ use \Icinga\Web\Form\Decorator\ConditionalHidden;
|
|||
use \Zend_Config;
|
||||
use \Zend_Form_Element_Text;
|
||||
use \Zend_Form_Element_Select;
|
||||
use \Zend_Form_Element_Button;
|
||||
|
||||
class AuthenticationForm extends Form
|
||||
{
|
||||
|
@ -56,6 +59,10 @@ class AuthenticationForm extends Form
|
|||
*/
|
||||
private $resources = null;
|
||||
|
||||
|
||||
private $backendForms = array();
|
||||
|
||||
|
||||
/**
|
||||
* Set an alternative array of resources that should be used instead of the DBFactory resource set
|
||||
* (used for testing)
|
||||
|
@ -67,20 +74,6 @@ class AuthenticationForm extends Form
|
|||
$this->resources = $resources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return content of the resources.ini or previously set resources for displaying in the database selection field
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getResources()
|
||||
{
|
||||
if ($this->resources === null ) {
|
||||
return DbAdapterFactory::getResources();
|
||||
} else {
|
||||
return $this->resources;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the configuration to be used for this form
|
||||
*
|
||||
|
@ -91,189 +84,214 @@ class AuthenticationForm extends Form
|
|||
$this->config = $cfg;
|
||||
}
|
||||
|
||||
private function addProviderFormForDb($name, $backend)
|
||||
{
|
||||
|
||||
$backends = array();
|
||||
foreach ($this->getResources() as $resname => $resource)
|
||||
{
|
||||
if ($resource['type'] !== 'db') {
|
||||
continue;
|
||||
}
|
||||
$backends[$resname] = $resname;
|
||||
private function addRemoveHint($name)
|
||||
{
|
||||
$this->addElement(
|
||||
'checkbox',
|
||||
'backend_' . $name . '_remove',
|
||||
array(
|
||||
'name' => 'backend_' . $name . '_remove',
|
||||
'label' => 'Remove this authentication provider',
|
||||
'value' => $name,
|
||||
'checked' => $this->isMarkedForDeletion($name)
|
||||
)
|
||||
);
|
||||
$this->enableAutoSubmit(array('backend_' . $name . '_remove'));
|
||||
return 'backend_' . $name . '_remove';
|
||||
}
|
||||
|
||||
private function addProviderForm($name, $backend)
|
||||
{
|
||||
$type = ucfirst(strtolower($backend->get('backend')));
|
||||
$formClass = '\Icinga\Form\Config\Authentication\\' . $type . 'BackendForm';
|
||||
if (!class_exists($formClass)) {
|
||||
Logger::error('Unsupported backend found in authentication configuration: ' . $backend->get('backend'));
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addElement(
|
||||
'select',
|
||||
'backend_' . $name . '_resource',
|
||||
array(
|
||||
'label' => 'Database connection',
|
||||
'required' => true,
|
||||
'value' => $backend->get('resource'),
|
||||
'multiOptions' => $backends
|
||||
)
|
||||
);
|
||||
$form = new $formClass();
|
||||
$form->setBackendName($name);
|
||||
$form->setBackend($backend);
|
||||
|
||||
if ($this->resources) {
|
||||
$form->setResources($this->resources);
|
||||
}
|
||||
// It would be nice to directly set the form via
|
||||
// this->setForm, but Zend doesn't handle form validation
|
||||
// properly if doing so.
|
||||
$form->create();
|
||||
foreach ($form->getElements() as $name => $element) {
|
||||
$this->addElement($element, $name);
|
||||
}
|
||||
|
||||
$this->addElement(
|
||||
'submit',
|
||||
'backend_' . $name . '_remove',
|
||||
array(
|
||||
'label' => 'Remove this backend',
|
||||
'required' => true
|
||||
)
|
||||
);
|
||||
|
||||
$this->addDisplayGroup(
|
||||
array(
|
||||
'backend_' . $name . '_resource',
|
||||
'backend_' . $name . '_remove'
|
||||
),
|
||||
'auth_provider_' . $name,
|
||||
array(
|
||||
'legend' => 'DB Authentication ' . $name
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function addProviderFormForLdap($name, $backend)
|
||||
{
|
||||
$this->addElement(
|
||||
'text',
|
||||
'backend_' . $name . '_hostname',
|
||||
array(
|
||||
'label' => 'LDAP server host',
|
||||
'value' => $backend->get('hostname', 'localhost'),
|
||||
'required' => true
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'backend_' . $name . '_root_dn',
|
||||
array(
|
||||
'label' => 'LDAP root dn',
|
||||
'value' => $backend->get('hostname', 'ou=people,dc=icinga,dc=org'),
|
||||
'required' => true
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'backend_' . $name . '_bind_dn',
|
||||
array(
|
||||
'label' => 'LDAP bind dn',
|
||||
'value' => $backend->get('bind_dn', 'cn=admin,cn=config'),
|
||||
'required' => true
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'password',
|
||||
'backend_' . $name . '_bind_pw',
|
||||
array(
|
||||
'label' => 'LDAP bind password',
|
||||
'value' => $backend->get('bind_pw', 'admin'),
|
||||
'required' => true
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'backend_' . $name . '_bind_user_class',
|
||||
array(
|
||||
'label' => 'LDAP user object class',
|
||||
'value' => $backend->get('user_class', 'inetOrgPerson'),
|
||||
'required' => true
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'backend_' . $name . '_bind_user_name_attribute',
|
||||
array(
|
||||
'label' => 'LDAP user name attribute',
|
||||
'value' => $backend->get('user_name_attribute', 'uid'),
|
||||
'required' => true
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'submit',
|
||||
'backend_' . $name . '_remove',
|
||||
array(
|
||||
'label' => 'Remove this backend'
|
||||
)
|
||||
);
|
||||
|
||||
$this->addDisplayGroup(
|
||||
array(
|
||||
'backend_' . $name . '_hostname',
|
||||
'backend_' . $name . '_root_dn',
|
||||
'backend_' . $name . '_bind_dn',
|
||||
'backend_' . $name . '_bind_pw',
|
||||
'backend_' . $name . '_bind_user_class',
|
||||
'backend_' . $name . '_bind_user_name_attribute',
|
||||
'backend_' . $name . '_remove'
|
||||
),
|
||||
'auth_provider_' . $name,
|
||||
array(
|
||||
'legend' => 'LDAP Authentication ' . $name
|
||||
)
|
||||
);
|
||||
$this->backendForms[] = $form;
|
||||
}
|
||||
|
||||
|
||||
public function addPriorityButtons($name, $pos)
|
||||
|
||||
|
||||
|
||||
public function addPriorityButtons($name, $order = array())
|
||||
{
|
||||
if ($pos > 0) {
|
||||
$formEls = array();
|
||||
$priorities = array(
|
||||
"up" => join(',', self::moveElementUp($name, $order)),
|
||||
"down" => join(',', self::moveElementDown($name, $order))
|
||||
);
|
||||
if ($priorities["up"] != join(',', $order)) {
|
||||
$this->addElement(
|
||||
'submit',
|
||||
'priority_change_'.$name.'_down',
|
||||
'button',
|
||||
'priority' . $name . '_up',
|
||||
array(
|
||||
'name' => 'priority',
|
||||
'label' => 'Move up in authentication order',
|
||||
'value' => $pos-1
|
||||
'value' => $priorities["up"],
|
||||
'type' => 'submit'
|
||||
)
|
||||
);
|
||||
$formEls[] = 'priority' . $name . '_up';
|
||||
}
|
||||
if ($pos+1 < count($this->config->keys())) {
|
||||
if ($priorities["down"] != join(',', $order)) {
|
||||
$this->addElement(
|
||||
'submit',
|
||||
'priority_change_'.$name.'_up',
|
||||
'button',
|
||||
'priority' . $name . '_down',
|
||||
array(
|
||||
'name' => 'priority',
|
||||
'label' => 'Move down in authentication order',
|
||||
'value' => $pos+1
|
||||
'value' => $priorities["down"],
|
||||
'type' => 'submit'
|
||||
)
|
||||
);
|
||||
$formEls[] = 'priority' . $name . '_down';
|
||||
}
|
||||
|
||||
return $formEls;
|
||||
}
|
||||
|
||||
|
||||
public function populate(array $values)
|
||||
{
|
||||
$last_priority = $this->getValue('current_priority');
|
||||
parent::populate($values);
|
||||
$this->getElement('current_priority')->setValue($last_priority);
|
||||
|
||||
}
|
||||
|
||||
private function getAuthenticationOrder ()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
$order = $request->getParam(
|
||||
'priority',
|
||||
$request->getParam('current_priority', null)
|
||||
);
|
||||
|
||||
if ($order === null) {
|
||||
$order = array_keys($this->config->toArray());
|
||||
} else {
|
||||
$order = explode(',', $order);
|
||||
}
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
|
||||
private function isMarkedForDeletion($backendName)
|
||||
{
|
||||
return intval($this->getRequest()->getParam('backend_' . $backendName . '_remove', 0)) === 1;
|
||||
}
|
||||
|
||||
private function addPersistentState()
|
||||
{
|
||||
|
||||
$this->addElement(
|
||||
'hidden',
|
||||
'current_priority',
|
||||
array(
|
||||
'name' => 'current_priority',
|
||||
'value' => join(',', $this->getAuthenticationOrder())
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->addElement(
|
||||
'submit',
|
||||
'add_backend',
|
||||
array(
|
||||
'label' => 'Add a new authentication provider',
|
||||
'class' => 'btn'
|
||||
)
|
||||
);
|
||||
$pos = 0;
|
||||
foreach ($this->config as $name => $backend) {
|
||||
$order = $this->getAuthenticationOrder();
|
||||
|
||||
$type = strtolower($backend->get('backend'));
|
||||
if ($type === 'db') {
|
||||
$this->addProviderFormForDb($name, $backend);
|
||||
} elseif ($type === 'ldap') {
|
||||
$this->addProviderFormForLdap($name, $backend);
|
||||
} else {
|
||||
Logger::error('Unsupported backend found in authentication configuration: ' . $backend->get('backend'));
|
||||
foreach ($order as $name) {
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'escape' => false,
|
||||
'name' => 'title_backend_' . $name,
|
||||
'value' => '<h4>Backend ' . $name . '</h4>'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->addRemoveHint($this->filterName($name));
|
||||
$backend = $this->config->get($name, null);
|
||||
if ($backend === null) {
|
||||
continue;
|
||||
}
|
||||
$this->addPriorityButtons($name, $pos);
|
||||
|
||||
$pos++;
|
||||
if (!$this->isMarkedForDeletion($this->filterName($name))) {
|
||||
$this->addProviderForm($name, $backend);
|
||||
$this->addPriorityButtons($name, $order);
|
||||
}
|
||||
}
|
||||
|
||||
$this->addPersistentState();
|
||||
$this->enableConditionalDecorator();
|
||||
$this->setSubmitLabel('Save changes');
|
||||
}
|
||||
}
|
||||
|
||||
public function getConfig()
|
||||
{
|
||||
$result = array();
|
||||
foreach ($this->backendForms as $name) {
|
||||
|
||||
$name->populate($this->getRequest()->getParams());
|
||||
$result += $name->getConfig();
|
||||
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function enableConditionalDecorator()
|
||||
{
|
||||
foreach ($this->getElements() as $element) {
|
||||
$element->addDecorator(new ConditionalHidden());
|
||||
}
|
||||
}
|
||||
|
||||
private static function moveElementUp($key, array $array)
|
||||
{
|
||||
$swap = null;
|
||||
for ($i=0; $i<count($array)-1; $i++) {
|
||||
if ($array[$i+1] !== $key) {
|
||||
continue;
|
||||
}
|
||||
$swap = $array[$i];
|
||||
$array[$i] = $array[$i+1];
|
||||
$array[$i+1] = $swap;
|
||||
return $array;
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
private static function moveElementDown($key, array $array)
|
||||
{
|
||||
$swap = null;
|
||||
for ($i=0; $i<count($array)-1; $i++) {
|
||||
if ($array[$i] !== $key) {
|
||||
continue;
|
||||
}
|
||||
$swap = $array[$i+1];
|
||||
$array[$i+1] = $array[$i];
|
||||
$array[$i] = $swap;
|
||||
return $array;
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@ class GeneralForm extends Form
|
|||
*/
|
||||
public function getResources()
|
||||
{
|
||||
if ($this->resources === null ) {
|
||||
if ($this->resources === null) {
|
||||
return DbAdapterFactory::getResources();
|
||||
} else {
|
||||
return $this->resources;
|
||||
|
@ -142,11 +142,16 @@ class GeneralForm extends Form
|
|||
'value' => $env === 'development'
|
||||
)
|
||||
);
|
||||
$this->addElement(new Note(array(
|
||||
'name' => 'note_env',
|
||||
'value' => 'Set true to show more detailed errors and disable certain optimizations '
|
||||
. 'in order to make debugging easier.'
|
||||
)));
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'note_env',
|
||||
'value' => 'Set true to show more detailed errors '
|
||||
. 'and disable certain optimizations '
|
||||
. 'in order to make debugging easier.'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -159,7 +164,7 @@ class GeneralForm extends Form
|
|||
private function addTimezoneSelection(Zend_Config $cfg)
|
||||
{
|
||||
$tzList = array();
|
||||
foreach(DateTimeZone::listIdentifiers() as $tz) {
|
||||
foreach (DateTimeZone::listIdentifiers() as $tz) {
|
||||
$tzList[$tz] = $tz;
|
||||
}
|
||||
|
||||
|
@ -173,11 +178,15 @@ class GeneralForm extends Form
|
|||
'value' => $cfg->get('timezone', date_default_timezone_get())
|
||||
)
|
||||
);
|
||||
$this->addElement(new Note(array(
|
||||
'name' => 'noteTimezone',
|
||||
'value' => 'Select the timezone to be used as the default. User\'s can set their own timezone if'.
|
||||
' they like to, but this is the timezone to be used as the default setting .'
|
||||
)));
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'noteTimezone',
|
||||
'value' => 'Select the timezone to be used as the default. User\'s can set their own timezone if'
|
||||
. ' they like to, but this is the timezone to be used as the default setting .'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -193,13 +202,17 @@ class GeneralForm extends Form
|
|||
array(
|
||||
'label' => 'Module folder',
|
||||
'required' => true,
|
||||
'value' => $cfg->get('moduleFolder', $this->getConfigDir() . '/config/enabledModules')
|
||||
'value' => $cfg->get('moduleFolder', $this->getConfigDir() . '/config/enabledModules')
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'noteModuleFolder',
|
||||
'value' => 'Use this folder to activate modules (must be writable by your webserver)'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->addElement(new Note(array(
|
||||
'name' => 'noteModuleFolder',
|
||||
'value' => 'Use this folder to activate modules (must be writable by your webserver)'
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -209,7 +222,8 @@ class GeneralForm extends Form
|
|||
*/
|
||||
private function addDateFormatSettings(Zend_Config $cfg)
|
||||
{
|
||||
$phpUrl = '<a href="http://php.net/manual/en/function.date.php" target="_new">the official PHP documentation</a>';
|
||||
$phpUrl = '<a href="http://php.net/manual/en/function.date.php" target="_new">'
|
||||
. 'the official PHP documentation</a>';
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
|
@ -220,10 +234,14 @@ class GeneralForm extends Form
|
|||
'value' => $cfg->get('dateFormat', 'd/m/Y')
|
||||
)
|
||||
);
|
||||
$this->addElement(new Note(array(
|
||||
'name' => 'noteDateFormat',
|
||||
'value' => 'Display dates according to this format. See ' . $phpUrl . ' for possible values'
|
||||
)));
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'noteDateFormat',
|
||||
'value' => 'Display dates according to this format. See ' . $phpUrl . ' for possible values'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
$this->addElement(
|
||||
|
@ -235,12 +253,22 @@ class GeneralForm extends Form
|
|||
'value' => $cfg->get('timeFormat', 'g:i A')
|
||||
)
|
||||
);
|
||||
$this->addElement(new Note(array(
|
||||
'name' => 'noteTimeFormat',
|
||||
'value' => 'Display times according to this format. See ' . $phpUrl . ' for possible values'
|
||||
)));
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'noteTimeFormat',
|
||||
'value' => 'Display times according to this format. See '
|
||||
. $phpUrl . ' for possible values'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add form elements for setting the user preference storage backend
|
||||
*
|
||||
* @param Zend_Config $cfg The Zend_config object of preference section
|
||||
*/
|
||||
public function addUserPreferencesDialog(Zend_Config $cfg)
|
||||
{
|
||||
$backend = $cfg->get('type', 'ini');
|
||||
|
@ -271,8 +299,7 @@ class GeneralForm extends Form
|
|||
)
|
||||
);
|
||||
$backends = array();
|
||||
foreach ($this->getResources() as $name => $resource)
|
||||
{
|
||||
foreach ($this->getResources() as $name => $resource) {
|
||||
if ($resource['type'] !== 'db') {
|
||||
continue;
|
||||
}
|
||||
|
@ -295,9 +322,11 @@ class GeneralForm extends Form
|
|||
|
||||
$txtPreferencesIniPath->addDecorator(new ConditionalHidden());
|
||||
$txtPreferencesDbResource->addDecorator(new ConditionalHidden());
|
||||
$this->enableAutoSubmit(array(
|
||||
'preferences_type'
|
||||
));
|
||||
$this->enableAutoSubmit(
|
||||
array(
|
||||
'preferences_type'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -328,6 +357,11 @@ class GeneralForm extends Form
|
|||
$this->setSubmitLabel('Save changes');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an Zend_Config object containing the configuration set in this form
|
||||
*
|
||||
* @return Zend_Config
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
if ($this->config === null) {
|
||||
|
@ -357,5 +391,4 @@ class GeneralForm extends Form
|
|||
|
||||
return $cfg;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,6 +83,12 @@ class LoggingForm extends Form
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true when logging is enabled according to the request and the configuration
|
||||
*
|
||||
* @param Zend_Config $config The logging section of the config.ini
|
||||
* @return bool
|
||||
*/
|
||||
private function loggingIsEnabled(Zend_Config $config)
|
||||
{
|
||||
$loggingRequestParam = $this->getRequest()->getParam('logging_enable', null);
|
||||
|
@ -146,13 +152,15 @@ class LoggingForm extends Form
|
|||
)
|
||||
);
|
||||
|
||||
$this->addElement(new Note(
|
||||
array(
|
||||
'name' => 'note_logging_app_path',
|
||||
'value'=> 'The logfile to write the icingaweb debug logs to. The webserver must be able to write'
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'note_logging_app_path',
|
||||
'value'=> 'The logfile to write the icingaweb debug logs to. The webserver must be able to write'
|
||||
. 'at this location'
|
||||
)
|
||||
)
|
||||
));
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'checkbox',
|
||||
|
@ -164,12 +172,14 @@ class LoggingForm extends Form
|
|||
)
|
||||
);
|
||||
|
||||
$this->addElement(new Note(
|
||||
array(
|
||||
'name' => 'note_logging_app_verbose',
|
||||
'value'=> 'Check to write more verbose output to the icinga log file'
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'note_logging_app_verbose',
|
||||
'value'=> 'Check to write more verbose output to the icinga log file'
|
||||
)
|
||||
)
|
||||
));
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'checkbox',
|
||||
|
@ -180,12 +190,14 @@ class LoggingForm extends Form
|
|||
'value' => $this->shouldDisplayDebugLog($debug)
|
||||
)
|
||||
);
|
||||
$this->addElement(new Note(
|
||||
array(
|
||||
'name' => 'note_logging_use_debug',
|
||||
'value'=> 'Check to write a seperate debug log (Warning: This file can grow very big)'
|
||||
$this->addElement(
|
||||
new Note(
|
||||
array(
|
||||
'name' => 'note_logging_use_debug',
|
||||
'value'=> 'Check to write a seperate debug log (Warning: This file can grow very big)'
|
||||
)
|
||||
)
|
||||
));
|
||||
);
|
||||
|
||||
|
||||
$textLoggingDebugPath = new Zend_Form_Element_Text(
|
||||
|
@ -215,5 +227,4 @@ class LoggingForm extends Form
|
|||
|
||||
$this->setSubmitLabel('Save changes');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,2 +1,20 @@
|
|||
<?php
|
||||
use Icinga\Web\Url;
|
||||
$createLdapBackend = Url::fromPath(
|
||||
'/config/createAuthenticationBackend',
|
||||
array('type' => 'ldap')
|
||||
)->getAbsoluteUrl();
|
||||
|
||||
$createDbBackend = Url::fromPath(
|
||||
'/config/createAuthenticationBackend',
|
||||
array('type' => 'db')
|
||||
)->getAbsoluteUrl();
|
||||
|
||||
?>
|
||||
<?= $this->tabs->render($this); ?>
|
||||
|
||||
<div>
|
||||
<a href="<?= $createLdapBackend ?>">Create a new LDAP authentication backend</a><br/>
|
||||
<a href="<?= $createDbBackend ?>">Create a new DB authentication backend</a>
|
||||
</div>
|
||||
<?= $this->form ?>
|
|
@ -0,0 +1,30 @@
|
|||
<?= $this->tabs->render($this); ?>
|
||||
<br/>
|
||||
<div class="alert alert-error">
|
||||
<h4><i class="icon-warning-sign"> </i>Saving authentication.ini failed</h4>
|
||||
<br/>
|
||||
<p>
|
||||
Your authentication configuration couldn't be stored (error: "<?= $this->exceptionMessage; ?>"). This could have one or more
|
||||
of the following reasons:
|
||||
</p>
|
||||
<ul>
|
||||
<li>You don't have file-system permissions to write to the authentication.ini file</li>
|
||||
<li>Something went wrong while writing the file</li>
|
||||
<li>There's an application error preventing you from persisting the configuration</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
Details can be seen in your application log (if you don't have access to this file, call your administrator in this case).
|
||||
<br/>
|
||||
In case you can access the configuration file (config/authentication.ini) by yourself, you can open it and
|
||||
insert the config manually:
|
||||
|
||||
</p>
|
||||
<p>
|
||||
<pre>
|
||||
<code>
|
||||
<?= $this->escape($this->iniConfigurationString); ?>
|
||||
</code>
|
||||
</pre>
|
||||
</p>
|
|
@ -309,6 +309,7 @@ abstract class Form extends Zend_Form
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Disable CSRF counter measure and remove its field if already added
|
||||
*
|
||||
|
|
|
@ -53,7 +53,7 @@ class ConditionalHidden extends Zend_Form_Decorator_Abstract
|
|||
*
|
||||
* @return string The input tag and options XHTML.
|
||||
*/
|
||||
public function render($content ='')
|
||||
public function render($content = '')
|
||||
{
|
||||
$attributes = $this->getElement()->getAttribs();
|
||||
$condition = isset($attributes['condition']) ? $attributes['condition'] : 1;
|
||||
|
|
Loading…
Reference in New Issue