2013-08-12 15:58:26 +02:00
|
|
|
<?php
|
2015-02-04 10:46:36 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
2013-08-12 15:58:26 +02:00
|
|
|
|
2014-11-07 13:53:03 +01:00
|
|
|
use Icinga\Application\Config;
|
2015-02-02 13:46:35 +01:00
|
|
|
use Icinga\Application\Icinga;
|
|
|
|
use Icinga\Application\Modules\Module;
|
|
|
|
use Icinga\Data\ResourceFactory;
|
2015-06-02 09:58:57 +02:00
|
|
|
use Icinga\Forms\Config\UserBackendConfigForm;
|
|
|
|
use Icinga\Forms\Config\UserBackendReorderForm;
|
2015-02-02 13:46:35 +01:00
|
|
|
use Icinga\Forms\Config\GeneralConfigForm;
|
2014-11-14 10:57:14 +01:00
|
|
|
use Icinga\Forms\Config\ResourceConfigForm;
|
|
|
|
use Icinga\Forms\ConfirmRemovalForm;
|
2015-02-02 13:46:35 +01:00
|
|
|
use Icinga\Security\SecurityException;
|
2015-04-17 16:09:35 +02:00
|
|
|
use Icinga\Web\Controller;
|
2015-02-02 13:46:35 +01:00
|
|
|
use Icinga\Web\Notification;
|
2015-06-02 09:58:57 +02:00
|
|
|
use Icinga\Web\Url;
|
2015-02-02 13:46:35 +01:00
|
|
|
use Icinga\Web\Widget;
|
2014-06-21 01:54:32 +02:00
|
|
|
|
2013-08-12 15:58:26 +02:00
|
|
|
/**
|
2015-02-02 13:46:35 +01:00
|
|
|
* Application and module configuration
|
2013-08-12 15:58:26 +02:00
|
|
|
*/
|
2015-04-17 16:09:35 +02:00
|
|
|
class ConfigController extends Controller
|
2013-08-12 15:58:26 +02:00
|
|
|
{
|
2015-02-02 13:46:35 +01:00
|
|
|
/**
|
|
|
|
* The first allowed config action according to the user's permissions
|
|
|
|
*
|
2015-03-12 13:39:17 +01:00
|
|
|
* @var string
|
2015-02-02 13:46:35 +01:00
|
|
|
*/
|
|
|
|
protected $firstAllowedAction;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize tabs and validate the user's permissions
|
|
|
|
*
|
|
|
|
* @throws SecurityException If the user does not have any configuration permission
|
|
|
|
*/
|
2014-06-24 21:31:59 +02:00
|
|
|
public function init()
|
2013-08-12 15:58:26 +02:00
|
|
|
{
|
2015-02-02 13:46:35 +01:00
|
|
|
$tabs = $this->getTabs();
|
|
|
|
$auth = $this->Auth();
|
|
|
|
$allowedActions = array();
|
2015-03-12 14:40:37 +01:00
|
|
|
if ($auth->hasPermission('config/application/general')) {
|
2015-06-01 16:35:27 +02:00
|
|
|
$tabs->add('general', array(
|
2015-02-23 16:50:31 +01:00
|
|
|
'title' => $this->translate('Adjust the general configuration of Icinga Web 2'),
|
2015-06-01 16:35:27 +02:00
|
|
|
'label' => $this->translate('General'),
|
|
|
|
'url' => 'config/general'
|
2015-02-02 13:46:35 +01:00
|
|
|
));
|
2015-06-01 16:35:27 +02:00
|
|
|
$allowedActions[] = 'general';
|
2015-02-02 13:46:35 +01:00
|
|
|
}
|
2015-06-02 10:23:40 +02:00
|
|
|
if ($auth->hasPermission('config/application/resources')) {
|
|
|
|
$tabs->add('resource', array(
|
|
|
|
'title' => $this->translate('Configure which resources are being utilized by Icinga Web 2'),
|
|
|
|
'label' => $this->translate('Resources'),
|
|
|
|
'url' => 'config/resource'
|
|
|
|
));
|
|
|
|
$allowedActions[] = 'resource';
|
|
|
|
}
|
2015-06-02 09:58:57 +02:00
|
|
|
if ($auth->hasPermission('config/application/userbackend')) {
|
|
|
|
$tabs->add('userbackend', array(
|
2015-02-23 16:50:31 +01:00
|
|
|
'title' => $this->translate('Configure how users authenticate with and log into Icinga Web 2'),
|
|
|
|
'label' => $this->translate('Authentication'),
|
2015-06-02 09:58:57 +02:00
|
|
|
'url' => 'config/userbackend'
|
2015-02-02 13:46:35 +01:00
|
|
|
));
|
2015-06-02 09:58:57 +02:00
|
|
|
$allowedActions[] = 'userbackend';
|
2015-02-02 13:46:35 +01:00
|
|
|
}
|
2015-06-02 10:23:40 +02:00
|
|
|
if ($auth->hasPermission('config/application/usergroupbackend')) {
|
|
|
|
$tabs->add('usergroupbackend', array(
|
|
|
|
'title' => $this->translate('Configure how users are associated with groups by Icinga Web 2'),
|
|
|
|
'label' => $this->translate('User Groups'),
|
|
|
|
'url' => 'usergroupbackend/list'
|
2015-02-02 13:46:35 +01:00
|
|
|
));
|
2015-06-02 10:23:40 +02:00
|
|
|
$allowedActions[] = 'usergroupbackend';
|
2015-02-02 13:46:35 +01:00
|
|
|
}
|
|
|
|
$this->firstAllowedAction = array_shift($allowedActions);
|
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
|
|
|
/**
|
2015-02-02 13:46:35 +01:00
|
|
|
* Forward or redirect to the first allowed configuration action
|
2013-08-12 15:58:26 +02:00
|
|
|
*/
|
|
|
|
public function indexAction()
|
|
|
|
{
|
2015-02-02 13:46:35 +01:00
|
|
|
if ($this->firstAllowedAction === null) {
|
2015-06-02 11:59:04 +02:00
|
|
|
throw new SecurityException($this->translate('No permission for application configuration'));
|
2015-02-02 13:46:35 +01:00
|
|
|
}
|
2015-06-17 13:43:59 +02:00
|
|
|
|
|
|
|
$this->redirectNow($this->getTabs()->get($this->firstAllowedAction)->getUrl());
|
2015-02-02 13:46:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-06-01 16:35:27 +02:00
|
|
|
* General configuration
|
2015-02-02 13:46:35 +01:00
|
|
|
*
|
2015-06-01 16:35:27 +02:00
|
|
|
* @throws SecurityException If the user lacks the permission for configuring the general configuration
|
2015-02-02 13:46:35 +01:00
|
|
|
*/
|
2015-06-01 16:35:27 +02:00
|
|
|
public function generalAction()
|
2015-02-02 13:46:35 +01:00
|
|
|
{
|
2015-03-12 14:40:37 +01:00
|
|
|
$this->assertPermission('config/application/general');
|
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;
|
2015-06-01 16:35:27 +02:00
|
|
|
$this->view->tabs->activate('general');
|
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
|
|
|
{
|
2015-02-02 13:46:35 +01:00
|
|
|
// Overwrite tabs created in init
|
|
|
|
// @TODO(el): This seems not natural to me. Module configuration should have its own controller.
|
|
|
|
$this->view->tabs = Widget::create('tabs')
|
|
|
|
->add('modules', array(
|
2015-02-27 09:32:44 +01:00
|
|
|
'label' => $this->translate('Modules'),
|
|
|
|
'title' => $this->translate('List intalled modules'),
|
2015-02-02 13:46:35 +01:00
|
|
|
'url' => 'config/modules'
|
|
|
|
))
|
|
|
|
->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')
|
2015-05-15 14:32:58 +02:00
|
|
|
->order('name');
|
2015-04-17 16:09:35 +02:00
|
|
|
$this->setupLimitControl();
|
|
|
|
$this->setupPaginationControl($this->view->modules);
|
|
|
|
// TODO: Not working
|
|
|
|
/*$this->setupSortControl(array(
|
|
|
|
'name' => $this->translate('Modulename'),
|
|
|
|
'path' => $this->translate('Installation Path'),
|
|
|
|
'enabled' => $this->translate('State')
|
|
|
|
));*/
|
2013-08-12 15:58:26 +02:00
|
|
|
}
|
|
|
|
|
2014-06-21 01:54:32 +02:00
|
|
|
public function moduleAction()
|
|
|
|
{
|
|
|
|
$app = Icinga::app();
|
|
|
|
$manager = $app->getModuleManager();
|
2015-03-06 13:25:04 +01:00
|
|
|
$name = $this->getParam('name');
|
2014-06-21 01:54:32 +02:00
|
|
|
if ($manager->hasInstalled($name)) {
|
2015-03-06 13:25:04 +01:00
|
|
|
$this->view->moduleData = $manager->select()->from('modules')->where('name', $name)->fetchRow();
|
|
|
|
if ($manager->hasLoaded($name)) {
|
|
|
|
$module = $manager->getModule($name);
|
|
|
|
} else {
|
|
|
|
$module = new Module($app, $name, $manager->getModuleDir($name));
|
|
|
|
}
|
|
|
|
|
2014-06-21 01:54:32 +02:00
|
|
|
$this->view->module = $module;
|
2015-03-06 13:25:04 +01:00
|
|
|
$this->view->tabs = $module->getConfigTabs()->activate('info');
|
2014-06-21 01:54:32 +02:00
|
|
|
} else {
|
|
|
|
$this->view->module = false;
|
2015-03-06 13:25:04 +01:00
|
|
|
$this->view->tabs = null;
|
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()
|
|
|
|
{
|
2015-03-12 14:53:20 +01:00
|
|
|
$this->assertPermission('config/modules');
|
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);
|
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()
|
|
|
|
{
|
2015-03-12 14:53:20 +01:00
|
|
|
$this->assertPermission('config/modules');
|
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
|
|
|
/**
|
2015-06-02 09:58:57 +02:00
|
|
|
* Action for listing and reordering user backends
|
2013-08-16 16:24:12 +02:00
|
|
|
*/
|
2015-06-02 09:58:57 +02:00
|
|
|
public function userbackendAction()
|
2013-08-16 16:24:12 +02:00
|
|
|
{
|
2015-06-02 09:58:57 +02:00
|
|
|
$this->assertPermission('config/application/userbackend');
|
|
|
|
$form = new UserBackendReorderForm();
|
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;
|
2015-06-02 09:58:57 +02:00
|
|
|
$this->view->tabs->activate('userbackend');
|
|
|
|
$this->render('userbackend/reorder');
|
2013-08-26 16:56:23 +02:00
|
|
|
}
|
|
|
|
|
2013-08-16 16:24:12 +02:00
|
|
|
/**
|
2015-06-02 09:58:57 +02:00
|
|
|
* Action for creating a new user backend
|
2013-08-16 16:24:12 +02:00
|
|
|
*/
|
2015-06-02 09:58:57 +02:00
|
|
|
public function createuserbackendAction()
|
2013-08-16 16:24:12 +02:00
|
|
|
{
|
2015-06-02 09:58:57 +02:00
|
|
|
$this->assertPermission('config/application/userbackend');
|
|
|
|
$form = new UserBackendConfigForm();
|
|
|
|
$form->setTitle($this->translate('Create New User Backend'));
|
2015-03-02 18:37:54 +01:00
|
|
|
$form->addDescription($this->translate(
|
|
|
|
'Create a new backend for authenticating your users. This backend'
|
|
|
|
. ' will be added at the end of your authentication order.'
|
|
|
|
));
|
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());
|
2015-06-02 09:58:57 +02:00
|
|
|
$form->setRedirectUrl('config/userbackend');
|
2014-08-29 15:16:13 +02:00
|
|
|
$form->handleRequest();
|
2013-11-20 19:10:38 +01:00
|
|
|
|
2013-08-26 16:56:23 +02:00
|
|
|
$this->view->form = $form;
|
2015-06-02 09:58:57 +02:00
|
|
|
$this->view->tabs->activate('userbackend');
|
|
|
|
$this->render('userbackend/create');
|
2013-08-26 16:56:23 +02:00
|
|
|
}
|
2013-08-16 16:24:12 +02:00
|
|
|
|
2013-08-26 16:56:23 +02:00
|
|
|
/**
|
2015-06-02 09:58:57 +02:00
|
|
|
* Action for editing user backends
|
2013-08-26 16:56:23 +02:00
|
|
|
*/
|
2015-06-02 09:58:57 +02:00
|
|
|
public function edituserbackendAction()
|
2013-08-26 16:56:23 +02:00
|
|
|
{
|
2015-06-02 09:58:57 +02:00
|
|
|
$this->assertPermission('config/application/userbackend');
|
|
|
|
$form = new UserBackendConfigForm();
|
|
|
|
$form->setTitle($this->translate('Edit User Backend'));
|
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());
|
2015-06-02 09:58:57 +02:00
|
|
|
$form->setRedirectUrl('config/userbackend');
|
|
|
|
$form->setAction(Url::fromRequest());
|
2014-08-29 15:16:13 +02:00
|
|
|
$form->handleRequest();
|
2013-11-26 10:35:46 +01:00
|
|
|
|
2013-08-16 16:24:12 +02:00
|
|
|
$this->view->form = $form;
|
2015-06-02 09:58:57 +02:00
|
|
|
$this->view->tabs->activate('userbackend');
|
|
|
|
$this->render('userbackend/modify');
|
2013-08-16 16:24:12 +02:00
|
|
|
}
|
2013-08-14 10:53:25 +02:00
|
|
|
|
2013-11-06 19:02:30 +01:00
|
|
|
/**
|
2015-06-02 09:58:57 +02:00
|
|
|
* Action for removing a user backend
|
2013-11-06 19:02:30 +01:00
|
|
|
*/
|
2015-06-02 09:58:57 +02:00
|
|
|
public function removeuserbackendAction()
|
2013-11-06 19:02:30 +01:00
|
|
|
{
|
2015-06-02 09:58:57 +02:00
|
|
|
$this->assertPermission('config/application/userbackend');
|
2014-08-29 15:16:13 +02:00
|
|
|
$form = new ConfirmRemovalForm(array(
|
2014-11-18 13:12:30 +01:00
|
|
|
'onSuccess' => function ($form) {
|
2015-06-02 09:58:57 +02:00
|
|
|
$configForm = new UserBackendConfigForm();
|
2014-11-07 13:53:03 +01:00
|
|
|
$configForm->setIniConfig(Config::app('authentication'));
|
2015-06-02 09:58:57 +02:00
|
|
|
$authBackend = $form->getRequest()->getQuery('backend');
|
2014-08-29 15:16:13 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
$configForm->remove($authBackend);
|
|
|
|
} catch (InvalidArgumentException $e) {
|
|
|
|
Notification::error($e->getMessage());
|
2015-05-27 10:46:20 +02:00
|
|
|
return false;
|
2014-08-29 15:16:13 +02:00
|
|
|
}
|
2013-11-06 19:02:30 +01:00
|
|
|
|
2014-08-29 15:16:13 +02:00
|
|
|
if ($configForm->save()) {
|
|
|
|
Notification::success(sprintf(
|
2015-06-02 09:58:57 +02:00
|
|
|
t('User backend "%s" has been successfully removed'),
|
2014-08-29 15:16:13 +02:00
|
|
|
$authBackend
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2013-11-06 19:02:30 +01:00
|
|
|
}
|
2014-08-29 15:16:13 +02:00
|
|
|
));
|
2015-06-02 09:58:57 +02:00
|
|
|
$form->setTitle($this->translate('Remove User Backend'));
|
|
|
|
$form->setRedirectUrl('config/userbackend');
|
|
|
|
$form->setAction(Url::fromRequest());
|
2014-08-29 15:16:13 +02:00
|
|
|
$form->handleRequest();
|
2013-11-06 19:02:30 +01:00
|
|
|
|
|
|
|
$this->view->form = $form;
|
2015-06-02 09:58:57 +02:00
|
|
|
$this->view->tabs->activate('userbackend');
|
|
|
|
$this->render('userbackend/remove');
|
2013-11-06 19:02:30 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2015-03-12 14:46:56 +01:00
|
|
|
$this->assertPermission('config/application/resources');
|
2014-11-18 13:11:52 +01:00
|
|
|
$this->view->resources = Config::app('resources', true)->keys();
|
2015-02-02 13:46:35 +01:00
|
|
|
$this->view->tabs->activate('resource');
|
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()
|
|
|
|
{
|
2015-03-12 14:46:56 +01:00
|
|
|
$this->assertPermission('config/application/resources');
|
2014-09-02 15:39:21 +02:00
|
|
|
$form = new ResourceConfigForm();
|
2015-03-02 18:37:54 +01:00
|
|
|
$form->setTitle($this->translate('Create A New Resource'));
|
|
|
|
$form->addDescription($this->translate('Resources are entities that provide data to Icinga Web 2.'));
|
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()
|
|
|
|
{
|
2015-03-12 14:46:56 +01:00
|
|
|
$this->assertPermission('config/application/resources');
|
2014-09-02 15:39:21 +02:00
|
|
|
$form = new ResourceConfigForm();
|
2015-03-02 18:37:54 +01:00
|
|
|
$form->setTitle($this->translate('Edit Existing Resource'));
|
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()
|
|
|
|
{
|
2015-03-12 14:46:56 +01:00
|
|
|
$this->assertPermission('config/application/resources');
|
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());
|
2015-05-27 10:48:27 +02:00
|
|
|
return false;
|
2014-09-02 15:39:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($configForm->save()) {
|
|
|
|
Notification::success(sprintf(t('Resource "%s" has been successfully removed'), $resource));
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
));
|
2015-03-02 18:37:54 +01:00
|
|
|
$form->setTitle($this->translate('Remove Existing Resource'));
|
2014-09-02 15:39:21 +02:00
|
|
|
$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) {
|
2015-03-02 18:37:54 +01:00
|
|
|
$form->addDescription(sprintf(
|
2014-09-02 15:39:21 +02:00
|
|
|
$this->translate(
|
2015-06-02 09:58:57 +02:00
|
|
|
'The resource "%s" is currently utilized for authentication by user backend "%s". ' .
|
2014-09-02 15:39:21 +02:00
|
|
|
'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
|
|
|
}
|