mirror of https://github.com/MISP/MISP
new: [event:restSearch] Initial work for GalaxyElement searches
parent
c92d0bdf23
commit
7bb01d9b76
|
@ -6742,6 +6742,16 @@ class Event extends AppModel
|
|||
$filters['wildcard'] = $filters['searchall'];
|
||||
}
|
||||
}
|
||||
|
||||
$subqueryElements = $this->harvestSubqueryElements($filters);
|
||||
$this->GalaxyCluster = ClassRegistry::init('GalaxyCluster');
|
||||
$tagsFromGalaxyMeta = $this->GalaxyCluster->getClusterTagsFromMeta($subqueryElements['galaxy']);
|
||||
if (!empty($filters['tags'])) {
|
||||
$filters['tags'][] = $tagsFromGalaxyMeta;
|
||||
} else {
|
||||
$filters['tags'] = $tagsFromGalaxyMeta;
|
||||
}
|
||||
|
||||
$filters['include_attribute_count'] = 1;
|
||||
$eventid = $this->filterEventIds($user, $filters, $elementCounter);
|
||||
$eventCount = count($eventid);
|
||||
|
@ -6944,4 +6954,33 @@ class Event extends AppModel
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function harvestSubqueryElements($options)
|
||||
{
|
||||
$acceptedRules = array(
|
||||
'galaxy' => 1,
|
||||
'orgc' => array('sector', 'local', 'nationality'),
|
||||
'taxonomy' => 1
|
||||
);
|
||||
$subqueryElement = array(
|
||||
'galaxy' => array(),
|
||||
'orgc' => array(),
|
||||
'taxonomy' => array(),
|
||||
);
|
||||
foreach($options as $rule => $value) {
|
||||
$split = explode(".", $rule, 2);
|
||||
if (count($split) > 1) {
|
||||
$scope = $split[0];
|
||||
$element = $split[1];
|
||||
if (isset($acceptedRules[$scope])) {
|
||||
if (is_array($acceptedRules[$scope]) && !in_array($element, $acceptedRules[$scope])) {
|
||||
continue;
|
||||
} else {
|
||||
$subqueryElement[$scope][$element] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $subqueryElement;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -207,4 +207,51 @@ class GalaxyCluster extends AppModel
|
|||
}
|
||||
return $events;
|
||||
}
|
||||
|
||||
public function getClusterTagsFromMeta($galaxyElements)
|
||||
{
|
||||
// OR operator between cluster metas
|
||||
// $conditions = array();
|
||||
// foreach ($galaxyElements as $galaxyElementKey => $galaxyElementValue) {
|
||||
// $conditions['OR'][]['AND'] = array(
|
||||
// 'GalaxyElement.key' => $galaxyElementKey,
|
||||
// 'GalaxyElement.value' => $galaxyElementValue,
|
||||
// );
|
||||
// }
|
||||
// $clusterTags = $this->GalaxyElement->find('list', array(
|
||||
// 'conditions' => $conditions,
|
||||
// 'fields' => array('GalaxyCluster.tag_name', 'GalaxyElement.value'),
|
||||
// 'contain' => array('GalaxyCluster'),
|
||||
// 'recursive' => -1
|
||||
// ));
|
||||
|
||||
// AND operator between cluster metas
|
||||
$tmpResults = array();
|
||||
foreach ($galaxyElements as $galaxyElementKey => $galaxyElementValue) {
|
||||
$tmpResults[] = array_values($this->GalaxyElement->find('list', array(
|
||||
'conditions' => array(
|
||||
'key' => $galaxyElementKey,
|
||||
'value' => $galaxyElementValue,
|
||||
),
|
||||
'fields' => array('galaxy_cluster_id'),
|
||||
'recursive' => -1
|
||||
)));
|
||||
}
|
||||
$clusterTags = array();
|
||||
if (!empty($tmpResults)) {
|
||||
// Get all Clusters matching all conditions
|
||||
$matchingClusters = $tmpResults[0];
|
||||
array_shift($tmpResults);
|
||||
foreach ($tmpResults as $tmpResult) {
|
||||
$matchingClusters = array_intersect($matchingClusters, $tmpResult);
|
||||
}
|
||||
|
||||
$clusterTags = $this->find('list', array(
|
||||
'conditions' => array('id' => $matchingClusters),
|
||||
'fields' => array('GalaxyCluster.tag_name'),
|
||||
'recursive' => -1
|
||||
));
|
||||
}
|
||||
return array_values($clusterTags);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue