mirror of https://github.com/MISP/MISP
Merge pull request #7187 from JakubOnderka/related-attributes
chg: [internal] Move fetching related attributes to one placepull/7334/head
commit
81a6454c94
|
@ -3685,28 +3685,7 @@ class EventsController extends AppController
|
|||
);
|
||||
}
|
||||
}
|
||||
foreach ($resultArray as $key => $result) {
|
||||
if ($has_pipe = strpos($result['default_type'], '|') !== false || $result['default_type'] === 'malware-sample') {
|
||||
$pieces = explode('|', $result['value']);
|
||||
if (in_array($result['default_type'], $this->Event->Attribute->primaryOnlyCorrelatingTypes)) {
|
||||
$or = array('Attribute.value1' => $pieces[0],
|
||||
'Attribute.value2' => $pieces[0]);
|
||||
} else {
|
||||
$or = array('Attribute.value1' => $pieces,
|
||||
'Attribute.value2' => $pieces);
|
||||
}
|
||||
} else {
|
||||
$or = array('Attribute.value1' => $result['value'], 'Attribute.value2' => $result['value']);
|
||||
}
|
||||
$options = array(
|
||||
'conditions' => array('OR' => $or),
|
||||
'fields' => array('Attribute.type', 'Attribute.category', 'Attribute.value', 'Attribute.comment'),
|
||||
'order' => false,
|
||||
'limit' => 11,
|
||||
'flatten' => 1
|
||||
);
|
||||
$resultArray[$key]['related'] = $this->Event->Attribute->fetchAttributes($this->Auth->user(), $options);
|
||||
}
|
||||
$this->Event->Attribute->fetchRelated($this->Auth->user(), $resultArray);
|
||||
$resultArray = array_values($resultArray);
|
||||
$typeCategoryMapping = array();
|
||||
foreach ($this->Event->Attribute->categoryDefinitions as $k => $cat) {
|
||||
|
@ -4988,20 +4967,8 @@ class EventsController extends AppController
|
|||
$typeCategoryMapping[$type][$k] = $k;
|
||||
}
|
||||
}
|
||||
$this->Event->Attribute->fetchRelated($this->Auth->user(), $resultArray);
|
||||
foreach ($resultArray as $key => $result) {
|
||||
if ($has_pipe = strpos($result['default_type'], '|') !== false || $result['default_type'] === 'malware-sample') {
|
||||
$pieces = explode('|', $result['value']);
|
||||
$or = array('Attribute.value1' => $pieces,
|
||||
'Attribute.value2' => $pieces);
|
||||
} else {
|
||||
$or = array('Attribute.value1' => $result['value'], 'Attribute.value2' => $result['value']);
|
||||
}
|
||||
$options = array(
|
||||
'conditions' => array('OR' => $or),
|
||||
'fields' => array('Attribute.type', 'Attribute.category', 'Attribute.value', 'Attribute.comment'),
|
||||
'order' => false
|
||||
);
|
||||
$resultArray[$key]['related'] = $this->Event->Attribute->fetchAttributes($this->Auth->user(), $options);
|
||||
if (isset($result['data'])) {
|
||||
App::uses('FileAccessTool', 'Tools');
|
||||
$fileAccessTool = new FileAccessTool();
|
||||
|
@ -5189,21 +5156,7 @@ class EventsController extends AppController
|
|||
$typeCategoryMapping[$type][$k] = $k;
|
||||
}
|
||||
}
|
||||
foreach ($resultArray as $key => $result) {
|
||||
if ($has_pipe = strpos($result['default_type'], '|') !== false || $result['default_type'] === 'malware-sample') {
|
||||
$pieces = explode('|', $result['value']);
|
||||
$or = array('Attribute.value1' => $pieces,
|
||||
'Attribute.value2' => $pieces);
|
||||
} else {
|
||||
$or = array('Attribute.value1' => $result['value'], 'Attribute.value2' => $result['value']);
|
||||
}
|
||||
$options = array(
|
||||
'conditions' => array('OR' => $or),
|
||||
'fields' => array('Attribute.type', 'Attribute.category', 'Attribute.value', 'Attribute.comment'),
|
||||
'order' => false
|
||||
);
|
||||
$resultArray[$key]['related'] = $this->Event->Attribute->fetchAttributes($this->Auth->user(), $options);
|
||||
}
|
||||
$this->Event->Attribute->fetchRelated($this->Auth->user(), $resultArray);
|
||||
$this->set('event', $event);
|
||||
$this->set('resultArray', $resultArray);
|
||||
$this->set('typeDefinitions', $this->Event->Attribute->typeDefinitions);
|
||||
|
|
|
@ -2013,6 +2013,45 @@ class Attribute extends AppModel
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $user
|
||||
* @param array $resultArray
|
||||
*/
|
||||
public function fetchRelated(array $user, array &$resultArray)
|
||||
{
|
||||
if (empty($resultArray)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$composeTypes = $this->getCompositeTypes();
|
||||
foreach ($resultArray as $key => $result) {
|
||||
if (in_array($result['default_type'], $composeTypes, true)) {
|
||||
$pieces = explode('|', $result['value']);
|
||||
if (in_array($result['default_type'], $this->primaryOnlyCorrelatingTypes, true)) {
|
||||
$or = ['Attribute.value1' => $pieces[0], 'Attribute.value2' => $pieces[0]];
|
||||
} else {
|
||||
$or = ['Attribute.value1' => $pieces, 'Attribute.value2' => $pieces];
|
||||
}
|
||||
} else {
|
||||
$or = ['Attribute.value1' => $result['value'], 'Attribute.value2' => $result['value']];
|
||||
}
|
||||
$options = array(
|
||||
'conditions' => [
|
||||
'OR' => $or,
|
||||
'NOT' => [
|
||||
'Attribute.type' => $this->nonCorrelatingTypes,
|
||||
],
|
||||
'Attribute.disable_correlation' => 0,
|
||||
],
|
||||
'fields' => ['Attribute.type', 'Attribute.category', 'Attribute.value', 'Attribute.comment'],
|
||||
'order' => false,
|
||||
'limit' => 11,
|
||||
'flatten' => 1,
|
||||
);
|
||||
$resultArray[$key]['related'] = $this->fetchAttributes($user, $options);
|
||||
}
|
||||
}
|
||||
|
||||
public function checkComposites()
|
||||
{
|
||||
$compositeTypes = $this->getCompositeTypes();
|
||||
|
|
Loading…
Reference in New Issue