chg: [event:view] Increase tag colleciton efficiency

pull/4492/head
mokaddem 2019-04-16 14:14:51 +02:00
parent 29f4b25f5a
commit 6e2635a346
2 changed files with 28 additions and 30 deletions

View File

@ -1086,6 +1086,10 @@ class EventsController extends AppController
}
$event = $results[0];
$attributeTagsName = $this->Event->Attribute->AttributeTag->extractAttributeTagsNameFromEvent($event, 'both');
$this->set('attributeTags', array_values($attributeTagsName['tags']));
$this->set('attributeClusters', array_values($attributeTagsName['clusters']));
if (isset($filters['distribution'])) {
if (!is_array($filters['distribution'])) {
$filters['distribution'] = array($filters['distribution']);
@ -1195,9 +1199,6 @@ class EventsController extends AppController
$this->set('advancedFilteringActive', $advancedFiltering['active'] ? 1 : 0);
$this->set('advancedFilteringActiveRules', $advancedFiltering['activeRules']);
$this->set('defaultFilteringRules', $this->defaultFilteringRules);
$attributeTagsName = $this->Event->Attribute->AttributeTag->extractAttributeTagsNameFromEvent($event['objects'], 'both');
$this->set('attributeTags', $attributeTagsName['tags']);
$this->set('attributeClusters', $attributeTagsName['clusters']);
$this->disableCache();
$this->layout = 'ajax';
$this->loadModel('Sighting');
@ -1337,6 +1338,9 @@ class EventsController extends AppController
}
}
}
$attributeTagsName = $this->Event->Attribute->AttributeTag->extractAttributeTagsNameFromEvent($event, 'both');
$this->set('attributeTags', array_values($attributeTagsName['tags']));
$this->set('attributeClusters', array_values($attributeTagsName['clusters']));
$startDate = $event['Event']['timestamp'];
$modDate = date("Y-m-d", $event['Event']['timestamp']);
$modificationMap[$modDate] = 1;
@ -1473,9 +1477,6 @@ class EventsController extends AppController
$this->set('advancedFilteringActive', $advancedFiltering['active'] ? 1 : 0);
$this->set('advancedFilteringActiveRules', $advancedFiltering['activeRules']);
$this->set('defaultFilteringRules', $this->defaultFilteringRules);
$attributeTagsName = $this->Event->Attribute->AttributeTag->extractAttributeTagsNameFromEvent($event['objects'], 'both');
$this->set('attributeTags', $attributeTagsName['tags']);
$this->set('attributeClusters', $attributeTagsName['clusters']);
$this->set('mitreAttackGalaxyId', $this->Event->GalaxyCluster->Galaxy->getMitreAttackGalaxyId());
$this->set('modificationMapCSV', $modificationMapCSV);
}

View File

@ -234,35 +234,32 @@ class AttributeTag extends AppModel
return $allClusters;
}
public function extractAttributeTagsNameFromEvent(&$event_elements, $to_extract='both')
public function extractAttributeTagsNameFromEvent(&$event, $to_extract='both')
{
$attribute_tags_name = array('tags' => array(), 'clusters' => array());
if ($to_extract == 'tags' || $to_extract == 'both') {
foreach ($event_elements as $i => $element) {
if ($element['objectType'] == 'object') {
$new_tags = $this->extractAttributeTagsNameFromEvent($element['Attribute'], 'tags');
$attribute_tags_name['tags'] = array_merge($attribute_tags_name['tags'], $new_tags['tags']);
} else {
if (!empty($element['AttributeTag'])) {
$new_tags = Hash::extract($element['AttributeTag'], '{n}.Tag.name');
$attribute_tags_name['tags'] = array_merge($attribute_tags_name['tags'], $new_tags);
}
}
}
}
if ($to_extract == 'clusters' || $to_extract == 'both') {
foreach ($event_elements as $i => $element) {
if ($element['objectType'] == 'object') {
$new_tags = $this->extractAttributeTagsNameFromEvent($element['Attribute'], 'clusters');
$attribute_tags_name['clusters'] = array_merge($attribute_tags_name['clusters'], $new_tags['clusters']);
} else {
if (!empty($element['Galaxy'])) {
$new_tags = Hash::extract($element['Galaxy'], '{n}.GalaxyCluster.{n}.tag_name');
$attribute_tags_name['clusters'] = array_merge($attribute_tags_name['clusters'], $new_tags);
}
foreach ($event['Attribute'] as $i => $attribute) {
if ($to_extract == 'tags' || $to_extract == 'both') {
$new_tags = Hash::combine($attribute['AttributeTag'], '{n}.Tag.name', '{n}.Tag.name');
$attribute_tags_name['tags'] = array_merge($attribute_tags_name['tags'], $new_tags);
}
if ($to_extract == 'clusters' || $to_extract == 'both') {
$new_tags = Hash::combine($attribute['Galaxy'], '{n}.GalaxyCluster.{n}.tag_name', '{n}.GalaxyCluster.{n}.tag_name');
$attribute_tags_name['clusters'] = array_merge($attribute_tags_name['clusters'], $new_tags);
}
}
foreach ($event['Object'] as $i => $object) {
foreach ($object['Attribute'] as $j => $object_attribute) {
if ($to_extract == 'tags' || $to_extract == 'both') {
$new_tags = Hash::combine($object_attribute['AttributeTag'], '{n}.Tag.name', '{n}.Tag.name');
$attribute_tags_name['tags'] = array_merge($attribute_tags_name['tags'], $new_tags);
}
if ($to_extract == 'clusters' || $to_extract == 'both') {
$new_tags = Hash::combine($object_attribute['Galaxy'], '{n}.GalaxyCluster.{n}.tag_name', '{n}.GalaxyCluster.{n}.tag_name');
$attribute_tags_name['clusters'] = array_merge($attribute_tags_name['clusters'], $new_tags);
}
}
}
$attribute_tags_name['tags'] = array_diff_key($attribute_tags_name['tags'], $attribute_tags_name['clusters']);
return $attribute_tags_name;
}