diff --git a/application/controllers/PhperrorController.php b/application/controllers/PhperrorController.php deleted file mode 100644 index 40a32c1a7..000000000 --- a/application/controllers/PhperrorController.php +++ /dev/null @@ -1,43 +0,0 @@ -getTabs()->add('error', array( - 'label' => $this->translate('Error'), - 'url' => $this->getRequest()->getUrl() - ))->activate('error'); - $msg = $this->translate( - "PHP version 5.4.x is required for Director >= 1.4.0, you're running %s." - . ' Please either upgrade PHP or downgrade Icinga Director' - ); - $this->view->title = $this->translate('Unsatisfied dependencies'); - $this->view->message = sprintf($msg, PHP_VERSION); - } - - public function dependenciesAction() - { - $checker = new DependencyChecker(Icinga::app()); - if ($checker->satisfiesDependencies($this->Module())) { - $this->redirectNow('director'); - } - $this->setAutorefreshInterval(15); - $this->getTabs()->add('error', [ - 'label' => $this->translate('Error'), - 'url' => $this->getRequest()->getUrl() - ])->activate('error'); - $this->view->title = $this->translate('Unsatisfied dependencies'); - $this->view->table = (new DependencyInfoTable($checker, $this->Module()))->render(); - $this->view->message = $this->translate( - "Icinga Director depends on the following modules, please install/upgrade as required" - ); - } -} diff --git a/application/views/scripts/phperror/dependencies.phtml b/application/views/scripts/phperror/dependencies.phtml deleted file mode 100644 index 1cbf31e25..000000000 --- a/application/views/scripts/phperror/dependencies.phtml +++ /dev/null @@ -1,9 +0,0 @@ -
-tabs ?> -

escape($this->title) ?>

-
- -
-

escape($this->message) ?>

-table ?> -
diff --git a/application/views/scripts/phperror/error.phtml b/application/views/scripts/phperror/error.phtml deleted file mode 100644 index 260bf7208..000000000 --- a/application/views/scripts/phperror/error.phtml +++ /dev/null @@ -1,8 +0,0 @@ -
-tabs ?> -

escape($this->title) ?>

-
- -
-

escape($this->message) ?>

