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\AlertMessageBox;
|
2014-06-21 01:54:32 +02:00
|
|
|
use Icinga\Web\Notification;
|
|
|
|
use Icinga\Application\Modules\Module;
|
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\Form\Config\GeneralForm;
|
|
|
|
use Icinga\Form\Config\Authentication\LdapBackendForm;
|
|
|
|
use Icinga\Form\Config\Authentication\DbBackendForm;
|
2014-07-24 15:50:01 +02:00
|
|
|
use Icinga\Form\Config\Authentication\AutologinBackendForm;
|
2014-06-21 02:27:27 +02:00
|
|
|
use Icinga\Form\Config\ResourceForm;
|
|
|
|
use Icinga\Form\Config\LoggingForm;
|
|
|
|
use Icinga\Form\Config\ConfirmRemovalForm;
|
|
|
|
use Icinga\Config\PreservingIniWriter;
|
2014-07-29 12:25:48 +02:00
|
|
|
use Icinga\Exception\ConfigurationError;
|
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'
|
|
|
|
));
|
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();
|
|
|
|
if ($request->isPost()) {
|
|
|
|
if ($form->isValid($request->getPost())) {
|
2014-08-22 11:05:20 +02:00
|
|
|
if ($this->writeConfigFile($form->getConfiguration(), 'config')) {
|
2014-07-21 14:33:52 +02:00
|
|
|
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 {
|
2014-08-22 11:05:20 +02:00
|
|
|
$form->setConfiguration(IcingaConfig::app());
|
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-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-08-19 13:17:31 +02:00
|
|
|
$this->view->tabs = Widget::create('tabs')->add('modules', array(
|
|
|
|
'title' => 'Modules',
|
|
|
|
'url' => 'config/modules'
|
|
|
|
));
|
|
|
|
|
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);
|
2014-07-24 15:50:01 +02:00
|
|
|
$this->view->tabs->activate('authentication');
|
2013-11-20 19:10:38 +01:00
|
|
|
|
2014-07-24 15:50:01 +02:00
|
|
|
$backendType = $this->getRequest()->getParam('type');
|
|
|
|
$authenticationConfig = IcingaConfig::app('authentication')->toArray();
|
2014-07-29 12:25:48 +02:00
|
|
|
try {
|
|
|
|
switch ($backendType) {
|
|
|
|
case 'ldap':
|
|
|
|
$form = new LdapBackendForm();
|
|
|
|
break;
|
|
|
|
case 'db':
|
|
|
|
$form = new DbBackendForm();
|
|
|
|
break;
|
|
|
|
case 'autologin':
|
|
|
|
foreach ($authenticationConfig as $ac) {
|
|
|
|
if (array_key_exists('backend', $ac) && $ac['backend'] === 'autologin') {
|
|
|
|
throw new ConfigurationError(
|
|
|
|
$this->translate('An autologin backend already exists')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$form = new AutologinBackendForm();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$this->addErrorMessage(sprintf(
|
|
|
|
$this->translate('There is no backend type `%s\''),
|
|
|
|
$backendType
|
|
|
|
));
|
2014-07-24 17:35:26 +02:00
|
|
|
$this->redirectNow('config/configurationerror');
|
2014-07-29 12:25:48 +02:00
|
|
|
}
|
|
|
|
} catch (ConfigurationError $e) {
|
|
|
|
$this->addErrorMessage($e->getMessage());
|
|
|
|
$this->redirectNow('config/configurationerror');
|
2013-08-16 16:24:12 +02:00
|
|
|
}
|
2013-08-26 16:56:23 +02:00
|
|
|
|
2014-07-24 15:50:01 +02:00
|
|
|
$request = $this->getRequest();
|
|
|
|
if ($request->isPost() && $form->isValid($request->getPost())) {
|
|
|
|
list($backendName, $backendConfig) = $form->getBackendConfig();
|
|
|
|
if (isset($authenticationConfig[$backendName])) {
|
|
|
|
$this->addErrorMessage(
|
|
|
|
$this->translate('Backend name already exists')
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$authenticationConfig[$backendName] = $backendConfig;
|
|
|
|
if ($this->writeConfigFile($authenticationConfig, 'authentication')) {
|
|
|
|
$this->addSuccessMessage(
|
|
|
|
$this->translate('Backend Modification Written.')
|
|
|
|
);
|
|
|
|
$this->redirectNow('config/authentication');
|
2013-08-26 16:56:23 +02:00
|
|
|
}
|
2013-08-19 18:25:20 +02:00
|
|
|
}
|
2013-08-26 16:56:23 +02:00
|
|
|
}
|
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');
|
2014-07-25 10:29:33 +02:00
|
|
|
if (false === isset($configArray[$authBackend])) {
|
|
|
|
$this->addErrorMessage(
|
|
|
|
$this->translate('Can\'t edit: Unknown Authentication Backend Provided')
|
|
|
|
);
|
|
|
|
$this->redirectNow('config/configurationerror');
|
2013-11-06 19:02:30 +01:00
|
|
|
}
|
2013-08-26 16:56:23 +02:00
|
|
|
|
2014-07-25 10:29:33 +02:00
|
|
|
if (false === array_key_exists('backend', $configArray[$authBackend])) {
|
|
|
|
$this->addErrorMessage(sprintf(
|
|
|
|
$this->translate('Backend "%s" has no `backend\' setting'),
|
|
|
|
$authBackend
|
|
|
|
));
|
|
|
|
$this->redirectNow('config/configurationerror');
|
|
|
|
}
|
|
|
|
$type = $configArray[$authBackend]['backend'];
|
2013-11-06 19:02:30 +01:00
|
|
|
switch ($type) {
|
|
|
|
case 'ldap':
|
|
|
|
$form = new LdapBackendForm();
|
|
|
|
break;
|
|
|
|
case 'db':
|
|
|
|
$form = new DbBackendForm();
|
|
|
|
break;
|
2014-07-25 10:29:33 +02:00
|
|
|
case 'autologin':
|
|
|
|
$form = new AutologinBackendForm();
|
|
|
|
break;
|
2013-11-06 19:02:30 +01:00
|
|
|
default:
|
2014-07-25 10:29:33 +02:00
|
|
|
$this->addErrorMessage(sprintf(
|
|
|
|
$this->translate('Can\'t edit: backend type "%s" of given resource not supported.'),
|
|
|
|
$type
|
|
|
|
));
|
|
|
|
$this->redirectNow('config/configurationerror');
|
2013-08-16 16:24:12 +02:00
|
|
|
}
|
2013-08-26 16:56:23 +02:00
|
|
|
|
2014-07-25 10:29:33 +02:00
|
|
|
$request = $this->getRequest();
|
|
|
|
if ($request->isPost()) {
|
|
|
|
if ($form->isValid($request->getPost())) {
|
|
|
|
list($backendName, $backendConfig) = $form->getBackendConfig();
|
|
|
|
$configArray[$backendName] = $backendConfig;
|
2013-08-26 16:56:23 +02:00
|
|
|
if ($backendName != $authBackend) {
|
2014-07-25 10:29:33 +02:00
|
|
|
unset($configArray[$authBackend]);
|
2013-08-26 16:56:23 +02:00
|
|
|
}
|
2014-07-25 10:29:33 +02:00
|
|
|
if ($this->writeAuthenticationFile($configArray)) {
|
|
|
|
// redirect to overview with success message
|
|
|
|
Notification::success(sprintf(
|
|
|
|
$this->translate('Backend "%s" saved'),
|
|
|
|
$backendName
|
|
|
|
));
|
|
|
|
$this->redirectNow('config/authentication');
|
|
|
|
}
|
|
|
|
return;
|
2013-08-26 16:56:23 +02:00
|
|
|
}
|
2014-07-25 10:29:33 +02:00
|
|
|
} else {
|
|
|
|
$form->setBackendConfig($authBackend, $configArray[$authBackend]);
|
2013-08-26 16:56:23 +02:00
|
|
|
}
|
|
|
|
|
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');
|
2014-07-25 14:49:05 +02:00
|
|
|
if (false === array_key_exists($authBackend, $configArray)) {
|
|
|
|
$this->addErrorMessage(
|
|
|
|
$this->translate('Can\'t perform removal: Unknown authentication backend provided')
|
|
|
|
);
|
|
|
|
$this->redirectNow('config/configurationerror');
|
2013-11-06 19:02:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$form = new ConfirmRemovalForm();
|
2014-07-25 14:49:05 +02:00
|
|
|
$request = $this->getRequest();
|
2013-11-06 19:02:30 +01:00
|
|
|
|
2014-07-25 14:49:05 +02:00
|
|
|
if ($request->isPost() && $form->isValid($request->getPost())) {
|
2013-11-06 19:02:30 +01:00
|
|
|
unset($configArray[$authBackend]);
|
|
|
|
if ($this->writeAuthenticationFile($configArray)) {
|
2014-07-25 14:49:05 +02:00
|
|
|
Notification::success(sprintf(
|
|
|
|
$this->translate('Authentication Backend "%s" Removed'),
|
|
|
|
$authBackend
|
|
|
|
));
|
|
|
|
$this->redirectNow('config/authentication');
|
2013-11-06 19:02:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$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));
|
2014-08-12 10:42:28 +02:00
|
|
|
$this->redirectNow('config/resource');
|
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');
|
|
|
|
}
|
|
|
|
|
2014-07-24 16:17:30 +02:00
|
|
|
/**
|
|
|
|
* Display a confirmation form to remove a resource
|
|
|
|
*/
|
2013-11-06 19:02:30 +01:00
|
|
|
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
|
|
|
|
2014-07-24 16:17:30 +02:00
|
|
|
// Fetch the resource to be removed
|
|
|
|
$resources = IcingaConfig::app('resources')->toArray();
|
|
|
|
$name = $this->getParam('resource');
|
|
|
|
if (false === array_key_exists($name, $resources)) {
|
|
|
|
$this->addErrorMessage(sprintf($this->translate('Cannot remove "%s". Resource not found.'), $name));
|
|
|
|
$this->redirectNow('config/configurationerror');
|
2013-11-06 19:02:30 +01:00
|
|
|
}
|
2013-11-13 18:12:00 +01:00
|
|
|
|
2013-11-26 10:35:46 +01:00
|
|
|
// Check if selected resource is currently used for authentication
|
2014-07-24 16:17:30 +02:00
|
|
|
$authConfig = IcingaConfig::app('authentication')->toArray();
|
2013-11-26 10:35:46 +01:00
|
|
|
foreach ($authConfig as $backendName => $config) {
|
2014-07-24 16:17:30 +02:00
|
|
|
if (array_key_exists('resource', $config) && $config['resource'] === $name) {
|
|
|
|
$this->addWarningMessage(
|
|
|
|
sprintf(
|
|
|
|
$this->translate(
|
|
|
|
'The resource "%s" is currently in use by the authentication backend "%s". ' .
|
|
|
|
'Removing the resource can result in noone being able to log in any longer.'
|
|
|
|
),
|
|
|
|
$name,
|
|
|
|
$backendName
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2013-11-26 10:35:46 +01:00
|
|
|
}
|
|
|
|
|
2014-07-24 16:17:30 +02:00
|
|
|
$form = new ConfirmRemovalForm();
|
|
|
|
$request = $this->getRequest();
|
|
|
|
if ($request->isPost() && $form->isValid($request->getPost())) {
|
2013-11-13 18:12:00 +01:00
|
|
|
unset($resources[$name]);
|
|
|
|
if ($this->writeConfigFile($resources, 'resources')) {
|
2014-07-24 16:17:30 +02:00
|
|
|
$this->addSuccessMessage(sprintf($this->translate('Resource "%s" successfully removed.'), $name));
|
2013-11-20 19:10:38 +01:00
|
|
|
$this->redirectNow('config/resource');
|
2013-11-13 18:12:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->view->form = $form;
|
2014-07-24 16:17:30 +02:00
|
|
|
$this->view->messageBox->addForm($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
|
|
|
}
|