From 84d100e9821e935d8a6cc3b4563ca7b40ae5ed8a Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Fri, 20 Sep 2019 22:15:15 +0200 Subject: [PATCH 1/7] new: [internal] Redis diagnostic --- app/Controller/ServersController.php | 4 +- app/Model/AppModel.php | 37 ++++++++++++++++--- app/Model/Server.php | 17 +++++++++ .../Elements/healthElements/diagnostics.ctp | 13 +++++++ 4 files changed, 64 insertions(+), 7 deletions(-) diff --git a/app/Controller/ServersController.php b/app/Controller/ServersController.php index 2ffc0892d..0c2c37127 100644 --- a/app/Controller/ServersController.php +++ b/app/Controller/ServersController.php @@ -1053,6 +1053,8 @@ class ServersController extends AppController // get the DB diagnostics $dbDiagnostics = $this->Server->dbSpaceUsage(); + $redisInfo = $this->Server->redisInfo(); + $moduleTypes = array('Enrichment', 'Import', 'Export', 'Cortex'); foreach ($moduleTypes as $type) { $moduleStatus[$type] = $this->Server->moduleDiagnostics($diagnostic_errors, $type); @@ -1063,7 +1065,7 @@ class ServersController extends AppController $sessionStatus = $this->Server->sessionDiagnostics($diagnostic_errors, $sessionCount); $this->set('sessionCount', $sessionCount); - $additionalViewVars = array('gpgStatus', 'sessionErrors', 'proxyStatus', 'sessionStatus', 'zmqStatus', 'stixVersion', 'cyboxVersion', 'mixboxVersion', 'maecVersion', 'stix2Version', 'pymispVersion', 'moduleStatus', 'yaraStatus', 'gpgErrors', 'proxyErrors', 'zmqErrors', 'stixOperational', 'stix', 'moduleErrors', 'moduleTypes', 'dbDiagnostics'); + $additionalViewVars = array('gpgStatus', 'sessionErrors', 'proxyStatus', 'sessionStatus', 'zmqStatus', 'stixVersion', 'cyboxVersion', 'mixboxVersion', 'maecVersion', 'stix2Version', 'pymispVersion', 'moduleStatus', 'yaraStatus', 'gpgErrors', 'proxyErrors', 'zmqErrors', 'stixOperational', 'stix', 'moduleErrors', 'moduleTypes', 'dbDiagnostics', 'redisInfo'); } // check whether the files are writeable $writeableDirs = $this->Server->writeableDirsDiagnostics($diagnostic_errors); diff --git a/app/Model/AppModel.php b/app/Model/AppModel.php index 107184f46..1c3955791 100644 --- a/app/Model/AppModel.php +++ b/app/Model/AppModel.php @@ -36,7 +36,7 @@ class AppModel extends Model public $inserted_ids = array(); - private $__redisConnection = false; + private $__redisConnection = null; private $__profiler = array(); @@ -1824,14 +1824,19 @@ class AppModel extends Model return preg_match('@^([a-z0-9_.]+[a-z0-9_.\- ]*[a-z0-9_.\-]|[a-z0-9_.])+$@i', $filename); } - public function setupRedis() + /** + * Similar method as `setupRedis`, but this method throw exception if Redis cannot be reached. + * @return Redis + * @throws Exception + */ + public function setupRedisWithException() { if ($this->__redisConnection) { return $this->__redisConnection; } if (!class_exists('Redis')) { - return false; + throw new Exception("Class Redis doesn't exists."); } $host = Configure::read('MISP.redis_host') ?: '127.0.0.1'; @@ -1841,16 +1846,36 @@ class AppModel extends Model $redis = new Redis(); if (!$redis->connect($host, $port)) { - return false; + throw new Exception("Could not connect to Redis: {$redis->getLastError()}"); } if (!empty($pass)) { - $redis->auth($pass); + if (!$redis->auth($pass)) { + throw new Exception("Could not authenticate to Redis: {$redis->getLastError()}"); + } } - $redis->select($database); + if (!$redis->select($database)) { + throw new Exception("Could not select Redis database $database: {$redis->getLastError()}"); + } + $this->__redisConnection = $redis; return $redis; } + /** + * Method for backward compatibility. + * @deprecated + * @see AppModel::setupRedisWithException + * @return bool|Redis + */ + public function setupRedis() + { + try { + return $this->setupRedisWithException(); + } catch (Exception $e) { + return false; + } + } + public function getKafkaPubTool() { if (!$this->loadedKafkaPubTool) { diff --git a/app/Model/Server.php b/app/Model/Server.php index 2623da770..7566f2430 100644 --- a/app/Model/Server.php +++ b/app/Model/Server.php @@ -4233,7 +4233,24 @@ class Server extends AppModel } return $result; } + } + public function redisInfo() + { + $output = array( + 'extensionVersion' => phpversion('redis'), + 'connection' => false, + ); + + try { + $redis = $this->setupRedisWithException(); + $output['connection'] = true; + $output = array_merge($output, $redis->info()); + } catch (Exception $e) { + $output['connection_error'] = $e->getMessage(); + } + + return $output; } public function writeableDirsDiagnostics(&$diagnostic_errors) diff --git a/app/View/Elements/healthElements/diagnostics.ctp b/app/View/Elements/healthElements/diagnostics.ctp index bbfca50d9..297361916 100644 --- a/app/View/Elements/healthElements/diagnostics.ctp +++ b/app/View/Elements/healthElements/diagnostics.ctp @@ -225,6 +225,19 @@ )); echo ''; ?> +

