From 087b09d363a3878e55bbce358b3116832492781e Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 11 Sep 2019 21:49:02 +0200 Subject: [PATCH] run: check module dependencies fixes #1938 --- .../controllers/PhperrorController.php | 17 +++++ .../views/scripts/phperror/dependencies.phtml | 71 +++++++++++++++++++ module.info | 2 +- run-missingdeps.php | 23 ++++++ run.php | 17 +++++ 5 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 application/views/scripts/phperror/dependencies.phtml create mode 100644 run-missingdeps.php diff --git a/application/controllers/PhperrorController.php b/application/controllers/PhperrorController.php index e091db7a..fbd29d8f 100644 --- a/application/controllers/PhperrorController.php +++ b/application/controllers/PhperrorController.php @@ -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); + } } diff --git a/application/views/scripts/phperror/dependencies.phtml b/application/views/scripts/phperror/dependencies.phtml new file mode 100644 index 00000000..7b344350 --- /dev/null +++ b/application/views/scripts/phperror/dependencies.phtml @@ -0,0 +1,71 @@ + +
+tabs ?> +

escape($this->title) ?>

+
+ +
+

escape($this->message) ?>

+ + + + + + + + + +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( + '%s (%s)', + $this->escape($module), + $this->escape($module), + $this->translate('more') + ); + } + + \printf( + '', + $link, + $this->escape($required), + $this->escape($installed) + ); +} + +?> + +
translate('Module name') ?>translate('Required') ?>translate('Installed') ?>
%s%s%s
+
diff --git a/module.info b/module.info index 70b5bb16..51bbbeae 100644 --- a/module.info +++ b/module.info @@ -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. diff --git a/run-missingdeps.php b/run-missingdeps.php new file mode 100644 index 00000000..888692de --- /dev/null +++ b/run-missingdeps.php @@ -0,0 +1,23 @@ +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; +} diff --git a/run.php b/run.php index ec074f60..1900a0fa 100644 --- a/run.php +++ b/run.php @@ -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; + } +}