mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-23 22:04:25 +02:00
Move ModuleController from incubator
The Notification dependency is removed and uses exceptions now, otherwise it's mostly the same like in the incubator refs #4092
This commit is contained in:
parent
81e27689bb
commit
04a23f0096
47
application/controllers/ModulesController.php
Executable file
47
application/controllers/ModulesController.php
Executable file
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
// @codingStandardsIgnoreStart
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
|
# namespace Icinga\Application\Controllers;
|
||||||
|
|
||||||
|
|
||||||
|
use Icinga\Web\ActionController;
|
||||||
|
use Icinga\Application\Icinga;
|
||||||
|
|
||||||
|
class ModulesController extends ActionController
|
||||||
|
{
|
||||||
|
protected $manager;
|
||||||
|
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
$this->manager = Icinga::app()->moduleManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function indexAction()
|
||||||
|
{
|
||||||
|
$this->view->modules = $this->manager->select()
|
||||||
|
->from('modules')
|
||||||
|
->order('name');
|
||||||
|
$this->render('overview');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function overviewAction()
|
||||||
|
{
|
||||||
|
$this->indexAction();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function enableAction()
|
||||||
|
{
|
||||||
|
$this->manager->enableModule($this->_getParam('name'));
|
||||||
|
$this->redirectNow('modules/overview?_render=body');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function disableAction()
|
||||||
|
{
|
||||||
|
$this->manager->disableModule($this->_getParam('name'));
|
||||||
|
$this->redirectNow('modules/overview?_render=body');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
3
application/views/scripts/inline.phtml
Normal file
3
application/views/scripts/inline.phtml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<?= $this->layout()->moduleStart ?>
|
||||||
|
<?= $this->layout()->content ?>
|
||||||
|
<?= $this->layout()->moduleEnd ?>
|
61
application/views/scripts/mixedPagination.phtml
Executable file
61
application/views/scripts/mixedPagination.phtml
Executable file
@ -0,0 +1,61 @@
|
|||||||
|
<? if ($this->pageCount > 1): ?>
|
||||||
|
<?php
|
||||||
|
if (is_array($this->preserve)) {
|
||||||
|
$preserve = $this->preserve;
|
||||||
|
} else {
|
||||||
|
$preserve = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$fromto = t('%d to %d of %d');
|
||||||
|
$total = $this->totalItemCount;
|
||||||
|
?>
|
||||||
|
<div class="pagination pagination-mini" style="margin:0px">
|
||||||
|
<ul>
|
||||||
|
<!-- Previous page link -->
|
||||||
|
<? if (isset($this->previous)): ?>
|
||||||
|
<li><a href="<?= $this->url($preserve + array('page' => $this->previous)); ?>" title="<?=
|
||||||
|
sprintf($fromto,
|
||||||
|
($this->current - 2) * $this->itemCountPerPage + 1,
|
||||||
|
($this->current - 1) * $this->itemCountPerPage,
|
||||||
|
$this->totalItemCount)
|
||||||
|
?>">« <?= t('Back') ?></a></li>
|
||||||
|
<? else: ?>
|
||||||
|
<li class="disabled"><span>« <?= t('Back') ?></span></li>
|
||||||
|
<?php
|
||||||
|
endif;
|
||||||
|
?>
|
||||||
|
<!-- Numbered page links -->
|
||||||
|
<? foreach ($this->pagesInRange as $page): ?>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$start = ($page - 1) * $this->itemCountPerPage + 1;
|
||||||
|
$end = $page * $this->itemCountPerPage;
|
||||||
|
if ($end > $total) {
|
||||||
|
$end = $total;
|
||||||
|
}
|
||||||
|
$title = sprintf($fromto, $start, $end, $total);
|
||||||
|
$active_class = $page === $this->current ? ' class="active"' : '';
|
||||||
|
|
||||||
|
?>
|
||||||
|
<?php if ($page === '...'): ?>
|
||||||
|
<li class="disabled"><span>...</span></li>
|
||||||
|
<?php else: ?>
|
||||||
|
<li<?= $active_class ?>><a href="<?= $this->url(
|
||||||
|
$preserve + array('page' => $page)
|
||||||
|
); ?>" title="<?= $title ?>"><?= $page; ?></a></li>
|
||||||
|
<? endif ?>
|
||||||
|
<? endforeach ?>
|
||||||
|
<!-- Next page link -->
|
||||||
|
<? if (isset($this->next)): ?>
|
||||||
|
<li><a href="<?= $this->url($preserve + array('page' => $this->next)); ?>" title="<?=
|
||||||
|
sprintf($fromto,
|
||||||
|
($this->current) * $this->itemCountPerPage + 1,
|
||||||
|
($this->current + 1) * $this->itemCountPerPage,
|
||||||
|
$total)
|
||||||
|
?>"><?= t('Next') ?> »</a></li>
|
||||||
|
<? else: ?>
|
||||||
|
<li class="disabled"><span><?= t('Next') ?> »</span></li>
|
||||||
|
<? endif ?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<? endif ?>
|
38
application/views/scripts/modules/overview.phtml
Normal file
38
application/views/scripts/modules/overview.phtml
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
$this->modules->limit(10);
|
||||||
|
$modules = $this->modules->paginate();
|
||||||
|
|
||||||
|
?>
|
||||||
|
<h3>Installed Modules</h3>
|
||||||
|
<?= $this->paginationControl($modules, null, null, array(
|
||||||
|
'preserve' => $this->preserve
|
||||||
|
)); ?>
|
||||||
|
<table >
|
||||||
|
<tbody>
|
||||||
|
<? foreach ($modules as $module): ?>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<? if ($module->enabled): ?>
|
||||||
|
<i class="icon-ok-sign"></i> <?= $this->qlink(
|
||||||
|
$module->name,
|
||||||
|
'modules/disable',
|
||||||
|
array('name' => $module->name),
|
||||||
|
array('target'=>'body')
|
||||||
|
) ?>
|
||||||
|
<? else: ?>
|
||||||
|
<i class="icon-remove-sign"></i> <?= $this->qlink(
|
||||||
|
$module->name,
|
||||||
|
'modules/enable',
|
||||||
|
array('name' => $module->name),
|
||||||
|
array('target'=>'body')
|
||||||
|
) ?>
|
||||||
|
<? endif ?>
|
||||||
|
(<?=
|
||||||
|
$module->enabled
|
||||||
|
? ($module->loaded ? 'enabled' : 'failed')
|
||||||
|
: 'disabled'
|
||||||
|
?>)</td>
|
||||||
|
</tr>
|
||||||
|
<? endforeach ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
24
application/views/scripts/modules/show.phtml
Normal file
24
application/views/scripts/modules/show.phtml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php $container = $this->container('modules-container',array(
|
||||||
|
"class" => "expanded_absolute"
|
||||||
|
))->beginContent() ?>
|
||||||
|
<table class="table table-bordered" style="width:100%">
|
||||||
|
<thead>
|
||||||
|
<tr style="text-align:left">
|
||||||
|
<th width="70%">Module</th>
|
||||||
|
<th width="15%">Type</th>
|
||||||
|
<th width="15%">Active</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php foreach($this->modules as $module): ?>
|
||||||
|
<tr>
|
||||||
|
<td><?= $module["name"] ?></td>
|
||||||
|
<td><?= $module["type"] ?></td>
|
||||||
|
<td><?= $module["active"] ?></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<?= $container; ?>
|
@ -18,6 +18,7 @@ use Icinga\Exception\ConfigurationError;
|
|||||||
* Usage example for CLI:
|
* Usage example for CLI:
|
||||||
* <code>
|
* <code>
|
||||||
* use Icinga\Application\Cli;
|
* use Icinga\Application\Cli;
|
||||||
|
|
||||||
* Cli::start();
|
* Cli::start();
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
@ -99,7 +100,7 @@ abstract class ApplicationBootstrap
|
|||||||
public function moduleManager()
|
public function moduleManager()
|
||||||
{
|
{
|
||||||
if ($this->moduleManager === null) {
|
if ($this->moduleManager === null) {
|
||||||
$this->moduleManager = new ModuleManager($this);
|
$this->moduleManager = new ModuleManager($this, "/etc/icinga2/modules_enabled");
|
||||||
}
|
}
|
||||||
return $this->moduleManager;
|
return $this->moduleManager;
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ use Icinga\Application\ApplicationBootstrap;
|
|||||||
use Icinga\Data\ArrayDatasource;
|
use Icinga\Data\ArrayDatasource;
|
||||||
use Icinga\Web\Notification;
|
use Icinga\Web\Notification;
|
||||||
use Icinga\Exception\ConfigurationError;
|
use Icinga\Exception\ConfigurationError;
|
||||||
|
use Icinga\Exception\SystemPermissionException;
|
||||||
|
|
||||||
// TODO: show whether enabling/disabling modules is allowed by checking enableDir
|
// TODO: show whether enabling/disabling modules is allowed by checking enableDir
|
||||||
// perms
|
// perms
|
||||||
@ -20,17 +21,20 @@ class Manager
|
|||||||
|
|
||||||
protected $enableDir;
|
protected $enableDir;
|
||||||
|
|
||||||
public function __construct(ApplicationBootstrap $app)
|
public function __construct(ApplicationBootstrap $app, $dir = null)
|
||||||
{
|
{
|
||||||
$this->app = $app;
|
$this->app = $app;
|
||||||
$this->prepareEssentials();
|
if ($dir === null) {
|
||||||
|
$dir = $this->app->getConfig()->getConfigDir()
|
||||||
|
. '/enabledModules';
|
||||||
|
}
|
||||||
|
$this->prepareEssentials($dir);
|
||||||
$this->detectEnabledModules();
|
$this->detectEnabledModules();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function prepareEssentials()
|
protected function prepareEssentials($moduleDir)
|
||||||
{
|
{
|
||||||
$this->enableDir = $this->app->getConfig()->getConfigDir()
|
$this->enableDir = $moduleDir;
|
||||||
. '/enabledModules';
|
|
||||||
|
|
||||||
if (! file_exists($this->enableDir) || ! is_dir($this->enableDir)) {
|
if (! file_exists($this->enableDir) || ! is_dir($this->enableDir)) {
|
||||||
throw new ProgrammingError(
|
throw new ProgrammingError(
|
||||||
@ -99,13 +103,20 @@ class Manager
|
|||||||
$target = $this->installedBaseDirs[$name];
|
$target = $this->installedBaseDirs[$name];
|
||||||
$link = $this->enableDir . '/' . $name;
|
$link = $this->enableDir . '/' . $name;
|
||||||
if (! is_writable($this->enableDir)) {
|
if (! is_writable($this->enableDir)) {
|
||||||
Notification::error("I do not have permissions to enable modules");
|
throw new SystemPermissionException(
|
||||||
|
"Insufficient system permissions for enabling modules",
|
||||||
|
"write",
|
||||||
|
$this->enableDir
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (file_exists($link) && is_link($link)) {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
if (@symlink($target, $link)) {
|
if (!@symlink($target, $link)) {
|
||||||
Notification::success("The module $name has been enabled");
|
$error = error_get_last();
|
||||||
} else {
|
if (strstr($error["message"], "File exists") === false) {
|
||||||
Notification::error("Enabling module $name failed");
|
throw new SystemPermissionException($error["message"], "symlink", $link);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -116,16 +127,29 @@ class Manager
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
if (! is_writable($this->enableDir)) {
|
if (! is_writable($this->enableDir)) {
|
||||||
Notification::error("I do not have permissions to disable modules");
|
throw new SystemPermissionException("Can't write the module directory", "write", $this->enableDir);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
$link = $this->enableDir . '/' . $name;
|
$link = $this->enableDir . '/' . $name;
|
||||||
|
if (!file_exists($link)) {
|
||||||
|
throw new ConfigurationError("The module $name could not be found, can't disable it");
|
||||||
|
}
|
||||||
|
if (!is_link($link)) {
|
||||||
|
throw new ConfigurationError(
|
||||||
|
"The module $name can't be disabled as this would delete the whole module. ".
|
||||||
|
"It looks like you have installed this module manually and moved it to your module folder.".
|
||||||
|
"In order to dynamically enable and disable modules, you have to create a symlink to ".
|
||||||
|
"the enabled_modules folder"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (file_exists($link) && is_link($link)) {
|
if (file_exists($link) && is_link($link)) {
|
||||||
if (@unlink($link)) {
|
if (!@unlink($link)) {
|
||||||
Notification::success("The module $name has been disabled");
|
$error = error_get_last();
|
||||||
} else {
|
throw new SystemPermissionException($error["message"], "unlink", $link);
|
||||||
Notification::error("Disabling module $name failed");
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
}
|
}
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
this.updateContainer = function(id,content,req) {
|
this.updateContainer = function(id,content,req) {
|
||||||
var target = id;
|
var target = id;
|
||||||
if (typeof id === "string") {
|
if (typeof id === "string") {
|
||||||
target = $('div[container-id='+id+']');
|
target = this.getContainer(id);
|
||||||
}
|
}
|
||||||
var ctrl = $('.container-controls',target);
|
var ctrl = $('.container-controls',target);
|
||||||
target.html(content);
|
target.html(content);
|
||||||
@ -100,6 +100,9 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.getContainer = function(id) {
|
this.getContainer = function(id) {
|
||||||
|
if(id == 'body') {
|
||||||
|
return $(document.body);
|
||||||
|
}
|
||||||
return $('div[container-id='+id+']');
|
return $('div[container-id='+id+']');
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -111,4 +114,4 @@
|
|||||||
return containerMgrInstance;
|
return containerMgrInstance;
|
||||||
|
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
};
|
};
|
||||||
var getDOMForDestination = function(destination) {
|
var getDOMForDestination = function(destination) {
|
||||||
var target = destination;
|
var target = destination;
|
||||||
if(typeof destination === "string") {
|
if (typeof destination === "string") {
|
||||||
target = containerMgr.getContainer(destination)[0];
|
target = containerMgr.getContainer(destination)[0];
|
||||||
} else if(typeof destination.context !== "undefined") {
|
} else if(typeof destination.context !== "undefined") {
|
||||||
target = destination[0];
|
target = destination[0];
|
||||||
@ -89,7 +89,7 @@
|
|||||||
if(destination) {
|
if(destination) {
|
||||||
pending.push({
|
pending.push({
|
||||||
request: req,
|
request: req,
|
||||||
DOM: getDOMForDestination(destination)
|
DOM: getDOMForDestination(destination)
|
||||||
});
|
});
|
||||||
req.destination = destination;
|
req.destination = destination;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user