mirror of https://github.com/MISP/MISP
new: [api] CSV export using thin overlay over restsearch
parent
88944cb792
commit
be5b684893
|
@ -1147,6 +1147,7 @@ class EventsController extends AppController
|
||||||
}
|
}
|
||||||
$this->set('sightingTypes', $this->Sighting->type);
|
$this->set('sightingTypes', $this->Sighting->type);
|
||||||
$this->set('currentUri', $this->params->here);
|
$this->set('currentUri', $this->params->here);
|
||||||
|
$this->layout = false;
|
||||||
$this->render('/Elements/eventattribute');
|
$this->render('/Elements/eventattribute');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2682,7 +2683,7 @@ class EventsController extends AppController
|
||||||
return new CakeResponse(array('body'=> implode(PHP_EOL, $rules), 'status' => 200, 'type' => 'txt'));
|
return new CakeResponse(array('body'=> implode(PHP_EOL, $rules), 'status' => 200, 'type' => 'txt'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// csv function
|
// csv function ***DEPRECATED***
|
||||||
// Usage: csv($key, $eventid) - key can be a valid auth key or the string 'download'. Download requires the user to be logged in interactively and will generate a .csv file
|
// Usage: csv($key, $eventid) - key can be a valid auth key or the string 'download'. Download requires the user to be logged in interactively and will generate a .csv file
|
||||||
// $eventid can be one of 3 options: left empty it will get all the visible to_ids attributes,
|
// $eventid can be one of 3 options: left empty it will get all the visible to_ids attributes,
|
||||||
// $ignore is a flag that allows the export tool to ignore the ids flag. 0 = only IDS signatures, 1 = everything.
|
// $ignore is a flag that allows the export tool to ignore the ids flag. 0 = only IDS signatures, 1 = everything.
|
||||||
|
@ -2696,8 +2697,8 @@ class EventsController extends AppController
|
||||||
'ordered_url_params' => compact($paramArray)
|
'ordered_url_params' => compact($paramArray)
|
||||||
);
|
);
|
||||||
$exception = false;
|
$exception = false;
|
||||||
$params = $this->_harvestParameters($filterData, $exception);
|
$filters = $this->_harvestParameters($filterData, $exception);
|
||||||
if ($params === false) {
|
if ($filters === false) {
|
||||||
return $exception;
|
return $exception;
|
||||||
}
|
}
|
||||||
$list = array();
|
$list = array();
|
||||||
|
@ -2705,6 +2706,7 @@ class EventsController extends AppController
|
||||||
if ($user === false) {
|
if ($user === false) {
|
||||||
return $exception;
|
return $exception;
|
||||||
}
|
}
|
||||||
|
$final = $this->Event->restSearch($user, 'csv', $filters);
|
||||||
// if it's a search, grab the attributeIDList from the session and get the IDs from it. Use those as the condition
|
// if it's a search, grab the attributeIDList from the session and get the IDs from it. Use those as the condition
|
||||||
// We don't need to look out for permissions since that's filtered by the search itself
|
// We don't need to look out for permissions since that's filtered by the search itself
|
||||||
// We just want all the attributes found by the search
|
// We just want all the attributes found by the search
|
||||||
|
@ -2733,46 +2735,8 @@ class EventsController extends AppController
|
||||||
$list[] = $attribute['Attribute']['id'];
|
$list[] = $attribute['Attribute']['id'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$final = array();
|
$responseType = 'csv';
|
||||||
if (isset($params['eventid']) && $params['eventid'] == 'all') {
|
return $this->RestResponse->viewData($final, $responseType, false, true, 'download.csv');
|
||||||
unset($params['eventid']);
|
|
||||||
}
|
|
||||||
foreach ($possibleParams as $possibleParam) {
|
|
||||||
if (isset($params[$possibleParam])) {
|
|
||||||
$params[$possibleParam] = $params[$possibleParam];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$params['limit'] = 1000;
|
|
||||||
$params['page'] = 1;
|
|
||||||
$i = 0;
|
|
||||||
$continue = true;
|
|
||||||
$params = array_merge($params, array(
|
|
||||||
'requested_obj_attributes' => $requested_obj_attributes,
|
|
||||||
'requested_attributes' => $requested_attributes,
|
|
||||||
'includeContext' => $includeContext
|
|
||||||
));
|
|
||||||
App::uses('CsvExport', 'Export');
|
|
||||||
$export = new CsvExport();
|
|
||||||
$final = $export->header($params);
|
|
||||||
while ($continue) {
|
|
||||||
$attributes = $this->Event->csv($user, $params, false, $continue);
|
|
||||||
$params['page'] += 1;
|
|
||||||
$final .= $export->handler($attributes, $params);
|
|
||||||
$final .= $export->separator($attributes);
|
|
||||||
}
|
|
||||||
$export->footer();
|
|
||||||
$this->response->type('csv'); // set the content type
|
|
||||||
if (empty($params['eventid'])) {
|
|
||||||
$filename = "misp.filtered_attributes.csv";
|
|
||||||
} elseif ($params['eventid'] === 'search') {
|
|
||||||
$filename = "misp.search_result.csv";
|
|
||||||
} else {
|
|
||||||
if (is_array($params['eventid'])) {
|
|
||||||
$params['eventid'] = 'list';
|
|
||||||
}
|
|
||||||
$filename = "misp.event_" . $params['eventid'] . ".csv";
|
|
||||||
}
|
|
||||||
return $this->RestResponse->viewData($final, 'csv', false, true, $filename);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function _addIOCFile($id)
|
public function _addIOCFile($id)
|
||||||
|
@ -2993,16 +2957,6 @@ class EventsController extends AppController
|
||||||
'paramArray' => $paramArray,
|
'paramArray' => $paramArray,
|
||||||
'ordered_url_params' => compact($paramArray)
|
'ordered_url_params' => compact($paramArray)
|
||||||
);
|
);
|
||||||
$validFormats = array(
|
|
||||||
'openioc' => array('xml', 'OpeniocExport', 'ioc'),
|
|
||||||
'json' => array('json', 'JsonExport', 'json'),
|
|
||||||
'xml' => array('xml', 'XmlExport', 'xml'),
|
|
||||||
'suricata' => array('txt', 'NidsSuricataExport', 'rules'),
|
|
||||||
'snort' => array('txt', 'NidsSnortExport', 'rules'),
|
|
||||||
'rpz' => array('rpz', 'RPZExport', 'rpz'),
|
|
||||||
'text' => array('text', 'TextExport', 'txt'),
|
|
||||||
'csv' => array('csv', 'CsvExport', 'csv')
|
|
||||||
);
|
|
||||||
$exception = false;
|
$exception = false;
|
||||||
$filters = $this->_harvestParameters($filterData, $exception);
|
$filters = $this->_harvestParameters($filterData, $exception);
|
||||||
unset($filterData);
|
unset($filterData);
|
||||||
|
@ -3020,8 +2974,8 @@ class EventsController extends AppController
|
||||||
if ($returnFormat === 'download') {
|
if ($returnFormat === 'download') {
|
||||||
$returnFormat = 'json';
|
$returnFormat = 'json';
|
||||||
}
|
}
|
||||||
$final = $this->Event->restSearch($user, $validFormats, $returnFormat, $filters);
|
$final = $this->Event->restSearch($user, $returnFormat, $filters);
|
||||||
$responseType = $validFormats[$returnFormat][0];
|
$responseType = $this->Event->validFormats[$returnFormat][0];
|
||||||
return $this->RestResponse->viewData($final, $responseType, false, true);
|
return $this->RestResponse->viewData($final, $responseType, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue