fix: Attempted fix for an issue with large stix exports getting truncated

pull/1641/head
Iglocska 2016-11-01 17:57:56 +01:00
parent dfda8b6349
commit d9bac88c73
2 changed files with 11 additions and 9 deletions

View File

@ -108,16 +108,16 @@ class EventShell extends AppShell
$this->Job->id = $id;
$dir = new Folder(APP . 'tmp/cached_exports/stix', true, 0750);
if ($user['Role']['perm_site_admin']) {
$stixFile = new File($dir->pwd() . DS . 'misp.stix' . '.ADMIN.xml');
$stixFilePath = $dir->pwd() . DS . 'misp.stix' . '.ADMIN.xml';
} else {
$stixFile = new File($dir->pwd() . DS . 'misp.stix' . '.' . $user['Organisation']['name'] . '.xml');
$stixFilePath = $dir->pwd() . DS . 'misp.stix' . '.' . $user['Organisation']['name'] . '.xml';
}
$result = $this->Event->stix(false, false, Configure::read('MISP.cached_attachments'), $user, 'xml', false, false, false, $id);
$result = $this->Event->stix(false, false, Configure::read('MISP.cached_attachments'), $user, 'xml', false, false, false, $id, true);
$timeDelta = (time()-$timeStart);
$this->Job->saveField('date_modified', date("y-m-d H:i:s"));
if ($result['success']) {
$stixFile->write($result['data']);
$stixFile->close();
rename($result['data'], $stixFilePath);
unlink($result['data']);
$this->Job->saveField('progress', 100);
$this->Job->saveField('message', 'Job done. (in '.$timeDelta.'s)');
} else {

View File

@ -2540,7 +2540,7 @@ class Event extends AppModel {
}
public function stix($id, $tags, $attachments, $user, $returnType = 'xml', $from = false, $to = false, $last = false, $jobId = false) {
public function stix($id, $tags, $attachments, $user, $returnType = 'xml', $from = false, $to = false, $last = false, $jobId = false, $returnFile = false) {
$eventIDs = $this->Attribute->dissectArgs($id);
$tagIDs = $this->Attribute->dissectArgs($tags);
$idList = $this->getAccessibleEventIds($eventIDs[0], $eventIDs[1], $tagIDs[0], $tagIDs[1]);
@ -2634,10 +2634,12 @@ class Event extends AppModel {
$stixFile->delete();
return array('success' => 0, 'message' => 'No matching events found to export.');
}
$data = $stixFile->read();
$tempFile->delete();
$stixFile->delete();
return array('success' => 1, 'data' => $data);
if (!$returnFile) {
$data = $stixFile->read();
$stixFile->delete();
}
return array('success' => 1, 'data' => $returnFile ? $stixFile->path : $data);
}
public function getAccessibleEventIds($include, $exclude, $includedTags, $excludedTags) {