add: [enrichment] Displaying + returning tags at attributes level from the module results

- If one of our UI master could review this and find
  a better way of displaying the tags at attribute
  level in the module results view, it would be
  very cool :D
pull/4584/head
chrisr3d 2019-06-14 18:16:09 +02:00
parent 8642bc5802
commit cf20d07cad
No known key found for this signature in database
GPG Key ID: 6BBED1B63A6D639F
3 changed files with 78 additions and 3 deletions

View File

@ -6097,6 +6097,14 @@ class Event extends AppModel
$attribute['event_id'] = $id;
if ($this->Attribute->save($attribute)) {
$saved_attributes++;
if (!empty($attribute['Tag'])) {
foreach ($attribute['Tag'] as $tag) {
$tag_id = $this->Attribute->AttributeTag->Tag->captureTag($tag, $user);
if ($tag_id) {
$this->Attribute->AttributeTag->attachTagToAttribute($this->Attribute->id, $id, $tag_id);
}
}
}
} else {
$failed_attributes++;
$lastAttributeError = $this->Attribute->validationErrors;
@ -6374,7 +6382,18 @@ class Event extends AppModel
$attribute['comment'] = $default_comment;
}
$this->Attribute->create();
return $this->Attribute->save($attribute);
$attribute_save = $this->Attribute->save($attribute);
if ($attribute_save) {
if (!empty($attribute['Tag'])) {
foreach ($attribute['Tag'] as $tag) {
$tag_id = $this->Attribute->AttributeTag->Tag->captureTag($tag, $user);
if ($tag_id) {
$this->Attribute->AttributeTag->attachTagToAttribute($this->Attribute->id, $event_id, $tag_id);
}
}
}
}
return $attribute_save;
}
public function processFreeTextDataRouter($user, $attributes, $id, $default_comment = '', $force = false, $adhereToWarninglists = false)

View File

@ -81,6 +81,7 @@
<th><?php echo __('Type');?></th>
<th><?php echo __('Value');?></th>
<th><?php echo __('UUID');?></th>
<th><?php echo __('Tags');?></th>
<th><?php echo __('IDS');?></th>
<th><?php echo __('Disable Correlation');?></th>
<th><?php echo __('Comment');?></th>
@ -92,7 +93,7 @@
?>
<tbody class='MISPObject'>
<tr class='tableHighlightBorderTop borderBlue blueRow' tabindex='0'>
<td colspan="6">
<td colspan="7">
<?php if(!empty($object['id'])) { ?>
<span class="bold"><?php echo __('ID: ');?></span><span class="ObjectID"><?php echo h($object['id']); ?></span><br />
<?php } ?>
@ -180,6 +181,26 @@
</td>
<td class="AttributeValue limitedWidth"><?php echo h($attribute['value']); ?></td>
<td class="AttributeUuid short"><?php echo h($attribute['uuid']); ?></td>
<td style="max-width:150px;width:10px;">
<?php if (!empty($attribute['Tag'])) { ?>
<span class="objectAttributeTagContainer">
<?php
foreach ($attribute['Tag'] as $tag) {
$tagText = explode('=', $tag['name']);
$tagText = trim(end($tagText), "\"");
$color = !empty($tag['colour']) ? $tag['colour'] : '#0088cc';
?>
<span style="display:inline-block;">
<span style="padding:1px;display:flex;white-space:nowrap;margin-right:2px;word-wrap:break-word;">
<span class="objectAttributeTag" style="display:inline-block;background-color:<?php echo h($color); ?>;color:white;" title="<?php echo h($tag['name']); ?>">
<?php echo h($tagText); ?>
</span>
</span>
</span>
<?php } ?>
</span>
<?php } ?>
</td>
<td class="short" style="width:40px;text-align:center;">
<input type="checkbox" class="AttributeToIds" <?php if (!empty($attribute['to_ids'])) echo 'checked'; ?>/>
</td>
@ -211,7 +232,7 @@
echo '</tr>';
}
}
echo '<tr><td colspan="8" /></tr>';
echo '<tr><td colspan="9" /></tr>';
?>
</tbody>
<?php
@ -227,6 +248,7 @@
<th><?php echo __('Type');?></th>
<th><?php echo __('Value');?></th>
<th><?php echo __('UUID');?></th>
<th><?php echo __('Tags');?></th>
<th><?php echo __('IDS');?></th>
<th><?php echo __('Disable Correlation');?></th>
<th><?php echo __('Comment');?></th>
@ -255,6 +277,26 @@
?>
<td class="AttributeValue limitedWidth"><?php echo h($attribute['value']); ?></td>
<td class="AttributeUuid short"><?php echo h($attribute['uuid']); ?></td>
<td style="max-width:150px;width:10px;">
<?php if (!empty($attribute['Tag'])) { ?>
<span class="attributeTagContainer">
<?php
foreach ($attribute['Tag'] as $tag) {
$tagText = explode('=', $tag['name']);
$tagText = trim(end($tagText), "\"");
$color = !empty($tag['colour']) ? $tag['colour'] : '#0088cc';
?>
<span style="display:inline-block;">
<span style="padding:1px;display:flex;white-space:nowrap;margin-right:2px;word-wrap:break-word;">
<span class="attributeTag" style="display:inline-block;background-color:<?php echo h($color); ?>;color:white;" title="<?php echo h($tag['name']); ?>">
<?php echo h($tagText); ?>
</span>
</span>
</span>
<?php } ?>
</span>
<?php } ?>
</td>
<td class="short" style="width:40px;text-align:center;">
<input type="checkbox" class="AttributeToIds" <?php if (isset($attribute['to_ids']) && $attribute['to_ids']) echo 'checked'; ?>/>
</td>

View File

@ -2521,6 +2521,13 @@ function moduleResultsSubmit(id) {
if (attribute['distribution'] != '4') {
attribute['sharing_group_id'] = '0';
}
if ($(this).find('.objectAttributeTagContainer').length) {
var tags = [];
$(this).find('.objectAttributeTag').each(function() {
tags.push({name: $(this).attr('title')});
});
attribute['Tag'] = tags;
}
object_attributes.push(attribute);
});
temp['Attribute'] = object_attributes;
@ -2558,6 +2565,13 @@ function moduleResultsSubmit(id) {
if (temp['distribution'] != '4') {
temp['sharing_group_id'] = '0';
}
if ($(this).find('.attributeTagContainer').length) {
var tags = [];
$(this).find('.attributeTag').each(function() {
tags.push({name: $(this).attr('title')});
});
temp['Tag'] = tags;
}
attributes.push(temp);
});
data_collected['Attribute'] = attributes;