2013-08-12 09:58:26 -04:00
|
|
|
<?php
|
2015-02-04 04:46:36 -05:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
2013-08-12 09:58:26 -04:00
|
|
|
|
2015-08-27 07:22:49 -04:00
|
|
|
namespace Icinga\Controllers;
|
|
|
|
|
|
2015-08-27 07:23:12 -04:00
|
|
|
use Exception;
|
|
|
|
|
use InvalidArgumentException;
|
2014-11-07 07:53:03 -05:00
|
|
|
use Icinga\Application\Config;
|
2015-02-02 07:46:35 -05:00
|
|
|
use Icinga\Application\Icinga;
|
|
|
|
|
use Icinga\Application\Modules\Module;
|
|
|
|
|
use Icinga\Data\ResourceFactory;
|
2015-07-23 10:18:09 -04:00
|
|
|
use Icinga\Exception\ConfigurationError;
|
|
|
|
|
use Icinga\Exception\NotFoundError;
|
2015-02-02 07:46:35 -05:00
|
|
|
use Icinga\Forms\Config\GeneralConfigForm;
|
2014-11-14 04:57:14 -05:00
|
|
|
use Icinga\Forms\Config\ResourceConfigForm;
|
2015-08-27 07:30:43 -04:00
|
|
|
use Icinga\Forms\Config\UserBackendConfigForm;
|
|
|
|
|
use Icinga\Forms\Config\UserBackendReorderForm;
|
2014-11-14 04:57:14 -05:00
|
|
|
use Icinga\Forms\ConfirmRemovalForm;
|
2015-02-02 07:46:35 -05:00
|
|
|
use Icinga\Security\SecurityException;
|
2015-04-17 10:09:35 -04:00
|
|
|
use Icinga\Web\Controller;
|
2015-02-02 07:46:35 -05:00
|
|
|
use Icinga\Web\Notification;
|
2015-09-30 18:06:37 -04:00
|
|
|
use Icinga\Web\Url;
|
2015-02-02 07:46:35 -05:00
|
|
|
use Icinga\Web\Widget;
|
2014-06-20 19:54:32 -04:00
|
|
|
|
2013-08-12 09:58:26 -04:00
|
|
|
/**
|
2015-02-02 07:46:35 -05:00
|
|
|
* Application and module configuration
|
2013-08-12 09:58:26 -04:00
|
|
|
*/
|
2015-04-17 10:09:35 -04:00
|
|
|
class ConfigController extends Controller
|
2013-08-12 09:58:26 -04:00
|
|
|
{
|
2015-02-02 07:46:35 -05:00
|
|
|
/**
|
2015-06-22 07:26:24 -04:00
|
|
|
* Create and return the tabs to display when showing application configuration
|
2015-02-02 07:46:35 -05:00
|
|
|
*/
|
2015-06-22 07:26:24 -04:00
|
|
|
public function createApplicationTabs()
|
|
|
|
|
{
|
|
|
|
|
$tabs = $this->getTabs();
|
|
|
|
|
$tabs->add('general', array(
|
|
|
|
|
'title' => $this->translate('Adjust the general configuration of Icinga Web 2'),
|
|
|
|
|
'label' => $this->translate('General'),
|
2015-07-29 11:18:52 -04:00
|
|
|
'url' => 'config/general',
|
|
|
|
|
'baseTarget' => '_main'
|
2015-06-22 07:26:24 -04:00
|
|
|
));
|
|
|
|
|
$tabs->add('resource', array(
|
|
|
|
|
'title' => $this->translate('Configure which resources are being utilized by Icinga Web 2'),
|
|
|
|
|
'label' => $this->translate('Resources'),
|
2015-07-29 11:18:52 -04:00
|
|
|
'url' => 'config/resource',
|
|
|
|
|
'baseTarget' => '_main'
|
2015-06-22 07:26:24 -04:00
|
|
|
));
|
|
|
|
|
return $tabs;
|
|
|
|
|
}
|
2015-02-02 07:46:35 -05:00
|
|
|
|
|
|
|
|
/**
|
2015-06-22 07:26:24 -04:00
|
|
|
* Create and return the tabs to display when showing authentication configuration
|
2015-02-02 07:46:35 -05:00
|
|
|
*/
|
2015-06-22 07:26:24 -04:00
|
|
|
public function createAuthenticationTabs()
|
2013-08-12 09:58:26 -04:00
|
|
|
{
|
2015-02-02 07:46:35 -05:00
|
|
|
$tabs = $this->getTabs();
|
2015-06-22 07:26:24 -04:00
|
|
|
$tabs->add('userbackend', array(
|
|
|
|
|
'title' => $this->translate('Configure how users authenticate with and log into Icinga Web 2'),
|
2015-10-01 03:01:03 -04:00
|
|
|
'label' => $this->translate('Users'),
|
2015-07-29 11:18:52 -04:00
|
|
|
'url' => 'config/userbackend',
|
|
|
|
|
'baseTarget' => '_main'
|
2015-06-22 07:26:24 -04:00
|
|
|
));
|
|
|
|
|
$tabs->add('usergroupbackend', array(
|
|
|
|
|
'title' => $this->translate('Configure how users are associated with groups by Icinga Web 2'),
|
2015-09-28 12:28:46 -04:00
|
|
|
'label' => $this->translate('User Groups'),
|
2015-07-29 11:18:52 -04:00
|
|
|
'url' => 'usergroupbackend/list',
|
|
|
|
|
'baseTarget' => '_main'
|
2015-06-22 07:26:24 -04:00
|
|
|
));
|
|
|
|
|
return $tabs;
|
2013-08-12 09:58:26 -04:00
|
|
|
}
|
|
|
|
|
|
2014-06-25 14:31:44 -04:00
|
|
|
public function devtoolsAction()
|
|
|
|
|
{
|
|
|
|
|
$this->view->tabs = null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-12 09:58:26 -04:00
|
|
|
/**
|
2015-06-22 07:26:24 -04:00
|
|
|
* Redirect to the general configuration
|
2013-08-12 09:58:26 -04:00
|
|
|
*/
|
|
|
|
|
public function indexAction()
|
|
|
|
|
{
|
2015-06-22 07:26:24 -04:00
|
|
|
$this->redirectNow('config/general');
|
2015-02-02 07:46:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-06-01 10:35:27 -04:00
|
|
|
* General configuration
|
2015-02-02 07:46:35 -05:00
|
|
|
*
|
2015-06-01 10:35:27 -04:00
|
|
|
* @throws SecurityException If the user lacks the permission for configuring the general configuration
|
2015-02-02 07:46:35 -05:00
|
|
|
*/
|
2015-06-01 10:35:27 -04:00
|
|
|
public function generalAction()
|
2015-02-02 07:46:35 -05:00
|
|
|
{
|
2015-03-12 09:40:37 -04:00
|
|
|
$this->assertPermission('config/application/general');
|
2014-09-01 10:16:56 -04:00
|
|
|
$form = new GeneralConfigForm();
|
2014-11-07 07:53:03 -05:00
|
|
|
$form->setIniConfig(Config::app());
|
2014-09-01 10:16:56 -04:00
|
|
|
$form->handleRequest();
|
2014-07-21 08:33:52 -04:00
|
|
|
|
2013-08-14 04:53:25 -04:00
|
|
|
$this->view->form = $form;
|
2015-06-22 07:26:24 -04:00
|
|
|
$this->createApplicationTabs()->activate('general');
|
2013-08-14 04:53:25 -04:00
|
|
|
}
|
|
|
|
|
|
2013-08-14 06:42:32 -04:00
|
|
|
/**
|
|
|
|
|
* Display the list of all modules
|
|
|
|
|
*/
|
2014-06-20 19:54:32 -04:00
|
|
|
public function modulesAction()
|
2013-08-12 09:58:26 -04:00
|
|
|
{
|
2015-07-24 07:34:47 -04:00
|
|
|
$this->assertPermission('config/modules');
|
2015-02-02 07:46:35 -05: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 03:32:44 -05:00
|
|
|
'label' => $this->translate('Modules'),
|
|
|
|
|
'title' => $this->translate('List intalled modules'),
|
2015-02-02 07:46:35 -05:00
|
|
|
'url' => 'config/modules'
|
|
|
|
|
))
|
|
|
|
|
->activate('modules');
|
2013-08-12 09:58:26 -04:00
|
|
|
$this->view->modules = Icinga::app()->getModuleManager()->select()
|
|
|
|
|
->from('modules')
|
2014-06-06 02:21:35 -04:00
|
|
|
->order('enabled', 'desc')
|
2015-05-15 08:32:58 -04:00
|
|
|
->order('name');
|
2015-04-17 10:09:35 -04:00
|
|
|
$this->setupLimitControl();
|
|
|
|
|
$this->setupPaginationControl($this->view->modules);
|
2013-08-12 09:58:26 -04:00
|
|
|
}
|
|
|
|
|
|
2014-06-20 19:54:32 -04:00
|
|
|
public function moduleAction()
|
|
|
|
|
{
|
2015-07-24 07:34:47 -04:00
|
|
|
$this->assertPermission('config/modules');
|
2014-06-20 19:54:32 -04:00
|
|
|
$app = Icinga::app();
|
|
|
|
|
$manager = $app->getModuleManager();
|
2015-03-06 07:25:04 -05:00
|
|
|
$name = $this->getParam('name');
|
2014-06-20 19:54:32 -04:00
|
|
|
if ($manager->hasInstalled($name)) {
|
2015-03-06 07:25:04 -05: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-20 19:54:32 -04:00
|
|
|
$this->view->module = $module;
|
2015-03-06 07:25:04 -05:00
|
|
|
$this->view->tabs = $module->getConfigTabs()->activate('info');
|
2014-06-20 19:54:32 -04:00
|
|
|
} else {
|
|
|
|
|
$this->view->module = false;
|
2015-03-06 07:25:04 -05:00
|
|
|
$this->view->tabs = null;
|
2014-06-20 19:54:32 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-12 09:58:26 -04:00
|
|
|
/**
|
2013-08-14 06:42:32 -04:00
|
|
|
* Enable a specific module provided by the 'name' param
|
2013-08-12 09:58:26 -04:00
|
|
|
*/
|
|
|
|
|
public function moduleenableAction()
|
|
|
|
|
{
|
2015-03-12 09:53:20 -04:00
|
|
|
$this->assertPermission('config/modules');
|
2013-08-29 11:44:02 -04:00
|
|
|
$module = $this->getParam('name');
|
2013-08-12 09:58:26 -04:00
|
|
|
$manager = Icinga::app()->getModuleManager();
|
2013-08-29 11:44:02 -04:00
|
|
|
try {
|
|
|
|
|
$manager->enableModule($module);
|
2014-09-29 09:20:19 -04:00
|
|
|
Notification::success(sprintf($this->translate('Module "%s" enabled'), $module));
|
2014-06-22 14:06:45 -04:00
|
|
|
$this->rerenderLayout()->reloadCss()->redirectNow('config/modules');
|
2013-08-29 11:44:02 -04:00
|
|
|
} catch (Exception $e) {
|
2014-10-24 07:49:49 -04:00
|
|
|
$this->view->exceptionMessage = $e->getMessage();
|
2013-08-29 11:44:02 -04:00
|
|
|
$this->view->moduleName = $module;
|
|
|
|
|
$this->view->action = 'enable';
|
|
|
|
|
$this->render('module-configuration-error');
|
|
|
|
|
}
|
2013-08-12 09:58:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-08-14 06:42:32 -04:00
|
|
|
* Disable a module specific module provided by the 'name' param
|
2013-08-12 09:58:26 -04:00
|
|
|
*/
|
|
|
|
|
public function moduledisableAction()
|
|
|
|
|
{
|
2015-03-12 09:53:20 -04:00
|
|
|
$this->assertPermission('config/modules');
|
2013-08-29 11:44:02 -04:00
|
|
|
$module = $this->getParam('name');
|
2013-08-12 09:58:26 -04:00
|
|
|
$manager = Icinga::app()->getModuleManager();
|
2013-08-29 11:44:02 -04:00
|
|
|
try {
|
|
|
|
|
$manager->disableModule($module);
|
2014-09-29 09:20:19 -04:00
|
|
|
Notification::success(sprintf($this->translate('Module "%s" disabled'), $module));
|
2014-06-22 14:06:45 -04:00
|
|
|
$this->rerenderLayout()->reloadCss()->redirectNow('config/modules');
|
2013-08-29 11:44:02 -04: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 09:58:26 -04:00
|
|
|
}
|
2013-08-14 04:53:25 -04:00
|
|
|
|
2013-08-16 10:24:12 -04:00
|
|
|
/**
|
2015-06-02 03:58:57 -04:00
|
|
|
* Action for listing and reordering user backends
|
2013-08-16 10:24:12 -04:00
|
|
|
*/
|
2015-06-02 03:58:57 -04:00
|
|
|
public function userbackendAction()
|
2013-08-16 10:24:12 -04:00
|
|
|
{
|
2015-06-02 03:58:57 -04:00
|
|
|
$this->assertPermission('config/application/userbackend');
|
|
|
|
|
$form = new UserBackendReorderForm();
|
2014-11-07 07:53:03 -05:00
|
|
|
$form->setIniConfig(Config::app('authentication'));
|
2014-08-29 09:16:13 -04:00
|
|
|
$form->handleRequest();
|
2014-04-16 05:50:58 -04:00
|
|
|
|
2014-08-29 09:16:13 -04:00
|
|
|
$this->view->form = $form;
|
2015-06-22 07:26:24 -04:00
|
|
|
$this->createAuthenticationTabs()->activate('userbackend');
|
2015-06-02 03:58:57 -04:00
|
|
|
$this->render('userbackend/reorder');
|
2013-08-26 10:56:23 -04:00
|
|
|
}
|
|
|
|
|
|
2013-08-16 10:24:12 -04:00
|
|
|
/**
|
2015-07-23 10:18:09 -04:00
|
|
|
* Create a new user backend
|
2013-08-16 10:24:12 -04:00
|
|
|
*/
|
2015-06-02 03:58:57 -04:00
|
|
|
public function createuserbackendAction()
|
2013-08-16 10:24:12 -04:00
|
|
|
{
|
2015-06-02 03:58:57 -04:00
|
|
|
$this->assertPermission('config/application/userbackend');
|
|
|
|
|
$form = new UserBackendConfigForm();
|
2015-09-30 18:32:16 -04:00
|
|
|
$form
|
|
|
|
|
->setRedirectUrl('config/userbackend')
|
|
|
|
|
->addDescription($this->translate(
|
|
|
|
|
'Create a new backend for authenticating your users. This backend'
|
|
|
|
|
. ' will be added at the end of your authentication order.'
|
|
|
|
|
))
|
|
|
|
|
->setIniConfig(Config::app('authentication'));
|
2015-07-23 10:18:09 -04:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$form->setResourceConfig(ResourceFactory::getResourceConfigs());
|
|
|
|
|
} catch (ConfigurationError $e) {
|
|
|
|
|
if ($this->hasPermission('config/application/resources')) {
|
|
|
|
|
Notification::error($e->getMessage());
|
|
|
|
|
$this->redirectNow('config/createresource');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw $e; // No permission for resource configuration, show the error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$form->setOnSuccess(function (UserBackendConfigForm $form) {
|
|
|
|
|
try {
|
|
|
|
|
$form->add(array_filter($form->getValues()));
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
$form->error($e->getMessage());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($form->save()) {
|
|
|
|
|
Notification::success(t('User backend successfully created'));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
});
|
2014-08-29 09:16:13 -04:00
|
|
|
$form->handleRequest();
|
2013-11-20 13:10:38 -05:00
|
|
|
|
2015-09-30 18:32:16 -04:00
|
|
|
$this->renderForm($form, $this->translate('New User Backend'));
|
2013-08-26 10:56:23 -04:00
|
|
|
}
|
2013-08-16 10:24:12 -04:00
|
|
|
|
2013-08-26 10:56:23 -04:00
|
|
|
/**
|
2015-07-23 10:18:09 -04:00
|
|
|
* Edit a user backend
|
2013-08-26 10:56:23 -04:00
|
|
|
*/
|
2015-06-02 03:58:57 -04:00
|
|
|
public function edituserbackendAction()
|
2013-08-26 10:56:23 -04:00
|
|
|
{
|
2015-06-02 03:58:57 -04:00
|
|
|
$this->assertPermission('config/application/userbackend');
|
2015-07-23 10:18:09 -04:00
|
|
|
$backendName = $this->params->getRequired('backend');
|
|
|
|
|
|
2015-06-02 03:58:57 -04:00
|
|
|
$form = new UserBackendConfigForm();
|
|
|
|
|
$form->setRedirectUrl('config/userbackend');
|
2015-07-23 10:18:09 -04:00
|
|
|
$form->setIniConfig(Config::app('authentication'));
|
|
|
|
|
$form->setOnSuccess(function (UserBackendConfigForm $form) use ($backendName) {
|
|
|
|
|
try {
|
|
|
|
|
$form->edit($backendName, array_map(
|
|
|
|
|
function ($v) {
|
|
|
|
|
return $v !== '' ? $v : null;
|
|
|
|
|
},
|
|
|
|
|
$form->getValues()
|
|
|
|
|
));
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
$form->error($e->getMessage());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($form->save()) {
|
|
|
|
|
Notification::success(sprintf(t('User backend "%s" successfully updated'), $backendName));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$form->load($backendName);
|
|
|
|
|
$form->setResourceConfig(ResourceFactory::getResourceConfigs());
|
|
|
|
|
$form->handleRequest();
|
|
|
|
|
} catch (NotFoundError $_) {
|
|
|
|
|
$this->httpNotFound(sprintf($this->translate('User backend "%s" not found'), $backendName));
|
|
|
|
|
}
|
2013-11-26 04:35:46 -05:00
|
|
|
|
2015-09-30 18:32:16 -04:00
|
|
|
$this->renderForm($form, $this->translate('Update User Backend'));
|
2013-08-16 10:24:12 -04:00
|
|
|
}
|
2013-08-14 04:53:25 -04:00
|
|
|
|
2013-11-06 13:02:30 -05:00
|
|
|
/**
|
2015-07-23 10:18:09 -04:00
|
|
|
* Display a confirmation form to remove the backend identified by the 'backend' parameter
|
2013-11-06 13:02:30 -05:00
|
|
|
*/
|
2015-06-02 03:58:57 -04:00
|
|
|
public function removeuserbackendAction()
|
2013-11-06 13:02:30 -05:00
|
|
|
{
|
2015-06-02 03:58:57 -04:00
|
|
|
$this->assertPermission('config/application/userbackend');
|
2015-07-23 10:18:09 -04:00
|
|
|
$backendName = $this->params->getRequired('backend');
|
|
|
|
|
|
|
|
|
|
$backendForm = new UserBackendConfigForm();
|
|
|
|
|
$backendForm->setIniConfig(Config::app('authentication'));
|
|
|
|
|
$form = new ConfirmRemovalForm();
|
2015-06-02 03:58:57 -04:00
|
|
|
$form->setRedirectUrl('config/userbackend');
|
2015-07-23 10:18:09 -04:00
|
|
|
$form->setOnSuccess(function (ConfirmRemovalForm $form) use ($backendName, $backendForm) {
|
|
|
|
|
try {
|
|
|
|
|
$backendForm->delete($backendName);
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
$form->error($e->getMessage());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($backendForm->save()) {
|
|
|
|
|
Notification::success(sprintf(t('User backend "%s" successfully removed'), $backendName));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
});
|
2014-08-29 09:16:13 -04:00
|
|
|
$form->handleRequest();
|
2013-11-06 13:02:30 -05:00
|
|
|
|
2015-09-30 18:32:16 -04:00
|
|
|
$this->renderForm($form, $this->translate('Remove User Backend'));
|
2013-11-06 13:02:30 -05:00
|
|
|
}
|
|
|
|
|
|
2014-07-23 06:55:43 -04:00
|
|
|
/**
|
2014-09-02 09:39:21 -04:00
|
|
|
* Display all available resources and a link to create a new one and to remove existing ones
|
2014-07-23 06:55:43 -04:00
|
|
|
*/
|
|
|
|
|
public function resourceAction()
|
2013-11-06 13:02:30 -05:00
|
|
|
{
|
2015-03-12 09:46:56 -04:00
|
|
|
$this->assertPermission('config/application/resources');
|
2015-08-17 05:27:41 -04:00
|
|
|
$this->view->resources = Config::app('resources', true);
|
2015-06-22 07:26:24 -04:00
|
|
|
$this->createApplicationTabs()->activate('resource');
|
2013-11-06 13:02:30 -05:00
|
|
|
}
|
|
|
|
|
|
2014-07-23 10:39:54 -04:00
|
|
|
/**
|
|
|
|
|
* Display a form to create a new resource
|
|
|
|
|
*/
|
2013-11-06 13:02:30 -05:00
|
|
|
public function createresourceAction()
|
|
|
|
|
{
|
2015-03-12 09:46:56 -04:00
|
|
|
$this->assertPermission('config/application/resources');
|
2015-09-30 18:10:53 -04:00
|
|
|
$this->getTabs()->add('resources/new', array(
|
|
|
|
|
'label' => $this->translate('New Resource'),
|
|
|
|
|
'url' => Url::fromRequest()
|
|
|
|
|
))->activate('resources/new');
|
2014-09-02 09:39:21 -04:00
|
|
|
$form = new ResourceConfigForm();
|
2015-03-02 12:37:54 -05:00
|
|
|
$form->addDescription($this->translate('Resources are entities that provide data to Icinga Web 2.'));
|
2014-11-07 07:53:03 -05:00
|
|
|
$form->setIniConfig(Config::app('resources'));
|
2014-09-02 09:39:21 -04:00
|
|
|
$form->setRedirectUrl('config/resource');
|
|
|
|
|
$form->handleRequest();
|
2013-11-20 13:10:38 -05:00
|
|
|
|
2013-11-13 12:12:00 -05:00
|
|
|
$this->view->form = $form;
|
2013-11-06 13:02:30 -05:00
|
|
|
$this->render('resource/create');
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-24 06:37:33 -04:00
|
|
|
/**
|
|
|
|
|
* Display a form to edit a existing resource
|
|
|
|
|
*/
|
2013-11-06 13:02:30 -05:00
|
|
|
public function editresourceAction()
|
|
|
|
|
{
|
2015-03-12 09:46:56 -04:00
|
|
|
$this->assertPermission('config/application/resources');
|
2015-09-30 18:09:33 -04:00
|
|
|
$this->getTabs()->add('resources/update', array(
|
|
|
|
|
'label' => $this->translate('Update Resource'),
|
|
|
|
|
'url' => Url::fromRequest()
|
|
|
|
|
))->activate('resources/update');
|
2014-09-02 09:39:21 -04:00
|
|
|
$form = new ResourceConfigForm();
|
2014-11-07 07:53:03 -05:00
|
|
|
$form->setIniConfig(Config::app('resources'));
|
2014-09-02 09:39:21 -04:00
|
|
|
$form->setRedirectUrl('config/resource');
|
|
|
|
|
$form->handleRequest();
|
2013-11-20 13:10:38 -05:00
|
|
|
|
2013-11-13 12:12:00 -05:00
|
|
|
$this->view->form = $form;
|
2013-11-06 13:02:30 -05:00
|
|
|
$this->render('resource/modify');
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-24 10:17:30 -04:00
|
|
|
/**
|
|
|
|
|
* Display a confirmation form to remove a resource
|
|
|
|
|
*/
|
2013-11-06 13:02:30 -05:00
|
|
|
public function removeresourceAction()
|
|
|
|
|
{
|
2015-03-12 09:46:56 -04:00
|
|
|
$this->assertPermission('config/application/resources');
|
2015-09-30 18:06:37 -04:00
|
|
|
$this->getTabs()->add('resources/remove', array(
|
|
|
|
|
'label' => $this->translate('Remove Resource'),
|
|
|
|
|
'url' => Url::fromRequest()
|
|
|
|
|
))->activate('resources/remove');
|
2014-09-02 09:39:21 -04:00
|
|
|
$form = new ConfirmRemovalForm(array(
|
2014-11-18 07:12:30 -05:00
|
|
|
'onSuccess' => function ($form) {
|
2014-09-02 09:39:21 -04:00
|
|
|
$configForm = new ResourceConfigForm();
|
2014-11-07 07:53:03 -05:00
|
|
|
$configForm->setIniConfig(Config::app('resources'));
|
2014-11-18 07:12:30 -05:00
|
|
|
$resource = $form->getRequest()->getQuery('resource');
|
2014-09-02 09:39:21 -04:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$configForm->remove($resource);
|
|
|
|
|
} catch (InvalidArgumentException $e) {
|
|
|
|
|
Notification::error($e->getMessage());
|
2015-05-27 04:48:27 -04:00
|
|
|
return false;
|
2014-09-02 09:39:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 12:12:00 -05:00
|
|
|
|
2013-11-26 04:35:46 -05:00
|
|
|
// Check if selected resource is currently used for authentication
|
2014-09-02 09:39:21 -04:00
|
|
|
$resource = $this->getRequest()->getQuery('resource');
|
2014-11-18 07:11:52 -05:00
|
|
|
$authConfig = Config::app('authentication');
|
2013-11-26 04:35:46 -05:00
|
|
|
foreach ($authConfig as $backendName => $config) {
|
2014-11-18 07:11:52 -05:00
|
|
|
if ($config->get('resource') === $resource) {
|
2015-03-02 12:37:54 -05:00
|
|
|
$form->addDescription(sprintf(
|
2014-09-02 09:39:21 -04:00
|
|
|
$this->translate(
|
2015-06-02 03:58:57 -04:00
|
|
|
'The resource "%s" is currently utilized for authentication by user backend "%s". ' .
|
2014-09-02 09:39:21 -04:00
|
|
|
'Removing the resource can result in noone being able to log in any longer.'
|
|
|
|
|
),
|
|
|
|
|
$resource,
|
|
|
|
|
$backendName
|
|
|
|
|
));
|
2013-11-13 12:12:00 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->view->form = $form;
|
2013-11-06 13:02:30 -05:00
|
|
|
$this->render('resource/remove');
|
|
|
|
|
}
|
2013-08-12 09:58:26 -04:00
|
|
|
}
|