-
diff --git a/library/Director/Application/Dependency.php b/library/Director/Application/Dependency.php deleted file mode 100644 index 0100e69fa..000000000 --- a/library/Director/Application/Dependency.php +++ /dev/null @@ -1,113 +0,0 @@ -=1.7.0 - * @param string $installedVersion - * @param bool $enabled - */ - public function __construct($name, $requirement, $installedVersion = null, $enabled = null) - { - $this->name = $name; - $this->setRequirement($requirement); - if ($installedVersion !== null) { - $this->setInstalledVersion($installedVersion); - } - if ($enabled !== null) { - $this->setEnabled($enabled); - } - } - - public function setRequirement($requirement) - { - if (preg_match('/^([<>=]+)\s*v?(\d+\.\d+\.\d+)$/', $requirement, $match)) { - $this->operator = $match[1]; - $this->requiredVersion = $match[2]; - $this->requirement = $requirement; - } else { - throw new \InvalidArgumentException("'$requirement' is not a valid version constraint"); - } - } - - /** - * @return bool - */ - public function isInstalled() - { - return $this->installedVersion !== null; - } - - /** - * @return string|null - */ - public function getInstalledVersion() - { - return $this->installedVersion; - } - - /** - * @param string $version - */ - public function setInstalledVersion($version) - { - $this->installedVersion = ltrim($version, 'v'); // v0.6.0 VS 0.6.0 - } - - /** - * @return bool - */ - public function isEnabled() - { - return $this->enabled === true; - } - - /** - * @param bool $enabled - */ - public function setEnabled($enabled = true) - { - $this->enabled = $enabled; - } - - public function isSatisfied() - { - if (! $this->isInstalled() || ! $this->isEnabled()) { - return false; - } - - return version_compare($this->installedVersion, $this->requiredVersion, $this->operator); - } - - public function getName() - { - return $this->name; - } - - public function getRequirement() - { - return $this->requirement; - } -} diff --git a/library/Director/Application/DependencyChecker.php b/library/Director/Application/DependencyChecker.php deleted file mode 100644 index 78031d04a..000000000 --- a/library/Director/Application/DependencyChecker.php +++ /dev/null @@ -1,70 +0,0 @@ -app = $app; - $this->modules = $app->getModuleManager(); - } - - /** - * @param Module $module - * @return Dependency[] - */ - public function getDependencies(Module $module) - { - $dependencies = []; - $isV290 = version_compare(Version::VERSION, '2.9.0', '>='); - foreach ($module->getRequiredModules() as $moduleName => $required) { - $dependency = new Dependency($moduleName, $required); - $dependency->setEnabled($this->modules->hasEnabled($moduleName)); - if ($this->modules->hasInstalled($moduleName)) { - $dependency->setInstalledVersion($this->modules->getModule($moduleName, false)->getVersion()); - } - $dependencies[] = $dependency; - } - if ($isV290) { - $libs = $this->app->getLibraries(); - foreach ($module->getRequiredLibraries() as $libraryName => $required) { - $dependency = new Dependency($libraryName, $required); - if ($libs->has($libraryName)) { - $dependency->setInstalledVersion($libs->get($libraryName)->getVersion()); - $dependency->setEnabled(); - } - $dependencies[] = $dependency; - } - } - - return $dependencies; - } - - // if (version_compare(Version::VERSION, '2.9.0', 'ge')) { - // } - /** - * @param Module $module - * @return bool - */ - public function satisfiesDependencies(Module $module) - { - foreach ($this->getDependencies($module) as $dependency) { - if (! $dependency->isSatisfied()) { - return false; - } - } - - return true; - } -} diff --git a/library/Director/Web/Table/Dependency/DependencyInfoTable.php b/library/Director/Web/Table/Dependency/DependencyInfoTable.php deleted file mode 100644 index 28aa856d9..000000000 --- a/library/Director/Web/Table/Dependency/DependencyInfoTable.php +++ /dev/null @@ -1,101 +0,0 @@ -module = $module; - $this->checker = $checker; - } - - protected function linkToModule($name, $icon) - { - return Html::link( - Html::escape($name), - Html::webUrl('config/module', ['name' => $name]), - [ - 'class' => "icon-$icon" - ] - ); - } - - public function render() - { - $html = ' - - - - - - - - -'; - foreach ($this->checker->getDependencies($this->module) as $dependency) { - $name = $dependency->getName(); - $isLibrary = substr($name, 0, 11) === 'icinga-php-'; - $rowAttributes = $isLibrary ? ['data-base-target' => '_self'] : null; - if ($dependency->isSatisfied()) { - if ($dependency->isSatisfied()) { - $icon = 'ok'; - } else { - $icon = 'cancel'; - } - $link = $isLibrary ? $this->noLink($name, $icon) : $this->linkToModule($name, $icon); - $installed = $dependency->getInstalledVersion(); - } elseif ($dependency->isInstalled()) { - $installed = sprintf('%s (%s)', $dependency->getInstalledVersion(), $this->translate('disabled')); - $link = $this->linkToModule($name, 'cancel'); - } else { - $installed = $this->translate('missing'); - $repository = $isLibrary ? $name : "icingaweb2-module-$name"; - $link = sprintf( - '%s (%s)', - $this->noLink($name, 'cancel'), - Html::linkToGitHub(Html::escape($this->translate('more')), 'Icinga', $repository) - ); - } - - $html .= $this->htmlRow([ - $link, - Html::escape($dependency->getRequirement()), - Html::escape($installed) - ], $rowAttributes); - } - - return $html . ' -
' . Html::escape($this->translate('Module name')) . '' . Html::escape($this->translate('Required')) . '' . Html::escape($this->translate('Installed')) . '
-'; - } - - protected function noLink($label, $icon) - { - return Html::link(Html::escape($label), Url::fromRequest()->with('rnd', rand(1, 100000)), [ - 'class' => "icon-$icon" - ]); - } - - protected function translate($string) - { - return \mt('director', $string); - } - - protected function htmlRow(array $cols, $rowAttributes) - { - $content = ''; - foreach ($cols as $escapedContent) { - $content .= Html::tag('td', null, $escapedContent); - } - return Html::tag('tr', $rowAttributes, $content); - } -} diff --git a/library/Director/Web/Table/Dependency/Html.php b/library/Director/Web/Table/Dependency/Html.php deleted file mode 100644 index 092f7997f..000000000 --- a/library/Director/Web/Table/Dependency/Html.php +++ /dev/null @@ -1,74 +0,0 @@ - $value) { - if (! preg_match('/^[a-z][a-z0-9:-]*$/i', $name)) { - throw new InvalidArgumentException("Invalid attribute name: '$name'"); - } - - $result .= " $name=\"" . self::escapeAttributeValue($value) . '"'; - } - } - - return "$result>$escapedContent"; - } - - public static function webUrl($path, $params) - { - return Url::fromPath($path, $params); - } - - public static function link($escapedLabel, $url, $attributes = []) - { - return static::tag('a', [ - 'href' => $url, - ] + $attributes, $escapedLabel); - } - - public static function linkToGitHub($escapedLabel, $namespace, $repository) - { - return static::link( - $escapedLabel, - 'https://github.com/' . urlencode($namespace) . '/' . urlencode($repository), - [ - 'target' => '_blank', - 'rel' => 'noreferrer', - 'class' => 'icon-forward' - ] - ); - } - - protected static function escapeAttributeValue($value) - { - $value = str_replace('"', '"', $value); - // Escape ambiguous ampersands - return preg_replace_callback('/&[0-9A-Z]+;/i', function ($match) { - $subject = $match[0]; - - if (htmlspecialchars_decode($subject, ENT_COMPAT | ENT_HTML5) === $subject) { - // Ambiguous ampersand - return str_replace('&', '&', $subject); - } - - return $subject; - }, $value); - } - - public static function escape($any) - { - return htmlspecialchars($any); - } -} diff --git a/phpcs.xml b/phpcs.xml index 4e701524e..d32f2bbda 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -2,7 +2,6 @@ configuration.php run.php - run-php5.3.php application/ library/Director/ test/ diff --git a/run-missingdeps.php b/run-missingdeps.php deleted file mode 100644 index 888692dea..000000000 --- a/run-missingdeps.php +++ /dev/null @@ -1,23 +0,0 @@ -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-php5.3.php b/run-php5.3.php deleted file mode 100644 index 1e49e1bdc..000000000 --- a/run-php5.3.php +++ /dev/null @@ -1,25 +0,0 @@ -isCli()) { - throw new IcingaException( - "PHP version 5.6.x is required for Director >= 1.7.0, you're running %s." - . ' Please either upgrade PHP or downgrade Icinga Director', - PHP_VERSION - ); -} else { - $request = Icinga::app()->getRequest(); - $path = $request->getPathInfo(); - if (! preg_match('#^/director#', $path)) { - return; - } - if (preg_match('#^/director/phperror/error#', $path)) { - return; - } - - header('Location: ' . Url::fromPath('director/phperror/error')); - exit; -} diff --git a/run.php b/run.php index 8f821ed14..6a7d03ea8 100644 --- a/run.php +++ b/run.php @@ -1,18 +1,3 @@ app); -if (! $checker->satisfiesDependencies($this)) { - include __DIR__ . '/run-missingdeps.php'; - return; -} - include __DIR__ . '/register-hooks.php'; diff --git a/test/php/library/Director/Application/DependencyTest.php b/test/php/library/Director/Application/DependencyTest.php deleted file mode 100644 index cc6047eee..000000000 --- a/test/php/library/Director/Application/DependencyTest.php +++ /dev/null @@ -1,72 +0,0 @@ -=0.3.0'); - $this->assertFalse($dependency->isInstalled()); - } - - public function testNotSatisfiedWhenNotInstalled() - { - $dependency = new Dependency('something', '>=0.3.0'); - $this->assertFalse($dependency->isSatisfied()); - } - - public function testIsInstalled() - { - $dependency = new Dependency('something', '>=0.3.0'); - $dependency->setInstalledVersion('1.10.0'); - $this->assertTrue($dependency->isInstalled()); - } - - public function testNotEnabled() - { - $dependency = new Dependency('something', '>=0.3.0'); - $this->assertFalse($dependency->isEnabled()); - } - - public function testIsEnabled() - { - $dependency = new Dependency('something', '>=0.3.0'); - $dependency->setEnabled(); - $this->assertTrue($dependency->isEnabled()); - } - - public function testNotSatisfiedWhenNotEnabled() - { - $dependency = new Dependency('something', '>=0.3.0'); - $dependency->setInstalledVersion('1.10.0'); - $this->assertFalse($dependency->isSatisfied()); - } - - public function testSatisfiedWhenEqual() - { - $dependency = new Dependency('something', '>=0.3.0'); - $dependency->setInstalledVersion('0.3.0'); - $dependency->setEnabled(); - $this->assertTrue($dependency->isSatisfied()); - } - - public function testSatisfiedWhenGreater() - { - $dependency = new Dependency('something', '>=0.3.0'); - $dependency->setInstalledVersion('0.10.0'); - $dependency->setEnabled(); - $this->assertTrue($dependency->isSatisfied()); - } - - public function testNotSatisfiedWhenSmaller() - { - $dependency = new Dependency('something', '>=20.3.0'); - $dependency->setInstalledVersion('4.999.999'); - $dependency->setEnabled(); - $this->assertFalse($dependency->isSatisfied()); - } -}