fix: [server] Handle case when checking CLI version is not possible

pull/6853/head
Jakub Onderka 2021-01-13 14:10:13 +01:00
parent 7162a8eeaa
commit ed816c4da6
4 changed files with 92 additions and 87 deletions

View File

@ -929,27 +929,6 @@ class ServersController extends AppController
$this->render('/Elements/healthElements/settings_row');
}
private function __loadAvailableLanguages()
{
return $this->Server->loadAvailableLanguages();
}
private function __loadTagCollections()
{
return $this->Server->loadTagCollections($this->Auth->user());
}
private function __loadLocalOrgs()
{
$this->loadModel('Organisation');
$local_orgs = $this->Organisation->find('list', array(
'conditions' => array('local' => 1),
'recursive' => -1,
'fields' => array('Organisation.id', 'Organisation.name')
));
return array_replace(array(0 => __('No organisation selected.')), $local_orgs);
}
public function serverSettings($tab=false)
{
if (!$this->_isSiteAdmin()) {
@ -975,7 +954,6 @@ class ServersController extends AppController
$mixboxVersion = array(0 => __('Incorrect mixbox version installed, found $current, expecting $expected'), 1 => __('OK'));
$maecVersion = array(0 => __('Incorrect maec version installed, found $current, expecting $expected'), 1 => __('OK'));
$pymispVersion = array(0 => __('Incorrect PyMISP version installed, found $current, expecting $expected'), 1 => __('OK'));
$plyaraVersion = array(0 => __('Incorrect plyara version installed, found $current, expecting $expected'), 1 => __('OK'));
$sessionErrors = array(0 => __('OK'), 1 => __('High'), 2 => __('Alternative setting used'), 3 => __('Test failed'));
$moduleErrors = array(0 => __('OK'), 1 => __('System not enabled'), 2 => __('No modules found'));
@ -1015,8 +993,8 @@ class ServersController extends AppController
$tabs[$result['tab']]['severity'] = $result['level'];
}
}
if (isset($result['optionsSource']) && !empty($result['optionsSource'])) {
$result['options'] = $this->{'__load' . $result['optionsSource']}();
if (isset($result['optionsSource']) && is_callable($result['optionsSource'])) {
$result['options'] = $result['optionsSource']();
}
$dumpResults[] = $result;
if ($result['tab'] == $tab) {
@ -1032,13 +1010,12 @@ class ServersController extends AppController
$diagnostic_errors = 0;
App::uses('File', 'Utility');
App::uses('Folder', 'Utility');
$additionalViewVars = array();
if ($tab == 'files') {
if ($tab === 'files') {
$files = $this->__manageFiles();
$this->set('files', $files);
}
// Only run this check on the diagnostics tab
if ($tab == 'diagnostics' || $tab == 'download' || $this->_isRest()) {
if ($tab === 'diagnostics' || $tab === 'download' || $this->_isRest()) {
$php_ini = php_ini_loaded_file();
$this->set('php_ini', $php_ini);
@ -1059,27 +1036,26 @@ class ServersController extends AppController
$this->set('commit', $gitStatus['commit']);
$this->set('latestCommit', $gitStatus['latestCommit']);
$phpSettings = array(
'max_execution_time' => array(
'explanation' => 'The maximum duration that a script can run (does not affect the background workers). A too low number will break long running scripts like comprehensive API exports',
'recommended' => 300,
'unit' => false
),
'memory_limit' => array(
'explanation' => 'The maximum memory that PHP can consume. It is recommended to raise this number since certain exports can generate a fair bit of memory usage',
'recommended' => 2048,
'unit' => 'M'
),
'upload_max_filesize' => array(
'explanation' => 'The maximum size that an uploaded file can be. It is recommended to raise this number to allow for the upload of larger samples',
'recommended' => 50,
'unit' => 'M'
),
'post_max_size' => array(
'explanation' => 'The maximum size of a POSTed message, this has to be at least the same size as the upload_max_filesize setting',
'recommended' => 50,
'unit' => 'M'
)
'max_execution_time' => array(
'explanation' => 'The maximum duration that a script can run (does not affect the background workers). A too low number will break long running scripts like comprehensive API exports',
'recommended' => 300,
'unit' => false
),
'memory_limit' => array(
'explanation' => 'The maximum memory that PHP can consume. It is recommended to raise this number since certain exports can generate a fair bit of memory usage',
'recommended' => 2048,
'unit' => 'M'
),
'upload_max_filesize' => array(
'explanation' => 'The maximum size that an uploaded file can be. It is recommended to raise this number to allow for the upload of larger samples',
'recommended' => 50,
'unit' => 'M'
),
'post_max_size' => array(
'explanation' => 'The maximum size of a POSTed message, this has to be at least the same size as the upload_max_filesize setting',
'recommended' => 50,
'unit' => 'M'
)
);
foreach ($phpSettings as $setting => $settingArray) {
@ -1133,7 +1109,9 @@ class ServersController extends AppController
$attachmentScan = ['status' => false, 'error' => $e->getMessage()];
}
$additionalViewVars = array('gpgStatus', 'sessionErrors', 'proxyStatus', 'sessionStatus', 'zmqStatus', 'stixVersion', 'cyboxVersion', 'mixboxVersion', 'maecVersion', 'stix2Version', 'pymispVersion', 'moduleStatus', 'yaraStatus', 'gpgErrors', 'proxyErrors', 'zmqErrors', 'stixOperational', 'stix', 'moduleErrors', 'moduleTypes', 'dbDiagnostics', 'dbSchemaDiagnostics', 'redisInfo', 'attachmentScan');
$view = compact('gpgStatus', 'sessionErrors', 'proxyStatus', 'sessionStatus', 'zmqStatus', 'stixVersion', 'cyboxVersion', 'mixboxVersion', 'maecVersion', 'stix2Version', 'pymispVersion', 'moduleStatus', 'yaraStatus', 'gpgErrors', 'proxyErrors', 'zmqErrors', 'stixOperational', 'stix', 'moduleErrors', 'moduleTypes', 'dbDiagnostics', 'dbSchemaDiagnostics', 'redisInfo', 'attachmentScan');
} else {
$view = [];
}
// check whether the files are writeable
$writeableDirs = $this->Server->writeableDirsDiagnostics($diagnostic_errors);
@ -1144,13 +1122,8 @@ class ServersController extends AppController
// check if the encoding is not set to utf8
$dbEncodingStatus = $this->Server->databaseEncodingDiagnostics($diagnostic_errors);
$viewVars = array(
'diagnostic_errors', 'tabs', 'tab', 'issues', 'finalSettings', 'writeableErrors', 'readableErrors', 'writeableDirs', 'writeableFiles', 'readableFiles', 'extensions', 'dbEncodingStatus'
);
$viewVars = array_merge($viewVars, $additionalViewVars);
foreach ($viewVars as $viewVar) {
$this->set($viewVar, ${$viewVar});
}
$view = array_merge($view, compact('diagnostic_errors', 'tabs', 'tab', 'issues', 'finalSettings', 'writeableErrors', 'readableErrors', 'writeableDirs', 'writeableFiles', 'readableFiles', 'extensions', 'dbEncodingStatus'));
$this->set($view);
$workerIssueCount = 4;
$worker_array = array();
@ -1429,8 +1402,8 @@ class ServersController extends AppController
$setting['value'] = $value;
}
$setting['setting'] = $setting['name'];
if (isset($setting['optionsSource']) && !empty($setting['optionsSource'])) {
$setting['options'] = $this->{'__load' . $setting['optionsSource']}();
if (isset($setting['optionsSource']) && is_callable($setting['optionsSource'])) {
$setting['options'] = $setting['optionsSource']();
}
$subGroup = explode('.', $setting['name']);
if ($subGroup[0] === 'Plugin') {

View File

@ -1208,7 +1208,9 @@ class Server extends AppModel
$setting['value'] = 0;
$setting['test'] = 'testLocalOrg';
$setting['type'] = 'numeric';
$setting['optionsSource'] = 'LocalOrgs';
$setting['optionsSource'] = function () {
return $this->loadLocalOrganisations();
};
} else {
$setting['test'] = 'testForEmpty';
$setting['type'] = 'string';
@ -1365,6 +1367,16 @@ class Server extends AppModel
return $options;
}
private function loadLocalOrganisations()
{
$localOrgs = $this->Organisation->find('list', array(
'conditions' => array('local' => 1),
'recursive' => -1,
'fields' => array('Organisation.id', 'Organisation.name')
));
return array_replace(array(0 => __('No organisation selected.')), $localOrgs);
}
public function testTagCollections($value)
{
$tag_collections = $this->loadTagCollections();
@ -3620,6 +3632,11 @@ class Server extends AppModel
return $validServers;
}
/**
* Check installed PHP extensions and their versions.
* @return array
* @throws JsonException
*/
public function extensionDiagnostics()
{
try {
@ -3637,10 +3654,11 @@ class Server extends AppModel
}
}
} catch (Exception $e) {
$this->logException('Could not load extensions from composer.json', $e, LOG_NOTICE);
$extensions = ['redis' => '', 'gd' => '', 'ssdeep' => '', 'zip' => '', 'intl' => '']; // Default extensions
}
$results = array();
$results = ['cli' => false];
foreach ($extensions as $extension => $reason) {
$results['extensions'][$extension] = [
'web_version' => phpversion($extension),
@ -3651,14 +3669,14 @@ class Server extends AppModel
'info' => $reason === true ? null : $reason,
];
}
if (!is_readable(APP . '/files/scripts/selftest.php')) {
$results['cli'] = false;
} else {
if (is_readable(APP . '/files/scripts/selftest.php')) {
$execResult = exec('php ' . APP . '/files/scripts/selftest.php ' . escapeshellarg(json_encode(array_keys($extensions))));
$execResult = $this->jsonDecode($execResult);
$results['cli']['phpversion'] = $execResult['phpversion'];
foreach ($execResult['extensions'] as $extension => $loaded) {
$results['extensions'][$extension]['cli_version'] = $loaded;
if (!empty($execResult)) {
$execResult = $this->jsonDecode($execResult);
$results['cli']['phpversion'] = $execResult['phpversion'];
foreach ($execResult['extensions'] as $extension => $loaded) {
$results['extensions'][$extension]['cli_version'] = $loaded;
}
}
}
@ -4343,7 +4361,9 @@ class Server extends AppModel
'errorMessage' => '',
'test' => 'testLanguage',
'type' => 'string',
'optionsSource' => 'AvailableLanguages',
'optionsSource' => function () {
return $this->loadAvailableLanguages();
},
'afterHook' => 'cleanCacheFiles'
),
'default_attribute_memory_coefficient' => array(
@ -4567,7 +4587,9 @@ class Server extends AppModel
'errorMessage' => '',
'test' => 'testLocalOrg',
'type' => 'numeric',
'optionsSource' => 'LocalOrgs',
'optionsSource' => function () {
return $this->loadLocalOrganisations();
},
),
'uuid' => array(
'level' => 0,
@ -4782,7 +4804,9 @@ class Server extends AppModel
'errorMessage' => '',
'test' => 'testTagCollections',
'type' => 'numeric',
'optionsSource' => 'TagCollections',
'optionsSource' => function () {
return $this->loadTagCollections();
}
),
'default_publish_alert' => array(
'level' => 0,
@ -6376,7 +6400,9 @@ class Server extends AppModel
'errorMessage' => '',
'test' => 'testLocalOrg',
'type' => 'numeric',
'optionsSource' => 'LocalOrgs',
'optionsSource' => function () {
return $this->loadLocalOrganisations();
},
),
'Sightings_range' => array(
'level' => 1,

View File

@ -72,7 +72,7 @@
<h3><?php echo __('Writeable Directories and files');?></h3>
<p><?php echo __('The following directories and files have to be writeable for MISP to function properly. Make sure that the apache user has write privileges for the directories below.');?></p>
<p><b><?php echo __('Directories');?></b></p>
<div style="background-color:#f7f7f9;width:400px;">
<div class="diagnostics-box">
<?php
foreach ($writeableDirs as $dir => $error) {
$colour = 'green';
@ -87,7 +87,7 @@
</div>
<br />
<p><b><?php echo __('Writeable Files');?></b></p>
<div style="background-color:#f7f7f9;width:400px;">
<div class="diagnostics-box">
<?php
foreach ($writeableFiles as $file => $error) {
$colour = 'green';
@ -101,7 +101,7 @@
?>
</div>
<p><b><?php echo __('Readable Files');?></b></p>
<div style="background-color:#f7f7f9;width:400px;">
<div class="diagnostics-box">
<?php
foreach ($readableFiles as $file => $error) {
$colour = 'green';
@ -250,7 +250,7 @@
)); ?>
</div>
<h3><?= __("Redis info") ?></h3>
<div style="background-color:#f7f7f9;width:400px;">
<div class="diagnostics-box">
<b><?= __('PHP extension version') ?>:</b> <?= $redisInfo['extensionVersion'] ?: ('<span class="red bold">' . __('Not installed.') . '</span>') ?><br>
<?php if ($redisInfo['connection']): ?>
<b><?= __('Redis version') ?>:</b> <?= $redisInfo['redis_version'] ?><br>
@ -264,7 +264,7 @@
</div>
<h3><?php echo __('Advanced attachment handler');?></h3>
<?php echo __('The advanced attachment tools are used by the add attachment functionality to extract additional data about the uploaded sample.');?>
<div style="background-color:#f7f7f9;width:400px;">
<div class="diagnostics-box">
<?php
if (empty($advanced_attachments)):
?>
@ -281,7 +281,7 @@
?>
</div>
<h3><?= __('Attachment scan module') ?></h3>
<div style="background-color:#f7f7f9;width:400px;">
<div class="diagnostics-box">
<?php if ($attachmentScan['status']): ?>
<b>Status:</b> <span class="green bold"><?= __('OK') ?></span><br>
<b>Software</b>: <?= implode(", ", $attachmentScan['software']) ?>
@ -300,7 +300,7 @@
<b>STIX2</b>: <?php echo $stix['stix2']['expected'];?><br />
<b>PyMISP</b>: <?php echo $stix['pymisp']['expected'];?><br />
<?php echo __('Other versions might work but are not tested / recommended.');?></p>
<div style="background-color:#f7f7f9;width:400px;">
<div class="diagnostics-box">
<?php
$colour = 'green';
$testReadError = false;
@ -341,7 +341,7 @@
</div>
<h3><?php echo __('Yara');?></h3>
<p><?php echo __('This tool tests whether plyara, the library used by the yara export tool is installed or not.');?></p>
<div style="background-color:#f7f7f9;width:400px;">
<div class="diagnostics-box">
<?php
$colour = 'green';
$message = __('OK');
@ -355,7 +355,7 @@
<h3><?php echo __('GnuPG');?></h3>
<p><?php echo __('This tool tests whether your GnuPG is set up correctly or not.');?></p>
<div style="background-color:#f7f7f9;width:400px;">
<div class="diagnostics-box">
<?php
$message = $gpgErrors[$gpgStatus['status']];
$color = $gpgStatus['status'] === 0 ? 'green' : 'red';
@ -367,7 +367,7 @@
</div>
<h3><?php echo __('ZeroMQ');?></h3>
<p><?php echo __('This tool tests whether the ZeroMQ extension is installed and functional.');?></p>
<div style="background-color:#f7f7f9;width:400px;">
<div class="diagnostics-box">
<?php
$colour = 'green';
$message = $zmqErrors[$zmqStatus];
@ -384,7 +384,7 @@
</div>
<h3><?php echo __('Proxy');?></h3>
<p><?php echo __('This tool tests whether your HTTP proxy settings are correct.');?></p>
<div style="background-color:#f7f7f9;width:400px;">
<div class="diagnostics-box">
<?php
$colour = 'green';
$message = $proxyErrors[$proxyStatus];
@ -399,7 +399,7 @@
<?php
foreach ($moduleTypes as $type):
?>
<div style="background-color:#f7f7f9;width:400px;">
<div class="diagnostics-box">
<?php
$colour = 'red';
if (isset($moduleErrors[$moduleStatus[$type]])) {
@ -418,7 +418,7 @@
?>
<h3><?php echo __('Session table');?></h3>
<p><?php echo __('This tool checks how large your database\'s session table is. <br />Sessions in CakePHP rely on PHP\'s garbage collection for clean-up and in certain distributions this can be disabled by default resulting in an ever growing cake session table. <br />If you are affected by this, just click the clean session table button below.');?></p>
<div style="background-color:#f7f7f9;width:400px;">
<div class="diagnostics-box">
<?php
$colour = 'green';
$message = $sessionErrors[$sessionStatus];
@ -460,7 +460,7 @@
?>
<h3><?php echo __('Orphaned attributes');?></h3>
<p><?php echo __('In some rare cases attributes can remain in the database after an event is deleted becoming orphaned attributes. This means that they do not belong to any event, which can cause issues with the correlation engine (known cases include event deletion directly in the database without cleaning up the attributes and situations involving a race condition with an event deletion happening before all attributes are synchronised over).');?></p>
<div style="background-color:#f7f7f9;width:400px;">
<div class="diagnostics-box">
<?php echo __('Orphaned attributes');?>…<span id="orphanedAttributeCount"><span style="color:orange;"><?php echo __('Run the test below');?></span></span>
</div><br />
<span class="btn btn-inverse" role="button" tabindex="0" aria-label="<?php echo __('Check for orphaned attribute');?>" title="<?php echo __('Check for orphaned attributes');?>" style="padding-top:1px;padding-bottom:1px;" onClick="checkOrphanedAttributes();"><?php echo __('Check for orphaned attributes');?></span><br /><br />
@ -474,7 +474,7 @@
<span class="btn btn-inverse" style="padding-top:1px;padding-bottom:1px;" onClick="location.href = '<?php echo $baseurl; ?>/pages/display/administration';"><?php echo __('Legacy Administrative Tools');?></span>
<h3><?php echo __('Verify bad link on attachments');?></h3>
<p><?php echo __('Verify each attachment referenced in database is accessible on filesystem.');?></p>
<div style="background-color:#f7f7f9;width:400px;">
<div class="diagnostics-box">
<?php echo __('Non existing attachments referenced in Database');?>…<span id="orphanedFileCount"><span style="color:orange;"><?php echo __('Run the test below');?></span></span>
</div><br>
<span class="btn btn-inverse" role="button" tabindex="0" aria-label="<?php echo __('Check bad link on attachments');?>" title="<?php echo __('Check bad link on attachments');?>" style="padding-top:1px;padding-bottom:1px;" onClick="checkAttachments();"><?php echo __('Check bad link on attachments');?></span>
@ -484,7 +484,7 @@
</div>
<script>
$(document).ready(function() {
$(function() {
updateSubModulesStatus();
$('#refreshSubmoduleStatus').click(function() { updateSubModulesStatus(); });
$('#updateAllJson').click(function() { updateAllJson(); });

View File

@ -2723,3 +2723,9 @@ th.rotate + th:not(.rotate) {
td.rotate + td:not(.rotate) {
padding-left: 30px;
}
.diagnostics-box {
background-color: #f7f7f9;
width: 400px;
padding: .3em 0.5em;
}