mirror of https://github.com/MISP/MISP
new: [modules] Export module can specify event fetch options
parent
4cbaf60da8
commit
e5d5b79e3f
|
@ -5614,30 +5614,38 @@ class Event extends AppModel
|
|||
return $attribute;
|
||||
}
|
||||
|
||||
public function export($user = false, $module = false, $options = array())
|
||||
/**
|
||||
* @param array $user
|
||||
* @param string $module
|
||||
* @param array $options
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function export(array $user, $module, array $options = array())
|
||||
{
|
||||
if (empty($user)) {
|
||||
return 'Invalid user.';
|
||||
}
|
||||
if (empty($module)) {
|
||||
return 'Invalid module.';
|
||||
throw new InvalidArgumentException('Invalid module.');
|
||||
}
|
||||
$this->Module = ClassRegistry::init('Module');
|
||||
$module = $this->Module->getEnabledModule($module, 'Export');
|
||||
if (!is_array($module)) {
|
||||
throw new NotFoundException('Invalid module.');
|
||||
}
|
||||
// Export module can specify additional options for event fetch
|
||||
if (isset($module['meta']['fetch_options'])) {
|
||||
$options = array_merge($options, $module['meta']['fetch_options']);
|
||||
}
|
||||
$events = $this->fetchEvent($user, $options);
|
||||
if (empty($events)) {
|
||||
return 'Invalid event.';
|
||||
throw new NotFoundException('Invalid event.');
|
||||
}
|
||||
$standard_format = false;
|
||||
$modulePayload = array('module' => $module['name']);
|
||||
if (!empty($module['meta']['require_standard_format'])) {
|
||||
$standard_format = true;
|
||||
}
|
||||
if (isset($module['meta']['config'])) {
|
||||
foreach ($module['meta']['config'] as $conf) {
|
||||
$modulePayload['config'][$conf] = Configure::read('Plugin.Export_' . $module['name'] . '_' . $conf);
|
||||
}
|
||||
}
|
||||
$standard_format = !empty($module['meta']['require_standard_format']);
|
||||
if ($standard_format) {
|
||||
App::uses('JSONConverterTool', 'Tools');
|
||||
$converter = new JSONConverterTool();
|
||||
|
@ -5647,11 +5655,11 @@ class Event extends AppModel
|
|||
}
|
||||
$modulePayload['data'] = $events;
|
||||
$result = $this->Module->queryModuleServer($modulePayload, false, 'Export');
|
||||
return array(
|
||||
'data' => $result['data'],
|
||||
'extension' => $module['mispattributes']['outputFileExtension'],
|
||||
'response' => $module['mispattributes']['responseType']
|
||||
);
|
||||
return [
|
||||
'data' => $result['data'],
|
||||
'extension' => $module['mispattributes']['outputFileExtension'],
|
||||
'response' => $module['mispattributes']['responseType']
|
||||
];
|
||||
}
|
||||
|
||||
public function cacheSgids($user, $useCache = false)
|
||||
|
|
Loading…
Reference in New Issue