2020-09-14 08:33:59 +02:00
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
// Function called to setup custom MarkdownIt rendering and parsing rules
|
2020-10-07 11:13:30 +02:00
|
|
|
|
var markdownItCustomPostInit = markdownItCustomPostInit
|
2020-09-14 08:33:59 +02:00
|
|
|
|
// Hint option passed to the CodeMirror constructor
|
|
|
|
|
var cmCustomHints = hintMISPElements
|
|
|
|
|
// Setup function called after the CodeMirror initialization
|
2020-10-07 11:13:30 +02:00
|
|
|
|
var cmCustomSetup = null
|
2020-09-14 08:33:59 +02:00
|
|
|
|
// 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
|
|
|
|
|
var markdownCustomPostRenderingListener = setupMISPElementMarkdownListeners
|
|
|
|
|
// Post rendering hook called after the markdown is display, allowing to perform any actions on the rendered markdown
|
|
|
|
|
var markdownCustomPostRenderingActions = attachRemoteMISPElements
|
|
|
|
|
// CodeMirror replacement/insertion actions that can be executed on the editor's text
|
|
|
|
|
var customReplacementActions = MISPElementReplacementActions
|
|
|
|
|
// Called after CodeMirror initialization to insert custom top bar buttons
|
|
|
|
|
var insertCustomToolbarButtons = insertMISPElementToolbarButtons
|
|
|
|
|
|
|
|
|
|
// Key of the model used by the form when saving
|
|
|
|
|
var modelNameForSave = 'EventReport';
|
|
|
|
|
// Key of the field used by the form when saving
|
|
|
|
|
var markdownModelFieldNameForSave = 'content';
|
|
|
|
|
|
2020-10-05 11:21:51 +02:00
|
|
|
|
var dotTemplateAttribute = doT.template("<span class=\"misp-element-wrapper attribute\" data-scope=\"{{=it.scope}}\" data-elementid=\"{{=it.elementid}}\"><span class=\"bold\"><span class=\"attr-type\"><span>{{=it.type}}</span></span><span class=\"blue\"><span class=\"attr-value\"><span>{{=it.value}}</span></span></span></span></span>");
|
|
|
|
|
var dotTemplateAttributePicture = doT.template("<div class=\"misp-picture-wrapper attributePicture\"><img data-scope=\"{{=it.scope}}\" data-elementid=\"{{=it.elementid}}\" href=\"#\" src=\"{{=it.src}}\" alt=\"{{=it.alt}}\" title=\"\"/></div>");
|
2020-09-29 12:16:50 +02:00
|
|
|
|
var dotTemplateGalaxyMatrix = doT.template("<div class=\"misp-picture-wrapper embeddedGalaxyMatrix\" data-scope=\"{{=it.scope}}\" data-elementid=\"{{=it.elementid}}\" data-eventid=\"{{=it.eventid}}\"></div>");
|
2020-10-05 11:21:51 +02:00
|
|
|
|
var dotTemplateTag = doT.template("<span class=\"tag misp-tag-wrapper embeddedTag\" data-scope=\"{{=it.scope}}\" data-elementid=\"{{!it.elementid}}\" data-eventid=\"{{=it.eventid}}\">{{=it.elementid}}</span>");
|
|
|
|
|
var dotTemplateObject = doT.template("<span class=\"misp-element-wrapper object\" data-scope=\"{{=it.scope}}\" data-elementid=\"{{=it.elementid}}\"><span class=\"bold\"><span class=\"obj-type\"><span>{{=it.type}}</span></span><span class=\"obj-value\"><span>{{=it.value}}</span></span></span></span>");
|
2020-10-05 14:07:51 +02:00
|
|
|
|
var dotTemplateObjectAttribute = doT.template("<span class=\"misp-element-wrapper object\" data-scope=\"{{=it.scope}}\" data-elementid=\"{{=it.elementid}}\"><span class=\"bold\"><span class=\"obj-type\"><span class=\"object-name\">{{=it.objectname}}</span>↦ <span class=\"object-attribute-type\">{{=it.type}}</span></span><span class=\"obj-value\"><span>{{=it.value}}</span></span></span></span>");
|
2020-09-14 08:33:59 +02:00
|
|
|
|
var dotTemplateInvalid = doT.template("<span class=\"misp-element-wrapper invalid\"><span class=\"bold red\">{{=it.scope}}<span class=\"blue\"> ({{=it.id}})</span></span></span>");
|
2020-10-01 16:55:17 +02:00
|
|
|
|
var dotCloseButtonTemplate = doT.template('<button type="button" class="close" style="margin-left: 5px;" data-scope=\"{{=it.scope}}\" data-elementid=\"{{!it.elementID}}\" onclick="closeThePopover(this)">×</button>');
|
2020-10-06 10:04:13 +02:00
|
|
|
|
var dotTemplateRenderingDisabled = doT.template("<span class=\"misp-element-wrapper attribute\" data-scope=\"{{=it.scope}}\" data-elementid=\"{{!it.elementid}}\" data-eventid=\"{{=it.eventid}}\">{{=it.value}}</span>");
|
|
|
|
|
|
|
|
|
|
var renderingRules = {
|
|
|
|
|
'attribute': true,
|
|
|
|
|
'attribute-picture': true,
|
|
|
|
|
'object': true,
|
|
|
|
|
'object-attribute': true,
|
|
|
|
|
'tag': true,
|
|
|
|
|
'galaxymatrix': true,
|
|
|
|
|
}
|
2020-10-01 16:55:17 +02:00
|
|
|
|
var galaxyMatrixTimer, tagTimers = {};
|
|
|
|
|
var cache_matrix = {}, cache_tag = {};
|
2020-09-14 08:33:59 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
_____ _ __ __ _
|
|
|
|
|
/ ____| | | | \/ (_)
|
|
|
|
|
| | ___ __| | ___| \ / |_ _ __ _ __ ___ _ __
|
|
|
|
|
| | / _ \ / _` |/ _ \ |\/| | | '__| '__/ _ \| '__|
|
|
|
|
|
| |___| (_) | (_| | __/ | | | | | | | | (_) | |
|
|
|
|
|
\_____\___/ \__,_|\___|_| |_|_|_| |_| \___/|_|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* Replacement actions and Toolbar addition */
|
|
|
|
|
function MISPElementReplacementActions(action) {
|
|
|
|
|
var start = cm.getCursor('start')
|
|
|
|
|
var end = cm.getCursor('end')
|
|
|
|
|
var content = cm.getRange(start, end)
|
|
|
|
|
var replacement = content
|
|
|
|
|
var setCursorTo = false
|
|
|
|
|
var noMatch = false
|
|
|
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
|
case 'element':
|
|
|
|
|
replacement = '@[MISPElement]()'
|
|
|
|
|
end = null
|
|
|
|
|
cm.replaceRange(replacement, start)
|
|
|
|
|
cm.setSelection({line: start.line, ch: start.ch + 2}, {line: start.line, ch: start.ch + 2 + 11})
|
|
|
|
|
cm.focus()
|
|
|
|
|
return true;
|
|
|
|
|
case 'attribute':
|
|
|
|
|
replacement = '@[attribute]()'
|
|
|
|
|
end = null
|
|
|
|
|
setCursorTo = {line: start.line, ch: start.ch + replacement.length - 1}
|
|
|
|
|
break;
|
|
|
|
|
case 'attribute-attachment':
|
|
|
|
|
replacement = '@![attribute]()'
|
|
|
|
|
end = null
|
|
|
|
|
setCursorTo = {line: start.line, ch: start.ch + replacement.length - 1}
|
|
|
|
|
break;
|
|
|
|
|
case 'object':
|
|
|
|
|
replacement = '@[object]()'
|
|
|
|
|
end = null
|
|
|
|
|
setCursorTo = {line: start.line, ch: start.ch + replacement.length - 1}
|
|
|
|
|
break;
|
2020-10-01 16:55:17 +02:00
|
|
|
|
case 'tag':
|
|
|
|
|
replacement = '@[tag]()'
|
|
|
|
|
end = null
|
|
|
|
|
setCursorTo = {line: start.line, ch: start.ch + replacement.length - 1}
|
|
|
|
|
break;
|
2020-10-05 11:38:30 +02:00
|
|
|
|
case 'galaxy-matrix':
|
2020-09-29 12:16:50 +02:00
|
|
|
|
replacement = '@[galaxymatrix]()'
|
|
|
|
|
end = null
|
|
|
|
|
setCursorTo = {line: start.line, ch: start.ch + replacement.length - 1}
|
|
|
|
|
break;
|
2020-09-14 08:33:59 +02:00
|
|
|
|
default:
|
|
|
|
|
noMatch = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (noMatch) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
cm.replaceRange(replacement, start, end)
|
|
|
|
|
if (setCursorTo !== false) {
|
|
|
|
|
cm.setCursor(setCursorTo.line, setCursorTo.ch)
|
|
|
|
|
}
|
|
|
|
|
cm.focus()
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function insertMISPElementToolbarButtons() {
|
|
|
|
|
insertTopToolbarSection()
|
2020-10-06 10:04:13 +02:00
|
|
|
|
insertTopToolbarButton('cube', 'attribute', 'Attribute')
|
|
|
|
|
insertTopToolbarButton('cubes', 'object', 'Object')
|
|
|
|
|
insertTopToolbarButton('image', 'attribute-attachment', 'Attribute picture')
|
|
|
|
|
insertTopToolbarButton('tag', 'tag', 'Tag')
|
|
|
|
|
insertTopToolbarButton('atlas', 'galaxy-matrix', 'Galaxy matrix')
|
2020-09-14 08:33:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Hints */
|
2020-10-02 10:48:52 +02:00
|
|
|
|
var MISPElementHints = {}
|
2020-09-14 08:33:59 +02:00
|
|
|
|
function buildMISPElementHints() {
|
2020-10-02 10:48:52 +02:00
|
|
|
|
MISPElementHints['attribute'] = []
|
|
|
|
|
Object.keys(proxyMISPElements['attribute']).forEach(function(uuid) {
|
|
|
|
|
var attribute = proxyMISPElements['attribute'][uuid]
|
|
|
|
|
MISPElementHints['attribute'].push(
|
|
|
|
|
[attribute.value, uuid],
|
|
|
|
|
[attribute.type, uuid],
|
|
|
|
|
[attribute.id, uuid],
|
|
|
|
|
[attribute.uuid, uuid],
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
MISPElementHints['object'] = []
|
|
|
|
|
Object.keys(proxyMISPElements['object']).forEach(function(uuid) {
|
|
|
|
|
var object = proxyMISPElements['object'][uuid]
|
|
|
|
|
MISPElementHints['object'].push(
|
|
|
|
|
[object.name, uuid],
|
|
|
|
|
[object.id, uuid],
|
|
|
|
|
[object.uuid, uuid],
|
|
|
|
|
)
|
2020-09-14 08:33:59 +02:00
|
|
|
|
})
|
2020-10-02 10:48:52 +02:00
|
|
|
|
MISPElementHints['galaxymatrix'] = []
|
|
|
|
|
Object.keys(proxyMISPElements['galaxymatrix']).forEach(function(uuid) {
|
|
|
|
|
var galaxy = proxyMISPElements['galaxymatrix'][uuid]
|
|
|
|
|
MISPElementHints['galaxymatrix'].push(
|
|
|
|
|
[galaxy.id, uuid],
|
|
|
|
|
[galaxy.uuid, uuid],
|
|
|
|
|
[galaxy.name, uuid],
|
|
|
|
|
[galaxy.namespace, uuid],
|
|
|
|
|
[galaxy.type, uuid],
|
|
|
|
|
)
|
2020-09-29 12:16:50 +02:00
|
|
|
|
})
|
2020-10-02 10:48:52 +02:00
|
|
|
|
MISPElementHints['tag'] = []
|
|
|
|
|
Object.keys(proxyMISPElements['tagname']).forEach(function(tagName) {
|
|
|
|
|
var tag = proxyMISPElements['tagname'][tagName]
|
|
|
|
|
MISPElementHints['tag'].push([tagName, tagName])
|
2020-09-14 08:33:59 +02:00
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function hintMISPElements(cm, options) {
|
2020-10-02 10:48:52 +02:00
|
|
|
|
var authorizedMISPElements = ['attribute', 'object', 'galaxymatrix', 'tag']
|
2020-10-01 17:06:56 +02:00
|
|
|
|
var availableScopes = ['attribute', 'object', 'galaxymatrix', 'tag']
|
2020-09-29 12:16:50 +02:00
|
|
|
|
var reMISPElement = RegExp('@\\[(?<scope>' + authorizedMISPElements.join('|') + ')\\]\\((?<elementid>[^\\)]+)?\\)');
|
2020-09-14 08:33:59 +02:00
|
|
|
|
var reExtendedWord = /\S/
|
2020-10-02 10:48:52 +02:00
|
|
|
|
var hintList = []
|
2020-09-14 08:33:59 +02:00
|
|
|
|
var scope, elementID, element
|
|
|
|
|
var cursor = cm.getCursor()
|
|
|
|
|
var line = cm.getLine(cursor.line)
|
|
|
|
|
var start = cursor.ch
|
|
|
|
|
var end = cursor.ch
|
|
|
|
|
while (start && reExtendedWord.test(line.charAt(start - 1))) --start
|
|
|
|
|
while (end < line.length && reExtendedWord.test(line.charAt(end))) ++end
|
|
|
|
|
var word = line.slice(start, end).toLowerCase()
|
|
|
|
|
|
2020-09-29 12:26:20 +02:00
|
|
|
|
if (word === '@[]()') {
|
|
|
|
|
availableScopes.forEach(function(scope) {
|
|
|
|
|
hintList.push({
|
|
|
|
|
text: '@[' + scope + ']()'
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
return {
|
|
|
|
|
list: hintList,
|
|
|
|
|
from: CodeMirror.Pos(cursor.line, start),
|
|
|
|
|
to: CodeMirror.Pos(cursor.line, end)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-14 08:33:59 +02:00
|
|
|
|
var res = reMISPElement.exec(word)
|
|
|
|
|
if (res !== null) {
|
|
|
|
|
scope = res.groups.scope
|
2020-09-29 12:16:50 +02:00
|
|
|
|
elementID = res.groups.elementid !== undefined ? res.groups.elementid : ''
|
2020-10-02 10:48:52 +02:00
|
|
|
|
if (scope === 'tag') {
|
|
|
|
|
element = proxyMISPElements['tagname'][elementID]
|
|
|
|
|
} else {
|
|
|
|
|
element = proxyMISPElements[scope][elementID]
|
|
|
|
|
}
|
2020-09-14 08:33:59 +02:00
|
|
|
|
if (element !== undefined) {
|
|
|
|
|
hintList.push(
|
|
|
|
|
{
|
2020-10-01 11:08:30 +02:00
|
|
|
|
text: '@[' + scope + '](' + element.uuid + ')',
|
2020-09-14 08:33:59 +02:00
|
|
|
|
render: function(elem, self, data) {
|
|
|
|
|
var hintElement = renderHintElement(scope, element)
|
|
|
|
|
$(elem).append(hintElement)
|
|
|
|
|
},
|
|
|
|
|
className: 'hint-container',
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
} else { // search in hint arrays
|
2020-09-29 12:16:50 +02:00
|
|
|
|
var addedItems = {}
|
2020-09-14 08:33:59 +02:00
|
|
|
|
var maxHints = 10
|
2020-10-02 10:48:52 +02:00
|
|
|
|
if (MISPElementHints[scope] !== undefined) {
|
|
|
|
|
for (var i = 0; i < MISPElementHints[scope].length; i++) {
|
|
|
|
|
var hintArray = MISPElementHints[scope][i];
|
|
|
|
|
var hintValue = hintArray[0]
|
|
|
|
|
var hintUUID = hintArray[1]
|
2020-09-14 08:33:59 +02:00
|
|
|
|
if (hintList.length >= maxHints) {
|
2020-10-02 10:48:52 +02:00
|
|
|
|
break
|
2020-09-14 08:33:59 +02:00
|
|
|
|
}
|
2020-10-02 15:21:22 +02:00
|
|
|
|
if (hintValue.includes(elementID)) {
|
2020-10-02 10:48:52 +02:00
|
|
|
|
if (addedItems[hintUUID] === undefined) {
|
|
|
|
|
if (scope === 'tag') {
|
|
|
|
|
element = proxyMISPElements['tagname'][hintUUID]
|
|
|
|
|
element.uuid = hintUUID
|
|
|
|
|
} else {
|
|
|
|
|
element = proxyMISPElements[scope][hintUUID]
|
2020-09-29 12:16:50 +02:00
|
|
|
|
}
|
2020-10-02 10:48:52 +02:00
|
|
|
|
if (element !== undefined) {
|
|
|
|
|
hintList.push({
|
|
|
|
|
text: '@[' + scope + '](' + element.uuid + ')',
|
|
|
|
|
element: element,
|
|
|
|
|
render: function(elem, self, data) {
|
|
|
|
|
var hintElement = renderHintElement(scope, data.element)
|
|
|
|
|
$(elem).append(hintElement)
|
|
|
|
|
},
|
|
|
|
|
className: 'hint-container',
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
addedItems[hintUUID] = true
|
2020-09-14 08:33:59 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-02 10:48:52 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-14 08:33:59 +02:00
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
list: hintList,
|
|
|
|
|
from: CodeMirror.Pos(cursor.line, start),
|
|
|
|
|
to: CodeMirror.Pos(cursor.line, end)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderHintElement(scope, element) {
|
|
|
|
|
var $node;
|
|
|
|
|
if (scope == 'attribute') {
|
|
|
|
|
$node = $('<span/>').addClass('hint-attribute')
|
2020-10-09 11:34:24 +02:00
|
|
|
|
if (isValidObjectAttribute(element)) {
|
|
|
|
|
$node.append($('<i/>').addClass('fas fa-cubes').css('margin-right', '3px'))
|
|
|
|
|
}
|
2020-10-02 11:22:51 +02:00
|
|
|
|
$node.append($('<i/>').addClass('').text('[' + element.category + '] '))
|
2020-09-14 08:33:59 +02:00
|
|
|
|
.append($('<span/>').addClass('bold').text(element.type + ' '))
|
2020-10-02 11:22:51 +02:00
|
|
|
|
.append(
|
|
|
|
|
$('<span/>').addClass('bold blue ellipsis-overflow')
|
|
|
|
|
.css({
|
|
|
|
|
'max-width': '500px',
|
|
|
|
|
'display': 'table-cell'
|
|
|
|
|
})
|
|
|
|
|
.text(element.value)
|
|
|
|
|
)
|
2020-09-14 08:33:59 +02:00
|
|
|
|
} else if (scope == 'object') {
|
2020-10-02 11:22:51 +02:00
|
|
|
|
var associatedTemplate = element.template_uuid + '.' + element.template_version
|
|
|
|
|
var objectTemplate = proxyMISPElements['objectTemplates'][associatedTemplate]
|
|
|
|
|
var topPriorityValue = element.Attribute.length
|
|
|
|
|
if (objectTemplate !== undefined) {
|
|
|
|
|
var temp = getPriorityValue(element, objectTemplate)
|
|
|
|
|
topPriorityValue = temp !== false ? temp : topPriorityValue
|
|
|
|
|
}
|
2020-09-14 08:33:59 +02:00
|
|
|
|
$node = $('<span/>').addClass('hint-object')
|
2020-10-02 11:22:51 +02:00
|
|
|
|
$node.append($('<i/>').addClass('').text('[' + element['meta-category'] + '] '))
|
2020-09-14 08:33:59 +02:00
|
|
|
|
.append($('<span/>').addClass('bold').text(element.name + ' '))
|
2020-10-02 11:22:51 +02:00
|
|
|
|
.append(
|
|
|
|
|
$('<span/>').addClass('bold blue ellipsis-overflow')
|
|
|
|
|
.css({
|
|
|
|
|
'max-width': '500px',
|
|
|
|
|
'display': 'table-cell'
|
|
|
|
|
})
|
|
|
|
|
.text(topPriorityValue)
|
|
|
|
|
)
|
2020-09-29 12:16:50 +02:00
|
|
|
|
} else if (scope == 'galaxymatrix') {
|
2020-10-02 10:48:52 +02:00
|
|
|
|
$node = $('<span/>').addClass('hint-galaxymatrix')
|
2020-10-02 11:22:51 +02:00
|
|
|
|
$node.append($('<i/>').addClass('').text('[' + element.namespace + '] '))
|
2020-09-29 12:16:50 +02:00
|
|
|
|
.append($('<span/>').addClass('bold').text(element.type + ' '))
|
|
|
|
|
.append($('<span/>').addClass('bold blue').text(element.name))
|
2020-10-02 10:48:52 +02:00
|
|
|
|
} else if (scope == 'tag') {
|
|
|
|
|
$node = $('<span/>').addClass('hint-tag')
|
|
|
|
|
$node.append(constructTagHtml(element.name, element.colour, {'box-shadow': 'none'}))
|
2020-09-14 08:33:59 +02:00
|
|
|
|
} else {
|
|
|
|
|
$node = $('<span>No match</span>') // should not happen
|
|
|
|
|
}
|
|
|
|
|
return $node
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
__ __ _ _ _____ _
|
|
|
|
|
| \/ | | | | | |_ _| |
|
|
|
|
|
| \ / | __ _ _ __| | ____| | _____ ___ __ | | | |_
|
|
|
|
|
| |\/| |/ _` | '__| |/ / _` |/ _ \ \ /\ / / '_ \ | | | __|
|
|
|
|
|
| | | | (_| | | | < (_| | (_) \ V V /| | | |_| |_| |_
|
|
|
|
|
|_| |_|\__,_|_| |_|\_\__,_|\___/ \_/\_/ |_| |_|_____|\__|
|
|
|
|
|
*/
|
2020-10-07 11:13:30 +02:00
|
|
|
|
function markdownItCustomPostInit() {
|
|
|
|
|
markdownItSetupRules()
|
2020-10-08 17:00:32 +02:00
|
|
|
|
fetchProxyMISPElements(function() {
|
|
|
|
|
doRender()
|
|
|
|
|
})
|
2020-10-07 11:13:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-14 08:33:59 +02:00
|
|
|
|
function markdownItSetupRules() {
|
|
|
|
|
md.renderer.rules.MISPElement = MISPElementRenderer;
|
|
|
|
|
md.renderer.rules.MISPPictureElement = MISPPictureElementRenderer;
|
|
|
|
|
md.inline.ruler.push('MISP_element_rule', MISPElementRule);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Parsing Rules */
|
|
|
|
|
function MISPElementRule(state, startLine, endLine, silent) {
|
|
|
|
|
var pos, start, labelStart, labelEnd, res, elementID, code, content, token, tokens, attrs, scope
|
|
|
|
|
var oldPos = state.pos,
|
|
|
|
|
max = state.posMax
|
|
|
|
|
|
|
|
|
|
if (state.src.charCodeAt(state.pos) !== 0x40/* @ */) { return false; }
|
|
|
|
|
if (state.src.charCodeAt(state.pos + 1) === 0x21/* ! */) {
|
|
|
|
|
if (state.src.charCodeAt(state.pos + 2) !== 0x5B/* [ */) { return false;}
|
|
|
|
|
} else {
|
|
|
|
|
if (state.src.charCodeAt(state.pos + 1) !== 0x5B/* [ */) { return false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var isPicture = state.src.charCodeAt(state.pos + 1) === 0x21/* ! */
|
|
|
|
|
|
|
|
|
|
if (isPicture) {
|
|
|
|
|
labelStart = state.pos + 3;
|
|
|
|
|
labelEnd = state.md.helpers.parseLinkLabel(state, state.pos + 2, false);
|
|
|
|
|
} else {
|
|
|
|
|
labelStart = state.pos + 2;
|
|
|
|
|
labelEnd = state.md.helpers.parseLinkLabel(state, state.pos + 1, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// parser failed to find ']', so it's not a valid link
|
|
|
|
|
if (labelEnd < 0) { return false; }
|
|
|
|
|
scope = state.src.slice(labelStart, labelEnd)
|
|
|
|
|
|
|
|
|
|
pos = labelEnd + 1;
|
|
|
|
|
if (pos < max && state.src.charCodeAt(pos) === 0x28/* ( */) {
|
|
|
|
|
start = pos;
|
2020-10-01 16:55:17 +02:00
|
|
|
|
if (scope == 'tag') { // tags may contain spaces
|
|
|
|
|
res = parseTag(state.src, pos, state.posMax);
|
|
|
|
|
} else {
|
|
|
|
|
res = state.md.helpers.parseLinkDestination(state.src, pos, state.posMax);
|
|
|
|
|
}
|
2020-09-14 08:33:59 +02:00
|
|
|
|
if (res.ok) {
|
2020-09-14 09:34:26 +02:00
|
|
|
|
// parseLinkDestination does not support trailing characters such as `.` after the link
|
|
|
|
|
// so we have to find the matching `)`
|
|
|
|
|
var destinationEnd = res.str.length - 1
|
|
|
|
|
var traillingCharNumber = 0
|
|
|
|
|
for (var i = res.str.length-1; i > 1; i--) {
|
|
|
|
|
var code = res.str.charCodeAt(i)
|
|
|
|
|
if (code === 0x29 /* ) */) {
|
|
|
|
|
destinationEnd = i
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
traillingCharNumber++
|
|
|
|
|
}
|
|
|
|
|
elementID = res.str.substring(1, destinationEnd);
|
|
|
|
|
pos = res.pos - 1 - traillingCharNumber;
|
2020-09-14 08:33:59 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pos >= max || state.src.charCodeAt(pos) !== 0x29/* ) */) {
|
|
|
|
|
state.pos = oldPos;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
pos++;
|
|
|
|
|
|
2020-10-01 16:55:17 +02:00
|
|
|
|
if (scope == 'tag') {
|
|
|
|
|
var reTagName = /^[^\n)]+$/
|
|
|
|
|
if (!reTagName.test(elementID)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
var reUUID = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/
|
|
|
|
|
if (!reUUID.test(elementID)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-09-14 08:33:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We found the end of the link, and know for a fact it's a valid link;
|
|
|
|
|
// so all that's left to do is to call tokenizer.
|
|
|
|
|
content = {
|
|
|
|
|
scope: scope,
|
|
|
|
|
elementID: elementID,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isPicture) {
|
|
|
|
|
token = state.push('MISPPictureElement', 'div', 0);
|
|
|
|
|
} else {
|
|
|
|
|
token = state.push('MISPElement', 'div', 0);
|
|
|
|
|
}
|
|
|
|
|
token.children = tokens;
|
|
|
|
|
token.content = content;
|
|
|
|
|
|
|
|
|
|
state.pos = pos;
|
|
|
|
|
state.posMax = max;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Rendering rules */
|
|
|
|
|
function MISPElementRenderer(tokens, idx, options, env, slf) {
|
2020-10-01 16:55:17 +02:00
|
|
|
|
var allowedScope = ['attribute', 'object', 'galaxymatrix', 'tag']
|
2020-09-14 08:33:59 +02:00
|
|
|
|
var token = tokens[idx];
|
|
|
|
|
var scope = token.content.scope
|
|
|
|
|
var elementID = token.content.elementID
|
|
|
|
|
if (allowedScope.indexOf(scope) == -1) {
|
|
|
|
|
return renderInvalidMISPElement(scope, elementID);
|
|
|
|
|
}
|
|
|
|
|
return renderMISPElement(scope, elementID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function MISPPictureElementRenderer(tokens, idx, options, env, slf) {
|
|
|
|
|
var allowedScope = ['attribute']
|
|
|
|
|
var token = tokens[idx];
|
|
|
|
|
var scope = token.content.scope
|
|
|
|
|
var elementID = token.content.elementID
|
|
|
|
|
if (allowedScope.indexOf(scope) == -1) {
|
|
|
|
|
return renderInvalidMISPElement(scope, elementID);
|
|
|
|
|
}
|
|
|
|
|
return renderMISPPictureElement(scope, elementID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderMISPElement(scope, elementID) {
|
|
|
|
|
var templateVariables
|
2020-10-08 17:00:32 +02:00
|
|
|
|
if (proxyMISPElements !== null) {
|
|
|
|
|
if (scope == 'attribute') {
|
|
|
|
|
var attribute = proxyMISPElements[scope][elementID]
|
|
|
|
|
if (attribute !== undefined) {
|
|
|
|
|
var templateToRender = dotTemplateAttribute
|
|
|
|
|
var attributeData = {
|
|
|
|
|
scope: 'attribute',
|
|
|
|
|
elementid: elementID,
|
|
|
|
|
type: attribute.type,
|
|
|
|
|
value: attribute.value
|
|
|
|
|
}
|
|
|
|
|
if (isValidObjectAttribute(attribute)) {
|
|
|
|
|
var mispObject = getObjectFromAttribute(attribute)
|
|
|
|
|
if (mispObject !== undefined) {
|
|
|
|
|
attributeData.type = attribute.object_relation
|
|
|
|
|
attributeData.objectname = mispObject.name
|
|
|
|
|
templateToRender = dotTemplateObjectAttribute
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
templateVariables = sanitizeObject(attributeData)
|
|
|
|
|
return renderTemplateBasedOnRenderingOptions(scope, templateToRender, templateVariables);
|
2020-10-05 14:07:51 +02:00
|
|
|
|
}
|
2020-10-08 17:00:32 +02:00
|
|
|
|
} else if (scope == 'object') {
|
|
|
|
|
var mispObject = proxyMISPElements[scope][elementID]
|
|
|
|
|
if (mispObject !== undefined) {
|
|
|
|
|
var associatedTemplate = mispObject.template_uuid + '.' + mispObject.template_version
|
|
|
|
|
var objectTemplate = proxyMISPElements['objectTemplates'][associatedTemplate]
|
|
|
|
|
var topPriorityValue = mispObject.Attribute.length
|
|
|
|
|
if (objectTemplate !== undefined) {
|
|
|
|
|
var temp = getPriorityValue(mispObject, objectTemplate)
|
|
|
|
|
topPriorityValue = temp !== false ? temp : topPriorityValue
|
2020-10-05 14:07:51 +02:00
|
|
|
|
}
|
2020-10-08 17:00:32 +02:00
|
|
|
|
templateVariables = sanitizeObject({
|
|
|
|
|
scope: 'object',
|
|
|
|
|
elementid: elementID,
|
|
|
|
|
type: mispObject.name,
|
|
|
|
|
value: topPriorityValue
|
|
|
|
|
})
|
|
|
|
|
return renderTemplateBasedOnRenderingOptions(scope, dotTemplateObject, templateVariables);
|
2020-10-05 14:07:51 +02:00
|
|
|
|
}
|
2020-10-08 17:00:32 +02:00
|
|
|
|
} else if (scope == 'tag') {
|
|
|
|
|
templateVariables = sanitizeObject({scope: 'tag', elementid: elementID, eventid: eventid, value: elementID})
|
|
|
|
|
return renderTemplateBasedOnRenderingOptions(scope, dotTemplateTag, templateVariables);
|
|
|
|
|
} else if (scope == 'galaxymatrix') {
|
|
|
|
|
templateVariables = sanitizeObject({scope: 'galaxymatrix', elementid: elementID, eventid: eventid, value: elementID})
|
|
|
|
|
return renderTemplateBasedOnRenderingOptions(scope, dotTemplateGalaxyMatrix, templateVariables);
|
2020-09-14 08:33:59 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return renderInvalidMISPElement(scope, elementID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderMISPPictureElement(scope, elementID) {
|
2020-10-08 17:00:32 +02:00
|
|
|
|
if (proxyMISPElements !== null) {
|
|
|
|
|
var attribute = proxyMISPElements[scope][elementID]
|
|
|
|
|
if (attribute !== undefined) {
|
|
|
|
|
var templateVariables = sanitizeObject({
|
|
|
|
|
scope: 'attribute',
|
|
|
|
|
elementid: elementID,
|
|
|
|
|
type: attribute.type,
|
|
|
|
|
value: attribute.value,
|
|
|
|
|
alt: scope + ' ' + elementID,
|
|
|
|
|
src: baseurl + '/attributes/viewPicture/' + attribute.id,
|
|
|
|
|
title: attribute.type + ' ' + attribute.value,
|
|
|
|
|
})
|
|
|
|
|
return renderTemplateBasedOnRenderingOptions('attribute-picture', dotTemplateAttributePicture, templateVariables);
|
|
|
|
|
}
|
2020-09-14 08:33:59 +02:00
|
|
|
|
}
|
|
|
|
|
return renderInvalidMISPElement(scope, elementID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderInvalidMISPElement(scope, elementID) {
|
|
|
|
|
var templateVariables = sanitizeObject({
|
|
|
|
|
scope: invalidMessage,
|
|
|
|
|
id: elementID
|
|
|
|
|
})
|
|
|
|
|
return dotTemplateInvalid(templateVariables);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-06 10:04:13 +02:00
|
|
|
|
function renderTemplateBasedOnRenderingOptions(scope, templateToRender, templateVariables) {
|
|
|
|
|
if (renderingRules[scope]) {
|
|
|
|
|
return templateToRender(templateVariables)
|
|
|
|
|
} else {
|
|
|
|
|
return dotTemplateRenderingDisabled(templateVariables)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function markdownItToggleRenderingRule(rulename, event) {
|
|
|
|
|
if (event !== undefined) {
|
|
|
|
|
event.stopPropagation()
|
|
|
|
|
}
|
|
|
|
|
if (renderingRules[rulename] === undefined) {
|
|
|
|
|
console.log('Rule does not exists')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
renderingRules[rulename] = !renderingRules[rulename]
|
|
|
|
|
doRender()
|
|
|
|
|
reloadRenderingRuleEnabledUI()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function reloadRenderingRuleEnabledUI() {
|
|
|
|
|
Object.keys(renderingRules).forEach(function(rulename) {
|
|
|
|
|
var enabled = renderingRules[rulename]
|
|
|
|
|
if (enabled) {
|
|
|
|
|
$('#markdownrendering-' + rulename + '-rendering-enabled').show()
|
|
|
|
|
$('#markdownrendering-' + rulename + '-rendering-disabled').hide()
|
|
|
|
|
} else {
|
|
|
|
|
$('#markdownrendering-' + rulename + '-rendering-enabled').hide()
|
|
|
|
|
$('#markdownrendering-' + rulename + '-rendering-disabled').show()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-14 08:33:59 +02:00
|
|
|
|
function setupMISPElementMarkdownListeners() {
|
|
|
|
|
$('.misp-element-wrapper').filter('.attribute').popover({
|
|
|
|
|
trigger: 'click',
|
|
|
|
|
html: true,
|
2020-10-09 13:34:46 +02:00
|
|
|
|
container: isInsideModal() ? 'body' : '#viewer-container',
|
2020-09-14 08:33:59 +02:00
|
|
|
|
placement: 'top',
|
|
|
|
|
title: getTitleFromMISPElementDOM,
|
|
|
|
|
content: getContentFromMISPElementDOM
|
|
|
|
|
})
|
|
|
|
|
$('.misp-picture-wrapper > img').popover({
|
|
|
|
|
trigger: 'click',
|
|
|
|
|
html: true,
|
2020-10-09 13:34:46 +02:00
|
|
|
|
container: isInsideModal() ? 'body' : '#viewer-container',
|
2020-09-14 08:33:59 +02:00
|
|
|
|
placement: 'top',
|
|
|
|
|
title: getTitleFromMISPElementDOM,
|
|
|
|
|
content: getContentFromMISPElementDOM,
|
|
|
|
|
placement: 'top'
|
|
|
|
|
})
|
|
|
|
|
$('.misp-element-wrapper').filter('.object').popover({
|
|
|
|
|
trigger: 'click',
|
|
|
|
|
html: true,
|
2020-10-09 13:34:46 +02:00
|
|
|
|
container: isInsideModal() ? 'body' : '#viewer-container',
|
2020-09-14 08:33:59 +02:00
|
|
|
|
placement: 'top',
|
|
|
|
|
title: getTitleFromMISPElementDOM,
|
|
|
|
|
content: getContentFromMISPElementDOM
|
|
|
|
|
})
|
2020-10-01 16:55:17 +02:00
|
|
|
|
$('.embeddedTag').popover({
|
|
|
|
|
trigger: 'click',
|
|
|
|
|
html: true,
|
2020-10-09 13:34:46 +02:00
|
|
|
|
container: isInsideModal() ? 'body' : '#viewer-container',
|
2020-10-01 16:55:17 +02:00
|
|
|
|
placement: 'top',
|
|
|
|
|
title: getTitleFromMISPElementDOM,
|
|
|
|
|
content: getContentFromMISPElementDOM
|
|
|
|
|
})
|
2020-09-14 08:33:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function attachRemoteMISPElements() {
|
2020-09-29 12:16:50 +02:00
|
|
|
|
$('.embeddedGalaxyMatrix[data-scope="galaxymatrix"]').each(function() {
|
2020-09-14 08:33:59 +02:00
|
|
|
|
var $div = $(this)
|
2020-09-29 12:16:50 +02:00
|
|
|
|
clearTimeout(galaxyMatrixTimer);
|
2020-09-14 08:33:59 +02:00
|
|
|
|
$div.append($('<div/>').css('font-size', '24px').append(loadingSpanAnimation))
|
2020-09-29 12:16:50 +02:00
|
|
|
|
var eventID = $div.data('eventid')
|
|
|
|
|
var elementID = $div.data('elementid')
|
|
|
|
|
var cacheKey = eventid + '-' + elementID
|
|
|
|
|
if (cache_matrix[cacheKey] === undefined) {
|
|
|
|
|
galaxyMatrixTimer = setTimeout(function() {
|
|
|
|
|
attachGalaxyMatrix($div, eventID, elementID)
|
2020-09-14 08:33:59 +02:00
|
|
|
|
}, slowDebounceDelay);
|
|
|
|
|
} else {
|
2020-09-29 12:16:50 +02:00
|
|
|
|
$div.html(cache_matrix[cacheKey])
|
2020-09-14 08:33:59 +02:00
|
|
|
|
}
|
|
|
|
|
})
|
2020-10-01 16:55:17 +02:00
|
|
|
|
$('.embeddedTag[data-scope="tag"]').each(function() {
|
|
|
|
|
var $div = $(this)
|
|
|
|
|
$div.append($('<span/>').append(loadingSpanAnimation))
|
|
|
|
|
var eventID = $div.data('eventid')
|
|
|
|
|
var elementID = $div.data('elementid')
|
|
|
|
|
var cacheKey = eventid + '-' + elementID
|
|
|
|
|
clearTimeout(tagTimers[cacheKey]);
|
|
|
|
|
if (cache_tag[cacheKey] === undefined) {
|
|
|
|
|
tagTimers[cacheKey] = setTimeout(function() {
|
|
|
|
|
attachTagInfo($div, eventID, elementID)
|
2020-10-01 17:06:56 +02:00
|
|
|
|
}, slowDebounceDelay);
|
2020-10-01 16:55:17 +02:00
|
|
|
|
} else {
|
|
|
|
|
$div.html(cache_tag[cacheKey])
|
|
|
|
|
}
|
|
|
|
|
})
|
2020-09-14 08:33:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-29 12:16:50 +02:00
|
|
|
|
function attachGalaxyMatrix($elem, eventid, elementID) {
|
|
|
|
|
var galaxy = proxyMISPElements['galaxymatrix'][elementID]
|
|
|
|
|
if (galaxy === undefined) {
|
|
|
|
|
console.log('Something wrong happened. Could not fetch galaxy from proxy')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
var galaxyType = galaxy.type
|
2020-09-14 08:33:59 +02:00
|
|
|
|
$.ajax({
|
|
|
|
|
data: {
|
|
|
|
|
"returnFormat": "attack",
|
2020-09-29 12:16:50 +02:00
|
|
|
|
"eventid": eventid,
|
|
|
|
|
"attackGalaxy": galaxyType
|
2020-09-14 08:33:59 +02:00
|
|
|
|
},
|
|
|
|
|
success:function(data, textStatus) {
|
|
|
|
|
$elem.empty().append($(data))
|
|
|
|
|
$elem.find('#attackmatrix_div').css({
|
|
|
|
|
'max-width': 'unset',
|
|
|
|
|
'min-width': 'unset',
|
|
|
|
|
'width': 'calc(100% - 5px)'
|
|
|
|
|
})
|
|
|
|
|
$elem.find('#checkbox_attackMatrix_showAll').click()
|
|
|
|
|
$elem.find('#attackmatrix_div .heatCell').each(function() {
|
|
|
|
|
if ($(this).css('background-color').length > 0 && $(this).css('background-color') != 'rgba(0, 0, 0, 0)') {
|
|
|
|
|
$(this).attr('style', 'background-color:' + $(this).css('background-color') + ' !important; color:' + $(this).css('color') + ' !important;');
|
|
|
|
|
}
|
|
|
|
|
})
|
2020-09-29 12:16:50 +02:00
|
|
|
|
var cacheKey = eventid + '-' + elementID
|
|
|
|
|
cache_matrix[cacheKey] = $elem.find('#attackmatrix_div')[0].outerHTML;
|
2020-09-14 08:33:59 +02:00
|
|
|
|
},
|
|
|
|
|
error: function(jqXHR, textStatus, errorThrown) {
|
|
|
|
|
var templateVariables = sanitizeObject({
|
|
|
|
|
scope: 'Error while fetching matrix',
|
|
|
|
|
id: graphID
|
|
|
|
|
})
|
|
|
|
|
var placeholder = dotTemplateInvalid(templateVariables)
|
|
|
|
|
$elem.empty()
|
|
|
|
|
.css({'text-align': 'center'})
|
|
|
|
|
.append($(placeholder))
|
|
|
|
|
},
|
|
|
|
|
type:"post",
|
|
|
|
|
url: baseurl + "/events/restSearch"
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-01 16:55:17 +02:00
|
|
|
|
function attachTagInfo($elem, eventid, elementID) {
|
|
|
|
|
$.ajax({
|
|
|
|
|
data: {
|
|
|
|
|
"tag": elementID,
|
|
|
|
|
},
|
|
|
|
|
success:function(data, textStatus) {
|
|
|
|
|
var $tag
|
|
|
|
|
data = $.parseJSON(data)
|
|
|
|
|
var tagData;
|
|
|
|
|
for (var i = 0; i < data.length; i++) {
|
|
|
|
|
var tag = data[i];
|
|
|
|
|
if (tag.Tag.name == elementID) {
|
|
|
|
|
tagData = data[i]
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (tagData === undefined) {
|
|
|
|
|
tagData = {}
|
2020-10-02 11:52:20 +02:00
|
|
|
|
$tag = constructTagHtml(elementID, '#ffffff', {'border': '1px solid #000'})
|
2020-10-01 16:55:17 +02:00
|
|
|
|
} else {
|
2020-10-02 11:07:52 +02:00
|
|
|
|
$tag = getTagReprensentation(tagData)
|
2020-10-02 10:48:52 +02:00
|
|
|
|
proxyMISPElements['tag'][elementID] = tagData
|
2020-10-01 16:55:17 +02:00
|
|
|
|
}
|
|
|
|
|
$elem.empty().append($tag)
|
|
|
|
|
var cacheKey = eventid + '-' + elementID
|
|
|
|
|
cache_tag[cacheKey] = $tag[0].outerHTML;
|
|
|
|
|
},
|
|
|
|
|
error: function(jqXHR, textStatus, errorThrown) {
|
|
|
|
|
var templateVariables = sanitizeObject({
|
|
|
|
|
scope: 'Error while fetching tag',
|
|
|
|
|
id: elementID
|
|
|
|
|
})
|
|
|
|
|
var placeholder = dotTemplateInvalid(templateVariables)
|
|
|
|
|
$elem.empty()
|
|
|
|
|
.css({'text-align': 'center'})
|
|
|
|
|
.append($(placeholder))
|
|
|
|
|
},
|
|
|
|
|
type:"post",
|
2020-10-02 11:41:03 +02:00
|
|
|
|
url: baseurl + "/tags/search/0/1/0"
|
2020-10-01 16:55:17 +02:00
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-14 08:33:59 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
_____ _
|
|
|
|
|
/ ____| (_)
|
|
|
|
|
| (___ __ ___ ___ _ __ __ _
|
|
|
|
|
\___ \ / _` \ \ / / | '_ \ / _` |
|
|
|
|
|
____) | (_| |\ V /| | | | | (_| |
|
|
|
|
|
|_____/ \__,_| \_/ |_|_| |_|\__, |
|
|
|
|
|
__/ |
|
|
|
|
|
|___/
|
|
|
|
|
*/
|
|
|
|
|
function replaceMISPElementByTheirValue(raw) {
|
|
|
|
|
var match, replacement, element
|
|
|
|
|
var final = ''
|
|
|
|
|
var authorizedMISPElements = ['attribute', 'object']
|
|
|
|
|
var reMISPElement = RegExp('@\\[(?<scope>' + authorizedMISPElements.join('|') + ')\\]\\((?<elementid>[\\d]+)\\)', 'g');
|
|
|
|
|
var offset = 0
|
|
|
|
|
while ((match = reMISPElement.exec(raw)) !== null) {
|
|
|
|
|
element = proxyMISPElements[match.groups.scope][match.groups.elementid]
|
|
|
|
|
if (element !== undefined) {
|
|
|
|
|
replacement = match.groups.scope + '-' + element.uuid
|
|
|
|
|
} else {
|
|
|
|
|
replacement = match.groups.scope + '-' + match.groups.elementid
|
|
|
|
|
}
|
|
|
|
|
final += raw.substring(offset, match.index) + replacement
|
|
|
|
|
offset = reMISPElement.lastIndex
|
|
|
|
|
}
|
|
|
|
|
final += raw.substring(offset)
|
|
|
|
|
return final
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 07:55:21 +02:00
|
|
|
|
/**
|
|
|
|
|
__ __
|
|
|
|
|
| \/ |
|
|
|
|
|
| \ / | ___ _ __ _ _
|
|
|
|
|
| |\/| |/ _ \ '_ \| | | |
|
|
|
|
|
| | | | __/ | | | |_| |
|
|
|
|
|
|_| |_|\___|_| |_|\__,_|
|
|
|
|
|
*/
|
|
|
|
|
function injectCustomRulesMenu() {
|
2020-10-06 10:04:13 +02:00
|
|
|
|
var $MISPElementMenuItem = createRulesMenuItem('MISP Elements', $('<img src="/favicon.ico">'), 'parser', 'MISP_element_rule')
|
2020-09-17 07:55:21 +02:00
|
|
|
|
$markdownDropdownRulesMenu.append($MISPElementMenuItem)
|
2020-10-06 10:04:13 +02:00
|
|
|
|
createSubMenu({
|
|
|
|
|
name: 'Markdown rendering rules',
|
|
|
|
|
icon: 'fab fa-markdown',
|
|
|
|
|
items: [
|
|
|
|
|
{name: 'Attribute', icon: 'fas fa-cube', ruleScope: 'render', ruleName: 'attribute', isToggleableRule: true },
|
|
|
|
|
{name: 'Attribute picture', icon: 'fas fa-image', ruleScope: 'render', ruleName: 'attribute-picture', isToggleableRule: true },
|
|
|
|
|
{name: 'Object', icon: 'fas fa-cubes', ruleScope: 'render', ruleName: 'object', isToggleableRule: true },
|
|
|
|
|
{name: 'Object Attribute', icon: 'fas fa-cube', ruleScope: 'render', ruleName: 'object-attribute', isToggleableRule: true },
|
|
|
|
|
{name: 'Tag', icon: 'fas fa-tag', ruleScope: 'render', ruleName: 'tag', isToggleableRule: true },
|
|
|
|
|
{name: 'Galaxy matrix', icon: 'fas fa-atlas', ruleScope: 'render', ruleName: 'galaxymatrix', isToggleableRule: true },
|
|
|
|
|
]
|
|
|
|
|
})
|
|
|
|
|
reloadRenderingRuleEnabledUI()
|
2020-09-17 07:55:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function markdownItToggleCustomRule(rulename, event) {
|
|
|
|
|
var enabled
|
|
|
|
|
if (rulename == 'MISP_element_rule') {
|
|
|
|
|
var rule = getRuleStatus('inline', 'ruler', 'MISP_element_rule')
|
|
|
|
|
if (rule !== false) {
|
|
|
|
|
enabled = rule.enabled
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
found: enabled !== undefined,
|
|
|
|
|
enabled: enabled
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-14 08:33:59 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
_ _ _ _ _
|
|
|
|
|
| | | | | (_) |
|
|
|
|
|
| | | | |_ _| |___
|
|
|
|
|
| | | | __| | / __|
|
|
|
|
|
| |__| | |_| | \__ \
|
|
|
|
|
\____/ \__|_|_|___/
|
|
|
|
|
*/
|
2020-10-08 17:00:32 +02:00
|
|
|
|
function fetchProxyMISPElements(callback) {
|
2020-10-07 11:13:30 +02:00
|
|
|
|
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)
|
2020-10-08 17:00:32 +02:00
|
|
|
|
callback()
|
2020-10-07 11:13:30 +02:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-14 08:33:59 +02:00
|
|
|
|
function getElementFromDom(node) {
|
|
|
|
|
var scope = $(node).data('scope')
|
|
|
|
|
var elementID = $(node).data('elementid')
|
|
|
|
|
if (scope !== undefined && elementID !== undefined) {
|
|
|
|
|
return {
|
|
|
|
|
element: proxyMISPElements[scope][elementID],
|
|
|
|
|
scope: scope,
|
|
|
|
|
elementID: elementID
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getTitleFromMISPElementDOM() {
|
|
|
|
|
var data = getElementFromDom(this)
|
|
|
|
|
var title = invalidMessage
|
|
|
|
|
var dismissButton = ''
|
|
|
|
|
if (data !== false) {
|
2020-10-01 16:55:17 +02:00
|
|
|
|
var templateVariables = sanitizeObject(data)
|
|
|
|
|
var dismissButton = dotCloseButtonTemplate(templateVariables)
|
|
|
|
|
title = data.scope.charAt(0).toUpperCase() + templateVariables.scope.slice(1) + ' ' + templateVariables.elementID
|
2020-09-14 08:33:59 +02:00
|
|
|
|
}
|
|
|
|
|
return title + dismissButton
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function closeThePopover(closeButton) {
|
|
|
|
|
var scope = $(closeButton).data('scope')
|
|
|
|
|
var elementID = $(closeButton).data('elementid')
|
2020-10-01 16:55:17 +02:00
|
|
|
|
var $MISPElement = $('[data-scope="' + scope + '"][data-elementid="' + elementID.replaceAll('\"', '\\\"') + '"]')
|
2020-10-09 14:43:10 +02:00
|
|
|
|
if ($MISPElement) {
|
|
|
|
|
$MISPElement.popover('hide');
|
|
|
|
|
} else {
|
|
|
|
|
$(closeButton).closest('.popover').remove()
|
|
|
|
|
}
|
2020-09-14 08:33:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-05 14:07:51 +02:00
|
|
|
|
function constructAttributeRow(attribute, fromObject)
|
2020-09-14 08:33:59 +02:00
|
|
|
|
{
|
2020-10-05 14:07:51 +02:00
|
|
|
|
fromObject = fromObject !== undefined ? fromObject : false
|
|
|
|
|
var attributeFieldsToRender = ['id', 'category', 'type'].concat(fromObject ? ['object_relation'] : [], ['value', 'comment'])
|
2020-09-14 08:33:59 +02:00
|
|
|
|
var $tr = $('<tr/>')
|
|
|
|
|
attributeFieldsToRender.forEach(function(field) {
|
|
|
|
|
$tr.append(
|
|
|
|
|
$('<td/>').text(attribute[field])
|
|
|
|
|
.css('white-space', ['id', 'type'].indexOf(field) != -1 ? 'nowrap' : 'none')
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
var $tags = $('<div/>')
|
|
|
|
|
if (attribute.AttributeTag !== undefined) {
|
|
|
|
|
attribute.AttributeTag.forEach(function(attributeTag) {
|
|
|
|
|
var tag = attributeTag.Tag
|
|
|
|
|
var $tag = $('<div/>').append(
|
|
|
|
|
$('<span/>')
|
|
|
|
|
.addClass('tagComplete nowrap')
|
|
|
|
|
.css({'background-color': tag.colour, 'color': getTextColour(tag.colour), 'box-shadow': '1px 1px 3px #888888c4'})
|
|
|
|
|
.text(tag.name)
|
|
|
|
|
)
|
|
|
|
|
$tags.append($tag)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
$tr.append($('<td/>').append($tags))
|
|
|
|
|
var $galaxies = $('<div/>')
|
|
|
|
|
if (attribute.Galaxy !== undefined) {
|
|
|
|
|
attribute.Galaxy.forEach(function(galaxy) {
|
|
|
|
|
var $galaxy = $('<div/>').append(
|
|
|
|
|
$('<span/>')
|
|
|
|
|
.addClass('tagComplete nowrap')
|
|
|
|
|
.css({'background-color': '#0088cc', 'color': getTextColour('#0088cc'), 'box-shadow': '1px 1px 3px #888888c4'})
|
|
|
|
|
.text(galaxy.name + ' :: ' + galaxy.GalaxyCluster[0].value)
|
|
|
|
|
)
|
|
|
|
|
$galaxies.append($galaxy)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
$tr.append($('<td/>').append($galaxies))
|
|
|
|
|
return $tr
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-05 14:07:51 +02:00
|
|
|
|
function constructAttributeHeader(attribute, showAll, fromObject) {
|
2020-09-14 08:33:59 +02:00
|
|
|
|
showAll = showAll !== undefined ? showAll : false
|
2020-10-05 14:07:51 +02:00
|
|
|
|
fromObject = fromObject !== undefined ? fromObject : false
|
|
|
|
|
var attributeFieldsToRender = ['id', 'category', 'type'].concat(fromObject ? ['object_relation'] : [], ['value', 'comment'])
|
2020-09-14 08:33:59 +02:00
|
|
|
|
var $tr = $('<tr/>')
|
|
|
|
|
attributeFieldsToRender.forEach(function(field) {
|
|
|
|
|
$tr.append($('<th/>').text(field))
|
|
|
|
|
})
|
|
|
|
|
if (showAll || (attribute.AttributeTag !== undefined && attribute.AttributeTag.length > 0)) {
|
|
|
|
|
$tr.append($('<th/>').text('tags'))
|
|
|
|
|
}
|
|
|
|
|
if (showAll || (attribute.Galaxy !== undefined && attribute.Galaxy.length > 0)) {
|
|
|
|
|
$tr.append($('<th/>').text('galaxies'))
|
|
|
|
|
}
|
|
|
|
|
var $thead = $('<thead/>').append($tr)
|
|
|
|
|
return $thead
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function constructObject(object) {
|
|
|
|
|
var objectFieldsToRender = ['id', 'name', 'description', 'distribution']
|
|
|
|
|
var $object = $('<div/>').addClass('similarObjectPanel')
|
|
|
|
|
.css({border: '1px solid #3465a4', 'border-radius': '5px'})
|
|
|
|
|
var $top = $('<div/>').addClass('blueElement')
|
|
|
|
|
.css({padding: '4px 5px'})
|
|
|
|
|
objectFieldsToRender.forEach(function(field) {
|
|
|
|
|
$top.append($('<div/>').append(
|
|
|
|
|
$('<span/>').addClass('bold').text(field + ': '),
|
|
|
|
|
$('<span/>').text(object[field])
|
|
|
|
|
))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
var $attributeTable = $('<table/>').addClass('table table-striped table-condensed')
|
|
|
|
|
.css({'margin-bottom': '3px'})
|
2020-10-05 14:07:51 +02:00
|
|
|
|
var $thead = constructAttributeHeader({}, true, true)
|
2020-09-14 08:33:59 +02:00
|
|
|
|
var $tbody = $('<tbody/>')
|
|
|
|
|
object.Attribute.forEach(function(attribute) {
|
2020-10-05 14:07:51 +02:00
|
|
|
|
$tbody.append(constructAttributeRow(attribute, true))
|
2020-09-14 08:33:59 +02:00
|
|
|
|
})
|
|
|
|
|
$attributeTable.append($thead, $tbody)
|
|
|
|
|
$object.append($top, $attributeTable)
|
|
|
|
|
return $('<div/>').append($object)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getPriorityValue(mispObject, objectTemplate) {
|
|
|
|
|
for (var i = 0; i < objectTemplate.ObjectTemplateElement.length; i++) {
|
|
|
|
|
var object_relation = objectTemplate.ObjectTemplateElement[i].object_relation;
|
|
|
|
|
for (var j = 0; j < mispObject.Attribute.length; j++) {
|
|
|
|
|
var attribute = mispObject.Attribute[j];
|
|
|
|
|
if (attribute.object_relation === object_relation) {
|
|
|
|
|
return attribute.value
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-01 16:55:17 +02:00
|
|
|
|
function constructTag(tagName) {
|
|
|
|
|
var tagData = proxyMISPElements['tag'][tagName]
|
2020-10-02 10:54:00 +02:00
|
|
|
|
var $info = 'No information about this tag'
|
|
|
|
|
if (tagData !== undefined) {
|
|
|
|
|
if (tagData.Taxonomy !== undefined) {
|
|
|
|
|
$info = constructTaxonomyInfo(tagData)
|
|
|
|
|
} else if(tagData.GalaxyCluster !== undefined) {
|
|
|
|
|
$info = constructGalaxyInfo(tagData)
|
|
|
|
|
}
|
2020-10-01 16:55:17 +02:00
|
|
|
|
}
|
|
|
|
|
return $('<div/>').append($info)
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-02 11:07:52 +02:00
|
|
|
|
function getTagReprensentation(tagData) {
|
|
|
|
|
var $tag
|
|
|
|
|
if(tagData.GalaxyCluster !== undefined) {
|
|
|
|
|
$tag = constructClusterTagHtml(tagData)
|
|
|
|
|
} else {
|
|
|
|
|
$tag = constructTagHtml(tagData.Tag.name, tagData.Tag.colour)
|
|
|
|
|
}
|
|
|
|
|
return $tag
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-02 10:48:52 +02:00
|
|
|
|
function constructTagHtml(tagName, tagColour, additionalCSS) {
|
|
|
|
|
additionalCSS = additionalCSS === undefined ? {} : additionalCSS
|
|
|
|
|
var $tag = $('<span/>').text(tagName)
|
|
|
|
|
.addClass('tag')
|
|
|
|
|
.css({
|
|
|
|
|
'background-color': tagColour,
|
|
|
|
|
'color': getTextColour(tagColour),
|
|
|
|
|
'box-shadow': '3px 3px 3px #888888',
|
|
|
|
|
})
|
|
|
|
|
.css(additionalCSS)
|
|
|
|
|
return $tag
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-02 11:07:52 +02:00
|
|
|
|
function constructClusterTagHtml(tagData) {
|
2020-10-02 11:52:20 +02:00
|
|
|
|
var addBorder = false
|
2020-10-02 11:41:03 +02:00
|
|
|
|
if (tagData.Tag.colour === undefined) {
|
|
|
|
|
tagData.Tag.colour = '#ffffff'
|
2020-10-02 11:52:20 +02:00
|
|
|
|
addBorder = true
|
2020-10-02 11:41:03 +02:00
|
|
|
|
}
|
2020-10-02 11:07:52 +02:00
|
|
|
|
var $tag = $('<span/>').append(
|
|
|
|
|
$('<i/>').addClass('fa fa-' + tagData.GalaxyCluster.Galaxy.icon).css('margin-right', '5px'),
|
|
|
|
|
$('<span/>').text(tagData.GalaxyCluster.type + ' ↦ ' + tagData.GalaxyCluster.value)
|
|
|
|
|
)
|
|
|
|
|
.addClass('tag')
|
|
|
|
|
.css({
|
|
|
|
|
'background-color': tagData.Tag.colour,
|
|
|
|
|
'color': getTextColour(tagData.Tag.colour),
|
|
|
|
|
'box-shadow': '3px 3px 3px #888888',
|
2020-10-02 11:52:20 +02:00
|
|
|
|
'border': (addBorder ? '1px solid #000' : 'none')
|
2020-10-02 11:07:52 +02:00
|
|
|
|
})
|
|
|
|
|
return $tag
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-01 16:55:17 +02:00
|
|
|
|
function constructTaxonomyInfo(tagData) {
|
|
|
|
|
var cacheKey = eventid + '-' + tagData.Tag.name
|
|
|
|
|
var tagHTML = cache_tag[cacheKey]
|
|
|
|
|
var $tag = $(tagHTML)
|
|
|
|
|
var $predicate = $('<div/>').append(
|
|
|
|
|
$('<span/>').append($tag),
|
|
|
|
|
$('<h3/>').text('Predicate info'),
|
|
|
|
|
$('<p/>').append(
|
|
|
|
|
$('<strong/>').text('Expanded tag: '),
|
|
|
|
|
$('<span/>').text(tagData.TaxonomyPredicate.expanded),
|
|
|
|
|
),
|
|
|
|
|
$('<p/>').append(
|
|
|
|
|
$('<strong/>').text('Description: '),
|
|
|
|
|
$('<span/>').text(tagData.TaxonomyPredicate.description),
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
var $meta = $('<div/>').append(
|
|
|
|
|
$('<h3/>').text('Taxonomy info'),
|
|
|
|
|
$('<p/>').append(
|
|
|
|
|
$('<strong/>').text(tagData.Taxonomy.namespace + ': '),
|
|
|
|
|
$('<span/>').text(tagData.Taxonomy.description),
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
return $('<div/>').append($predicate, $meta)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function constructGalaxyInfo(tagData) {
|
|
|
|
|
var cacheKey = eventid + '-' + tagData.Tag.name
|
|
|
|
|
var tagHTML = cache_tag[cacheKey]
|
|
|
|
|
var $tag = $(tagHTML)
|
|
|
|
|
var $cluster = $('<div/>').append(
|
|
|
|
|
$('<span/>').append($tag),
|
|
|
|
|
$('<h3/>').text('Cluster info'),
|
|
|
|
|
)
|
|
|
|
|
var fields = ['description', 'source', 'author']
|
|
|
|
|
fields.forEach(function(field) {
|
|
|
|
|
$cluster.append(
|
|
|
|
|
$('<div/>').css({
|
|
|
|
|
'max-height': '100px',
|
|
|
|
|
'overflow-y': 'auto',
|
|
|
|
|
})
|
|
|
|
|
.append(
|
|
|
|
|
$('<strong/>').text(field + ': '),
|
|
|
|
|
$('<span/>').text(tagData.GalaxyCluster[field] === undefined || tagData.GalaxyCluster[field].length == 0 ? '-' : tagData.GalaxyCluster[field]),
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
var $clusterMeta = $('<div/>').css({
|
|
|
|
|
'height': '100px',
|
|
|
|
|
'overflow-y': 'auto',
|
|
|
|
|
'resize': 'vertical',
|
|
|
|
|
'border': '1px solid #0088cc',
|
|
|
|
|
'border-radius': '3px',
|
|
|
|
|
'padding': '5px'
|
|
|
|
|
})
|
|
|
|
|
if (tagData.GalaxyCluster.meta !== undefined) {
|
|
|
|
|
Object.keys(tagData.GalaxyCluster.meta).forEach(function(metaKey) {
|
|
|
|
|
var metaValue = tagData.GalaxyCluster.meta[metaKey]
|
|
|
|
|
$clusterMeta.append(
|
|
|
|
|
$('<div/>').append(
|
|
|
|
|
$('<strong/>').addClass('blue').text(metaKey + ': '),
|
|
|
|
|
$('<span/>').text(metaValue),
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
$cluster.append($clusterMeta)
|
|
|
|
|
var $galaxy = $('<div/>').append(
|
|
|
|
|
$('<h3/>').text('Galaxy info'),
|
|
|
|
|
$('<div/>').append(
|
|
|
|
|
$('<div/>').append(
|
|
|
|
|
$('<strong/>').text('Name: '),
|
|
|
|
|
$('<span/>').text(tagData.GalaxyCluster.Galaxy.name),
|
|
|
|
|
),
|
|
|
|
|
$('<div/>').append(
|
|
|
|
|
$('<strong/>').text('Description: '),
|
|
|
|
|
$('<span/>').text(tagData.GalaxyCluster.Galaxy.description),
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
return $('<div/>').append($cluster, $galaxy)
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-14 08:33:59 +02:00
|
|
|
|
function getContentFromMISPElementDOM() {
|
|
|
|
|
var data = getElementFromDom(this)
|
|
|
|
|
if (data !== false) {
|
2020-10-05 14:07:51 +02:00
|
|
|
|
if (data.scope == 'attribute' && isValidObjectAttribute(data.element)) {
|
|
|
|
|
data.scope = 'object'
|
|
|
|
|
data.element = getObjectFromAttribute(data.element)
|
|
|
|
|
}
|
2020-09-14 08:33:59 +02:00
|
|
|
|
if (data.scope == 'attribute') {
|
|
|
|
|
var $thead = constructAttributeHeader(data.element)
|
|
|
|
|
var $row = constructAttributeRow(data.element)
|
|
|
|
|
var $attribute = $('<div/>').append(
|
|
|
|
|
$('<table/>')
|
|
|
|
|
.addClass('table table-condensed')
|
|
|
|
|
.append($thead)
|
|
|
|
|
.append($('<tbody/>').append($row))
|
|
|
|
|
)
|
|
|
|
|
return $attribute.html()
|
|
|
|
|
} else if (data.scope == 'object') {
|
|
|
|
|
var $object = constructObject(data.element)
|
|
|
|
|
return $object.html()
|
2020-10-01 16:55:17 +02:00
|
|
|
|
} else if (data.scope == 'tag') {
|
|
|
|
|
var $tag = constructTag(data.elementID)
|
|
|
|
|
return $tag.html()
|
2020-09-14 08:33:59 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return invalidMessage
|
2020-10-01 16:55:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-05 14:07:51 +02:00
|
|
|
|
function isValidObjectAttribute(attribute) {
|
|
|
|
|
var mispObject = getObjectFromAttribute(attribute)
|
|
|
|
|
return attribute.object_relation !== null && mispObject !== undefined
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getObjectFromAttribute(attribute) {
|
|
|
|
|
return proxyMISPElements['object'][attribute.object_uuid]
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-01 16:55:17 +02:00
|
|
|
|
function parseTag(str, pos, max) {
|
|
|
|
|
var level = 0
|
|
|
|
|
var lines = 0
|
|
|
|
|
var code
|
|
|
|
|
var start = pos
|
|
|
|
|
var result = {
|
|
|
|
|
ok: false,
|
|
|
|
|
pos: 0,
|
|
|
|
|
lines: 0,
|
|
|
|
|
str: ''
|
|
|
|
|
};
|
|
|
|
|
while (pos < max) {
|
|
|
|
|
code = str.charCodeAt(pos);
|
|
|
|
|
|
|
|
|
|
// ascii control characters
|
|
|
|
|
if (code < 0x20 || code === 0x7F) { break; }
|
|
|
|
|
|
|
|
|
|
if (code === 0x5C /* \ */ && pos + 1 < max) {
|
|
|
|
|
pos += 2;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (code === 0x28 /* ( */) {
|
|
|
|
|
level++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (code === 0x29 /* ) */) {
|
|
|
|
|
level--;
|
2020-10-02 14:15:44 +02:00
|
|
|
|
if (level === 0) {
|
|
|
|
|
pos++;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-10-01 16:55:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pos++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (start === pos) { return result; }
|
|
|
|
|
if (level !== 0) { return result; }
|
|
|
|
|
|
|
|
|
|
result.str = md.utils.unescapeAll(str.slice(start, pos));
|
|
|
|
|
result.lines = lines;
|
|
|
|
|
result.pos = pos;
|
|
|
|
|
result.ok = true;
|
|
|
|
|
return result;
|
2020-09-14 08:33:59 +02:00
|
|
|
|
}
|