Merge branch '2.4' of https://github.com/MISP/MISP into develop

pull/7427/head
chrisr3d 2021-05-11 17:52:31 +02:00
commit 308787918e
5 changed files with 103 additions and 58 deletions

View File

@ -6300,14 +6300,13 @@ class Event extends AppModel
} else {
$failed_attributes++;
$lastAttributeError = $this->Attribute->validationErrors;
$original_uuid = $this->Object->Attribute->find('first', array(
'conditions' => array('Attribute.event_id' => $id, 'Attribute.object_id' => 0, 'Attribute.deleted' => 0,
'Attribute.type' => $attribute['type'], 'Attribute.value' => $attribute['value']),
'recursive' => -1,
'fields' => array('Attribute.uuid')
));
$original_uuid = $this->__findOriginalUUID(
$attribute['type'],
$attribute['value'],
$id
);
if (!empty($original_uuid)) {
$recovered_uuids[$attribute['uuid']] = $original_uuid['Attribute']['uuid'];
$recovered_uuids[$attribute['uuid']] = $original_uuid;
} else {
$failed[] = $attribute['uuid'];
}
@ -6430,53 +6429,53 @@ class Event extends AppModel
$this->Job->saveField('progress', (($current + $total_attributes) * 100 / $items_count));
}
}
}
if (!empty($references)) {
$reference_errors = array();
foreach($references as $reference) {
$object_id = $reference['objectId'];
$reference = $reference['reference'];
if (in_array($reference['object_uuid'], $failed) || in_array($reference['referenced_uuid'], $failed)) {
continue;
}
if (isset($recovered_uuids[$reference['object_uuid']])) {
$reference['object_uuid'] = $recovered_uuids[$reference['object_uuid']];
}
if (isset($recovered_uuids[$reference['referenced_uuid']])) {
$reference['referenced_uuid'] = $recovered_uuids[$reference['referenced_uuid']];
}
$current_reference = $this->Object->ObjectReference->find('all', array(
'conditions' => array('ObjectReference.object_id' => $object_id,
'ObjectReference.referenced_uuid' => $reference['referenced_uuid'],
'ObjectReference.relationship_type' => $reference['relationship_type'],
'ObjectReference.event_id' => $id, 'ObjectReference.deleted' => 0),
'recursive' => -1,
'fields' => ('ObjectReference.uuid')
));
if (!empty($current_reference)) {
continue;
}
list($referenced_id, $referenced_uuid, $referenced_type) = $this->Object->ObjectReference->getReferencedInfo(
$reference['referenced_uuid'],
array('Event' => array('id' => $id)),
false,
$user
);
if (!$referenced_id && !$referenced_uuid && !$referenced_type) {
continue;
}
$reference = array(
'event_id' => $id,
'referenced_id' => $referenced_id,
'referenced_uuid' => $referenced_uuid,
'referenced_type' => $referenced_type,
'object_id' => $object_id,
'object_uuid' => $reference['object_uuid'],
'relationship_type' => $reference['relationship_type']
);
$this->Object->ObjectReference->create();
if (!$this->Object->ObjectReference->save($reference)) {
$reference_errors[] = $this->Object->ObjectReference->validationErrors;
if (!empty($references)) {
$reference_errors = array();
foreach($references as $reference) {
$object_id = $reference['objectId'];
$reference = $reference['reference'];
if (in_array($reference['object_uuid'], $failed) || in_array($reference['referenced_uuid'], $failed)) {
continue;
}
if (isset($recovered_uuids[$reference['object_uuid']])) {
$reference['object_uuid'] = $recovered_uuids[$reference['object_uuid']];
}
if (isset($recovered_uuids[$reference['referenced_uuid']])) {
$reference['referenced_uuid'] = $recovered_uuids[$reference['referenced_uuid']];
}
$current_reference = $this->Object->ObjectReference->find('all', array(
'conditions' => array('ObjectReference.object_id' => $object_id,
'ObjectReference.referenced_uuid' => $reference['referenced_uuid'],
'ObjectReference.relationship_type' => $reference['relationship_type'],
'ObjectReference.event_id' => $id, 'ObjectReference.deleted' => 0),
'recursive' => -1,
'fields' => ('ObjectReference.uuid')
));
if (!empty($current_reference)) {
continue;
}
list($referenced_id, $referenced_uuid, $referenced_type) = $this->Object->ObjectReference->getReferencedInfo(
$reference['referenced_uuid'],
array('Event' => array('id' => $id)),
false,
$user
);
if (!$referenced_id && !$referenced_uuid && !$referenced_type) {
continue;
}
$reference = array(
'event_id' => $id,
'referenced_id' => $referenced_id,
'referenced_uuid' => $referenced_uuid,
'referenced_type' => $referenced_type,
'object_id' => $object_id,
'object_uuid' => $reference['object_uuid'],
'relationship_type' => $reference['relationship_type']
);
$this->Object->ObjectReference->create();
if (!$this->Object->ObjectReference->save($reference)) {
$reference_errors[] = $this->Object->ObjectReference->validationErrors;
}
}
}
}
@ -6613,6 +6612,52 @@ class Event extends AppModel
return 0;
}
private function __findOriginalUUID($attribute_type, $attribute_value, $event_id)
{
$original_uuid = $this->Object->Attribute->find(
'first',
array(
'conditions' => array(
'Attribute.event_id' => $event_id,
'Attribute.deleted' => 0,
'Attribute.object_id' => 0,
'Attribute.type' => $attribute_type,
'Attribute.value' => $attribute_value
),
'recursive' => -1,
'fields' => array('Attribute.uuid')
)
);
if (!empty($original_uuid)) {
return ['Attribute']['uuid'];
}
$original_uuid = $this->Object->find(
'first',
array(
'conditions' => array(
'Attribute.event_id' => $event_id,
'Attribute.deleted' => 0,
'Attribute.type' => $attribute_type,
'Attribute.value1' => $attribute_value,
'Object.event_id' => $event_id
),
'recursive' => -1,
'fields' => array('Object.uuid'),
'joins' => array(
array(
'table' => 'attributes',
'alias' => 'Attribute',
'type' => 'inner',
'conditions' => array(
'Attribute.object_id = Object.id'
)
)
)
)
);
return (!empty($original_uuid)) ? $original_uuid['Object']['uuid'] : $original_uuid;
}
private function __saveObjectAttribute($attribute, $default_comment, $event_id, $object_id, $user)
{
$attribute['object_id'] = $object_id;

View File

@ -149,7 +149,7 @@
echo h($item['Job']['job_status']);
if ($item['Job']['failed']):
?>
<div class="fa fa-search useCursorPointer queryPopover" title="<?php echo __('View stacktrace');?>" role="button" tabindex="0" aria-label="<?php echo __('View stacktrace');?>" data-url="<?php echo $basurl; ?>/jobs/getError" data-id="<?php echo h($item['Job']['process_id']); ?>"></div>
<div class="fa fa-search useCursorPointer queryPopover" title="<?php echo __('View stacktrace');?>" role="button" tabindex="0" aria-label="<?php echo __('View stacktrace');?>" data-url="<?php echo $baseurl; ?>/jobs/getError" data-id="<?php echo h($item['Job']['process_id']); ?>"></div>
<?php
endif;
?>

@ -1 +1 @@
Subproject commit 94ec98d544177c9b00c2bc0fe7913a1a5270db0c
Subproject commit a3cdbc1309e36c41f6a090fdb35eeebd86dff3e1

@ -1 +1 @@
Subproject commit 60be6a5938b930151eb5f8ce62d333c807334851
Subproject commit 8bb8a1d22c572b150820ff0a260ccba4e422d6ac

@ -1 +1 @@
Subproject commit ad917763716b7d2b612620939966628d40c91936
Subproject commit c768c55b6fda118e20ee93d8f5111b94388281af