mirror of https://github.com/MISP/MISP
chg: [UI] Event export description
parent
d8f2043d24
commit
2964335f04
|
@ -1462,16 +1462,7 @@ class AppController extends Controller
|
|||
protected function _jsonDecode($dataToDecode)
|
||||
{
|
||||
try {
|
||||
if (defined('JSON_THROW_ON_ERROR')) {
|
||||
// JSON_THROW_ON_ERROR is supported since PHP 7.3
|
||||
return json_decode($dataToDecode, true, 512, JSON_THROW_ON_ERROR);
|
||||
} else {
|
||||
$decoded = json_decode($dataToDecode, true);
|
||||
if ($decoded === null) {
|
||||
throw new UnexpectedValueException('Could not parse JSON: ' . json_last_error_msg(), json_last_error());
|
||||
}
|
||||
return $decoded;
|
||||
}
|
||||
return JsonTool::decode($dataToDecode);
|
||||
} catch (Exception $e) {
|
||||
throw new HttpException('Invalid JSON input. Make sure that the JSON input is a correctly formatted JSON string. This request has been blocked to avoid an unfiltered request.', 405, $e);
|
||||
}
|
||||
|
|
|
@ -3315,17 +3315,37 @@ class EventsController extends AppController
|
|||
|
||||
public function restSearchExport($id = null, $returnFormat = null)
|
||||
{
|
||||
if (is_null($returnFormat)) {
|
||||
if (is_numeric($id)) {
|
||||
$idList = [$id];
|
||||
} else {
|
||||
$idList = $this->_jsonDecode($id);
|
||||
}
|
||||
if ($returnFormat === null) {
|
||||
$exportFormats = [
|
||||
'attack' => __('Attack matrix'),
|
||||
'attack-sightings' => __('Attack matrix by sightings'),
|
||||
'context' => __('Aggregated context data'),
|
||||
'context-markdown' => __('Aggregated context data as Markdown'),
|
||||
'csv' => __('CSV'),
|
||||
'hashes' => __('Hashes'),
|
||||
'hosts' => __('Hosts file'),
|
||||
'json' => __('MISP JSON'),
|
||||
'netfilter' => __('Netfilter'),
|
||||
'opendata' => __('Open data'),
|
||||
'openioc' => __('OpenIOC'),
|
||||
'rpz' => __('RPZ'),
|
||||
'snort' => __('Snort rules'),
|
||||
'stix' => __('STIX 1 XML'),
|
||||
'stix-json' => __('STIX 1 JSON'),
|
||||
'stix2' => __('STIX 2'),
|
||||
'suricata' => __('Suricata rules'),
|
||||
'text' => __('Text file'),
|
||||
'xml' => __('MISP XML'),
|
||||
'yara' => __('YARA rules'),
|
||||
'yara-json' => __('YARA rules (JSON)'),
|
||||
];
|
||||
|
||||
$idList = is_numeric($id) ? [$id] : $this->_jsonDecode($id);
|
||||
if (empty($idList)) {
|
||||
throw new NotFoundException(__('Invalid input.'));
|
||||
}
|
||||
$this->set('idList', $idList);
|
||||
$this->set('exportFormats', array_keys($this->Event->validFormats));
|
||||
$this->set('exportFormats', $exportFormats);
|
||||
$this->render('ajax/eventRestSearchExportConfirmationForm');
|
||||
} else {
|
||||
$returnFormat = empty($this->Event->validFormats[$returnFormat]) ? 'json' : $returnFormat;
|
||||
|
@ -3349,11 +3369,9 @@ class EventsController extends AppController
|
|||
$validFormat = $this->Event->validFormats[$returnFormat];
|
||||
$responseType = $validFormat[0];
|
||||
$final = $this->Event->restSearch($this->Auth->user(), $returnFormat, $filters, false, false, $elementCounter, $renderView);
|
||||
if (!empty($renderView) && !empty($final)) {
|
||||
if ($renderView) {
|
||||
$final = json_decode($final->intoString(), true);
|
||||
foreach ($final as $key => $data) {
|
||||
$this->set($key, $data);
|
||||
}
|
||||
$this->set($final);
|
||||
$this->set('responseType', $responseType);
|
||||
$this->set('returnFormat', $returnFormat);
|
||||
$this->set('renderView', $renderView);
|
||||
|
|
|
@ -11,7 +11,7 @@ echo $this->element('genericElements/Form/genericForm', [
|
|||
'class' => 'input span6',
|
||||
'div' => 'input clear',
|
||||
'type' => 'select',
|
||||
'options' => array_combine($exportFormats, $exportFormats),
|
||||
'options' => $exportFormats,
|
||||
],
|
||||
],
|
||||
'submit' => [
|
||||
|
|
Loading…
Reference in New Issue