+
+ : ' . __('Not installed.') . '') ?>
+ + :
+ :
+ : B
+ : B
+ : B + + Redis is not available. + +

From 2b28d0c39e3f534798c79fc3fdac2872ee00b1a1 Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Mon, 23 Sep 2019 09:38:15 +0200 Subject: [PATCH 2/7] fix: [UI] GnuPG diagnostic message --- app/Controller/ServersController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Controller/ServersController.php b/app/Controller/ServersController.php index 2ffc0892d..a52f90010 100644 --- a/app/Controller/ServersController.php +++ b/app/Controller/ServersController.php @@ -907,7 +907,7 @@ class ServersController extends AppController ); $writeableErrors = array(0 => __('OK'), 1 => __('not found'), 2 => __('is not writeable')); $readableErrors = array(0 => __('OK'), 1 => __('not readable')); - $gpgErrors = array(0 => __('OK'), 1 => __('FAIL: settings not set'), 2 => __('FAIL: Failed to load GnuPG'), 3 => __('FAIL: Issues with the key/passphrase'), 4 => __('FAIL: encrypt failed')); + $gpgErrors = array(0 => __('OK'), 1 => __('FAIL: settings not set'), 2 => __('FAIL: Failed to load GnuPG'), 3 => __('FAIL: Issues with the key/passphrase'), 4 => __('FAIL: sign failed')); $proxyErrors = array(0 => __('OK'), 1 => __('not configured (so not tested)'), 2 => __('Getting URL via proxy failed')); $zmqErrors = array(0 => __('OK'), 1 => __('not enabled (so not tested)'), 2 => __('Python ZeroMQ library not installed correctly.'), 3 => __('ZeroMQ script not running.')); $stixOperational = array(0 => __('Some of the libraries related to STIX are not installed. Make sure that all libraries listed below are correctly installed.'), 1 => __('OK')); From e8cede8d097f6d84217d6559dca26bdd0db49657 Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Wed, 25 Sep 2019 17:02:46 +0200 Subject: [PATCH 3/7] fix: [UI] Notices margin --- app/webroot/css/main.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/webroot/css/main.css b/app/webroot/css/main.css index 97b0b365a..caf510376 100644 --- a/app/webroot/css/main.css +++ b/app/webroot/css/main.css @@ -2390,3 +2390,7 @@ table tr:hover .down-expand-button { .large-left-margin { margin-left:8px; } + +#notice_message { + margin: 10px; +} From 96ba73e50f219dc2e00d5b0db2d04508417aaf56 Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Wed, 25 Sep 2019 19:34:20 +0200 Subject: [PATCH 4/7] fix: [UI] MISP logo is in center at login page --- app/View/Users/login.ctp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/View/Users/login.ctp b/app/View/Users/login.ctp index 294d7b1f7..7007d6544 100644 --- a/app/View/Users/login.ctp +++ b/app/View/Users/login.ctp @@ -2,12 +2,12 @@ Session->flash('auth'); ?> - +
-
Html->image('custom/' . h(Configure::read('MISP.welcome_logo')), array('alt' => __('Logo'), 'onerror' => "this.style.display='none';")); ?> +

-
+
@@ -34,7 +34,7 @@ endif; echo $this->Form->create('User'); ?> - + Form->input('email', array('autocomplete' => 'off', 'autofocus')); echo $this->Form->input('password', array('autocomplete' => 'off')); From bd9d65a2a1def6e46c6abb4d17f88edc717fc848 Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Fri, 27 Sep 2019 14:18:35 +0200 Subject: [PATCH 5/7] fix: [shell] Update updateWarningLists from CLI --- app/Console/Command/AdminShell.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/Console/Command/AdminShell.php b/app/Console/Command/AdminShell.php index 66743fb89..1974ea246 100644 --- a/app/Console/Command/AdminShell.php +++ b/app/Console/Command/AdminShell.php @@ -159,13 +159,12 @@ class AdminShell extends AppShell } } - public function updateWarningLists() { - $result = $this->Galaxy->update(); - if ($result) { - echo 'Warning lists updated' . PHP_EOL; - } else { - echo 'Could not update warning lists' . PHP_EOL; - } + public function updateWarningLists() + { + $result = $this->Warninglist->update(); + $success = count($result['success']); + $fails = count($result['fails']); + echo "$success warninglists updated, $fails fails" . PHP_EOL; } public function updateNoticeLists() { From 8e947f182b33b967c2b653fd06bc932369084d93 Mon Sep 17 00:00:00 2001 From: StefanKelm Date: Fri, 27 Sep 2019 15:39:10 +0200 Subject: [PATCH 6/7] Update global_menu.ctp Align menu with other entries --- app/View/Elements/global_menu.ctp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/View/Elements/global_menu.ctp b/app/View/Elements/global_menu.ctp index 831c18711..cfef2b6c1 100755 --- a/app/View/Elements/global_menu.ctp +++ b/app/View/Elements/global_menu.ctp @@ -188,7 +188,7 @@ 'requirement' => $isAdmin ), array( - 'text' => __('Decaying Models'), + 'text' => __('List Decaying Models'), 'url' => '/decayingModel/index', ), array( From c4f9afe27d4237eebab2167f998ba9a30f5c0137 Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Fri, 27 Sep 2019 17:57:38 +0200 Subject: [PATCH 7/7] fix: [UI] Remove duplicate condition in footer.ctp --- app/View/Elements/footer.ctp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/View/Elements/footer.ctp b/app/View/Elements/footer.ctp index b6e5a5c70..c5cf3ecbb 100644 --- a/app/View/Elements/footer.ctp +++ b/app/View/Elements/footer.ctp @@ -32,7 +32,7 @@
Html->image('custom/' . h(Configure::read('MISP.footer_logo')), array('alt' => 'Footer Logo', 'onerror' => "this.style.display='none';", 'style' => 'height:24px')); + echo $this->Html->image('custom/' . h(Configure::read('MISP.footer_logo')), array('alt' => 'Footer Logo', 'onerror' => "this.style.display='none';", 'style' => 'height:24px')); } ?>