chg: [stix] allow passing the publish flag to the stix upload

misp-stix
iglocska 2021-10-26 08:54:04 +02:00 committed by chrisr3d
parent c9d7ad2462
commit 4061440cc6
1 changed files with 5 additions and 7 deletions

View File

@ -2190,24 +2190,22 @@ class EventsController extends AppController
}
}
public function upload_stix($stix_version = '1')
public function upload_stix($stix_version = '1', $publish = false)
{
if ($this->request->is('post')) {
$scriptDir = APP . 'files' . DS . 'scripts';
if ($this->_isRest()) {
$randomFileName = $this->Event->generateRandomFileName();
$tempFile = new File($scriptDir . DS . 'tmp' . DS . $randomFileName, true, 0644);
if (!$tempFile->write($this->request->input())) {
throw new Exception("Could not write content of STIX file.");
if (isset($this->params['named']['publish'])) {
$publish = $this->params['named']['publish'];
}
$tempFile->close();
$filePath = FileAccessTool::writeToTempFile($this->request->input());
$result = $this->Event->upload_stix(
$this->Auth->user(),
$scriptDir,
$randomFileName,
$stix_version,
'uploaded_stix_file.' . ($stix_version == '1' ? 'xml' : 'json'),
false
$publish
);
if (is_numeric($result)) {
$event = $this->Event->fetchEvent($this->Auth->user(), array('eventid' => $result));