2013-08-12 15:58:26 +02:00
|
|
|
<?php
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
2014-09-02 16:18:49 +02:00
|
|
|
use Icinga\Web\Controller\ActionController;
|
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\Widget;
|
|
|
|
use Icinga\Application\Icinga;
|
2014-11-07 13:53:03 +01:00
|
|
|
use Icinga\Application\Config;
|
2014-11-14 10:57:14 +01:00
|
|
|
use Icinga\Forms\Config\GeneralConfigForm;
|
|
|
|
use Icinga\Forms\Config\AuthenticationBackendReorderForm;
|
|
|
|
use Icinga\Forms\Config\AuthenticationBackendConfigForm;
|
|
|
|
use Icinga\Forms\Config\ResourceConfigForm;
|
|
|
|
use Icinga\Forms\ConfirmRemovalForm;
|
2014-08-29 15:16:13 +02:00
|
|
|
use Icinga\Data\ResourceFactory;
|
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
|
|
|
*/
|
2014-09-02 16:18:49 +02:00
|
|
|
class ConfigController extends ActionController
|
2013-08-12 15:58:26 +02:00
|
|
|
{
|
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()
|
|
|
|
{
|
2014-09-01 16:16:56 +02:00
|
|
|
$form = new GeneralConfigForm();
|
2014-11-07 13:53:03 +01:00
|
|
|
$form->setIniConfig(Config::app());
|
2014-09-01 16:16:56 +02:00
|
|
|
$form->handleRequest();
|
2014-07-21 14:33:52 +02:00
|
|
|
|
2013-08-14 10:53:25 +02:00
|
|
|
$this->view->form = $form;
|
2014-09-01 16:16:56 +02:00
|
|
|
$this->view->tabs->activate('index');
|
2013-08-14 10:53:25 +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-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-09-29 15:20:19 +02:00
|
|
|
Notification::success(sprintf($this->translate('Module "%s" enabled'), $module));
|
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) {
|
2014-10-24 13:49:49 +02:00
|
|
|
$this->view->exceptionMessage = $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-09-29 15:20:19 +02:00
|
|
|
Notification::success(sprintf($this->translate('Module "%s" disabled'), $module));
|
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-08-29 15:16:13 +02:00
|
|
|
* Action for listing and 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
|
|
|
{
|
2014-08-29 15:16:13 +02:00
|
|
|
$form = new AuthenticationBackendReorderForm();
|
2014-11-07 13:53:03 +01:00
|
|
|
$form->setIniConfig(Config::app('authentication'));
|
2014-08-29 15:16:13 +02:00
|
|
|
$form->handleRequest();
|
2014-04-16 11:50:58 +02:00
|
|
|
|
2014-08-29 15:16:13 +02:00
|
|
|
$this->view->form = $form;
|
|
|
|
$this->view->tabs->activate('authentication');
|
|
|
|
$this->render('authentication/reorder');
|
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()
|
|
|
|
{
|
2014-08-29 15:16:13 +02:00
|
|
|
$form = new AuthenticationBackendConfigForm();
|
2014-11-07 13:53:03 +01:00
|
|
|
$form->setIniConfig(Config::app('authentication'));
|
2014-08-29 15:16:13 +02:00
|
|
|
$form->setResourceConfig(ResourceFactory::getResourceConfigs());
|
|
|
|
$form->setRedirectUrl('config/authentication');
|
|
|
|
$form->handleRequest();
|
2013-11-20 19:10:38 +01:00
|
|
|
|
2013-08-26 16:56:23 +02:00
|
|
|
$this->view->form = $form;
|
2014-08-29 15:16:13 +02:00
|
|
|
$this->view->tabs->activate('authentication');
|
2013-08-26 16:56:23 +02:00
|
|
|
$this->render('authentication/create');
|
|
|
|
}
|
2013-08-16 16:24:12 +02:00
|
|
|
|
2013-08-26 16:56:23 +02:00
|
|
|
/**
|
2014-08-29 15:16:13 +02:00
|
|
|
* Action for editing authentication backends
|
2013-08-26 16:56:23 +02:00
|
|
|
*/
|
|
|
|
public function editauthenticationbackendAction()
|
|
|
|
{
|
2014-08-29 15:16:13 +02:00
|
|
|
$form = new AuthenticationBackendConfigForm();
|
2014-11-07 13:53:03 +01:00
|
|
|
$form->setIniConfig(Config::app('authentication'));
|
2014-08-29 15:16:13 +02:00
|
|
|
$form->setResourceConfig(ResourceFactory::getResourceConfigs());
|
|
|
|
$form->setRedirectUrl('config/authentication');
|
|
|
|
$form->handleRequest();
|
2013-11-26 10:35:46 +01:00
|
|
|
|
2013-08-16 16:24:12 +02:00
|
|
|
$this->view->form = $form;
|
2014-08-29 15:16:13 +02:00
|
|
|
$this->view->tabs->activate('authentication');
|
2013-08-16 16:24:12 +02:00
|
|
|
$this->render('authentication/modify');
|
|
|
|
}
|
2013-08-14 10:53:25 +02:00
|
|
|
|
2013-11-06 19:02:30 +01:00
|
|
|
/**
|
2014-08-29 15:16:13 +02:00
|
|
|
* Action for removing a backend from the authentication list
|
2013-11-06 19:02:30 +01:00
|
|
|
*/
|
|
|
|
public function removeauthenticationbackendAction()
|
|
|
|
{
|
2014-08-29 15:16:13 +02:00
|
|
|
$form = new ConfirmRemovalForm(array(
|
2014-11-18 13:12:30 +01:00
|
|
|
'onSuccess' => function ($form) {
|
2014-08-29 15:16:13 +02:00
|
|
|
$configForm = new AuthenticationBackendConfigForm();
|
2014-11-07 13:53:03 +01:00
|
|
|
$configForm->setIniConfig(Config::app('authentication'));
|
2014-11-18 13:12:30 +01:00
|
|
|
$authBackend = $form->getRequest()->getQuery('auth_backend');
|
2014-08-29 15:16:13 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
$configForm->remove($authBackend);
|
|
|
|
} catch (InvalidArgumentException $e) {
|
|
|
|
Notification::error($e->getMessage());
|
|
|
|
return;
|
|
|
|
}
|
2013-11-06 19:02:30 +01:00
|
|
|
|
2014-08-29 15:16:13 +02:00
|
|
|
if ($configForm->save()) {
|
|
|
|
Notification::success(sprintf(
|
|
|
|
t('Authentication backend "%s" has been successfully removed'),
|
|
|
|
$authBackend
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2013-11-06 19:02:30 +01:00
|
|
|
}
|
2014-08-29 15:16:13 +02:00
|
|
|
));
|
|
|
|
$form->setRedirectUrl('config/authentication');
|
|
|
|
$form->handleRequest();
|
2013-11-06 19:02:30 +01:00
|
|
|
|
|
|
|
$this->view->form = $form;
|
2014-08-29 15:16:13 +02:00
|
|
|
$this->view->tabs->activate('authentication');
|
2013-11-06 19:02:30 +01:00
|
|
|
$this->render('authentication/remove');
|
|
|
|
}
|
|
|
|
|
2014-07-23 12:55:43 +02:00
|
|
|
/**
|
2014-09-02 15:39:21 +02:00
|
|
|
* Display all available resources and a link to create a new one and to remove existing ones
|
2014-07-23 12:55:43 +02:00
|
|
|
*/
|
|
|
|
public function resourceAction()
|
2013-11-06 19:02:30 +01:00
|
|
|
{
|
2014-11-18 13:11:52 +01:00
|
|
|
$this->view->resources = Config::app('resources', true)->keys();
|
2014-09-02 15:39:21 +02:00
|
|
|
$this->view->tabs->activate('resources');
|
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-09-02 15:39:21 +02:00
|
|
|
$form = new ResourceConfigForm();
|
2014-11-07 13:53:03 +01:00
|
|
|
$form->setIniConfig(Config::app('resources'));
|
2014-09-02 15:39:21 +02:00
|
|
|
$form->setRedirectUrl('config/resource');
|
|
|
|
$form->handleRequest();
|
2013-11-20 19:10:38 +01:00
|
|
|
|
2013-11-13 18:12:00 +01:00
|
|
|
$this->view->form = $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()
|
|
|
|
{
|
2014-09-02 15:39:21 +02:00
|
|
|
$form = new ResourceConfigForm();
|
2014-11-07 13:53:03 +01:00
|
|
|
$form->setIniConfig(Config::app('resources'));
|
2014-09-02 15:39:21 +02:00
|
|
|
$form->setRedirectUrl('config/resource');
|
|
|
|
$form->handleRequest();
|
2013-11-20 19:10:38 +01:00
|
|
|
|
2013-11-13 18:12:00 +01:00
|
|
|
$this->view->form = $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()
|
|
|
|
{
|
2014-09-02 15:39:21 +02:00
|
|
|
$form = new ConfirmRemovalForm(array(
|
2014-11-18 13:12:30 +01:00
|
|
|
'onSuccess' => function ($form) {
|
2014-09-02 15:39:21 +02:00
|
|
|
$configForm = new ResourceConfigForm();
|
2014-11-07 13:53:03 +01:00
|
|
|
$configForm->setIniConfig(Config::app('resources'));
|
2014-11-18 13:12:30 +01:00
|
|
|
$resource = $form->getRequest()->getQuery('resource');
|
2014-09-02 15:39:21 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
$configForm->remove($resource);
|
|
|
|
} catch (InvalidArgumentException $e) {
|
|
|
|
Notification::error($e->getMessage());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($configForm->save()) {
|
|
|
|
Notification::success(sprintf(t('Resource "%s" has been successfully removed'), $resource));
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
));
|
|
|
|
$form->setRedirectUrl('config/resource');
|
|
|
|
$form->handleRequest();
|
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-09-02 15:39:21 +02:00
|
|
|
$resource = $this->getRequest()->getQuery('resource');
|
2014-11-18 13:11:52 +01:00
|
|
|
$authConfig = Config::app('authentication');
|
2013-11-26 10:35:46 +01:00
|
|
|
foreach ($authConfig as $backendName => $config) {
|
2014-11-18 13:11:52 +01:00
|
|
|
if ($config->get('resource') === $resource) {
|
2014-09-02 15:39:21 +02:00
|
|
|
$form->addError(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.'
|
|
|
|
),
|
|
|
|
$resource,
|
|
|
|
$backendName
|
|
|
|
));
|
2013-11-13 18:12:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->view->form = $form;
|
2013-11-06 19:02:30 +01:00
|
|
|
$this->render('resource/remove');
|
|
|
|
}
|
2013-08-12 15:58:26 +02:00
|
|
|
}
|