2013-08-12 15:58:26 +02:00
|
|
|
<?php
|
|
|
|
// @codingStandardsIgnoreStart
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
/**
|
|
|
|
* Icinga 2 Web - Head for multiple monitoring frontends
|
|
|
|
* Copyright (C) 2013 Icinga Development Team
|
2013-08-16 14:56:23 +02:00
|
|
|
*
|
2013-08-12 15:58:26 +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-16 14:56:23 +02:00
|
|
|
*
|
2013-08-12 15:58:26 +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-16 14:56:23 +02:00
|
|
|
*
|
2013-08-12 15:58:26 +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-16 14:56:23 +02:00
|
|
|
*
|
2013-08-12 15:58:26 +02:00
|
|
|
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
|
|
|
* @author Icinga Development Team <info@icinga.org>
|
|
|
|
*/
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
2013-08-16 14:56:23 +02:00
|
|
|
use \Icinga\Application\Benchmark;
|
|
|
|
use \Icinga\Authentication\Manager;
|
|
|
|
use \Icinga\Web\Controller\BaseConfigController;
|
|
|
|
use \Icinga\Web\Widget\Tab;
|
|
|
|
use \Icinga\Web\Url;
|
|
|
|
use \Icinga\Web\Hook\Configuration\ConfigurationTabBuilder;
|
|
|
|
use \Icinga\Application\Icinga;
|
2013-08-19 18:25:20 +02:00
|
|
|
use \Icinga\Application\Config as IcingaConfig;
|
2013-08-14 10:53:25 +02:00
|
|
|
use \Icinga\Form\Config\GeneralForm;
|
2013-08-15 14:27:53 +02:00
|
|
|
use \Icinga\Form\Config\AuthenticationForm;
|
2013-08-16 16:24:12 +02:00
|
|
|
use \Icinga\Form\Config\Authentication\LdapBackendForm;
|
|
|
|
use \Icinga\Form\Config\Authentication\DbBackendForm;
|
2013-08-14 10:53:25 +02:00
|
|
|
use \Icinga\Form\Config\LoggingForm;
|
|
|
|
use \Icinga\Config\PreservingIniWriter;
|
2013-08-12 15:58:26 +02:00
|
|
|
|
|
|
|
/**
|
2013-08-14 12:42:32 +02:00
|
|
|
* Application wide controller for application preferences
|
2013-08-12 15:58:26 +02:00
|
|
|
*/
|
|
|
|
class ConfigController extends BaseConfigController
|
|
|
|
{
|
2013-08-14 12:42:32 +02:00
|
|
|
/**
|
|
|
|
* Create tabs for this configuration controller
|
|
|
|
*
|
2013-08-16 14:56:23 +02:00
|
|
|
* @return array
|
|
|
|
*
|
|
|
|
* @see BaseConfigController::createProvidedTabs()
|
2013-08-14 12:42:32 +02:00
|
|
|
*/
|
2013-08-12 15:58:26 +02:00
|
|
|
public static function createProvidedTabs()
|
|
|
|
{
|
|
|
|
return array(
|
2013-08-16 14:56:23 +02:00
|
|
|
'index' => new Tab(
|
2013-08-12 15:58:26 +02:00
|
|
|
array(
|
2013-08-19 18:25:20 +02:00
|
|
|
'name' => 'index',
|
|
|
|
'title' => 'Application',
|
|
|
|
'url' => Url::fromPath('/config')
|
2013-08-12 15:58:26 +02:00
|
|
|
)
|
|
|
|
),
|
2013-08-19 18:25:20 +02:00
|
|
|
'authentication' => new Tab(
|
2013-08-15 14:27:53 +02:00
|
|
|
array(
|
2013-08-19 18:25:20 +02:00
|
|
|
'name' => 'auth',
|
|
|
|
'title' => 'Authentication',
|
|
|
|
'url' => Url::fromPath('/config/authentication')
|
2013-08-15 14:27:53 +02:00
|
|
|
)
|
|
|
|
),
|
|
|
|
|
2013-08-19 18:25:20 +02:00
|
|
|
'logging' => new Tab(
|
2013-08-12 15:58:26 +02:00
|
|
|
array(
|
2013-08-19 18:25:20 +02:00
|
|
|
'name' => 'logging',
|
|
|
|
'title' => 'Logging',
|
|
|
|
'url' => Url::fromPath('/config/logging')
|
2013-08-14 10:53:25 +02:00
|
|
|
)
|
|
|
|
),
|
2013-08-19 18:25:20 +02:00
|
|
|
'modules' => new Tab(
|
2013-08-14 10:53:25 +02:00
|
|
|
array(
|
2013-08-19 18:25:20 +02:00
|
|
|
'name' => 'modules',
|
|
|
|
'title' => 'Modules',
|
|
|
|
'url' => Url::fromPath('/config/moduleoverview')
|
2013-08-12 15:58:26 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-08-14 12:42:32 +02:00
|
|
|
* Index action, entry point for configuration
|
2013-08-12 15:58:26 +02:00
|
|
|
*/
|
|
|
|
public function indexAction()
|
|
|
|
{
|
2013-08-14 10:53:25 +02:00
|
|
|
$form = new GeneralForm();
|
2013-08-20 17:06:44 +02:00
|
|
|
|
2013-08-14 10:53:25 +02:00
|
|
|
$form->setConfiguration(IcingaConfig::app());
|
|
|
|
$form->setRequest($this->_request);
|
|
|
|
if ($form->isSubmittedAndValid()) {
|
2013-08-19 18:25:20 +02:00
|
|
|
if (!$this->writeConfigFile($form->getConfig(), 'config')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$this->redirectNow('/config');
|
2013-08-14 10:53:25 +02:00
|
|
|
}
|
|
|
|
$this->view->form = $form;
|
|
|
|
}
|
|
|
|
|
2013-08-16 16:24:12 +02:00
|
|
|
|
2013-08-19 18:25:20 +02:00
|
|
|
/**
|
|
|
|
* Form for modifying the logging configuration
|
|
|
|
*/
|
2013-08-14 10:53:25 +02:00
|
|
|
public function loggingAction()
|
|
|
|
{
|
|
|
|
$form = new LoggingForm();
|
|
|
|
$form->setConfiguration(IcingaConfig::app());
|
|
|
|
$form->setRequest($this->_request);
|
2013-08-19 18:25:20 +02:00
|
|
|
if ($form->isSubmittedAndValid()) {
|
|
|
|
$config = $form->getConfig();
|
|
|
|
if (!$this->writeConfigFile($form->getConfig(), 'config')) {
|
2013-08-20 17:06:44 +02:00
|
|
|
return;
|
2013-08-19 18:25:20 +02:00
|
|
|
}
|
|
|
|
$this->redirectNow('/config/logging');
|
|
|
|
}
|
2013-08-14 10:53:25 +02:00
|
|
|
$this->view->form = $form;
|
2013-08-12 15:58:26 +02:00
|
|
|
}
|
|
|
|
|
2013-08-14 12:42:32 +02:00
|
|
|
/**
|
|
|
|
* Display the list of all modules
|
|
|
|
*/
|
2013-08-12 15:58:26 +02:00
|
|
|
public function moduleoverviewAction()
|
|
|
|
{
|
|
|
|
$this->view->modules = Icinga::app()->getModuleManager()->select()
|
|
|
|
->from('modules')
|
|
|
|
->order('name');
|
|
|
|
$this->render('module/overview');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-08-14 12:42:32 +02:00
|
|
|
* Enable a specific module provided by the 'name' param
|
2013-08-12 15:58:26 +02:00
|
|
|
*/
|
|
|
|
public function moduleenableAction()
|
|
|
|
{
|
|
|
|
$manager = Icinga::app()->getModuleManager();
|
|
|
|
$manager->enableModule($this->_getParam('name'));
|
|
|
|
$manager->loadModule($this->_getParam('name'));
|
|
|
|
$this->redirectNow('config/moduleoverview?_render=body');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-08-14 12:42:32 +02:00
|
|
|
* Disable a module specific module provided by the 'name' param
|
2013-08-12 15:58:26 +02:00
|
|
|
*/
|
|
|
|
public function moduledisableAction()
|
|
|
|
{
|
|
|
|
$manager = Icinga::app()->getModuleManager();
|
|
|
|
$manager->disableModule($this->_getParam('name'));
|
|
|
|
$this->redirectNow('config/moduleoverview?_render=body');
|
|
|
|
}
|
2013-08-14 10:53:25 +02:00
|
|
|
|
2013-08-16 16:24:12 +02:00
|
|
|
/**
|
|
|
|
* 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()) {
|
2013-08-19 18:25:20 +02:00
|
|
|
$modifiedConfig = $form->getConfig();
|
|
|
|
if (empty($modifiedConfig)) {
|
|
|
|
$form->addError('You need at least one authentication backend.');
|
|
|
|
} else if (!$this->writeAuthenticationFile($modifiedConfig)) {
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
$this->redirectNow('/config/authentication');
|
|
|
|
}
|
2013-08-16 16:24:12 +02:00
|
|
|
}
|
|
|
|
$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;
|
|
|
|
}
|
2013-08-19 18:25:20 +02:00
|
|
|
if (!$this->writeAuthenticationFile($backendCfg)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$this->redirectNow('/config/authentication');
|
2013-08-16 16:24:12 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
$this->view->form = $form;
|
|
|
|
$this->render('authentication/modify');
|
|
|
|
}
|
2013-08-14 10:53:25 +02:00
|
|
|
|
2013-08-19 18:25:20 +02:00
|
|
|
/**
|
2013-08-21 11:02:53 +02:00
|
|
|
* Write changes to an authentication file
|
2013-08-19 18:25:20 +02:00
|
|
|
*
|
2013-08-21 11:02:53 +02:00
|
|
|
* @param array $config The configuration changes
|
|
|
|
*
|
|
|
|
* @return bool True when persisting succeeded, otherwise false
|
2013-08-19 18:25:20 +02:00
|
|
|
*
|
2013-08-21 11:02:53 +02:00
|
|
|
* @see writeConfigFile()
|
2013-08-19 18:25:20 +02:00
|
|
|
*/
|
|
|
|
private function writeAuthenticationFile($config) {
|
2013-08-27 12:56:35 +02:00
|
|
|
return $this->writeConfigFile($config, 'authentication');
|
2013-08-19 18:25:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-08-21 11:02:53 +02:00
|
|
|
* Write changes to a configuration file $file, using the supplied writer or PreservingIniWriter if none is set
|
2013-08-19 18:25:20 +02:00
|
|
|
*
|
2013-08-21 11:02:53 +02:00
|
|
|
* @param array|Zend_Config $config The configuration to write
|
|
|
|
* @param string $file The filename to write to (without .ini)
|
|
|
|
* @param Zend_Config_Writer $writer An optional writer to use for persisting changes
|
2013-08-19 18:25:20 +02:00
|
|
|
*
|
2013-08-21 11:02:53 +02:00
|
|
|
* @return bool True when persisting succeeded, otherwise false
|
2013-08-19 18:25:20 +02:00
|
|
|
*/
|
|
|
|
private function writeConfigFile($config, $file, $writer = null)
|
|
|
|
{
|
|
|
|
if (is_array($config)) {
|
|
|
|
$config = new Zend_Config($config);
|
|
|
|
}
|
|
|
|
if ($writer === null) {
|
|
|
|
$writer = new PreservingIniWriter(
|
|
|
|
array(
|
|
|
|
'config' => $config,
|
|
|
|
'filename' => IcingaConfig::app($file)->getConfigFile()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
$writer->write();
|
|
|
|
return true;
|
|
|
|
} catch (Exception $exc) {
|
|
|
|
$this->view->exceptionMessage = $exc->getMessage();
|
|
|
|
$this->view->iniConfigurationString = $writer->render();
|
|
|
|
$this->view->file = $file;
|
|
|
|
$this->render('show-configuration');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2013-08-12 15:58:26 +02:00
|
|
|
}
|
2013-08-16 14:56:23 +02:00
|
|
|
// @codingStandardsIgnoreEnd
|