2013-08-12 15:58:26 +02:00
|
|
|
<?php
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
2014-06-21 02:27:27 +02:00
|
|
|
use Icinga\Web\Controller\BaseConfigController;
|
|
|
|
use Icinga\Web\Widget\Tab;
|
|
|
|
use Icinga\Web\Widget\AlertMessageBox;
|
2014-06-21 01:54:32 +02:00
|
|
|
use Icinga\Web\Notification;
|
|
|
|
use Icinga\Application\Modules\Module;
|
2014-06-21 02:27:27 +02:00
|
|
|
use Icinga\Web\Url;
|
2014-07-23 12:35:39 +02:00
|
|
|
use Icinga\Web\Form;
|
2014-06-21 02:27:27 +02:00
|
|
|
use Icinga\Web\Widget;
|
|
|
|
use Icinga\Application\Icinga;
|
|
|
|
use Icinga\Application\Config as IcingaConfig;
|
|
|
|
use Icinga\Data\ResourceFactory;
|
|
|
|
use Icinga\Form\Config\GeneralForm;
|
|
|
|
use Icinga\Form\Config\Authentication\LdapBackendForm;
|
|
|
|
use Icinga\Form\Config\Authentication\DbBackendForm;
|
|
|
|
use Icinga\Form\Config\ResourceForm;
|
|
|
|
use Icinga\Form\Config\LoggingForm;
|
|
|
|
use Icinga\Form\Config\ConfirmRemovalForm;
|
|
|
|
use Icinga\Config\PreservingIniWriter;
|
2013-08-12 15:58:26 +02:00
|
|
|
|
2014-06-21 01:54:32 +02:00
|
|
|
|
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
|
|
|
|
{
|
2014-06-24 21:31:59 +02:00
|
|
|
public function init()
|
2013-08-12 15:58:26 +02:00
|
|
|
{
|
2014-06-24 21:31:59 +02:00
|
|
|
$this->view->tabs = Widget::create('tabs')->add('index', array(
|
|
|
|
'title' => 'Application',
|
|
|
|
'url' => 'config'
|
|
|
|
))->add('authentication', array(
|
|
|
|
'title' => 'Authentication',
|
|
|
|
'url' => 'config/authentication'
|
|
|
|
))->add('resources', array(
|
|
|
|
'title' => 'Resources',
|
|
|
|
'url' => 'config/resource'
|
|
|
|
))->add('logging', array(
|
|
|
|
'title' => 'Logging',
|
|
|
|
'url' => 'config/logging'
|
|
|
|
))->add('modules', array(
|
|
|
|
'title' => 'Modules',
|
|
|
|
'url' => 'config/modules'
|
|
|
|
));
|
2013-08-12 15:58:26 +02:00
|
|
|
}
|
|
|
|
|
2014-06-25 20:31:44 +02:00
|
|
|
public function devtoolsAction()
|
|
|
|
{
|
|
|
|
$this->view->tabs = null;
|
|
|
|
}
|
|
|
|
|
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-11-26 10:35:46 +01:00
|
|
|
$this->view->messageBox = new AlertMessageBox(true);
|
2014-02-25 11:23:36 +01:00
|
|
|
$this->view->tabs->activate('index');
|
2014-07-21 14:33:52 +02:00
|
|
|
|
2013-11-20 19:10:38 +01:00
|
|
|
$form = new GeneralForm();
|
2014-07-21 14:33:52 +02:00
|
|
|
$request = $this->getRequest();
|
|
|
|
$currentConfig = IcingaConfig::app();
|
|
|
|
if ($request->isPost()) {
|
|
|
|
if ($form->isValid($request->getPost())) {
|
|
|
|
$formConfig = $form->getConfiguration();
|
|
|
|
$newConfig = new Zend_Config($currentConfig->toArray(), true);
|
|
|
|
$newConfig->global = $formConfig->global;
|
|
|
|
$newConfig->preferences = $formConfig->preferences;
|
|
|
|
if ($this->writeConfigFile($newConfig, 'config')) {
|
|
|
|
Notification::success($this->translate('New configuration has successfully been stored'));
|
|
|
|
$this->redirectNow('config');
|
|
|
|
}
|
2013-08-19 18:25:20 +02:00
|
|
|
}
|
2014-07-21 14:33:52 +02:00
|
|
|
} else {
|
|
|
|
$form->setConfiguration($currentConfig);
|
2013-08-14 10:53:25 +02:00
|
|
|
}
|
2014-07-21 14:33:52 +02:00
|
|
|
|
2013-08-14 10:53:25 +02:00
|
|
|
$this->view->form = $form;
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
2013-11-26 10:35:46 +01:00
|
|
|
$this->view->messageBox = new AlertMessageBox(true);
|
2014-02-25 11:23:36 +01:00
|
|
|
$this->view->tabs->activate('logging');
|
2013-11-20 19:10:38 +01:00
|
|
|
|
2013-08-14 10:53:25 +02:00
|
|
|
$form = new LoggingForm();
|
2014-07-18 10:29:23 +02:00
|
|
|
$request = $this->getRequest();
|
|
|
|
if ($request->isPost()) {
|
|
|
|
if ($form->isValid($request->getPost())) {
|
|
|
|
$appConfig = IcingaConfig::app();
|
|
|
|
$appConfig->logging = new Zend_Config($form->getValues());
|
|
|
|
if ($this->writeConfigFile($appConfig, 'config')) {
|
|
|
|
$this->addSuccessMessage($this->translate('Logging configuration has sucessfully been stored'));
|
|
|
|
$this->redirectNow('config/logging');
|
|
|
|
}
|
2013-08-19 18:25:20 +02:00
|
|
|
}
|
2014-07-18 10:29:23 +02:00
|
|
|
} else {
|
|
|
|
$loggingConfig = Icinga::app()->getConfig()->logging;
|
|
|
|
if ($loggingConfig === null) {
|
|
|
|
$loggingConfig = new Zend_Config(array());
|
|
|
|
}
|
|
|
|
$form->populate($loggingConfig->toArray());
|
2013-08-19 18:25:20 +02:00
|
|
|
}
|
2014-07-10 11:16:31 +02:00
|
|
|
|
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
|
|
|
|
*/
|
2014-06-21 01:54:32 +02:00
|
|
|
public function modulesAction()
|
2013-08-12 15:58:26 +02:00
|
|
|
{
|
2014-02-25 11:23:36 +01:00
|
|
|
$this->view->tabs->activate('modules');
|
2013-08-12 15:58:26 +02:00
|
|
|
$this->view->modules = Icinga::app()->getModuleManager()->select()
|
|
|
|
->from('modules')
|
2014-06-06 08:21:35 +02:00
|
|
|
->order('enabled', 'desc')
|
2014-06-21 02:27:27 +02:00
|
|
|
->order('name')->paginate();
|
2013-08-12 15:58:26 +02:00
|
|
|
}
|
|
|
|
|
2014-06-21 01:54:32 +02:00
|
|
|
public function moduleAction()
|
|
|
|
{
|
|
|
|
$name = $this->getParam('name');
|
|
|
|
$app = Icinga::app();
|
|
|
|
$manager = $app->getModuleManager();
|
|
|
|
if ($manager->hasInstalled($name)) {
|
2014-06-21 02:27:27 +02:00
|
|
|
$this->view->moduleData = Icinga::app()->getModuleManager()->select()
|
|
|
|
->from('modules')->where('name', $name)->fetchRow();
|
2014-06-21 01:54:32 +02:00
|
|
|
$module = new Module($app, $name, $manager->getModuleDir($name));
|
|
|
|
$this->view->module = $module;
|
|
|
|
} else {
|
|
|
|
$this->view->module = false;
|
|
|
|
}
|
2014-06-24 21:31:59 +02:00
|
|
|
$this->view->tabs = $module->getConfigTabs()->activate('info');
|
2014-06-21 01:54:32 +02:00
|
|
|
}
|
|
|
|
|
2013-08-12 15:58:26 +02:00
|
|
|
/**
|
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()
|
|
|
|
{
|
2013-08-29 17:44:02 +02:00
|
|
|
$module = $this->getParam('name');
|
2013-08-12 15:58:26 +02:00
|
|
|
$manager = Icinga::app()->getModuleManager();
|
2013-08-29 17:44:02 +02:00
|
|
|
try {
|
|
|
|
$manager->enableModule($module);
|
|
|
|
$manager->loadModule($module);
|
2014-06-21 01:54:32 +02:00
|
|
|
Notification::success('Module "' . $module . '" enabled');
|
2014-06-22 20:06:45 +02:00
|
|
|
$this->rerenderLayout()->reloadCss()->redirectNow('config/modules');
|
2013-08-29 17:44:02 +02:00
|
|
|
} catch (Exception $e) {
|
2013-11-20 19:10:38 +01:00
|
|
|
$this->view->exceptionMesssage = $e->getMessage();
|
2013-08-29 17:44:02 +02:00
|
|
|
$this->view->moduleName = $module;
|
|
|
|
$this->view->action = 'enable';
|
|
|
|
$this->render('module-configuration-error');
|
|
|
|
}
|
2013-08-12 15:58:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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()
|
|
|
|
{
|
2013-08-29 17:44:02 +02:00
|
|
|
$module = $this->getParam('name');
|
2013-08-12 15:58:26 +02:00
|
|
|
$manager = Icinga::app()->getModuleManager();
|
2013-08-29 17:44:02 +02:00
|
|
|
try {
|
|
|
|
$manager->disableModule($module);
|
2014-06-21 01:54:32 +02:00
|
|
|
Notification::success('Module "' . $module . '" disabled');
|
2014-06-22 20:06:45 +02:00
|
|
|
$this->rerenderLayout()->reloadCss()->redirectNow('config/modules');
|
2013-08-29 17:44:02 +02:00
|
|
|
} catch (Exception $e) {
|
|
|
|
$this->view->exceptionMessage = $e->getMessage();
|
|
|
|
$this->view->moduleName = $module;
|
|
|
|
$this->view->action = 'disable';
|
|
|
|
$this->render('module-configuration-error');
|
|
|
|
}
|
2013-08-12 15:58:26 +02:00
|
|
|
}
|
2013-08-14 10:53:25 +02:00
|
|
|
|
2013-08-16 16:24:12 +02:00
|
|
|
/**
|
2014-07-23 12:35:39 +02:00
|
|
|
* Action for reordering authentication backends
|
2013-08-16 16:24:12 +02:00
|
|
|
*/
|
2014-04-16 11:50:58 +02:00
|
|
|
public function authenticationAction()
|
2013-08-16 16:24:12 +02:00
|
|
|
{
|
2013-11-26 10:35:46 +01:00
|
|
|
$this->view->messageBox = new AlertMessageBox(true);
|
2014-07-23 12:35:39 +02:00
|
|
|
$this->view->tabs->activate('authentication');
|
2013-08-16 16:24:12 +02:00
|
|
|
|
2014-07-23 12:35:39 +02:00
|
|
|
$config = IcingaConfig::app('authentication');
|
|
|
|
$backendOrder = array_keys($config->toArray());
|
|
|
|
$form = new Form();
|
|
|
|
$form->setName('form_reorder_authbackend');
|
|
|
|
$request = $this->getRequest();
|
|
|
|
if ($request->isPost()) {
|
|
|
|
$requestData = $request->getPost();
|
|
|
|
if ($form->isValid($requestData)) { // Validate the CSRF token
|
|
|
|
$reordered = false;
|
|
|
|
foreach ($backendOrder as $backendName) {
|
|
|
|
if (isset($requestData[$backendName])) {
|
|
|
|
array_splice($backendOrder, array_search($backendName, $backendOrder), 1);
|
|
|
|
array_splice($backendOrder, $requestData[$backendName], 0, $backendName);
|
|
|
|
$reordered = true;
|
|
|
|
break;
|
|
|
|
}
|
2013-08-26 16:56:23 +02:00
|
|
|
}
|
2014-04-16 11:50:58 +02:00
|
|
|
|
2014-07-23 12:35:39 +02:00
|
|
|
if ($reordered) {
|
|
|
|
$reorderedConfig = array();
|
|
|
|
foreach ($backendOrder as $backendName) {
|
|
|
|
$reorderedConfig[$backendName] = $config->{$backendName};
|
|
|
|
}
|
2013-08-26 16:56:23 +02:00
|
|
|
|
2014-07-23 12:35:39 +02:00
|
|
|
if ($this->writeAuthenticationFile($reorderedConfig)) {
|
|
|
|
Notification::success($this->translate('Authentication order updated!'));
|
|
|
|
$this->redirectNow('config/authentication');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-08-16 16:24:12 +02:00
|
|
|
}
|
2014-04-16 11:50:58 +02:00
|
|
|
|
2014-07-23 12:35:39 +02:00
|
|
|
$this->view->form = $form->create(); // Necessary in case its a GET request
|
|
|
|
$this->view->backendNames = $backendOrder;
|
2013-08-26 16:56:23 +02:00
|
|
|
}
|
|
|
|
|
2013-08-16 16:24:12 +02:00
|
|
|
/**
|
|
|
|
* Action for creating a new authentication backend
|
|
|
|
*/
|
|
|
|
public function createauthenticationbackendAction()
|
|
|
|
{
|
2013-11-26 10:35:46 +01:00
|
|
|
$this->view->messageBox = new AlertMessageBox(true);
|
2013-11-20 19:10:38 +01:00
|
|
|
|
2013-08-16 16:24:12 +02:00
|
|
|
if ($this->getRequest()->getParam('type') === 'ldap') {
|
|
|
|
$form = new LdapBackendForm();
|
|
|
|
} else {
|
|
|
|
$form = new DbBackendForm();
|
|
|
|
}
|
2013-08-26 16:56:23 +02:00
|
|
|
if ($this->getParam('auth_backend')) {
|
|
|
|
$form->setBackendName($this->getParam('auth_backend'));
|
|
|
|
}
|
2013-08-16 16:24:12 +02:00
|
|
|
$form->setRequest($this->getRequest());
|
2013-08-26 16:56:23 +02:00
|
|
|
|
2013-08-16 16:24:12 +02:00
|
|
|
if ($form->isSubmittedAndValid()) {
|
|
|
|
$backendCfg = IcingaConfig::app('authentication')->toArray();
|
2013-11-13 18:12:00 +01:00
|
|
|
foreach ($backendCfg as $backendName => $settings) {
|
|
|
|
unset($backendCfg[$backendName]['name']);
|
|
|
|
}
|
2013-08-16 16:24:12 +02:00
|
|
|
foreach ($form->getConfig() as $backendName => $settings) {
|
2013-11-13 18:12:00 +01:00
|
|
|
unset($settings->{'name'});
|
2013-08-26 16:56:23 +02:00
|
|
|
if (isset($backendCfg[$backendName])) {
|
2013-11-26 10:35:46 +01:00
|
|
|
$this->addErrorMessage('Backend name already exists');
|
2013-08-26 16:56:23 +02:00
|
|
|
$this->view->form = $form;
|
|
|
|
$this->render('authentication/create');
|
|
|
|
return;
|
|
|
|
}
|
2013-08-16 16:24:12 +02:00
|
|
|
$backendCfg[$backendName] = $settings;
|
|
|
|
}
|
2013-08-26 16:56:23 +02:00
|
|
|
if ($this->writeAuthenticationFile($backendCfg)) {
|
|
|
|
// redirect to overview with success message
|
2014-06-24 21:11:48 +02:00
|
|
|
Notification::success('Backend Modification Written.');
|
2013-11-20 19:10:38 +01:00
|
|
|
$this->redirectNow("config/authentication");
|
2013-08-19 18:25:20 +02:00
|
|
|
}
|
2013-08-26 16:56:23 +02:00
|
|
|
return;
|
|
|
|
}
|
2013-11-20 19:10:38 +01:00
|
|
|
|
|
|
|
$this->view->messageBox->addForm($form);
|
2013-08-26 16:56:23 +02:00
|
|
|
$this->view->form = $form;
|
|
|
|
$this->render('authentication/create');
|
|
|
|
}
|
2013-08-16 16:24:12 +02:00
|
|
|
|
2013-11-06 19:02:30 +01:00
|
|
|
|
2013-08-26 16:56:23 +02:00
|
|
|
/**
|
|
|
|
* Form for editing backends
|
|
|
|
*
|
|
|
|
* Mostly the same like the createAuthenticationBackendAction, but with additional checks for backend existence
|
|
|
|
* and form population
|
|
|
|
*/
|
|
|
|
public function editauthenticationbackendAction()
|
|
|
|
{
|
2013-11-26 10:35:46 +01:00
|
|
|
$this->view->messageBox = new AlertMessageBox(true);
|
|
|
|
|
2013-08-26 16:56:23 +02:00
|
|
|
$configArray = IcingaConfig::app('authentication', true)->toArray();
|
|
|
|
$authBackend = $this->getParam('auth_backend');
|
|
|
|
if (!isset($configArray[$authBackend])) {
|
2013-11-20 19:10:38 +01:00
|
|
|
$this->addErrorMessage('Can\'t edit: Unknown Authentication Backend Provided');
|
|
|
|
$this->configurationerrorAction();
|
2013-08-26 16:56:23 +02:00
|
|
|
return;
|
|
|
|
}
|
2013-11-06 19:02:30 +01:00
|
|
|
if (!array_key_exists('resource', $configArray[$authBackend])) {
|
2013-11-20 19:10:38 +01:00
|
|
|
$this->addErrorMessage('Configuration error: Backend "' . $authBackend . '" has no Resource');
|
|
|
|
$this->configurationerrorAction();
|
2013-11-06 19:02:30 +01:00
|
|
|
return;
|
|
|
|
}
|
2013-08-26 16:56:23 +02:00
|
|
|
|
2013-11-06 19:02:30 +01:00
|
|
|
$type = ResourceFactory::getResourceConfig($configArray[$authBackend]['resource'])->type;
|
|
|
|
switch ($type) {
|
|
|
|
case 'ldap':
|
|
|
|
$form = new LdapBackendForm();
|
|
|
|
break;
|
|
|
|
case 'db':
|
|
|
|
$form = new DbBackendForm();
|
|
|
|
break;
|
|
|
|
default:
|
2013-11-20 19:10:38 +01:00
|
|
|
$this->addErrorMessage('Can\'t edit: backend type "' . $type . '" of given resource not supported.');
|
|
|
|
$this->configurationerrorAction();
|
2013-11-06 19:02:30 +01:00
|
|
|
return;
|
2013-08-16 16:24:12 +02:00
|
|
|
}
|
2013-08-26 16:56:23 +02:00
|
|
|
|
|
|
|
$form->setBackendName($this->getParam('auth_backend'));
|
|
|
|
$form->setBackend(IcingaConfig::app('authentication', true)->$authBackend);
|
|
|
|
$form->setRequest($this->getRequest());
|
|
|
|
|
|
|
|
if ($form->isSubmittedAndValid()) {
|
|
|
|
$backendCfg = IcingaConfig::app('authentication')->toArray();
|
|
|
|
foreach ($form->getConfig() as $backendName => $settings) {
|
|
|
|
$backendCfg[$backendName] = $settings;
|
|
|
|
// Remove the old section if the backend is renamed
|
|
|
|
if ($backendName != $authBackend) {
|
|
|
|
unset($backendCfg[$authBackend]);
|
|
|
|
}
|
2013-11-13 18:12:00 +01:00
|
|
|
unset($settings['name']);
|
2013-08-26 16:56:23 +02:00
|
|
|
}
|
|
|
|
if ($this->writeAuthenticationFile($backendCfg)) {
|
|
|
|
// redirect to overview with success message
|
2014-06-24 21:11:48 +02:00
|
|
|
Notification::success('Backend "' . $authBackend . '" created');
|
2013-11-20 19:10:38 +01:00
|
|
|
$this->redirectNow("config/authentication");
|
2013-08-26 16:56:23 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-20 19:10:38 +01:00
|
|
|
$this->view->messageBox->addForm($form);
|
2013-08-26 16:56:23 +02:00
|
|
|
$this->view->name = $authBackend;
|
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-11-06 19:02:30 +01:00
|
|
|
/**
|
|
|
|
* Action for removing a backend from the authentication list.
|
|
|
|
*
|
|
|
|
* Redirects to the overview after removal is finished
|
|
|
|
*/
|
|
|
|
public function removeauthenticationbackendAction()
|
|
|
|
{
|
2013-11-26 10:35:46 +01:00
|
|
|
$this->view->messageBox = new AlertMessageBox(true);
|
2013-11-20 19:10:38 +01:00
|
|
|
|
2013-11-06 19:02:30 +01:00
|
|
|
$configArray = IcingaConfig::app('authentication', true)->toArray();
|
|
|
|
$authBackend = $this->getParam('auth_backend');
|
|
|
|
if (!isset($configArray[$authBackend])) {
|
2014-06-24 21:11:48 +02:00
|
|
|
Notification::error('Can\'t perform removal: Unknown Authentication Backend Provided');
|
2013-11-20 19:10:38 +01:00
|
|
|
$this->render('authentication/remove');
|
2013-11-06 19:02:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$form = new ConfirmRemovalForm();
|
|
|
|
$form->setRequest($this->getRequest());
|
|
|
|
$form->setRemoveTarget('auth_backend', $authBackend);
|
|
|
|
|
|
|
|
if ($form->isSubmittedAndValid()) {
|
|
|
|
unset($configArray[$authBackend]);
|
|
|
|
if ($this->writeAuthenticationFile($configArray)) {
|
2014-06-24 21:11:48 +02:00
|
|
|
Notification::success('Authentication Backend "' . $authBackend . '" Removed');
|
2013-11-20 19:10:38 +01:00
|
|
|
$this->redirectNow("config/authentication");
|
2013-11-06 19:02:30 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->view->form = $form;
|
|
|
|
$this->view->name = $authBackend;
|
|
|
|
$this->render('authentication/remove');
|
|
|
|
}
|
|
|
|
|
2014-07-23 12:55:43 +02:00
|
|
|
/**
|
|
|
|
* Display all available resources and a link to create a new one
|
|
|
|
*/
|
|
|
|
public function resourceAction()
|
2013-11-06 19:02:30 +01:00
|
|
|
{
|
2014-07-23 12:55:43 +02:00
|
|
|
$this->view->messageBox = new AlertMessageBox(true);
|
2014-02-25 11:23:36 +01:00
|
|
|
$this->view->tabs->activate('resources');
|
|
|
|
|
2013-11-13 18:12:00 +01:00
|
|
|
$this->view->resources = IcingaConfig::app('resources', true)->toArray();
|
2013-11-06 19:02:30 +01:00
|
|
|
}
|
|
|
|
|
2014-07-23 16:39:54 +02:00
|
|
|
/**
|
|
|
|
* Display a form to create a new resource
|
|
|
|
*/
|
2013-11-06 19:02:30 +01:00
|
|
|
public function createresourceAction()
|
|
|
|
{
|
2014-07-23 16:39:54 +02:00
|
|
|
$this->view->messageBox = new AlertMessageBox(true);
|
|
|
|
|
2014-04-16 12:58:45 +02:00
|
|
|
$form = new ResourceForm();
|
2014-07-23 16:39:54 +02:00
|
|
|
$request = $this->getRequest();
|
|
|
|
if ($request->isPost() && $form->isValid($request->getPost())) {
|
|
|
|
list($name, $config) = $form->getResourceConfig();
|
|
|
|
$resources = IcingaConfig::app('resources')->toArray();
|
|
|
|
if (array_key_exists($name, $resources)) {
|
|
|
|
$this->addErrorMessage(sprintf($this->translate('Resource name "%s" already in use.'), $name));
|
2013-11-20 19:10:38 +01:00
|
|
|
} else {
|
2014-07-23 16:39:54 +02:00
|
|
|
$resources[$name] = $config;
|
2013-11-20 19:10:38 +01:00
|
|
|
if ($this->writeConfigFile($resources, 'resources')) {
|
2014-07-23 16:39:54 +02:00
|
|
|
$this->addSuccessMessage(sprintf($this->translate('Resource "%s" successfully created.'), $name));
|
2013-11-20 19:10:38 +01:00
|
|
|
}
|
2013-11-13 18:12:00 +01:00
|
|
|
}
|
|
|
|
}
|
2013-11-20 19:10:38 +01:00
|
|
|
|
2013-11-13 18:12:00 +01:00
|
|
|
$this->view->form = $form;
|
2014-07-23 16:39:54 +02:00
|
|
|
$this->view->messageBox->addForm($form);
|
2013-11-06 19:02:30 +01:00
|
|
|
$this->render('resource/create');
|
|
|
|
}
|
|
|
|
|
2014-07-24 12:37:33 +02:00
|
|
|
/**
|
|
|
|
* Display a form to edit a existing resource
|
|
|
|
*/
|
2013-11-06 19:02:30 +01:00
|
|
|
public function editresourceAction()
|
|
|
|
{
|
2013-11-26 10:35:46 +01:00
|
|
|
$this->view->messageBox = new AlertMessageBox(true);
|
2013-11-20 19:10:38 +01:00
|
|
|
|
2014-07-24 12:37:33 +02:00
|
|
|
// Fetch the resource to be edited
|
|
|
|
$resources = IcingaConfig::app('resources')->toArray();
|
|
|
|
$name = $this->getParam('resource');
|
|
|
|
if (false === array_key_exists($name, $resources)) {
|
|
|
|
$this->addErrorMessage(sprintf($this->translate('Cannot edit "%s". Resource not found.'), $name));
|
|
|
|
$this->redirectNow('config/configurationerror');
|
2013-11-06 19:02:30 +01:00
|
|
|
}
|
2014-07-24 12:37:33 +02:00
|
|
|
|
2014-04-16 12:58:45 +02:00
|
|
|
$form = new ResourceForm();
|
2014-07-24 12:37:33 +02:00
|
|
|
$request = $this->getRequest();
|
|
|
|
if ($request->isPost()) {
|
|
|
|
if ($form->isValid($request->getPost())) {
|
|
|
|
list($newName, $config) = $form->getResourceConfig();
|
|
|
|
|
|
|
|
if ($newName !== $name) {
|
|
|
|
// Resource name has changed
|
|
|
|
unset($resources[$name]); // We can safely use unset as all values are part of the form
|
|
|
|
}
|
|
|
|
|
|
|
|
$resources[$newName] = $config;
|
|
|
|
if ($this->writeConfigFile($resources, 'resources')) {
|
|
|
|
$this->addSuccessMessage(sprintf($this->translate('Resource "%s" successfully edited.'), $name));
|
|
|
|
$this->redirectNow('config/resource');
|
|
|
|
}
|
2013-11-13 18:12:00 +01:00
|
|
|
}
|
2014-07-24 12:37:33 +02:00
|
|
|
} else {
|
|
|
|
$form->setResourceConfig($name, $resources[$name]);
|
2013-11-13 18:12:00 +01:00
|
|
|
}
|
2013-11-20 19:10:38 +01:00
|
|
|
|
2013-11-13 18:12:00 +01:00
|
|
|
$this->view->form = $form;
|
2014-07-24 12:37:33 +02:00
|
|
|
$this->view->messageBox->addForm($form);
|
2013-11-06 19:02:30 +01:00
|
|
|
$this->render('resource/modify');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function removeresourceAction()
|
|
|
|
{
|
2013-11-26 10:35:46 +01:00
|
|
|
$this->view->messageBox = new AlertMessageBox(true);
|
2013-11-20 19:10:38 +01:00
|
|
|
|
2013-11-06 19:02:30 +01:00
|
|
|
$resources = ResourceFactory::getResourceConfigs()->toArray();
|
2013-11-13 18:12:00 +01:00
|
|
|
$name = $this->getParam('resource');
|
2013-11-06 19:02:30 +01:00
|
|
|
if (!isset($resources[$name])) {
|
2013-11-26 10:35:46 +01:00
|
|
|
$this->addSuccessMessage('Can\'t remove: Unknown resource provided');
|
2013-11-20 19:10:38 +01:00
|
|
|
$this->render('resource/remove');
|
2013-11-06 19:02:30 +01:00
|
|
|
return;
|
|
|
|
}
|
2013-11-13 18:12:00 +01:00
|
|
|
|
|
|
|
$form = new ConfirmRemovalForm();
|
|
|
|
$form->setRequest($this->getRequest());
|
|
|
|
$form->setRemoveTarget('resource', $name);
|
2014-03-03 18:16:07 +01:00
|
|
|
|
2013-11-26 10:35:46 +01:00
|
|
|
// Check if selected resource is currently used for authentication
|
|
|
|
$authConfig = IcingaConfig::app('authentication', true)->toArray();
|
|
|
|
foreach ($authConfig as $backendName => $config) {
|
2014-03-03 18:16:07 +01:00
|
|
|
if (array_key_exists('resource', $config) && $config['resource'] === $name) {
|
2013-11-26 10:35:46 +01:00
|
|
|
$this->addErrorMessage(
|
|
|
|
'Warning: The resource "' . $name . '" is currently used for user authentication by "' . $backendName . '". ' .
|
|
|
|
' Deleting it could eventally make login impossible.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-13 18:12:00 +01:00
|
|
|
if ($form->isSubmittedAndValid()) {
|
|
|
|
unset($resources[$name]);
|
|
|
|
if ($this->writeConfigFile($resources, 'resources')) {
|
2013-11-20 19:10:38 +01:00
|
|
|
$this->addSuccessMessage('Resource "' . $name . '" removed.');
|
|
|
|
$this->redirectNow('config/resource');
|
2013-11-13 18:12:00 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->view->name = $name;
|
|
|
|
$this->view->form = $form;
|
2013-11-06 19:02:30 +01:00
|
|
|
$this->render('resource/remove');
|
|
|
|
}
|
|
|
|
|
2013-11-20 19:10:38 +01:00
|
|
|
/**
|
|
|
|
* Redirect target only for error-states
|
|
|
|
*
|
|
|
|
* When an error is opened in the side-pane, redirecting this request to the index or the overview will look
|
|
|
|
* weird. This action returns a clear page containing only an AlertMessageBox.
|
|
|
|
*/
|
|
|
|
public function configurationerrorAction()
|
|
|
|
{
|
2013-11-26 10:35:46 +01:00
|
|
|
$this->view->messageBox = new AlertMessageBox(true);
|
2014-06-24 20:30:41 +02:00
|
|
|
$this->render('error/error', null, true);
|
2013-11-20 19:10:38 +01: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
|
|
|
}
|