mirror of https://github.com/MISP/MISP
chg: [internal] Use ProcessTool in Exports
parent
eb8955b220
commit
acd88ade13
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
App::uses('ProcessTool', 'Tools');
|
||||
|
||||
class OpendataExport
|
||||
{
|
||||
|
@ -67,12 +68,11 @@ class OpendataExport
|
|||
|
||||
public function footer()
|
||||
{
|
||||
$my_server = ClassRegistry::init('Server');
|
||||
$cmd = $my_server->getPythonVersion() . ' ' . $this->__scripts_dir . $this->__script_name;
|
||||
$cmd = [ProcessTool::pythonBin(), $this->__scripts_dir . $this->__script_name];
|
||||
if (!empty($this->__auth)) {
|
||||
$this->__request_object['auth'] = $this->__auth;
|
||||
}
|
||||
if ($this->__search){
|
||||
if ($this->__search) {
|
||||
return $this->__search_query($cmd);
|
||||
}
|
||||
return $this->__delete ? $this->__delete_query($cmd) : $this->__add_query($cmd);
|
||||
|
@ -83,7 +83,7 @@ class OpendataExport
|
|||
return '';
|
||||
}
|
||||
|
||||
private function __add_query($cmd)
|
||||
private function __add_query(array $cmd)
|
||||
{
|
||||
unset($this->__default_filters['returnFormat']);
|
||||
$body = json_encode($this->__default_filters);
|
||||
|
@ -95,7 +95,9 @@ class OpendataExport
|
|||
$this->__request_object['setup'] = $setupFilename;
|
||||
$this->__request_object['misp_url'] = $this->__url;
|
||||
$commandFile = $this->__generateCommandFile();
|
||||
$results = shell_exec($cmd . ' --query_data ' . $commandFile);
|
||||
$cmd[] = '--query_data';
|
||||
$cmd[] = $commandFile;
|
||||
$results = ProcessTool::execute($cmd);
|
||||
unlink($commandFile);
|
||||
unlink($bodyFilename);
|
||||
unlink($setupFilename);
|
||||
|
@ -128,13 +130,15 @@ class OpendataExport
|
|||
return $this->__simple_query($cmd);
|
||||
}
|
||||
|
||||
private function __simple_query($cmd)
|
||||
private function __simple_query(array $cmd)
|
||||
{
|
||||
if (!empty($this->__setup['resources'])) {
|
||||
$this->__request_object['search'] = $this->__setup['resources'];
|
||||
}
|
||||
$commandFile = $this->__generateCommandFile();
|
||||
$results = shell_exec($cmd . ' --query_data ' . $commandFile);
|
||||
$cmd[] = '--query_data';
|
||||
$cmd[] = $commandFile;
|
||||
$results = ProcessTool::execute($cmd);
|
||||
unlink($commandFile);
|
||||
return $results;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
<?php
|
||||
App::uses('JsonExport', 'Export');
|
||||
App::uses('AppModel', 'Model');
|
||||
App::uses('ProcessTool', 'Tools');
|
||||
|
||||
class YaraExport
|
||||
{
|
||||
private $__script_path = APP . 'files/scripts/yara/yaraexport.py';
|
||||
private $__tmp_dir = APP . 'tmp/yara/';
|
||||
private $__end_of_cmd = ' 2>>' . APP . 'tmp/logs/yara_export.log';
|
||||
private $__n_attributes = 0;
|
||||
private $__MAX_n_attributes = 15000;
|
||||
private $__yara_file_gen = null;
|
||||
|
@ -35,7 +35,7 @@ class YaraExport
|
|||
}
|
||||
$this->__initialize_yara_file();
|
||||
$this->__initialize_misp_file($options);
|
||||
if($options['returnFormat'] === 'yara-json'){
|
||||
if($options['returnFormat'] === 'yara-json') {
|
||||
$this->__raw_mode = false;
|
||||
}
|
||||
return '';
|
||||
|
@ -132,10 +132,20 @@ class YaraExport
|
|||
$in = $this->__curr_input_file->path;
|
||||
$out1 = $this->__yara_file_gen->path;
|
||||
$out2 = $this->__yara_file_asis->path;
|
||||
$logging = $this->__end_of_cmd;
|
||||
$raw_flag = $this->__raw_mode ? '--raw' : '';
|
||||
$my_server = ClassRegistry::init('Server');
|
||||
$result = shell_exec($my_server->getPythonVersion() . " $pythonScript --input $in --out-generated $out1 --out-asis $out2 $raw_flag $logging");
|
||||
|
||||
$command = [
|
||||
ProcessTool::pythonBin(),
|
||||
$pythonScript,
|
||||
'--input', $in,
|
||||
'--out-generated', $out1,
|
||||
'--out-asis', $out2,
|
||||
];
|
||||
if ($this->__raw_mode) {
|
||||
$command[] = '--raw';
|
||||
}
|
||||
|
||||
ProcessTool::execute($command, null, true);
|
||||
|
||||
$this->__curr_input_file->close();
|
||||
$this->__curr_input_file->delete();
|
||||
$this->__n_attributes = 0;
|
||||
|
|
Loading…
Reference in New Issue