Merge branch 'hotfix-2.3.14' into develop

pull/762/head
iglocska 2014-10-27 16:21:03 +01:00
commit 682923f980
4 changed files with 102 additions and 0 deletions

1
VERSION.json Normal file
View File

@ -0,0 +1 @@
{"major":2, "minor":3, "hotfix":14}

View File

@ -333,6 +333,11 @@ class ServersController extends AppController {
App::uses('File', 'Utility');
App::uses('Folder', 'Utility');
// check if the current version of MISP is outdated or not
$version = $this->__checkVersion();
$this->set('version', $version);
if ($version && (!$version['upToDate'] || $version['upToDate'] == 'older')) $diagnostic_errors++;
// check writeable directories
$writeableDirs = array(
'tmp' => 0, 'files' => 0, 'files' . DS . 'scripts' . DS . 'tmp' => 0,
@ -438,6 +443,27 @@ class ServersController extends AppController {
}
}
private function __checkVersion() {
if (!$this->_isSiteAdmin()) throw new MethodNotAllowedException();
set_error_handler(function() {});
$options = array('http' => array('user_agent'=> $_SERVER['HTTP_USER_AGENT']));
$context = stream_context_create($options);
$tags = file_get_contents('https://api.github.com/repos/MISP/MISP/tags', false, $context);
restore_error_handler();
if ($tags != false) {
$json_decoded_tags = json_decode($tags);
// find the latest version tag in the v[major].[minor].[hotfix] format
for ($i = 0; $i < count($json_decoded_tags); $i++) {
if (preg_match('/^v[0-9]+\.[0-9]+\.[0-9]+$/', $json_decoded_tags[$i]->name)) break;
}
return $this->Server->checkVersion($json_decoded_tags[$i]->name);
} else {
return false;
}
}
public function serverSettingsEdit($setting, $id, $forceSave = false) {
if (!$this->_isSiteAdmin()) throw new MethodNotAllowedException();
if (!isset($setting) || !isset($id)) throw new MethodNotAllowedException();

View File

@ -938,4 +938,34 @@ class Server extends AppModel {
Configure::write($setting, $value);
Configure::dump('config.php', 'default', array('MISP', 'GnuPG', 'SecureAuth', 'Security', 'debug'));
}
public function checkVersion($newest) {
App::uses('Folder', 'Utility');
$file = new File (ROOT . DS . 'VERSION.json', true);
$version_array = json_decode($file->read());
$file->close();
$current = 'v' . $version_array->major . '.' . $version_array->minor . '.' . $version_array->hotfix;
$newest_array = $this->__dissectVersion($newest);
$upToDate = $this->__compareVersions(array($version_array->major, $version_array->minor, $version_array->hotfix), $newest_array, 0);
return array ('current' => $current, 'newest' => $newest, 'upToDate' => $upToDate);
}
private function __dissectVersion($version) {
$version = substr($version, 1);
return explode('.', $version);
}
private function __compareVersions($current, $newest, $i) {
if ($current[$i] == $newest[$i]) {
if ($i < 2) {
return $this->__compareVersions($current, $newest, $i+1);
} else {
return 'same';
}
} else if ($current[$i] < $newest[$i]) {
return 'older';
} else {
return 'newer';
}
}
}

View File

@ -1,4 +1,49 @@
<div style="border:1px solid #dddddd; margin-top:1px; width:100%; padding:10px">
<h3>MISP version</h3>
<p>Since version 2.3.14, every version of MISP includes a json file with the current version. This is checked against the latest tag on github, if there is a version mismatch the tool will warn you about it. Make sure that you update MISP regularly.</p>
<div style="background-color:#f7f7f9;width:300px;">
<span>Currently installed version.....
<?php
switch ($version['upToDate']) {
case 'newer':
$fontColour = 'orange';
$versionText = 'Upcoming development version';
break;
case 'older':
$fontColour = 'red';
$versionText = 'Outdated version';
break;
case 'same':
$fontColour = 'green';
$versionText = 'OK';
break;
default:
$fontColour = 'red';
$versionText = 'Could not retrieve version from github';
}
?>
<span style="color:<?php echo $fontColour; ?>;">
<?php
echo $version['current'];
?>
</span>
</span><br />
<span>Latest available version.....
<span style="color:<?php echo $fontColour; ?>;">
<?php
echo $version['newest'];
?>
</span>
</span><br />
<span>Status.....
<span style="color:<?php echo $fontColour; ?>;">
<?php
echo $versionText;
?>
</span>
</span>
</div>
<h3>Writeable Directories</h3>
<p>The following directories have to be writeable for MISP to function properly. Make sure that the apache user has write privileges for the directories below.</p>
<div style="background-color:#f7f7f9;width:300px;">