String.prototype.ucfirst = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
}
function deleteObject(type, action, id, event) {
var destination = 'attributes';
var alternateDestinations = ['shadow_attributes', 'template_elements', 'taxonomies', 'objects', 'object_references'];
if (alternateDestinations.indexOf(type) > -1) destination = type;
else destination = type;
url = "/" + destination + "/" + action + "/" + id;
$.get(url, function(data) {
openPopup("#confirmation_box");
$("#confirmation_box").html(data);
});
}
function quickDeleteSighting(id, rawId, context) {
url = "/sightings/quickDelete/" + id + "/" + rawId + "/" + context;
$.get(url, function(data) {
$("#confirmation_box").html(data);
openPopup("#confirmation_box");
});
}
function publishPopup(id, type) {
var action = "alert";
if (type == "publish") action = "publish";
var destination = 'attributes';
$.get( "/events/" + action + "/" + id, function(data) {
$("#confirmation_box").html(data);
openPopup("#confirmation_box");
});
}
function delegatePopup(id) {
simplePopup("/event_delegations/delegateEvent/" + id);
}
function genericPopup(url, popupTarget, callback) {
$.get(url, function(data) {
$(popupTarget).html(data);
$(popupTarget).fadeIn();
left = ($(window).width() / 2) - ($(popupTarget).width() / 2);
$(popupTarget).css({'left': left + 'px'});
$("#gray_out").fadeIn();
if (callback !== undefined) {
callback();
}
});
}
function screenshotPopup(screenshotData, title) {
popupHtml = '';
popupHtml += '
'+item.text+' | '; popupHtml += '
")[1].split("")[0]; $("#UserGpgkey").val(result); showMessage('success', "Key found!"); }, error: function (data, textStatus, errorThrown) { showMessage('fail', textStatus + ": " + errorThrown); } }); } function lookupPGPKey(emailFieldName) { simplePopup("/users/fetchPGPKey/" + $('#' + emailFieldName).val()); } function zeroMQServerAction(action) { $.ajax({ type: "get", url: "/servers/" + action + "ZeroMQServer/", beforeSend: function (XMLHttpRequest) { $(".loading").show(); }, success: function (data) { $(".loading").hide(); if (action !== 'status') { window.location.reload(); } else { $("#confirmation_box").html(data); openPopup("#confirmation_box"); } }, error: function (data, textStatus, errorThrown) { showMessage('fail', textStatus + ": " + errorThrown); } }); } function convertServerFilterRules(rules) { validOptions.forEach(function (type) { container = "#"+ modelContext + type.ucfirst() + "Rules"; if($(container).val() != '') rules[type] = JSON.parse($(container).val()); }); serverRuleUpdate(); return rules; } function serverRuleUpdate() { var statusOptions = ["OR", "NOT"]; validOptions.forEach(function(type) { validFields.forEach(function(field) { if (type === 'push') { var indexedList = {}; window[field].forEach(function(item) { indexedList[item.id] = item.name; }); } statusOptions.forEach(function(status) { if (rules[type][field][status].length > 0) { $('#' + type + '_' + field + '_' + status).show(); var t = ''; rules[type][field][status].forEach(function(item) { if (t.length > 0) t += ', '; if (type === 'pull') t += item; else t += indexedList[item]; }); $('#' + type + '_' + field + '_' + status + '_text').text(t); } else { $('#' + type + '_' + field + '_' + status).hide(); } }); }); }); serverRuleGenerateJSON(); } function serverRuleFormActivate(type) { if (type != 'pull' && type != 'push') return false; $('.server_rule_popover').hide(); $('#gray_out').fadeIn(); $('#server_' + type + '_rule_popover').show(); } function serverRuleCancel() { $("#gray_out").fadeOut(); $(".server_rule_popover").fadeOut(); } function serverRuleGenerateJSON() { validOptions.forEach(function(type) { if ($('#Server' + type.ucfirst() + "Rules").length) { $('#Server' + type.ucfirst() + "Rules").val(JSON.stringify(rules[type])); } else { $('#Feed' + type.ucfirst() + "Rules").val(JSON.stringify(rules[type])); } }); } function serverRulePopulateTagPicklist() { var fields = ["tags", "orgs"]; var target = ""; fields.forEach(function(field) { target = ""; window[field].forEach(function(element) { if ($.inArray(element.id, rules["push"][field]["OR"]) != -1) target = "#" + field + "pushLeftValues"; else if ($.inArray(element.id, rules["push"][field]["NOT"]) != -1) target = "#" + field + "pushRightValues"; else target = "#" + field + "pushMiddleValues"; $(target).append($('', { value: element.id, text : element.name })); }); target = "#" + field + "pullLeftValues"; rules["pull"][field]["OR"].forEach(function(t) { $(target).append($('', { value: t, text : t })); }); target = "#" + field + "pullRightValues"; rules["pull"][field]["NOT"].forEach(function(t) { $(target).append($('', { value: t, text : t })); }); }); } function submitServerRulePopulateTagPicklistValues(context) { validFields.forEach(function(field) { rules[context][field]["OR"] = []; $("#" + field + context + "LeftValues option").each(function() { rules[context][field]["OR"].push($(this).val()); }); rules[context][field]["NOT"] = []; $("#" + field + context + "RightValues option").each(function() { rules[context][field]["NOT"].push($(this).val()); }); }); $('#server_' + context + '_rule_popover').fadeOut(); $('#gray_out').fadeOut(); serverRuleUpdate(); } // type = pull/push, field = tags/orgs, from = Left/Middle/Right, to = Left/Middle/Right function serverRuleMoveFilter(type, field, from, to) { var opposites = {"Left": "Right", "Right": "Left"}; // first fetch the value var value = ""; if (type == "pull" && from == "Middle") { var doInsert = true; value = $("#" + field + type + "NewValue").val(); if (value.length !== 0 && value.trim()) { $("#" + field + type + to + "Values" + " option").each(function() { if (value == $(this).val()) doInsert = false; }); $("#" + field + type + opposites[to] + "Values" + " option").each(function() { if (value == $(this).val()) $(this).remove(); }); if (doInsert) { $("#" + field + type + to + "Values").append($('', { value: value, text : value })); } } $("#" + field + type + "NewValue").val(''); } else { $("#" + field + type + from + "Values option:selected").each(function () { if (type != "pull" || to != "Middle") { value = $(this).val(); text = $(this).text(); $("#" + field + type + to + "Values").append($('', { value: value, text : text })); } $(this).remove(); }); } } function syncUserSelected() { if ($('#UserRoleId :selected').val() in syncRoles) { $('#syncServers').show(); } else { $('#syncServers').hide(); } } function filterAttributes(filter, id) { url = "/events/viewEventAttributes/" + id + "/attributeFilter:" + filter; if(filter === 'value'){ filter = $('#attributesFilterField').val().trim(); url += "/searchFor:" + filter; } else if(filter !== 'all') { url += "/filterColumnsOverwrite:" + filter; filter = $('#attributesFilterField').val().trim(); url += "/searchFor:" + filter; } if (deleted) url += '/deleted:true'; $.ajax({ type:"get", url:url, beforeSend: function (XMLHttpRequest) { $(".loading").show(); }, success:function (data) { $("#attributes_div").html(data); $(".loading").hide(); }, error:function() { showMessage('fail', 'Something went wrong - could not fetch attributes.'); } }); } function pivotObjectReferences(url, uuid) { url += '/focus:' + uuid; console.log(url); $.ajax({ type:"get", url:url, beforeSend: function (XMLHttpRequest) { $(".loading").show(); }, success:function (data) { $("#attributes_div").html(data); $(".loading").hide(); }, error:function() { showMessage('fail', 'Something went wrong - could not fetch attributes.'); } }); } function toggleDeletedAttributes(url) { url = url.replace(/view\//i, 'viewEventAttributes/'); if (url.indexOf('deleted:') > -1) { url = url.replace(/\/deleted:[^\/]*/i, ''); } else { url = url + '/deleted:true' } $.ajax({ type:"get", url:url, beforeSend: function (XMLHttpRequest) { $(".loading").show(); }, success:function (data) { $("#attributes_div").html(data); $(".loading").hide(); }, error:function() { showMessage('fail', 'Something went wrong - could not fetch attributes.'); } }); } function mergeOrganisationUpdate() { var orgTypeOptions = ['local', 'external']; var orgTypeSelects = ['OrganisationOrgsLocal', 'OrganisationOrgsExternal']; var orgTypeId = $('#OrganisationTargetType').val(); var orgType = orgTypeSelects[orgTypeId]; var orgID = $('#' + orgTypeSelects[orgTypeId]).val(); console.log(orgTypeSelects[orgTypeId]); console.log(orgID); org = orgArray[orgTypeOptions[orgTypeId]][orgID]['Organisation']; console.log(org); $('#org_id').text(org['id']); $('#org_name').text(org['name']); $('#org_uuid').text(org['uuid']); $('#org_local').text(orgTypeOptions[$('#OrganisationTargetType').val()]); } function mergeOrganisationTypeToggle() { if ($('#OrganisationTargetType').val() == 0) { $('#orgsLocal').show(); $('#orgsExternal').hide(); } else { $('#orgsLocal').hide(); $('#orgsExternal').show(); } } function feedDistributionChange() { if ($('#FeedDistribution').val() == 4) $('#SGContainer').show(); else $('#SGContainer').hide(); } function checkUserPasswordEnabled() { if ($('#UserEnablePassword').is(':checked')) { $('#PasswordDiv').show(); } else { $('#PasswordDiv').hide(); } } function checkUserExternalAuth() { if ($('#UserExternalAuthRequired').is(':checked')) { $('#externalAuthDiv').show(); $('#passwordDivDiv').hide(); } else { $('#externalAuthDiv').hide(); $('#passwordDivDiv').show(); } } function toggleSettingSubGroup(group) { $('.subGroup_' + group).toggle(); } function runHoverLookup(type, id) { $.ajax({ success:function (html) { ajaxResults[type + "_" + id] = html; $('.popover').remove(); $('#' + type + '_' + id + '_container').popover({ title: 'Lookup results:', content: html, placement: 'top', html: true, trigger: 'hover', container: 'body' }).popover('show'); }, cache: false, url:"/attributes/hoverEnrichment/" + id, }); } $(".eventViewAttributeHover").mouseenter(function() { $('.popover').remove(); type = $(this).attr('data-object-type'); id = $(this).attr('data-object-id'); if (type + "_" + id in ajaxResults) { $('#' + type + '_' + id + '_container').popover({ title: 'Lookup results:', content: ajaxResults[type + "_" + id], placement: 'top', html: true, trigger: 'hover', container: 'body' }).popover('show'); } else { timer = setTimeout(function() { runHoverLookup(type, id) }, 500 ); } }).mouseleave(function() { clearTimeout(timer); }); $(".queryPopover").click(function() { url = $(this).data('url'); id = $(this).data('id'); $.get(url + '/' + id, function(data) { $('#popover_form').html(data); openPopup('#popover_form'); }); }); function serverOwnerOrganisationChange(host_org_id) { if ($('#ServerOrganisationType').val() == "0" && $('#ServerLocal').val() == host_org_id) { $('#InternalDiv').show(); } else { $('#ServerInternal').prop("checked", false); $('#InternalDiv').hide(); } } function requestAPIAccess() { url = "/users/request_API/"; $.ajax({ type:"get", url:url, beforeSend: function (XMLHttpRequest) { $(".loading").show(); }, success:function (data) { $(".loading").hide(); handleGenericAjaxResponse(data); }, error:function() { showMessage('fail', 'Something went wrong - could not request API access.'); } }); } function initPopoverContent(context) { for (var property in formInfoFields) { if (formInfoFields.hasOwnProperty(property)) { $('#' + property + 'InfoPopover').popover("destroy").popover({ placement: 'right', html: 'true', trigger: 'hover', content: getFormInfoContent(property, '#' + context + formInfoFields[property]) }); } } } function getFormInfoContent(property, field) { var content = window[property + 'FormInfoValues'][$(field).val()]; if (content === undefined || content === null) { return 'N/A'; } return content; } function formCategoryChanged(id) { // fill in the types var options = $('#' + id +'Type').prop('options'); $('option', $('#' + id +'Type')).remove(); $.each(category_type_mapping[$('#' + id +'Category').val()], function(val, text) { options[options.length] = new Option(text, val); }); // enable the form element $('#AttributeType').prop('disabled', false); } function malwareCheckboxSetter(context) { idDiv = "#" + context + "Category" +'Div'; var value = $("#" + context + "Category").val(); // get the selected value // set the malware checkbox if the category is in the zip types $("#" + context + "Malware").prop('checked', formZipTypeValues[value] == "true"); } function feedFormUpdate() { $('.optionalField').hide(); switch($('#FeedSourceFormat').val()) { case 'freetext': $('#TargetDiv').show(); $('#OverrideIdsDiv').show(); $('#PublishDiv').show(); if ($('#FeedTarget').val() != 0) { $('#TargetEventDiv').show(); $('#DeltaMergeDiv').show(); } $('#settingsCommonExcluderegexDiv').show(); break; case 'csv': $('#TargetDiv').show(); $('#OverrideIdsDiv').show(); $('#PublishDiv').show(); if ($('#FeedTarget').val() != 0) { $('#TargetEventDiv').show(); $('#DeltaMergeDiv').show(); } $('#settingsCsvValueDiv').show(); $('#settingsCsvDelimiterDiv').show(); $('#settingsCommonExcluderegexDiv').show(); break; } if ($('#FeedInputSource').val() == 'local') { $('#DeleteLocalFileDiv').show(); $('#HeadersDiv').hide(); } else { $('#DeleteLocalFileDiv').hide(); $('#HeadersDiv').show(); } } $('.servers_default_role_checkbox').click(function() { var id = $(this).data("id"); var state = $(this).is(":checked"); $(".servers_default_role_checkbox").not(this).attr('checked', false); $.ajax({ beforeSend: function (XMLHttpRequest) { $(".loading").show(); }, success:function (data, textStatus) { handleGenericAjaxResponse(data); }, complete:function() { $(".loading").hide(); }, type:"get", cache: false, url: '/admin/roles/set_default/' + (state ? id : ""), }); }); function setContextFields() { if (showContext) { $('.context').show(); $('#show_context').addClass("attribute_filter_text_active"); $('#show_context').removeClass("attribute_filter_text"); } else { $('.context').hide(); $('#show_context').addClass("attribute_filter_text"); $('#show_context').removeClass("attribute_filter_text_active"); } } function toggleContextFields() { if (!showContext) { showContext = true; } else { showContext = false; } setContextFields(); } function checkOrphanedAttributes() { $.ajax({ beforeSend: function (XMLHttpRequest) { $(".loading").show(); }, success:function (data, textStatus) { var color = 'red'; var text = ' (Removal recommended)'; if (data == '0') { color = 'green'; text = ' (OK)'; } $("#orphanedAttributeCount").html('' + data + text + ''); }, complete:function() { $(".loading").hide(); }, type:"get", cache: false, url: "/attributes/checkOrphanedAttributes/", }); } function checkAttachments() { $.ajax({ beforeSend: function (XMLHttpRequest) { $(".loading").show(); }, success:function (data, textStatus) { var color = 'red'; var text = ' (Bad links detected)'; if (data !== undefined && data.trim() == '0') { color = 'green'; text = ' (OK)'; } $("#orphanedFileCount").html('' + data + text + ''); }, complete:function() { $(".loading").hide(); }, type:"get", cache: false, url: "/attributes/checkAttachments/", }); } function loadTagTreemap() { $.ajax({ async:true, beforeSend: function (XMLHttpRequest) { $(".loading").show(); }, success:function (data, textStatus) { $(".treemapdiv").html(data); }, complete:function() { $(".loading").hide(); }, type:"get", cache: false, url: "/users/tagStatisticsGraph", }); } function loadSightingsData(timestamp) { url = "/sightings/toplist"; if (timestamp != undefined) { url = url + '/' + timestamp; } $.ajax({ async:true, beforeSend: function (XMLHttpRequest) { $(".loading").show(); }, success:function (data, textStatus) { $(".sightingsdiv").html(data); }, complete:function() { $(".loading").hide(); }, type:"get", cache: false, url: url, }); } function quickEditEvent(id, field) { $.ajax({ async:true, beforeSend: function (XMLHttpRequest) { $(".loading").show(); }, success:function (data, textStatus) { $("#" + field + "Field").html(data); }, complete:function() { $(".loading").hide(); }, type:"get", cache: false, url: "/events/quickEdit/" + id + "/" + field, }); } function selectAllInbetween(last, current) { if (last === false || last == current) return false; var from = $('#' + last).parent().parent().index(); var to = $('#' + current).parent().parent().index(); if (to < from) { var temp = from; from = to; to = temp; } $('.select_proposal, .select_attribute').each(function () { if ($('#' + this.id).parent().parent().index() >= from && $('#' + this.id).parent().parent().index() <= to) { $(this).prop('checked', true); } }); } $('.galaxy-toggle-button').click(function() { var element = $(this).data('toggle-type'); if ($(this).children('span').hasClass('icon-minus')) { $(this).children('span').addClass('icon-plus'); $(this).children('span').removeClass('icon-minus'); $('#' + element + '_div').hide(); } else { $(this).children('span').removeClass('icon-plus'); $(this).children('span').addClass('icon-minus'); $('#' + element + '_div').show(); } }); $('.addGalaxy').click(function() { var target_type = $(this).data('target-type'); var target_id = $(this).data('target-id'); getPopup(target_type + '/' + target_id, 'galaxies', 'selectGalaxy'); }); function quickSubmitGalaxyForm(event_id, cluster_id) { $('#GalaxyTargetId').val(cluster_id); $('#GalaxySelectClusterForm').submit(); return false; } function checkAndSetPublishedInfo() { var id = $('#hiddenSideMenuData').data('event-id'); $.get( "/events/checkPublishedStatus/" + id, function(data) { if (data == 1) { $('.published').removeClass('hidden'); $('.not-published').addClass('hidden'); } else { $('.published').addClass('hidden'); $('.not-published').removeClass('hidden'); } }); } $(document).keyup(function(e){ if (e.keyCode === 27) { $("#gray_out").fadeOut(); $("#popover_form").fadeOut(); $("#screenshot_box").fadeOut(); $("#confirmation_box").fadeOut(); $(".loading").hide(); resetForms(); } }); function closeScreenshot() { $("#screenshot_box").fadeOut(); $("#gray_out").fadeOut(); } function loadSightingGraph(id, scope) { $.get( "/sightings/viewSightings/" + id + "/" + scope, function(data) { $("#sightingsData").html(data); }); } function checkRolePerms() { if ($("#RolePermission").val() == '0' || $("#RolePermission").val() == '1') { $('.readonlydisabled').prop('checked', false); $('.readonlydisabled').hide(); } else { $('.readonlydisabled').show(); $('.permFlags').show(); } if ($("#RolePermSiteAdmin").prop('checked')) { $('.checkbox').prop('checked', true); } } // clicking on an element with this class will select all of its contents in a // single click $('.quickSelect').click(function() { var range = document.createRange(); var selection = window.getSelection(); range.selectNodeContents(this); selection.removeAllRanges(); selection.addRange(range); }); function updateMISP() { $.get( "/servers/update", function(data) { $("#confirmation_box").html(data); openPopup("#confirmation_box"); }); } function submitMISPUpdate() { var formData = $('#PromptForm').serialize(); $.ajax({ beforeSend: function (XMLHttpRequest) { $(".loading").show(); }, data: formData, success:function (data, textStatus) { $('#gitResult').text(data); $('#gitResult').removeClass('hidden'); }, complete:function() { $(".loading").hide(); $("#confirmation_box").fadeOut(); $("#gray_out").fadeOut(); }, type:"post", cache: false, url:"/servers/update", }); } $(".cortex-json").click(function() { var cortex_data = $(this).data('cortex-json'); // BUG: CWE-79 Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') // cortex_data = JSON.stringify(cortex_data, null, 2); // FIXED: cortex_data = htmlEncode(JSON.stringify(cortex_data, null, 2)); var popupHtml = '
' + cortex_data + ''; popupHtml += ''; $('#screenshot_box').html(popupHtml); $('#screenshot_box').show(); $('#screenshot_box').css({'padding': '5px'}); left = ($(window).width() / 2) - ($('#screenshot_box').width() / 2); if (($('#screenshot_box').height() + 250) > $(window).height()) { $('#screenshot_box').height($(window).height() - 250); $('#screenshot_box').css("overflow-y", "scroll"); $('#screenshot_box').css("overflow-x", "hidden"); } $('#screenshot_box').css({'left': left + 'px'}); $("#gray_out").fadeIn(); }); // Show $(id) if the enable parameter evaluates to true. Hide it otherwise function checkAndEnable(id, enable) { if (enable) { $(id).show(); } else { $(id).hide(); } } // Show and enable checkbox $(id) if the enable parameter evaluates to true. Hide and disable it otherwise. function checkAndEnableCheckbox(id, enable) { if (enable) { $(id).removeAttr("disabled"); $(id).prop('checked', true); } else { $(id).prop('checked', false); $(id).attr("disabled", true); } } function enableDisableObjectRows(rows) { rows.forEach(function(i) { if ($("#Attribute" + i + "ValueSelect").length != 0) { checkAndEnableCheckbox("#Attribute" + i + "Save", true); } else if ($("#Attribute" + i + "Attachment").length != 0) { checkAndEnableCheckbox("#Attribute" + i + "Save", $("#Attribute" + i + "Attachment").val() != ""); } else { checkAndEnableCheckbox("#Attribute" + i + "Save", $("#Attribute" + i + "Value").val() != ""); } $("#Attribute" + i + "Value").bind('input propertychange', function() { checkAndEnableCheckbox("#Attribute" + i + "Save", $(this).val() != ""); }); $("#Attribute" + i + "Attachment").on('change', function() { checkAndEnableCheckbox("#Attribute" + i + "Save", $("#Attribute" + i + "Attachment").val() != ""); }); }); } function objectReferenceInput() { var types = ["Attribute", "Object"]; for (var type in types) { for (var k in targetEvent[types[type]]) { if (targetEvent[types[type]][k]['uuid'] == $('#ObjectReferenceReferencedUuid').val()) { $('#targetSelect').val($('#ObjectReferenceReferencedUuid').val()); changeObjectReferenceSelectOption(); } } } } function objectReferenceCheckForCustomRelationship() { var relationship_type_field = $('#ObjectReferenceRelationshipTypeSelect option:selected'); var relationship_type = $(relationship_type_field).val(); if (relationship_type == 'custom') { $('#ObjectReferenceRelationshipType').parent().removeClass('hidden'); } else { $('#ObjectReferenceRelationshipType').parent().addClass('hidden'); } } function add_basic_auth() { var headers = $('#FeedHeaders').val().split("\n"); $('#FeedHeaders').val(""); headers.forEach(function(header) { header = header.trim(); if (header != "") { header = header.split(":"); var key = header.shift(); var value = header.join(":"); if (key != 'Authorization') { $('#FeedHeaders').val($('#FeedHeaders').val() + key.trim() + ":" + value.trim() + "\n"); } } }); var basicAuth = $('#BasicAuthUsername').val().trim() + ':' + $('#BasicAuthPassword').val().trim(); $('#FeedHeaders').val($('#FeedHeaders').val() + "Authorization: Basic " + btoa(basicAuth) + "\n"); $('#basicAuthFormEnable').show(); $('#basicAuthForm').hide(); } function changeObjectReferenceSelectOption() { var object = $('#targetSelect option:selected'); var uuid = $(object).val(); $('#ObjectReferenceReferencedUuid').val(uuid); var type = $(object).data('type'); if (type == "Attribute") { $('#targetData').html(""); for (var k in targetEvent[type][uuid]) { if ($.inArray(k, ['uuid', 'category', 'type', 'value', 'to_ids']) !== -1) { $('#targetData').append('