run: check module dependencies

fixes  #1938
This commit is contained in:
Thomas Gelf 2019-09-11 21:49:02 +02:00
parent 17f8ef1dd0
commit 087b09d363
5 changed files with 129 additions and 1 deletions

View File

@ -2,6 +2,7 @@
namespace Icinga\Module\Director\Controllers;
use Icinga\Application\Icinga;
use Icinga\Web\Controller;
class PhperrorController extends Controller
@ -19,4 +20,20 @@ class PhperrorController extends Controller
$this->view->title = $this->translate('Unsatisfied dependencies');
$this->view->message = sprintf($msg, PHP_VERSION);
}
public function dependenciesAction()
{
$this->setAutorefreshInterval(15);
$this->view->dependencies = $this->Module()->getDependencies();
$this->view->modules = Icinga::app()->getModuleManager();
$this->getTabs()->add('error', array(
'label' => $this->translate('Error'),
'url' => $this->getRequest()->getUrl()
))->activate('error');
$msg = $this->translate(
"Icinga Director depends on the following modules, please install/upgrade as required"
);
$this->view->title = $this->translate('Unsatisfied dependencies');
$this->view->message = sprintf($msg, PHP_VERSION);
}
}

View File

@ -0,0 +1,71 @@
<?php
use Icinga\Application\Modules\Manager;
?>
<div class="controls">
<?= $this->tabs ?>
<h1><?= $this->escape($this->title) ?></h1>
</div>
<div class="content">
<p class="error"><?= $this->escape($this->message) ?></p>
<table class="common-table table-row-selectable">
<thead>
<tr>
<th><?= $this->translate('Module name') ?></th>
<th><?= $this->translate('Required') ?></th>
<th><?= $this->translate('Installed') ?></th>
</tr>
</thead>
<tbody data-base-target="_next">
<?php
foreach ($this->dependencies as $module => $required) {
/** @var Manager $this->modules */
if ($modules->hasEnabled($module)) {
$installed = $modules->getModule($module, false)->getVersion();
$installed = \ltrim($installed, 'v'); // v0.6.0 VS 0.6.0
if (\preg_match('/^([<>=]+)\s*v?(\d+\.\d+\.\d+)$/', $required, $match)) {
$operator = $match[1];
$vRequired = $match[2];
if (\version_compare($installed, $vRequired, $operator)) {
$icon = 'ok';
} else {
$icon = 'cancel';
}
} else {
$icon = 'cancel';
}
$link = $this->qlink(
$module,
'config/module',
['name' => $module],
['class' => "icon-$icon"]
);
} elseif ($modules->hasInstalled($module)) {
$installed = $this->translate('disabled');
$link = $this->qlink($module, 'config/module', ['name' => $module], ['class' => 'icon-cancel']);
} else {
$installed = $this->translate('missing');
$link = sprintf(
'<a href="#" class="icon-cancel">%s</a> (<a href="https://github.com/Icinga/icingaweb2-module-%s"'
. ' target="_blank" rel="noreferrer">%s</a>)',
$this->escape($module),
$this->escape($module),
$this->translate('more')
);
}
\printf(
'<tr><td>%s</a></td><td>%s</td><td>%s</td></tr>',
$link,
$this->escape($required),
$this->escape($installed)
);
}
?>
</tbody>
</table>
</div>

View File

@ -1,6 +1,6 @@
Name: Icinga Director
Version: master
Depends: monitoring
Depends: reactbundle (>=0.6.0), ipl (>=0.3.0), incubator (>=0.3.0)
Description: Director - Config tool for Icinga 2
Icinga Director is a configuration tool that has been designed to make
Icinga 2 configuration easy and understandable.

23
run-missingdeps.php Normal file
View File

@ -0,0 +1,23 @@
<?php
use Icinga\Application\Icinga;
use Icinga\Exception\IcingaException;
use Icinga\Web\Url;
if (Icinga::app()->isCli()) {
throw new IcingaException(
"Missing dependencies, please check "
);
} else {
$request = Icinga::app()->getRequest();
$path = $request->getPathInfo();
if (! preg_match('#^/director#', $path)) {
return;
}
if (preg_match('#^/director/phperror/dependencies#', $path)) {
return;
}
header('Location: ' . Url::fromPath('director/phperror/dependencies'));
exit;
}

17
run.php
View File

@ -65,3 +65,20 @@ $this->provideHook('cube/Actions', 'CubeLinks');
require_once __DIR__ . '/library/vendor/ipl/Loader/CompatLoader.php';
CompatLoader::delegateLoadingToIcingaWeb($this->app);
$modules = $this->app->getModuleManager();
foreach ($this->getDependencies() as $module => $required) {
if ($modules->hasEnabled($module)) {
$installed = $modules->getModule($module, false)->getVersion();
$installed = \ltrim($installed, 'v'); // v0.6.0 VS 0.6.0
if (preg_match('/^([<>=]+)\s*v?(\d+\.\d+\.\d+)$/', $required, $match)) {
$operator = $match[1];
$vRequired = $match[2];
if (\version_compare($installed, $vRequired, $operator)) {
continue;
}
}
include __DIR__ . '/run-missingdeps.php';
return;
}
}