mirror of https://github.com/MISP/MISP
chg: [module] Serialize post data at one place
parent
8b81895997
commit
150600e4af
|
@ -2439,7 +2439,6 @@ class AttributesController extends AppController
|
|||
} else {
|
||||
$data[$attribute[0]['Attribute']['type']] = $attribute[0]['Attribute']['value'];
|
||||
}
|
||||
$data = json_encode($data);
|
||||
$result = $this->Module->queryModuleServer('/query', $data, true);
|
||||
if ($result) {
|
||||
if (!is_array($result)) {
|
||||
|
|
|
@ -4759,7 +4759,6 @@ class EventsController extends AppController
|
|||
if (!empty($options)) {
|
||||
$data['config'] = $options;
|
||||
}
|
||||
$data = json_encode($data);
|
||||
$result = $this->Module->queryModuleServer('/query', $data, false, $type);
|
||||
if (!$result) {
|
||||
throw new MethodNotAllowedException(__('%s service not reachable.', $type));
|
||||
|
@ -4805,7 +4804,6 @@ class EventsController extends AppController
|
|||
if (!empty($options)) {
|
||||
$data['config'] = $options;
|
||||
}
|
||||
$data = json_encode($data);
|
||||
$result = $this->Module->queryModuleServer('/query', $data, false, $type);
|
||||
if (!$result) {
|
||||
throw new MethodNotAllowedException(__('%s service not reachable.', $type));
|
||||
|
@ -4996,7 +4994,7 @@ class EventsController extends AppController
|
|||
if (!empty($filename)) {
|
||||
$modulePayload['filename'] = $filename;
|
||||
}
|
||||
$result = $this->Module->queryModuleServer('/query', json_encode($modulePayload), false, $moduleFamily = 'Import');
|
||||
$result = $this->Module->queryModuleServer('/query', $modulePayload, false, $moduleFamily = 'Import');
|
||||
if (!$result) {
|
||||
throw new Exception(__('Import service not reachable.'));
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ class ModulesController extends AppController
|
|||
}
|
||||
|
||||
// Query
|
||||
$result = $this->Module->queryModuleServer('/query', json_encode($data), true);
|
||||
$result = $this->Module->queryModuleServer('/query', $data, true);
|
||||
if (!$result) {
|
||||
$result = array('error' => 'Something went wrong, no response from module.');
|
||||
}
|
||||
|
|
|
@ -5751,7 +5751,7 @@ class Event extends AppModel
|
|||
}
|
||||
}
|
||||
$modulePayload['data'] = $events;
|
||||
$result = $this->Module->queryModuleServer('/query', json_encode($modulePayload, true), false, 'Export');
|
||||
$result = $this->Module->queryModuleServer('/query', $modulePayload, false, 'Export');
|
||||
return array(
|
||||
'data' => $result['data'],
|
||||
'extension' => $module['mispattributes']['outputFileExtension'],
|
||||
|
@ -6135,7 +6135,6 @@ class Event extends AppModel
|
|||
} else {
|
||||
$data[$attribute['type']] = $attribute['value'];
|
||||
}
|
||||
$data = json_encode($data);
|
||||
$result = $this->Module->queryModuleServer('/query', $data, false, 'Enrichment');
|
||||
if (!$result) {
|
||||
throw new MethodNotAllowedException(h($module['name']) . ' service not reachable.');
|
||||
|
|
|
@ -198,6 +198,14 @@ class Module extends AppModel
|
|||
return "$url:$port";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $uri
|
||||
* @param array|false $post
|
||||
* @param bool $hover
|
||||
* @param string $moduleFamily
|
||||
* @param Exception|false $exception
|
||||
* @return array|false
|
||||
*/
|
||||
public function queryModuleServer($uri, $post = false, $hover = false, $moduleFamily = 'Enrichment', &$exception = false)
|
||||
{
|
||||
$url = $this->__getModuleServer($moduleFamily);
|
||||
|
@ -226,9 +234,9 @@ class Module extends AppModel
|
|||
}
|
||||
$httpSocket = new HttpSocket($settings);
|
||||
$request = array(
|
||||
'header' => array(
|
||||
'Content-Type' => 'application/json',
|
||||
)
|
||||
'header' => array(
|
||||
'Content-Type' => 'application/json',
|
||||
)
|
||||
);
|
||||
if ($moduleFamily == 'Cortex') {
|
||||
if (!empty(Configure::read('Plugin.' . $moduleFamily . '_authkey'))) {
|
||||
|
@ -237,6 +245,10 @@ class Module extends AppModel
|
|||
}
|
||||
try {
|
||||
if ($post) {
|
||||
if (!is_array($post)) {
|
||||
throw new InvalidArgumentException("Post data must be array, " . gettype($post) . " given.");
|
||||
}
|
||||
$post = json_encode($post);
|
||||
$response = $httpSocket->post($url . $uri, $post, $request);
|
||||
} else {
|
||||
if ($moduleFamily == 'Cortex') {
|
||||
|
|
Loading…
Reference in New Issue