chg: [eventReport:markdownEditor] Fetch MISP elements with a different

request
pull/6412/head
mokaddem 2020-10-07 11:13:30 +02:00
parent dfc2434215
commit aafdeab9d6
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
6 changed files with 49 additions and 10 deletions

View File

@ -64,15 +64,23 @@ class EventReportsController extends AppController
if ($this->_isRest()) {
return $this->RestResponse->viewData($report, $this->response->type());
}
$proxyMISPElements = $this->EventReport->getProxyMISPElements($this->Auth->user(), $report['EventReport']['event_id']);
$this->set('ajax', $ajax);
$this->set('proxyMISPElements', $proxyMISPElements);
$this->set('id', $reportId);
$this->set('report', $report);
$this->injectDistributionLevelToViewContext();
$this->injectPermissionsToViewContext($this->Auth->user(), $report);
}
public function getProxyMISPElements($reportId)
{
if (!$this->_isRest()) {
throw new MethodNotAllowedException(__('This function can only be reached via the API.'));
}
$report = $this->EventReport->simpleFetchById($this->Auth->user(), $reportId);
$proxyMISPElements = $this->EventReport->getProxyMISPElements($this->Auth->user(), $report['EventReport']['event_id']);
return $this->RestResponse->viewData($proxyMISPElements, $this->response->type());
}
public function viewSummary($reportId)
{
$report = $this->EventReport->simpleFetchById($this->Auth->user(), $reportId);

View File

@ -408,7 +408,7 @@ class EventReport extends AppModel
}
/**
* getProxyMISPElements Extract MISP Elements from an event and make them accessible by their ID
* getProxyMISPElements Extract MISP Elements from an event and make them accessible by their UUID
*
* @param array $user
* @param int|string $eventid

View File

@ -1,6 +1,6 @@
<script>
'use strict';
var proxyMISPElements = <?= json_encode(is_array($proxyMISPElements) ? $proxyMISPElements : array($proxyMISPElements), JSON_HEX_TAG); ?>;
var proxyMISPElements = null
var eventid = '<?= !isset($eventid) ? '' : h($eventid) ?>'
var reportid = '<?= h($reportid) ?>'
var invalidMessage = '<?= __('invalid scope or id') ?>'

View File

@ -46,7 +46,6 @@
'variables' => [
'reportid' => $report['EventReport']['id'],
'eventid' => $report['EventReport']['event_id'],
'proxyMISPElements' => $proxyMISPElements,
]
],
'additionalMarkdownHelpModalElements' => [[

View File

@ -1,11 +1,11 @@
'use strict';
// Function called to setup custom MarkdownIt rendering and parsing rules
var markdownItCustomRules = markdownItSetupRules
var markdownItCustomPostInit = markdownItCustomPostInit
// Hint option passed to the CodeMirror constructor
var cmCustomHints = hintMISPElements
// Setup function called after the CodeMirror initialization
var cmCustomSetup = buildMISPElementHints
var cmCustomSetup = null
// Hook allowing to alter the raw text before returning the GFM version to the user to be downloaded
var markdownGFMSubstitution = replaceMISPElementByTheirValue
// Post rendering hook called after the markdown is displayed, allowing to register listener
@ -42,7 +42,6 @@ var renderingRules = {
}
var galaxyMatrixTimer, tagTimers = {};
var cache_matrix = {}, cache_tag = {};
proxyMISPElements['tag'] = []
/**
_____ _ __ __ _
@ -307,6 +306,11 @@ function renderHintElement(scope, element) {
| | | | (_| | | | < (_| | (_) \ V V /| | | |_| |_| |_
|_| |_|\__,_|_| |_|\_\__,_|\___/ \_/\_/ |_| |_|_____|\__|
*/
function markdownItCustomPostInit() {
markdownItSetupRules()
fetchProxyMISPElements()
}
function markdownItSetupRules() {
md.renderer.rules.MISPElement = MISPElementRenderer;
md.renderer.rules.MISPPictureElement = MISPPictureElementRenderer;
@ -773,6 +777,34 @@ function markdownItToggleCustomRule(rulename, event) {
| |__| | |_| | \__ \
\____/ \__|_|_|___/
*/
function fetchProxyMISPElements() {
var url = baseurl + '/eventReports/getProxyMISPElements/' + reportid
var errorMessage = 'Could not fetch MISP Elements'
$.ajax({
dataType: "json",
url: url,
data: {},
beforeSend: function() {
toggleMarkdownEditorLoading(true, 'Loading MISP Elements')
},
success: function(data) {
if (data) {
proxyMISPElements = data
proxyMISPElements['tag'] = []
buildMISPElementHints()
} else {
showMessage('fail', errorMessage);
}
},
error: function (data, textStatus, errorThrown) {
showMessage('fail', errorMessage + '. ' + textStatus + ": " + errorThrown);
},
complete: function() {
toggleMarkdownEditorLoading(false)
}
})
}
function getElementFromDom(node) {
var scope = $(node).data('scope')
var elementID = $(node).data('elementid')

View File

@ -122,8 +122,8 @@ function initMarkdownIt() {
};
md.renderer.rules.paragraph_open = injectLineNumbers;
md.renderer.rules.heading_open = injectLineNumbers;
if (typeof markdownItCustomRules === 'function') {
markdownItCustomRules()
if (typeof markdownItCustomPostInit === 'function') {
markdownItCustomPostInit()
}
}