mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-19 20:04:24 +02:00
security: Guard application and module configuration
This commit is contained in:
parent
94193abdc0
commit
4bac5dfc37
@ -1,41 +1,70 @@
|
|||||||
<?php
|
<?php
|
||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
|
||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
|
||||||
|
|
||||||
use Icinga\Web\Controller\ActionController;
|
|
||||||
use Icinga\Web\Notification;
|
|
||||||
use Icinga\Application\Modules\Module;
|
|
||||||
use Icinga\Web\Widget;
|
|
||||||
use Icinga\Application\Icinga;
|
|
||||||
use Icinga\Application\Config;
|
use Icinga\Application\Config;
|
||||||
use Icinga\Forms\Config\GeneralConfigForm;
|
use Icinga\Application\Icinga;
|
||||||
use Icinga\Forms\Config\AuthenticationBackendReorderForm;
|
use Icinga\Application\Modules\Module;
|
||||||
|
use Icinga\Data\ResourceFactory;
|
||||||
use Icinga\Forms\Config\AuthenticationBackendConfigForm;
|
use Icinga\Forms\Config\AuthenticationBackendConfigForm;
|
||||||
|
use Icinga\Forms\Config\AuthenticationBackendReorderForm;
|
||||||
|
use Icinga\Forms\Config\GeneralConfigForm;
|
||||||
use Icinga\Forms\Config\ResourceConfigForm;
|
use Icinga\Forms\Config\ResourceConfigForm;
|
||||||
use Icinga\Forms\ConfirmRemovalForm;
|
use Icinga\Forms\ConfirmRemovalForm;
|
||||||
use Icinga\Data\ResourceFactory;
|
use Icinga\Security\SecurityException;
|
||||||
|
use Icinga\Web\Controller\ActionController;
|
||||||
|
use Icinga\Web\Notification;
|
||||||
|
use Icinga\Web\Widget;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Application wide controller for application preferences
|
* Application and module configuration
|
||||||
*/
|
*/
|
||||||
class ConfigController extends ActionController
|
class ConfigController extends ActionController
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* The first allowed config action according to the user's permissions
|
||||||
|
*
|
||||||
|
* @type string
|
||||||
|
*/
|
||||||
|
protected $firstAllowedAction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize tabs and validate the user's permissions
|
||||||
|
*
|
||||||
|
* @throws SecurityException If the user does not have any configuration permission
|
||||||
|
*/
|
||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
$this->view->tabs = Widget::create('tabs')->add('index', array(
|
$tabs = $this->getTabs();
|
||||||
|
$auth = $this->Auth();
|
||||||
|
$allowedActions = array();
|
||||||
|
if ($auth->hasPermission('system/config/application')) {
|
||||||
|
$tabs->add('application', array(
|
||||||
'title' => $this->translate('Application'),
|
'title' => $this->translate('Application'),
|
||||||
'url' => 'config'
|
'url' => 'config/application'
|
||||||
))->add('authentication', array(
|
));
|
||||||
|
$allowedActions[] = 'application';
|
||||||
|
}
|
||||||
|
if ($auth->hasPermission('system/config/authentication')) {
|
||||||
|
$tabs->add('authentication', array(
|
||||||
'title' => $this->translate('Authentication'),
|
'title' => $this->translate('Authentication'),
|
||||||
'url' => 'config/authentication'
|
'url' => 'config/authentication'
|
||||||
))->add('resources', array(
|
));
|
||||||
|
$allowedActions[] = 'authentication';
|
||||||
|
}
|
||||||
|
if ($auth->hasPermission('system/config/resources')) {
|
||||||
|
$tabs->add('resource', array(
|
||||||
'title' => $this->translate('Resources'),
|
'title' => $this->translate('Resources'),
|
||||||
'url' => 'config/resource'
|
'url' => 'config/resource'
|
||||||
))->add('roles', array(
|
));
|
||||||
|
$allowedActions[] = 'resource';
|
||||||
|
}
|
||||||
|
if ($auth->hasPermission('system/config/roles')) {
|
||||||
|
$tabs->add('roles', array(
|
||||||
'title' => $this->translate('Roles'),
|
'title' => $this->translate('Roles'),
|
||||||
'url' => 'roles'
|
'url' => 'roles'
|
||||||
));
|
));
|
||||||
|
$allowedActions[] = 'roles';
|
||||||
|
}
|
||||||
|
$this->firstAllowedAction = array_shift($allowedActions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function devtoolsAction()
|
public function devtoolsAction()
|
||||||
@ -44,16 +73,35 @@ class ConfigController extends ActionController
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Index action, entry point for configuration
|
* Forward or redirect to the first allowed configuration action
|
||||||
*/
|
*/
|
||||||
public function indexAction()
|
public function indexAction()
|
||||||
{
|
{
|
||||||
|
if ($this->firstAllowedAction === null) {
|
||||||
|
throw new SecurityException('No permission for configuration');
|
||||||
|
}
|
||||||
|
$action = $this->getTabs()->get($this->firstAllowedAction);
|
||||||
|
if (substr($action->getUrl()->getPath(), 0, 7) === 'config/') {
|
||||||
|
$this->forward($this->firstAllowedAction);
|
||||||
|
} else {
|
||||||
|
$this->redirectNow($action->getUrl());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Application configuration
|
||||||
|
*
|
||||||
|
* @throws SecurityException If the user lacks the permission for configuring the application
|
||||||
|
*/
|
||||||
|
public function applicationAction()
|
||||||
|
{
|
||||||
|
$this->assertPermission('system/config/application');
|
||||||
$form = new GeneralConfigForm();
|
$form = new GeneralConfigForm();
|
||||||
$form->setIniConfig(Config::app());
|
$form->setIniConfig(Config::app());
|
||||||
$form->handleRequest();
|
$form->handleRequest();
|
||||||
|
|
||||||
$this->view->form = $form;
|
$this->view->form = $form;
|
||||||
$this->view->tabs->activate('index');
|
$this->view->tabs->activate('application');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,16 +109,19 @@ class ConfigController extends ActionController
|
|||||||
*/
|
*/
|
||||||
public function modulesAction()
|
public function modulesAction()
|
||||||
{
|
{
|
||||||
$this->view->tabs = Widget::create('tabs')->add('modules', array(
|
// 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(
|
||||||
'title' => $this->translate('Modules'),
|
'title' => $this->translate('Modules'),
|
||||||
'url' => 'config/modules'
|
'url' => 'config/modules'
|
||||||
));
|
))
|
||||||
|
->activate('modules');
|
||||||
$this->view->tabs->activate('modules');
|
|
||||||
$this->view->modules = Icinga::app()->getModuleManager()->select()
|
$this->view->modules = Icinga::app()->getModuleManager()->select()
|
||||||
->from('modules')
|
->from('modules')
|
||||||
->order('enabled', 'desc')
|
->order('enabled', 'desc')
|
||||||
->order('name')->paginate();
|
->order('name')
|
||||||
|
->paginate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function moduleAction()
|
public function moduleAction()
|
||||||
@ -79,8 +130,12 @@ class ConfigController extends ActionController
|
|||||||
$app = Icinga::app();
|
$app = Icinga::app();
|
||||||
$manager = $app->getModuleManager();
|
$manager = $app->getModuleManager();
|
||||||
if ($manager->hasInstalled($name)) {
|
if ($manager->hasInstalled($name)) {
|
||||||
$this->view->moduleData = Icinga::app()->getModuleManager()->select()
|
$this->view->moduleData = Icinga::app()
|
||||||
->from('modules')->where('name', $name)->fetchRow();
|
->getModuleManager()
|
||||||
|
->select()
|
||||||
|
->from('modules')
|
||||||
|
->where('name', $name)
|
||||||
|
->fetchRow();
|
||||||
$module = new Module($app, $name, $manager->getModuleDir($name));
|
$module = new Module($app, $name, $manager->getModuleDir($name));
|
||||||
$this->view->module = $module;
|
$this->view->module = $module;
|
||||||
} else {
|
} else {
|
||||||
@ -94,6 +149,7 @@ class ConfigController extends ActionController
|
|||||||
*/
|
*/
|
||||||
public function moduleenableAction()
|
public function moduleenableAction()
|
||||||
{
|
{
|
||||||
|
$this->assertPermission('system/config/modules');
|
||||||
$module = $this->getParam('name');
|
$module = $this->getParam('name');
|
||||||
$manager = Icinga::app()->getModuleManager();
|
$manager = Icinga::app()->getModuleManager();
|
||||||
try {
|
try {
|
||||||
@ -114,6 +170,7 @@ class ConfigController extends ActionController
|
|||||||
*/
|
*/
|
||||||
public function moduledisableAction()
|
public function moduledisableAction()
|
||||||
{
|
{
|
||||||
|
$this->assertPermission('system/config/modules');
|
||||||
$module = $this->getParam('name');
|
$module = $this->getParam('name');
|
||||||
$manager = Icinga::app()->getModuleManager();
|
$manager = Icinga::app()->getModuleManager();
|
||||||
try {
|
try {
|
||||||
@ -133,6 +190,7 @@ class ConfigController extends ActionController
|
|||||||
*/
|
*/
|
||||||
public function authenticationAction()
|
public function authenticationAction()
|
||||||
{
|
{
|
||||||
|
$this->assertPermission('system/config/authentication');
|
||||||
$form = new AuthenticationBackendReorderForm();
|
$form = new AuthenticationBackendReorderForm();
|
||||||
$form->setIniConfig(Config::app('authentication'));
|
$form->setIniConfig(Config::app('authentication'));
|
||||||
$form->handleRequest();
|
$form->handleRequest();
|
||||||
@ -147,6 +205,7 @@ class ConfigController extends ActionController
|
|||||||
*/
|
*/
|
||||||
public function createauthenticationbackendAction()
|
public function createauthenticationbackendAction()
|
||||||
{
|
{
|
||||||
|
$this->assertPermission('system/config/authentication');
|
||||||
$form = new AuthenticationBackendConfigForm();
|
$form = new AuthenticationBackendConfigForm();
|
||||||
$form->setIniConfig(Config::app('authentication'));
|
$form->setIniConfig(Config::app('authentication'));
|
||||||
$form->setResourceConfig(ResourceFactory::getResourceConfigs());
|
$form->setResourceConfig(ResourceFactory::getResourceConfigs());
|
||||||
@ -163,6 +222,7 @@ class ConfigController extends ActionController
|
|||||||
*/
|
*/
|
||||||
public function editauthenticationbackendAction()
|
public function editauthenticationbackendAction()
|
||||||
{
|
{
|
||||||
|
$this->assertPermission('system/config/authentication');
|
||||||
$form = new AuthenticationBackendConfigForm();
|
$form = new AuthenticationBackendConfigForm();
|
||||||
$form->setIniConfig(Config::app('authentication'));
|
$form->setIniConfig(Config::app('authentication'));
|
||||||
$form->setResourceConfig(ResourceFactory::getResourceConfigs());
|
$form->setResourceConfig(ResourceFactory::getResourceConfigs());
|
||||||
@ -179,6 +239,7 @@ class ConfigController extends ActionController
|
|||||||
*/
|
*/
|
||||||
public function removeauthenticationbackendAction()
|
public function removeauthenticationbackendAction()
|
||||||
{
|
{
|
||||||
|
$this->assertPermission('system/config/authentication');
|
||||||
$form = new ConfirmRemovalForm(array(
|
$form = new ConfirmRemovalForm(array(
|
||||||
'onSuccess' => function ($form) {
|
'onSuccess' => function ($form) {
|
||||||
$configForm = new AuthenticationBackendConfigForm();
|
$configForm = new AuthenticationBackendConfigForm();
|
||||||
@ -215,8 +276,9 @@ class ConfigController extends ActionController
|
|||||||
*/
|
*/
|
||||||
public function resourceAction()
|
public function resourceAction()
|
||||||
{
|
{
|
||||||
|
$this->assertPermission('system/config/resources');
|
||||||
$this->view->resources = Config::app('resources', true)->keys();
|
$this->view->resources = Config::app('resources', true)->keys();
|
||||||
$this->view->tabs->activate('resources');
|
$this->view->tabs->activate('resource');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -224,6 +286,7 @@ class ConfigController extends ActionController
|
|||||||
*/
|
*/
|
||||||
public function createresourceAction()
|
public function createresourceAction()
|
||||||
{
|
{
|
||||||
|
$this->assertPermission('system/config/resources');
|
||||||
$form = new ResourceConfigForm();
|
$form = new ResourceConfigForm();
|
||||||
$form->setIniConfig(Config::app('resources'));
|
$form->setIniConfig(Config::app('resources'));
|
||||||
$form->setRedirectUrl('config/resource');
|
$form->setRedirectUrl('config/resource');
|
||||||
@ -238,6 +301,7 @@ class ConfigController extends ActionController
|
|||||||
*/
|
*/
|
||||||
public function editresourceAction()
|
public function editresourceAction()
|
||||||
{
|
{
|
||||||
|
$this->assertPermission('system/config/resources');
|
||||||
$form = new ResourceConfigForm();
|
$form = new ResourceConfigForm();
|
||||||
$form->setIniConfig(Config::app('resources'));
|
$form->setIniConfig(Config::app('resources'));
|
||||||
$form->setRedirectUrl('config/resource');
|
$form->setRedirectUrl('config/resource');
|
||||||
@ -252,6 +316,7 @@ class ConfigController extends ActionController
|
|||||||
*/
|
*/
|
||||||
public function removeresourceAction()
|
public function removeresourceAction()
|
||||||
{
|
{
|
||||||
|
$this->assertPermission('system/config/resources');
|
||||||
$form = new ConfirmRemovalForm(array(
|
$form = new ConfirmRemovalForm(array(
|
||||||
'onSuccess' => function ($form) {
|
'onSuccess' => function ($form) {
|
||||||
$configForm = new ResourceConfigForm();
|
$configForm = new ResourceConfigForm();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user