fix: [stix import] Some strings are defined in a cleaner way

pull/6022/head
chrisr3d 2020-01-22 15:39:06 +01:00
parent 88dbc83efe
commit 089fbb6231
No known key found for this signature in database
GPG Key ID: 6BBED1B63A6D639F
2 changed files with 9 additions and 9 deletions

View File

@ -2146,15 +2146,16 @@ class EventsController extends AppController
if (!$this->userRole['perm_modify']) {
throw new UnauthorizedException(__('You do not have permission to do that.'));
}
$scriptDir = APP . 'files' . DS . 'scripts';
if ($this->request->is('post')) {
if ($this->_isRest()) {
$randomFileName = $this->Event->generateRandomFileName();
$tmpDir = APP . "files" . DS . "scripts" . DS . "tmp";
$tempFile = new File($tmpDir . DS . $randomFileName, true, 0644);
$tempFile = new File($scriptDir . DS . 'tmp' . DS . $randomFileName, true, 0644);
$tempFile->write($this->request->input());
$tempFile->close();
$result = $this->Event->upload_stix(
$this->Auth->user(),
$scriptDir,
$randomFileName,
$stix_version,
'uploaded_stix_file.' . ($stix_version == '1' ? 'xml' : 'json'),
@ -2176,10 +2177,10 @@ class EventsController extends AppController
$original_file = !empty($this->data['Event']['original_file']) ? $this->data['Event']['stix']['name'] : '';
if (isset($this->data['Event']['stix']) && $this->data['Event']['stix']['size'] > 0 && is_uploaded_file($this->data['Event']['stix']['tmp_name'])) {
$randomFileName = $this->Event->generateRandomFileName();
$tmpDir = APP . "files" . DS . "scripts" . DS . "tmp";
move_uploaded_file($this->data['Event']['stix']['tmp_name'], $tmpDir . DS . $randomFileName);
move_uploaded_file($this->data['Event']['stix']['tmp_name'], $scriptDir . DS . 'tmp' . DS . $randomFileName);
$result = $this->Event->upload_stix(
$this->Auth->user(),
$scriptDir,
$randomFileName,
$stix_version,
$original_file,

View File

@ -5673,19 +5673,18 @@ class Event extends AppModel
return $this->save($event);
}
public function upload_stix($user, $filename, $stix_version, $original_file, $publish)
public function upload_stix($user, $scriptDir, $filename, $stix_version, $original_file, $publish)
{
App::uses('Folder', 'Utility');
App::uses('File', 'Utility');
$tempFilePath = $scriptDir . DS . 'tmp' . DS . $filename;
if ($stix_version == '2') {
$scriptFile = APP . 'files/scripts/stix2/stix2misp.py';
$tempFilePath = APP . 'files/scripts/tmp/' . $filename;
$scriptFile = $scriptDir . DS . 'stix2' . DS . 'stix2misp.py';
$shell_command = $this->getPythonVersion() . ' ' . $scriptFile . ' ' . $tempFilePath;
$output_path = $tempFilePath . '.stix2';
$stix_version = "STIX 2.0";
} elseif ($stix_version == '1' || $stix_version == '1.1' || $stix_version == '1.2') {
$scriptFile = APP . 'files/scripts/stix2misp.py';
$tempFilePath = APP . 'files/scripts/tmp/' . $filename;
$scriptFile = $scriptDir . DS . 'stix2misp.py';
$shell_command = $this->getPythonVersion() . ' ' . $scriptFile . ' ' . $filename;
$output_path = $tempFilePath . '.json';
$stix_version = "STIX 1.1";