mirror of https://github.com/MISP/MISP
new: [events:index] Multi-select export of events
parent
21997abc52
commit
3f9629ad0c
|
@ -246,6 +246,7 @@ class ACLComponent extends Component
|
|||
'reportValidationIssuesEvents' => array(),
|
||||
'restoreDeletedEvents' => array(),
|
||||
'restSearch' => array('*'),
|
||||
'restSearchExport' => array('*'),
|
||||
'runTaxonomyExclusivityCheck' => array('*'),
|
||||
'saveFreeText' => array('perm_add'),
|
||||
'stix' => array('*'),
|
||||
|
|
|
@ -3210,6 +3210,56 @@ class EventsController extends AppController
|
|||
return $difference . " " . $periods[$j] . " ago";
|
||||
}
|
||||
|
||||
public function restSearchExport($id=null)
|
||||
{
|
||||
if ($this->request->is('post') || $this->request->is('put')) {
|
||||
$returnFormat = empty($this->request->data['Event']['returnFormat']) ? 'json' : $this->request->data['Event']['returnFormat'];
|
||||
$idList = !isset($this->request->data['Event']['id']) ? $id : $this->request->data['Event']['id'];
|
||||
if (!is_array($idList)) {
|
||||
if (is_numeric($idList) || Validation::uuid($idList)) {
|
||||
$idList = array($idList);
|
||||
} else {
|
||||
$idList = $this->Event->jsonDecode($idList);
|
||||
}
|
||||
}
|
||||
if (empty($idList)) {
|
||||
throw new NotFoundException(__('Invalid input.'));
|
||||
}
|
||||
$filters = [
|
||||
'eventid' => $idList
|
||||
];
|
||||
|
||||
$elementCounter = 0;
|
||||
$renderView = false;
|
||||
$validFormat = $this->Event->validFormats[$returnFormat];
|
||||
$responseType = empty($validFormat[0]) ? 'json' : $validFormat[0];
|
||||
$final = $this->Event->restSearch($this->Auth->user(), $returnFormat, $filters, false, false, $elementCounter, $renderView);
|
||||
if (!empty($renderView) && !empty($final)) {
|
||||
$final = json_decode($final->intoString(), true);
|
||||
foreach ($final as $key => $data) {
|
||||
$this->set($key, $data);
|
||||
}
|
||||
$this->set('renderView', $renderView);
|
||||
$this->render('/Events/eventRestSearchExportResult');
|
||||
} else {
|
||||
$filename = $this->RestSearch->getFilename($filters, 'Event', $responseType);
|
||||
return $this->RestResponse->viewData($final, $responseType, false, true, $filename, array('X-Result-Count' => $elementCounter, 'X-Export-Module-Used' => $returnFormat, 'X-Response-Format' => $responseType));
|
||||
}
|
||||
} else {
|
||||
if (is_numeric($id)) {
|
||||
$idList = [$id];
|
||||
} else {
|
||||
$idList = json_decode($id, true);
|
||||
}
|
||||
if (empty($idList)) {
|
||||
throw new NotFoundException(__('Invalid input.'));
|
||||
}
|
||||
$this->request->data['Event']['id'] = json_encode($idList);
|
||||
$this->set('exportFormats', array_keys($this->Event->validFormats));
|
||||
$this->render('ajax/eventRestSearchExportConfirmationForm');
|
||||
}
|
||||
}
|
||||
|
||||
public function xml($key, $eventid = false, $withAttachment = false, $tags = false, $from = false, $to = false, $last = false)
|
||||
{
|
||||
$this->_legacyAPIRemap(array(
|
||||
|
|
|
@ -285,6 +285,13 @@ $divider = $this->element('/genericElements/SideMenu/side_menu_divider');
|
|||
}
|
||||
break;
|
||||
|
||||
case 'event_restsearch_export':
|
||||
echo $this->element('/genericElements/SideMenu/side_menu_link', array(
|
||||
'url' => $baseurl . '/events/index',
|
||||
'text' => __('List Events')
|
||||
));
|
||||
break;
|
||||
|
||||
case 'tag-collections':
|
||||
echo $this->element('/genericElements/SideMenu/side_menu_link', array(
|
||||
'url' => $baseurl . '/tag_collections/index',
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
$modelForForm = 'Event';
|
||||
echo $this->element('genericElements/Form/genericForm', [
|
||||
'form' => $this->Form,
|
||||
'data' => [
|
||||
'title' => __('Export the %s selected events into the selected format', count($idArray)),
|
||||
'model' => $modelForForm,
|
||||
'fields' => [
|
||||
[
|
||||
'field' => 'id',
|
||||
'type' => 'hidden',
|
||||
],
|
||||
[
|
||||
'field' => 'returnFormat',
|
||||
'label' => __('RestSearch Export Format'),
|
||||
'class' => 'input span6',
|
||||
'div' => 'input clear',
|
||||
'type' => 'select',
|
||||
'options' => Hash::combine($exportFormats, '{n}', '{n}'),
|
||||
],
|
||||
],
|
||||
'submit' => [
|
||||
'action' => $this->request->params['action'],
|
||||
],
|
||||
],
|
||||
]);
|
|
@ -0,0 +1,11 @@
|
|||
<div class="index">
|
||||
<div id="restSearchExportResult">
|
||||
<?php
|
||||
if (!empty($renderView)) {
|
||||
echo $this->render('/Events/module_views/' . $renderView, false);
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
if (!$ajax) echo $this->element('/genericElements/SideMenu/side_menu', array('menuList' => 'event_restsearch_export', 'menuItem' => 'result'));
|
|
@ -68,6 +68,13 @@
|
|||
'fa-icon' => 'trash',
|
||||
'class' => 'hidden mass-select',
|
||||
'onClick' => 'multiSelectDeleteEvents'
|
||||
),
|
||||
array(
|
||||
'id' => 'multi-export-button',
|
||||
'title' => __('Export selected events'),
|
||||
'fa-icon' => 'file-export',
|
||||
'class' => 'hidden mass-select',
|
||||
'onClick' => 'multiSelectExportEvents'
|
||||
)
|
||||
)
|
||||
),
|
||||
|
|
|
@ -905,6 +905,19 @@ function multiSelectDeleteEvents() {
|
|||
}).fail(xhrFailCallback);
|
||||
}
|
||||
|
||||
function multiSelectExportEvents() {
|
||||
var selected = [];
|
||||
$(".select").each(function() {
|
||||
if ($(this).is(":checked")) {
|
||||
var temp = $(this).data("id");
|
||||
if (temp != null) {
|
||||
selected.push(temp);
|
||||
}
|
||||
}
|
||||
});
|
||||
openGenericModal(baseurl + "/events/restSearchExport/" + JSON.stringify(selected))
|
||||
}
|
||||
|
||||
function multiSelectToggleFeeds(on, cache) {
|
||||
var selected = [];
|
||||
$(".select").each(function() {
|
||||
|
|
Loading…
Reference in New Issue