Skip to content

Commit

Permalink
Make Version::get() failsafe
Browse files Browse the repository at this point in the history
refs #9247
  • Loading branch information
Al2Klimov committed Sep 24, 2015
1 parent feb27b8 commit e2d6089
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
24 changes: 8 additions & 16 deletions application/views/scripts/about/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,18 @@
<h1>Icinga Web 2</h1>
<?php
$versionInfo = array();
if ($version !== false) {
foreach (array(
'appVersion' => $this->translate('Version: %s'),
'gitCommitID' => $this->translate('Git commit ID: %s'),
'gitCommitDate' => $this->translate('Git commit date: %s')
) as $key => $label) {
if (array_key_exists($key, $version) && null !== ($value = $version[$key])) {
$versionInfo[] = sprintf($label, htmlspecialchars($value));
}
foreach (array(
'appVersion' => $this->translate('Version: %s'),
'gitCommitID' => $this->translate('Git commit ID: %s'),
'gitCommitDate' => $this->translate('Git commit date: %s')
) as $key => $label) {
if (array_key_exists($key, $version) && null !== ($value = $version[$key])) {
$versionInfo[] = sprintf($label, htmlspecialchars($value));
}
}

echo (
0 === count($versionInfo)
? '<p class="message-error">' . $this->translate(
'Can\'t determine Icinga Web 2\'s version'
)
: '<p>' . nl2br(implode("\n", $versionInfo), false)
) . '</p>';
?>
<p><?= implode('<br>', $versionInfo) ?></p>
<p>Copyright &copy; 2013-2015&emsp;<a href="https://www.icinga.org"><?=
$this->translate('The Icinga Project')
?></a><br>License: GNU GPL v2 or later</p>
Expand Down
12 changes: 6 additions & 6 deletions library/Icinga/Application/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ class Version
/**
* Get the version of this instance of Icinga Web 2
*
* @return array|false array on success, false otherwise
* @return array
*/
public static function get()
{
$version = array('appVersion' => self::VERSION);

if (false !== ($appVersion = @file_get_contents(Icinga::app()->getApplicationDir('GITCOMMIT')))) {
$matches = array();
if (@preg_match('/^(?P<gitCommitID>\w+) (?P<gitCommitDate>\S+)/', $appVersion, $matches)) {
$matches['appVersion'] = self::VERSION;
return $matches;
return array_merge($version, $matches);
}
}

Expand All @@ -38,12 +39,11 @@ public static function get()
if (false !== $gitCommitID) {
$matches = array();
if (@preg_match('/(?<!.)(?P<gitCommitID>[0-9a-f]+)$/ms', $gitCommitID, $matches)) {
$matches['appVersion'] = self::VERSION;
return $matches;
return array_merge($version, $matches);
}
}
}

return false;
return $version;
}
}

0 comments on commit e2d6089

Please sign in to comment.