From f0a1a07592c0528ba37c772decf16deada08c490 Mon Sep 17 00:00:00 2001 From: mokaddem Date: Wed, 25 Nov 2020 08:19:23 +0100 Subject: [PATCH 001/437] chg: [galaxyElement] Added draft of element flattening and unflattening --- app/Controller/GalaxyElementsController.php | 11 +++++ app/Lib/Tools/ArrayFlattenerTool.php | 55 +++++++++++++++++++++ app/View/GalaxyElements/ajax/index.ctp | 2 + 3 files changed, 68 insertions(+) create mode 100644 app/Lib/Tools/ArrayFlattenerTool.php diff --git a/app/Controller/GalaxyElementsController.php b/app/Controller/GalaxyElementsController.php index 68c3759c6..e60003aae 100644 --- a/app/Controller/GalaxyElementsController.php +++ b/app/Controller/GalaxyElementsController.php @@ -26,4 +26,15 @@ class GalaxyElementsController extends AppController $this->render('ajax/index'); } } + + public function indexTree($clusterId) + { + $elements = $this->GalaxyElement->fetchElements($this->Auth->user(), $clusterId); + $keyedValue = []; + foreach ($elements as $i => $element) { + $keyedValue[$element['key']][] = $element['value']; + } + $expanded = Hash::expand($keyedValue); + return $this->RestResponse->viewData($expanded); + } } diff --git a/app/Lib/Tools/ArrayFlattenerTool.php b/app/Lib/Tools/ArrayFlattenerTool.php new file mode 100644 index 000000000..a7b321459 --- /dev/null +++ b/app/Lib/Tools/ArrayFlattenerTool.php @@ -0,0 +1,55 @@ +array_flatten($array); + } + + public function unflatten($array) + { + return $this->array_unflatten($array); + } + + /** + * array_flatten Perform a DFS while flattening the array + */ + private function array_flatten($toFlatten, $prefix='', $separator='.') + { + $result = array(); + foreach ($toFlatten as $k => $v) + { + $new_key = $prefix . (empty($prefix) ? '' : '.') . $k; + if (is_array($v)) { + $result = array_merge($result, $this->array_flatten($v, $new_key, $separator)); + } else { + $result[$new_key] = $v; + } + } + return $result; + } + + private function array_unflatten($toUnflatten, $separator='.') + { + $result = array(); + foreach ($toUnflatten as $k => $v) + { + $decomposedKey = explode($separator, $k); + $result = $this->buildMultiDimensionalArrayFromKeypath($decomposedKey, $result, $v); + } + return $result; + } + + private function buildMultiDimensionalArrayFromKeypath($keypath, $result, $value) + { + if (empty($keypath)) { + $result = $value; + } else { + foreach ($keypath as $key) { + array_shift($keypath); + $result[$key] = $this->buildMultiDimensionalArrayFromKeypath($keypath, $result, $value); + } + } + return $result; + } +} diff --git a/app/View/GalaxyElements/ajax/index.ctp b/app/View/GalaxyElements/ajax/index.ctp index de3307d62..532052ecb 100755 --- a/app/View/GalaxyElements/ajax/index.ctp +++ b/app/View/GalaxyElements/ajax/index.ctp @@ -1,4 +1,6 @@ - diff --git a/app/View/Events/index.ctp b/app/View/Events/index.ctp index cacdfb804..f54efefbe 100644 --- a/app/View/Events/index.ctp +++ b/app/View/Events/index.ctp @@ -127,6 +127,5 @@ echo $this->Html->css('distribution-graph'); echo $this->Html->script('network-distribution-graph'); ?> - element('/genericElements/SideMenu/side_menu', array('menuList' => 'event-collection', 'menuItem' => 'index')); diff --git a/app/View/Events/view.ctp b/app/View/Events/view.ctp index f604f344d..06be58a8c 100644 --- a/app/View/Events/view.ctp +++ b/app/View/Events/view.ctp @@ -561,4 +561,3 @@ $(function () { }); }); - diff --git a/app/View/Layouts/default.ctp b/app/View/Layouts/default.ctp index 3b79002e4..572ff527f 100644 --- a/app/View/Layouts/default.ctp +++ b/app/View/Layouts/default.ctp @@ -33,7 +33,7 @@ )); ?> - +
@@ -71,7 +71,8 @@ 'bootstrap-datepicker', 'bootstrap-colorpicker', 'misp', - 'keyboard-shortcuts' + 'keyboard-shortcuts-definition', + 'keyboard-shortcuts', ) )); echo $this->element('footer'); diff --git a/app/webroot/js/keyboard-shortcuts-definition.js b/app/webroot/js/keyboard-shortcuts-definition.js new file mode 100644 index 000000000..bd6acbe3f --- /dev/null +++ b/app/webroot/js/keyboard-shortcuts-definition.js @@ -0,0 +1,61 @@ +function getShortcutsDefinition() { + var shortcuts = [ + { + "key": "l", + "description": "Go to event list", + "action": function () { + document.location.href = baseurl + '/events/index'; + } + }, + { + "key": "e", + "description": "Go to add event page", + "action": function () { + document.location.href = baseurl + '/events/add'; + } + } + ]; + + var $body = $(document.body); + if ($body.data('controller') === 'events' && $body.data('action') === 'view') { + shortcuts.push({ + "key": "t", + "description": "Open the tag selection modal", + "action": function () { + $('.addTagButton').first().click(); + } + }); + shortcuts.push({ + "key": "f", + "description": "Open the freetext import modal", + "action": function () { + $('#freetext-button').click(); + } + }); + shortcuts.push({ + "key": "a", + "description": "Add an attribute", + "action": function () { + $('#create-button').click(); + } + }); + shortcuts.push({ + "key": "s", + "description": "Focus the filter attribute bar", + "action": function () { + $('#quickFilterField').focus(); + } + }); + } + + if ($body.data('controller') === 'events' && $body.data('action') === 'index') { + shortcuts.push({ + "key": "s", + "description": "Focus the filter events bar", + "action": function () { + $('#quickFilterField').focus(); + } + }); + } + return shortcuts; +} diff --git a/app/webroot/js/keyboard-shortcuts.js b/app/webroot/js/keyboard-shortcuts.js index 1895bf0b0..0375a15ec 100644 --- a/app/webroot/js/keyboard-shortcuts.js +++ b/app/webroot/js/keyboard-shortcuts.js @@ -21,13 +21,7 @@ let keyboardShortcutsManager = { init() { /* Codacy comment to notify that baseurl is a read-only global variable. */ /* global baseurl */ - let shortcutURIs = []; - for(let keyboardShortcutElement of $('.keyboardShortcutsConfig')) { - shortcutURIs.push(keyboardShortcutElement.value); - this.ajaxGet(baseurl + keyboardShortcutElement.value).then((response) => { - this.mapKeyboardShortcuts(JSON.parse(response)); - }); - } + this.mapKeyboardShortcuts(getShortcutsDefinition()); this.setKeyboardListener(); }, @@ -61,7 +55,7 @@ let keyboardShortcutsManager = { * @param {} config The shortcut JSON list: [{key: string, description: string, action: string(eval-able JS code)}] */ mapKeyboardShortcuts(config) { - for(let shortcut of config.shortcuts) { + for(let shortcut of config) { this.shortcutKeys.set(shortcut.key, shortcut); } this.addShortcutListToHTML(); @@ -76,39 +70,14 @@ let keyboardShortcutsManager = { window.onkeyup = (keyboardEvent) => { if(this.shortcutKeys.has(keyboardEvent.key)) { let activeElement = document.activeElement.tagName; - if( !this.ESCAPED_TAG_NAMES.includes(activeElement)) { - eval(this.shortcutKeys.get(keyboardEvent.key).action); + if(!this.ESCAPED_TAG_NAMES.includes(activeElement)) { + this.shortcutKeys.get(keyboardEvent.key).action(); } } else if(this.NAVIGATION_KEYS.includes(keyboardEvent.key)) { window.dispatchEvent(new CustomEvent(this.EVENTS[keyboardEvent.key], {detail: keyboardEvent})); } } }, - - /** - * Queries the given URL with a GET request and returns a Promise - * that resolves when the response arrives. - * @param string url The URL to fetch. - */ - ajaxGet(url) { - return new Promise(function(resolve, reject) { - let req = new XMLHttpRequest(); - req.open("GET", url); - req.onload = function() { - if (req.status === 200) { - resolve(req.response); - } else { - reject(new Error(req.statusText)); - } - }; - - req.onerror = function() { - reject(new Error("Network error")); - }; - - req.send(); - }); - } } // Inits the keyboard shortcut manager's main routine. diff --git a/app/webroot/shortcuts/event_index.json b/app/webroot/shortcuts/event_index.json deleted file mode 100644 index 15e6fa1cb..000000000 --- a/app/webroot/shortcuts/event_index.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "shortcuts": [ - { - "key": "s", - "description": "Focus the filter events bar", - "action": "$('#quickFilterField').focus()" - } - ] -} \ No newline at end of file diff --git a/app/webroot/shortcuts/event_view.json b/app/webroot/shortcuts/event_view.json deleted file mode 100644 index c411c8802..000000000 --- a/app/webroot/shortcuts/event_view.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "shortcuts": [ - { - "key": "t", - "description": "Open the tag selection modal", - "action": "$('.addTagButton').first().click()" - }, - { - "key": "f", - "description": "Open the freetext import modal", - "action": "$('#freetext-button').click()" - }, - { - "key": "a", - "description": "Add an attribute", - "action": "$('#create-button').click()" - }, - { - "key": "s", - "description": "Focus the filter attribute bar", - "action": "$('#quickFilterField').focus()" - } - ] -} diff --git a/app/webroot/shortcuts/global_menu.json b/app/webroot/shortcuts/global_menu.json deleted file mode 100644 index 6ee3ca893..000000000 --- a/app/webroot/shortcuts/global_menu.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "shortcuts": [ - { - "key": "l", - "description": "Go to event list", - "action": "document.location.href = baseurl + '/events/index'" - }, - { - "key": "e", - "description": "Go to add event page", - "action": "document.location.href = baseurl + '/events/add'" - } - ] -} - From d16172ca61a010d2e2b6995be53a2affe8f59110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Tue, 2 Mar 2021 12:42:37 +0100 Subject: [PATCH 259/437] chg: Bump PyMISP --- PyMISP | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyMISP b/PyMISP index 2ceb38c74..4a2367ec9 160000 --- a/PyMISP +++ b/PyMISP @@ -1 +1 @@ -Subproject commit 2ceb38c741f9432432114998d0c0f8fa36686083 +Subproject commit 4a2367ec965d70d84a0091ea3a6978916a7df25a From 66e371a19c36c2d1e860cc3943153b5922357453 Mon Sep 17 00:00:00 2001 From: iglocska Date: Tue, 2 Mar 2021 13:03:54 +0100 Subject: [PATCH 260/437] fix: [comments] updated for two recent changes in the code --- app/Model/Event.php | 1 + app/Model/SharingGroupServer.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Model/Event.php b/app/Model/Event.php index eae81f0a7..ed9fbcead 100755 --- a/app/Model/Event.php +++ b/app/Model/Event.php @@ -2190,6 +2190,7 @@ class Event extends AppModel foreach ($results as $eventKey => &$event) { /* + // REMOVING THIS FOR NOW - users should see data they own, even if they're not in the sharing group. if ($event['Event']['distribution'] == 4 && !in_array($event['Event']['sharing_group_id'], $sgids)) { $this->Log = ClassRegistry::init('Log'); $this->Log->create(); diff --git a/app/Model/SharingGroupServer.php b/app/Model/SharingGroupServer.php index 18a7f334f..6a1e56e51 100644 --- a/app/Model/SharingGroupServer.php +++ b/app/Model/SharingGroupServer.php @@ -94,7 +94,7 @@ class SharingGroupServer extends AppModel return $sgs; } - // pass a sharing group ID, returns true if it has an attached server object with "all_orgs" ticked + // pass a sharing group ID, returns true if it has the local server object attached with "all_orgs" set public function checkIfAuthorised($id) { $sg = $this->find('first', array( From 62537961f0f1caafe171d977b5af2643137726e4 Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Tue, 2 Mar 2021 14:44:41 +0100 Subject: [PATCH 261/437] fix: [internal] Undefined index when importing from module --- app/Controller/AppController.php | 4 ++-- app/Controller/EventsController.php | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Controller/AppController.php b/app/Controller/AppController.php index c2fa205d3..63c388cb1 100755 --- a/app/Controller/AppController.php +++ b/app/Controller/AppController.php @@ -1453,10 +1453,10 @@ class AppController extends Controller if ($this->userRole['perm_site_admin']) { return true; } - if ($this->userRole['perm_modify_org'] && $event['Event']['orgc_id'] == $this->Auth->user('org_id')) { + if ($this->userRole['perm_modify_org'] && $event['Event']['orgc_id'] == $this->Auth->user()['org_id']) { return true; } - if ($this->userRole['perm_modify'] && $event['Event']['user_id'] == $this->Auth->user('id')) { + if ($this->userRole['perm_modify'] && $event['Event']['user_id'] == $this->Auth->user()['id']) { return true; } return false; diff --git a/app/Controller/EventsController.php b/app/Controller/EventsController.php index 3a64d2f49..829853d94 100644 --- a/app/Controller/EventsController.php +++ b/app/Controller/EventsController.php @@ -4938,6 +4938,7 @@ class EventsController extends AppController if (!$event) { throw new NotFoundException(__('Invalid event.')); } + $mayModify = $this->__canModifyEvent($event); $eventId = $event['Event']['id']; $this->loadModel('Module'); @@ -5108,7 +5109,7 @@ class EventsController extends AppController $this->set('module', $module); $this->set('eventId', $eventId); $this->set('event', $event); - $this->set('mayModify', $this->__canModifyEvent($event)); + $this->set('mayModify', $mayModify); } public function exportModule($module, $id, $standard = false) From c8533ead788ad08aa5995c1bb84eaeb31e3d5198 Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Tue, 2 Mar 2021 18:04:49 +0100 Subject: [PATCH 262/437] chg: [internal] Cleanup code that is resposible for fetching server setting --- app/Model/Server.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/app/Model/Server.php b/app/Model/Server.php index f9d07cc92..554addd56 100644 --- a/app/Model/Server.php +++ b/app/Model/Server.php @@ -4,6 +4,7 @@ App::uses('GpgTool', 'Tools'); /** * @property-read array $serverSettings + * @property Organisation $Organisation */ class Server extends AppModel { @@ -1235,16 +1236,23 @@ class Server extends AppModel return true; } + /** + * @return array + */ public function getCurrentServerSettings() { - $this->Module = ClassRegistry::init('Module'); $serverSettings = $this->serverSettings; $moduleTypes = array('Enrichment', 'Import', 'Export', 'Cortex'); $serverSettings = $this->readModuleSettings($serverSettings, $moduleTypes); return $serverSettings; } - private function readModuleSettings($serverSettings, $moduleTypes) + /** + * @param array $serverSettings + * @param array $moduleTypes + * @return array + */ + private function readModuleSettings(array $serverSettings, array $moduleTypes) { $this->Module = ClassRegistry::init('Module'); foreach ($moduleTypes as $moduleType) { @@ -1253,12 +1261,12 @@ class Server extends AppModel foreach ($results as $module => $data) { foreach ($data as $result) { $setting = array('level' => 1, 'errorMessage' => ''); - if ($result['type'] == 'boolean') { + if ($result['type'] === 'boolean') { $setting['test'] = 'testBool'; $setting['type'] = 'boolean'; $setting['description'] = __('Enable or disable the %s module.', $module); $setting['value'] = false; - } elseif ($result['type'] == 'orgs') { + } elseif ($result['type'] === 'orgs') { $setting['description'] = __('Restrict the %s module to the given organisation.', $module); $setting['value'] = 0; $setting['test'] = 'testLocalOrg'; @@ -1335,15 +1343,11 @@ class Server extends AppModel public function serverSettingsRead($unsorted = false) { - $this->Module = ClassRegistry::init('Module'); $serverSettings = $this->getCurrentServerSettings(); $currentSettings = Configure::read(); - if (Configure::read('Plugin.Enrichment_services_enable')) { - $this->readModuleSettings($serverSettings, array('Enrichment')); - } $finalSettingsUnsorted = $this->__serverSettingsRead($serverSettings, $currentSettings); foreach ($finalSettingsUnsorted as $key => $temp) { - if (in_array($temp['tab'], array_keys($this->__settingTabMergeRules))) { + if (isset($this->__settingTabMergeRules[$temp['tab']])) { $finalSettingsUnsorted[$key]['tab'] = $this->__settingTabMergeRules[$temp['tab']]; } } From 7431beefa12bff1807dee5351dae9e6586e2c5a9 Mon Sep 17 00:00:00 2001 From: Jeroen Pinoy Date: Tue, 2 Mar 2021 22:03:05 +0000 Subject: [PATCH 263/437] chg: [UI] fix keyboard shortcut manager popup triangle --- app/View/Elements/footer.ctp | 2 +- app/webroot/js/keyboard-shortcuts.js | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/View/Elements/footer.ctp b/app/View/Elements/footer.ctp index 387c8d56f..dacd6c010 100644 --- a/app/View/Elements/footer.ctp +++ b/app/View/Elements/footer.ctp @@ -1,5 +1,5 @@