diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php index 5e69c219b..fb8e63f34 100644 --- a/application/controllers/ConfigController.php +++ b/application/controllers/ConfigController.php @@ -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 diff --git a/application/forms/Config/Authentication/BaseBackendForm.php b/application/forms/Config/Authentication/BaseBackendForm.php new file mode 100644 index 000000000..1844d4d47 --- /dev/null +++ b/application/forms/Config/Authentication/BaseBackendForm.php @@ -0,0 +1,140 @@ + + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{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(); +} diff --git a/application/forms/Config/Authentication/DbBackendForm.php b/application/forms/Config/Authentication/DbBackendForm.php new file mode 100644 index 000000000..de2b0464f --- /dev/null +++ b/application/forms/Config/Authentication/DbBackendForm.php @@ -0,0 +1,122 @@ + + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{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 + ); + } +} diff --git a/application/forms/Config/Authentication/LdapBackendForm.php b/application/forms/Config/Authentication/LdapBackendForm.php new file mode 100644 index 000000000..ea92c756b --- /dev/null +++ b/application/forms/Config/Authentication/LdapBackendForm.php @@ -0,0 +1,157 @@ + + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{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 + ); + } +} diff --git a/application/forms/Config/AuthenticationForm.php b/application/forms/Config/AuthenticationForm.php index d835a956f..135ddefdc 100644 --- a/application/forms/Config/AuthenticationForm.php +++ b/application/forms/Config/AuthenticationForm.php @@ -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' => '

Backend ' . $name . '

' + ) + ) + ); + $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'); } -} \ No newline at end of file + + 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; $iresources === 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 = 'the official PHP documentation'; + $phpUrl = '' + . 'the official PHP documentation'; $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; } - -} \ No newline at end of file +} diff --git a/application/forms/Config/LoggingForm.php b/application/forms/Config/LoggingForm.php index 107e75ff2..962f2f152 100644 --- a/application/forms/Config/LoggingForm.php +++ b/application/forms/Config/LoggingForm.php @@ -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'); } - -} \ No newline at end of file +} diff --git a/application/views/scripts/config/authentication.phtml b/application/views/scripts/config/authentication.phtml index f0b046499..1e041a914 100644 --- a/application/views/scripts/config/authentication.phtml +++ b/application/views/scripts/config/authentication.phtml @@ -1,2 +1,20 @@ + 'ldap') +)->getAbsoluteUrl(); + +$createDbBackend = Url::fromPath( + '/config/createAuthenticationBackend', + array('type' => 'db') +)->getAbsoluteUrl(); + +?> tabs->render($this); ?> + +
+ Create a new LDAP authentication backend
+ Create a new DB authentication backend +
form ?> \ No newline at end of file diff --git a/application/views/scripts/config/authentication/show-configuration.phtml b/application/views/scripts/config/authentication/show-configuration.phtml new file mode 100644 index 000000000..afc255224 --- /dev/null +++ b/application/views/scripts/config/authentication/show-configuration.phtml @@ -0,0 +1,30 @@ +tabs->render($this); ?> +
+
+

Saving authentication.ini failed

+
+

+ Your authentication configuration couldn't be stored (error: "exceptionMessage; ?>"). This could have one or more + of the following reasons: +

+
    +
  • You don't have file-system permissions to write to the authentication.ini file
  • +
  • Something went wrong while writing the file
  • +
  • There's an application error preventing you from persisting the configuration
  • +
+
+ +

+ Details can be seen in your application log (if you don't have access to this file, call your administrator in this case). +
+ In case you can access the configuration file (config/authentication.ini) by yourself, you can open it and + insert the config manually: + +

+

+

+        
+escape($this->iniConfigurationString); ?>
+        
+    
+

\ No newline at end of file diff --git a/library/Icinga/Web/Form.php b/library/Icinga/Web/Form.php index 593977d40..d31c235d3 100644 --- a/library/Icinga/Web/Form.php +++ b/library/Icinga/Web/Form.php @@ -309,6 +309,7 @@ abstract class Form extends Zend_Form } } + /** * Disable CSRF counter measure and remove its field if already added * diff --git a/library/Icinga/Web/Form/Decorator/ConditionalHidden.php b/library/Icinga/Web/Form/Decorator/ConditionalHidden.php index 7dc54a8fe..e3356d44c 100644 --- a/library/Icinga/Web/Form/Decorator/ConditionalHidden.php +++ b/library/Icinga/Web/Form/Decorator/ConditionalHidden.php @@ -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;