diff --git a/app/Controller/Component/RestResponseComponent.php b/app/Controller/Component/RestResponseComponent.php index 3938a522c..1c30fd4ba 100644 --- a/app/Controller/Component/RestResponseComponent.php +++ b/app/Controller/Component/RestResponseComponent.php @@ -1533,7 +1533,10 @@ class RestResponseComponent extends Component $field['values'] = array_keys(ClassRegistry::init("Attribute")->categoryDefinitions); } private function __overwriteDistribution($scope, &$field) { - $field['values'] = array_keys(ClassRegistry::init("Attribute")->distributionLevels); + $field['values'] = array(); + foreach(ClassRegistry::init("Attribute")->distributionLevels as $d => $text) { + $field['values'][] = array('label' => $text, 'value' => $d); + } } private function __overwriteTags($scope, &$field) { $this->{$scope} = ClassRegistry::init("Tag"); diff --git a/app/files/warninglists b/app/files/warninglists index 04e8f468d..3ededf3dd 160000 --- a/app/files/warninglists +++ b/app/files/warninglists @@ -1 +1 @@ -Subproject commit 04e8f468d9b789956adb1bea44fa108c4012229f +Subproject commit 3ededf3ddf92573e1037305859857418f73fdf25 diff --git a/app/webroot/js/misp.js b/app/webroot/js/misp.js index f12ad86de..e2dc54a32 100644 --- a/app/webroot/js/misp.js +++ b/app/webroot/js/misp.js @@ -4101,54 +4101,6 @@ function submit_feed_overlap_tool(feedId) { }); } -function populate_rest_history(scope) { - if (scope === 'history') { - scope = ''; - var container_class = 'history_queries'; - } else { - scope = '1'; - var container_class = 'bookmarked_queries'; - } - $.get("/rest_client_history/index/" + scope, function(data) { - $('.' + container_class).html(data); - }); -} - -function loadRestClientHistory(k, data_container) { - $('#ServerMethod').val(data_container[k]['RestClientHistory']['http_method']); - $('#ServerUseFullPath').prop("checked", data_container[k]['RestClientHistory']['use_full_path']); - $('#ServerShowResult').prop("checked", data_container[k]['RestClientHistory']['show_result']); - $('#ServerSkipSslValidation').prop("checked", data_container[k]['RestClientHistory']['skip_ssl_validation']); - $('#ServerUrl').val(data_container[k]['RestClientHistory']['url']); - $('#ServerHeader').val(data_container[k]['RestClientHistory']['headers']); - $('#ServerBody').val(data_container[k]['RestClientHistory']['body']); - toggleRestClientBookmark(); -} - -function toggleRestClientBookmark() { - if ($('#ServerBookmark').prop("checked") == true) { - $('#bookmark-name').css('display', 'block'); - } else { - $('#bookmark-name').css('display', 'none'); - } -} - -function removeRestClientHistoryItem(id) { - $.ajax({ - data: '[]', - success:function (data, textStatus) { - populate_rest_history('bookmark'); - populate_rest_history('history'); - }, - error:function() { - handleGenericAjaxResponse({'saved':false, 'errors':['Request failed due to an unexpected error.']}); - }, - type:"post", - cache: false, - url: '/rest_client_history/delete/' + id, - }); -} - function changeTaxonomyRequiredState(checkbox) { var checkbox_state = $(checkbox).is(":checked"); var taxonomy_id = $(checkbox).data('taxonomy-id'); diff --git a/app/webroot/js/restClient.js b/app/webroot/js/restClient.js index cefd5da78..0b33190f7 100644 --- a/app/webroot/js/restClient.js +++ b/app/webroot/js/restClient.js @@ -31,6 +31,61 @@ function setApiInfoBox(isTyping) { } } +function loadRestClientHistory(k, data_container) { + $('#ServerMethod').val(data_container[k]['RestClientHistory']['http_method']); + $('#ServerUseFullPath').prop("checked", data_container[k]['RestClientHistory']['use_full_path']); + $('#ServerShowResult').prop("checked", data_container[k]['RestClientHistory']['show_result']); + $('#ServerSkipSslValidation').prop("checked", data_container[k]['RestClientHistory']['skip_ssl_validation']); + $('#ServerUrl').val(data_container[k]['RestClientHistory']['url']); + $('#ServerHeader').val(data_container[k]['RestClientHistory']['headers']); + toggleRestClientBookmark(); + $('#ServerBody').val(data_container[k]['RestClientHistory']['body']); + $('#TemplateSelect').val(data_container[k]['RestClientHistory']['url']).trigger("chosen:updated"); + updateQueryTool(data_container[k]['RestClientHistory']['url'], false); + $('#querybuilder').find('select').trigger('chosen:updated'); + setApiInfoBox(false); +} + +function populate_rest_history(scope) { + if (scope === 'history') { + scope = ''; + var container_class = 'history_queries'; + } else { + scope = '1'; + var container_class = 'bookmarked_queries'; + } + $.get("/rest_client_history/index/" + scope, function(data) { + $('.' + container_class).html(data); + }); +} + +function toggleRestClientBookmark() { + if ($('#ServerBookmark').prop("checked") == true) { + $('#bookmark-name').css('display', 'block'); + } else { + $('#bookmark-name').css('display', 'none'); + } +} + +function removeRestClientHistoryItem(id) { + $.ajax({ + data: '[]', + success:function (data, textStatus) { + populate_rest_history('bookmark'); + populate_rest_history('history'); + }, + error:function() { + handleGenericAjaxResponse({'saved':false, 'errors':['Request failed due to an unexpected error.']}); + }, + type:"post", + cache: false, + url: '/rest_client_history/delete/' + id, + }); +} + + + + var allValidApis; var fieldsConstraint; var querybuilderTool; @@ -87,7 +142,7 @@ function setApiInfoBox(isTyping) { $('#ServerUrl').data('urlWithoutParam', selected_template); $('#ServerBody').val(allValidApis[selected_template].body); setApiInfoBox(false); - updateQueryTool(selected_template); + updateQueryTool(selected_template, true); } }); @@ -150,9 +205,18 @@ function setApiInfoBox(isTyping) { }); -function updateQueryTool(url) { +function updateQueryTool(url, isEmpty) { var apiJson = allValidApis[url]; var filtersJson = fieldsConstraint[url]; + + isEmpty = isEmpty === undefined ? false : isEmpty; + var body = $('#ServerBody').val(); + if (!isEmpty && body !== undefined && body.length > 0) { + body = JSON.parse(body); + } else { + body = {}; + } + var filters = []; for (var k in filtersJson) { if (filtersJson.hasOwnProperty(k)) { @@ -196,6 +260,11 @@ function updateQueryTool(url) { }; mandatoryFields.forEach(function(mandatory) { var r = filtersJson[mandatory]; + var action = r.id.split('.')[1]; + if (body[action] !== undefined) { + r.value = body[action]; + delete body[action]; + } r.flags = { no_delete: true, filter_readonly: true @@ -211,6 +280,21 @@ function updateQueryTool(url) { }; } + Object.keys(body).forEach(function(k) { + var values = body[k]; + if (Array.isArray(values)) { + values.forEach(function(value) { + var r = $.extend({}, filtersJson[k], true); + r.value = value; + rules.rules[0].rules.push(r); + }); + } else { + var r = filtersJson[k]; + r.value = values; + rules.rules[0].rules.push(r); + } + }); + // add Params input field var paramFields = apiJson.params; $('#divAdditionalParamInput').remove();