Merge branch 'attributeFetcherFix' into 2.4

pull/3427/head
iglocska 2018-07-02 16:57:49 +02:00
commit c9c843cb39
1 changed files with 42 additions and 24 deletions

View File

@ -2605,39 +2605,57 @@ class Attribute extends AppModel {
)); ));
return $results; return $results;
} }
$results = $this->find('all', $params);
// return false if we're paginating
if (isset($options['limit']) && empty($results)) return false;
if ($options['enforceWarninglist']) { if ($options['enforceWarninglist']) {
$this->Warninglist = ClassRegistry::init('Warninglist'); $this->Warninglist = ClassRegistry::init('Warninglist');
$warninglists = $this->Warninglist->fetchForEventView(); $warninglists = $this->Warninglist->fetchForEventView();
} }
$results = array_values($results);
$proposals_block_attributes = Configure::read('MISP.proposals_block_attributes'); if (empty($params['limit'])) {
foreach ($results as $key => $attribute) { $pagesToFetch = $this->find('count', array('conditions' => $params['conditions']));
if ($options['enforceWarninglist'] && !$this->Warninglist->filterWarninglistAttributes($warninglists, $attribute['Attribute'])) { $loopLimit = 100000;
unset($results[$key]); $pagesToFetch = ceil($pagesToFetch / $loopLimit);
continue; $loop = true;
} else {
$loop = false;
$pagesToFetch = 1;
}
$attributes = array();
for ($i = 0; $i < $pagesToFetch; $i++) {
if ($loop) {
$params['limit'] = $loopLimit;
$params['page'] = $i+1;
} }
if (!empty($options['includeAttributeUuid']) || !empty($options['includeEventUuid'])) { $results = $this->find('all', $params);
$results[$key]['Attribute']['event_uuid'] = $results[$key]['Event']['uuid']; // return false if we're paginating
} if (isset($options['limit']) && empty($results)) return false;
if ($proposals_block_attributes) { $results = array_values($results);
if (!empty($attribute['ShadowAttribute'])) { $proposals_block_attributes = Configure::read('MISP.proposals_block_attributes');
unset($results[$key]); foreach ($results as $key => $attribute) {
} else { if ($options['enforceWarninglist'] && !$this->Warninglist->filterWarninglistAttributes($warninglists, $attribute['Attribute'])) {
unset($results[$key]['ShadowAttribute']); continue;
} }
} if (!empty($options['includeAttributeUuid']) || !empty($options['includeEventUuid'])) {
if ($options['withAttachments']) { $results[$key]['Attribute']['event_uuid'] = $results[$key]['Event']['uuid'];
if ($this->typeIsAttachment($attribute['Attribute']['type'])) {
$encodedFile = $this->base64EncodeAttachment($attribute['Attribute']);
$results[$key]['Attribute']['data'] = $encodedFile;
} }
if ($proposals_block_attributes) {
if (!empty($attribute['ShadowAttribute'])) {
continue;
} else {
unset($results[$key]['ShadowAttribute']);
}
}
if ($options['withAttachments']) {
if ($this->typeIsAttachment($attribute['Attribute']['type'])) {
$encodedFile = $this->base64EncodeAttachment($attribute['Attribute']);
$results[$key]['Attribute']['data'] = $encodedFile;
}
}
$attributes[] = $results[$key];
} }
} }
$results = array_values($results); return $attributes;
return $results;
} }
// Method gets and converts the contents of a file passed along as a base64 encoded string with the original filename into a zip archive // Method gets and converts the contents of a file passed along as a base64 encoded string with the original filename into a zip archive