mirror of https://github.com/MISP/MISP
new: [API] Added the includeEventTags parameter to the /attributes/restSearch API
- appends all event level tags to each attributepull/3658/head
parent
0123f23739
commit
51b3ef61dd
|
@ -2083,7 +2083,7 @@ class AttributesController extends AppController
|
|||
}
|
||||
|
||||
public function restSearch($returnFormat = 'json', $value = false, $type = false, $category = false, $org = false, $tags = false, $from = false, $to = false, $last = false, $eventid = false, $withAttachments = false, $uuid = false, $publish_timestamp = false, $published = false, $timestamp = false, $enforceWarninglist = false, $to_ids = false, $deleted = false, $includeEventUuid = false, $event_timestamp = false, $threat_level_id = false) {
|
||||
$paramArray = array('value' , 'type', 'category', 'org', 'tags', 'from', 'to', 'last', 'eventid', 'withAttachments', 'uuid', 'publish_timestamp', 'timestamp', 'enforceWarninglist', 'to_ids', 'deleted', 'includeEventUuid', 'event_timestamp', 'threat_level_id');
|
||||
$paramArray = array('value' , 'type', 'category', 'org', 'tags', 'from', 'to', 'last', 'eventid', 'withAttachments', 'uuid', 'publish_timestamp', 'timestamp', 'enforceWarninglist', 'to_ids', 'deleted', 'includeEventUuid', 'event_timestamp', 'threat_level_id', 'includeEventTags');
|
||||
$filterData = array(
|
||||
'request' => $this->request,
|
||||
'named_params' => $this->params['named'],
|
||||
|
@ -2134,7 +2134,8 @@ class AttributesController extends AppController
|
|||
'enforceWarninglist' => !empty($filters['enforceWarninglist']) ? $filters['enforceWarninglist'] : 0,
|
||||
'includeAllTags' => true,
|
||||
'flatten' => 1,
|
||||
'includeEventUuid' => !empty($filters['includeEventUuid']) ? $filters['includeEventUuid'] : 0
|
||||
'includeEventUuid' => !empty($filters['includeEventUuid']) ? $filters['includeEventUuid'] : 0,
|
||||
'includeEventTags' => !empty($filters['includeEventTags']) ? $filters['includeEventTags'] : 0
|
||||
);
|
||||
if (!empty($filtes['deleted'])) {
|
||||
$params['deleted'] = 1;
|
||||
|
|
|
@ -29,15 +29,21 @@ class JsonExport
|
|||
if (isset($attribute['Object']) && empty($attribute['Object']['id'])) {
|
||||
unset($attribute['Object']);
|
||||
}
|
||||
if (isset($attribute['AttributeTag'])) {
|
||||
$attributeTags = array();
|
||||
foreach ($attribute['AttributeTag'] as $tk => $tag) {
|
||||
$attribute['Tag'][$tk] = $attribute['AttributeTag'][$tk]['Tag'];
|
||||
$tagTypes = array('AttributeTag', 'EventTag');
|
||||
foreach($tagTypes as $tagType) {
|
||||
if (isset($attribute[$tagType])) {
|
||||
$attributeTags = array();
|
||||
foreach ($attribute[$tagType] as $tk => $tag) {
|
||||
if ($tagType === 'EventTag') {
|
||||
$attribute[$tagType][$tk]['Tag']['inherited'] = 1;
|
||||
}
|
||||
$attribute['Tag'][] = $attribute[$tagType][$tk]['Tag'];
|
||||
}
|
||||
unset($attribute[$tagType]);
|
||||
}
|
||||
unset($attribute['AttributeTag']);
|
||||
unset($attribute['value1']);
|
||||
unset($attribute['value2']);
|
||||
}
|
||||
unset($attribute['value1']);
|
||||
unset($attribute['value2']);
|
||||
return json_encode($attribute);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,15 +30,21 @@ class XmlExport
|
|||
if (isset($attribute['Object']) && empty($attribute['Object']['id'])) {
|
||||
unset($attribute['Object']);
|
||||
}
|
||||
if (isset($attribute['AttributeTag'])) {
|
||||
$attributeTags = array();
|
||||
foreach ($attribute['AttributeTag'] as $tk => $tag) {
|
||||
$attribute['Tag'][$tk] = $attribute['AttributeTag'][$tk]['Tag'];
|
||||
$tagTypes = array('AttributeTag', 'EventTag');
|
||||
foreach($tagTypes as $tagType) {
|
||||
if (isset($attribute[$tagType])) {
|
||||
$attributeTags = array();
|
||||
foreach ($attribute[$tagType] as $tk => $tag) {
|
||||
if ($tagType === 'EventTag') {
|
||||
$attribute[$tagType][$tk]['Tag']['inherited'] = 1;
|
||||
}
|
||||
$attribute['Tag'][] = $attribute[$tagType][$tk]['Tag'];
|
||||
}
|
||||
unset($attribute[$tagType]);
|
||||
}
|
||||
unset($attribute['AttributeTag']);
|
||||
unset($attribute['value1']);
|
||||
unset($attribute['value2']);
|
||||
}
|
||||
unset($attribute['value1']);
|
||||
unset($attribute['value2']);
|
||||
$xmlObject = Xml::fromArray(array('Attribute' => $attribute), array('format' => 'tags'));
|
||||
$xmlString = $xmlObject->asXML();
|
||||
return substr($xmlString, strpos($xmlString, "\n") + 1);
|
||||
|
|
|
@ -2865,6 +2865,9 @@ class Attribute extends AppModel
|
|||
$pagesToFetch = 1;
|
||||
}
|
||||
$attributes = array();
|
||||
if (!empty($options['includeEventTags'])) {
|
||||
$eventTags = array();
|
||||
}
|
||||
while ($continue) {
|
||||
if ($loop) {
|
||||
$params['page'] = $params['page'] + 1;
|
||||
|
@ -2887,6 +2890,27 @@ class Attribute extends AppModel
|
|||
$results = array_values($results);
|
||||
$proposals_block_attributes = Configure::read('MISP.proposals_block_attributes');
|
||||
foreach ($results as $key => $attribute) {
|
||||
if (!empty($options['includeEventTags'])) {
|
||||
if (!isset($eventTags[$results[$key]['Event']['id']])) {
|
||||
$tagConditions = array('EventTag.event_id' => $attribute['Event']['id']);
|
||||
if (empty($options['includeAllTags'])) {
|
||||
$tagConditions['Tag.exportable'] = 1;
|
||||
}
|
||||
$temp = $this->Event->EventTag->find('all', array(
|
||||
'recursive' => -1,
|
||||
'contain' => array('Tag'),
|
||||
'conditions' => $tagConditions
|
||||
));
|
||||
foreach ($temp as $tag) {
|
||||
$tag['EventTag']['Tag'] = $tag['Tag'];
|
||||
unset($tag['Tag']);
|
||||
$eventTags[$results[$key]['Event']['id']][] = $tag;
|
||||
}
|
||||
}
|
||||
foreach ($eventTags[$results[$key]['Event']['id']] as $eventTag) {
|
||||
$results[$key]['EventTag'][] = $eventTag['EventTag'];
|
||||
}
|
||||
}
|
||||
if ($options['enforceWarninglist'] && !$this->Warninglist->filterWarninglistAttributes($warninglists, $attribute['Attribute'])) {
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue