phperror/error: provide a failsafe error message

...for PHP 5.3

fixes #1033
This commit is contained in:
Thomas Gelf 2017-07-26 11:49:51 +02:00
parent cc01446269
commit c2a6bef46e
4 changed files with 63 additions and 2 deletions

View File

@ -0,0 +1,22 @@
<?php
namespace Icinga\Module\Director\Controllers;
use Icinga\Web\Controller;
class PhperrorController extends Controller
{
public function errorAction()
{
$this->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);
}
}

View File

@ -0,0 +1,8 @@
<div class="controls">
<?= $this->tabs ?>
<h1><?= $this->escape($this->title) ?></h1>
</div>
<div class="content">
<p class="error"><?= $this->escape($this->message) ?></p>
</div>

26
run-php5.3.php Normal file
View File

@ -0,0 +1,26 @@
<?php
use Icinga\Application\Icinga;
use Icinga\Exception\IcingaException;
use Icinga\Web\Url;
if (Icinga::app()->isCli()) {
throw new IcingaException(
"PHP version 5.4.x is required for Director >= 1.4.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;
}

View File

@ -1,10 +1,16 @@
<?php
use Icinga\Application\Icinga;
use Icinga\Application\Modules\Module;
use ipl\Loader\CompatLoader;
if (version_compare(PHP_VERSION, '5.4.0') < 0) {
include __DIR__ . '/run-php5.3.php';
return;
}
$prefix = '\\Icinga\\Module\\Director\\';
/** @var Module $this */
$this->provideHook('monitoring/HostActions');
$this->provideHook('monitoring/ServiceActions');
@ -51,7 +57,6 @@ $this->provideHook('director/Job', $prefix . 'Job\\SyncJob');
$this->provideHook('cube/Actions', 'CubeLinks');
// ipl compat, unless it is released:
if (class_exists('ipl\\Html\\ValidHtml')) {
return;
}