new: [evenReport] Support of extended event

pull/6412/head
mokaddem 2020-10-08 09:05:44 +02:00
parent bd77f9be70
commit d891143b8c
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
5 changed files with 53 additions and 7 deletions

View File

@ -170,7 +170,7 @@ class EventReportsController extends AppController
public function index()
{
$filters = $this->IndexFilter->harvestParameters(['event_id', 'value', 'context', 'index_for_event']);
$filters = $this->IndexFilter->harvestParameters(['event_id', 'value', 'context', 'index_for_event', 'extended_event']);
$filters['embedded_view'] = $this->request->is('ajax');
$compiledConditions = $this->generateIndexConditions($filters);
if ($this->_isRest()) {
@ -186,6 +186,7 @@ class EventReportsController extends AppController
$this->set('reports', $reports);
$this->injectIndexVariablesToViewContext($filters);
if (!empty($filters['index_for_event'])) {
$this->set('extendedEvent', !empty($filters['extended_event']));
$this->render('ajax/indexForEvent');
}
}
@ -194,7 +195,15 @@ class EventReportsController extends AppController
private function generateIndexConditions($filters = [])
{
$aclConditions = $this->EventReport->buildACLConditions($this->Auth->user());
$eventConditions = !empty($filters['event_id']) ? ['EventReport.event_id' => $filters['event_id']] : [];
$eventConditions = [];
if (!empty($filters['event_id'])) {
$extendingEvents = [];
if (!empty($filters['extended_event'])) {
$extendingEventIds = $this->EventReport->Event->getExtendingEventIdsFromEvent($this->Auth->user(), $filters['event_id']);
}
$eventConditions = ['EventReport.event_id' => array_merge([$filters['event_id']], $extendingEventIds)];
}
$contextConditions = [];
if (empty($filters['context'])) {
$filters['context'] = 'default';

View File

@ -7369,4 +7369,16 @@ class Event extends AppModel
// default value if no match found
return Configure::read('MISP.email_subject_TLP_string') ?: "tlp:amber";
}
public function getExtendingEventIdsFromEvent($user, $eventID)
{
$event = $this->fetchSimpleEvent($user, $eventID);
if (!empty($event)) {
$extendingEventIds = $this->fetchSimpleEventIds($user, ['conditions' => [
'extends_uuid' => $event['Event']['uuid']
]]);
return $extendingEventIds;
}
return [];
}
}

View File

@ -421,15 +421,27 @@ class EventReport extends AppModel
throw new NotFoundException(__('Invalid Event'));
}
$event = $event[0];
$attributes = Hash::combine($event, 'Attribute.{n}.uuid', 'Attribute.{n}');
$parentEventId = $this->Event->fetchSimpleEventIds($user, ['conditions' => [
'uuid' => $event['Event']['extends_uuid']
]]);
if (!empty($parentEventId)) {
$parentEvent = $this->Event->fetchEvent($user, ['eventid' => $parentEventId, 'extended' => true]);
if (!empty($parentEvent)) {
$parentEvent = $parentEvent[0];
} else {
$parentEvent = $event;
}
}
$attributes = Hash::combine($parentEvent, 'Attribute.{n}.uuid', 'Attribute.{n}');
$this->AttributeTag = ClassRegistry::init('AttributeTag');
$allTagNames = Hash::combine($event['EventTag'], '{n}.Tag.name', '{n}.Tag');
$attributeTags = Hash::combine($this->AttributeTag->getAttributesTags($event['Attribute'], true), '{n}.name', '{n}');
$allTagNames = array_merge($allTagNames, $attributeTags);
$attributeTags = Hash::combine($this->AttributeTag->getAttributesTags($parentEvent['Attribute'], true), '{n}.name', '{n}');
$parentEventTags = Hash::combine($parentEvent['EventTag'], '{n}.Tag.name', '{n}.Tag');
$allTagNames = array_merge($allTagNames, $attributeTags, $parentEventTags);
$objects = [];
$templateConditions = [];
$recordedConditions = [];
foreach ($event['Object'] as $k => $object) {
foreach ($parentEvent['Object'] as $k => $object) {
$objects[$object['uuid']] = $object;
$objectAttributes = [];
foreach ($object['Attribute'] as $i => $objectAttribute) {
@ -448,6 +460,7 @@ class EventReport extends AppModel
$recordedConditions[$uniqueCondition] = true;
}
}
$templateConditions = empty($templateConditions) ? ['ObjectTemplate.id' => 0] : $templateConditions;
$this->ObjectTemplate = ClassRegistry::init('ObjectTemplate');
$templates = $this->ObjectTemplate->find('all', array(
'conditions' => $templateConditions,

View File

@ -1,4 +1,7 @@
<div id="eventReportQuickIndex">
<?php if ($extendedEvent): ?>
<div class="alert alert-info"><?= __('Viewing reports in extended event view') ?></div>
<?php endif; ?>
<div style="margin-bottom: 10px;">
<button class="btn btn-small btn-primary" onclick="openGenericModal(baseurl + '/eventReports/add/<?= h($event_id) ?>')">
<i class="<?= $this->FontAwesome->getClass('plus') ?>"></i> <?= __('Add Event Report') ?>
@ -50,6 +53,15 @@
'class' => 'useCursorPointer',
'data_path' => 'EventReport.name',
),
array(
'name' => __('Event ID'),
'requirement' => $extendedEvent,
'data_path' => 'EventReport.event_id',
'class' => 'short',
'element' => 'links',
'data_path' => 'EventReport.event_id',
'url' => $baseurl . '/events/view/%s'
),
array(
'name' => __('Last update'),
'sort' => 'timestamp',

View File

@ -545,7 +545,7 @@ $(document).ready(function () {
$("#discussions_div").html(data);
});
$.get("<?php echo $baseurl; ?>/eventReports/index/event_id:<?= h($event['Event']['id']); ?>/index_for_event:1", function(data) {
$.get("<?php echo $baseurl; ?>/eventReports/index/event_id:<?= h($event['Event']['id']); ?>/index_for_event:1<?= $extended ? '/extended_event:1' : ''?>", function(data) {
$("#eventreport_index_div").html(data);
if ($('#eventreport_index_div table tbody > tr').length) { // open if contain a report
$('#eventreport_toggle').click()