mirror of https://github.com/MISP/MISP
chg: [workflow] Better arg parsing and if modules support attribute filters
parent
b9fb55713e
commit
86555e4d60
|
@ -415,13 +415,13 @@ class Workflow extends AppModel
|
|||
}
|
||||
}
|
||||
|
||||
public function executeWorkflow($id)
|
||||
public function executeWorkflow($id, array $data=[])
|
||||
{
|
||||
$user = ['Role' => ['perm_site_admin' => true]];
|
||||
$workflow = $this->fetchWorkflow($user, $id);
|
||||
$trigger_ids = $this->workflowGraphTool->extractTriggersFromWorkflow($workflow['Workflow']['data'], false);
|
||||
foreach ($trigger_ids as $trigger_id) {
|
||||
$data = ['uuid' => '2683b27f-c509-4458-84f9-8980f60548df'];
|
||||
$data = ['Event.uuid' => ['2683b27f-c509-4458-84f9-8980f60548df']];
|
||||
$this->walkGraph($workflow, $trigger_id, null, $data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,17 @@ class WorkflowBaseModule
|
|||
protected function getParams($node): array
|
||||
{
|
||||
$indexedParam = [];
|
||||
$nodeParam = [];
|
||||
foreach ($node['data']['params'] as $param) {
|
||||
$nodeParam[$param['label']] = $param;
|
||||
}
|
||||
foreach ($this->params as $param) {
|
||||
$param['value'] = $nodeParam[$param['label']]['value'] ?? null;
|
||||
$indexedParam[$param['label']] = $param;
|
||||
}
|
||||
return $indexedParam;
|
||||
}
|
||||
|
||||
|
||||
protected function getParamsWithValues($node): array
|
||||
{
|
||||
$indexedParam = $this->getParams($node);
|
||||
|
@ -57,7 +62,7 @@ class WorkflowBaseModule
|
|||
return true;
|
||||
}
|
||||
|
||||
public function push_zmq($message)
|
||||
public function push_zmq($message, $namespace='')
|
||||
{
|
||||
if (!self::$loadedPubSubTool) {
|
||||
App::uses('PubSubTool', 'Tools');
|
||||
|
@ -66,7 +71,7 @@ class WorkflowBaseModule
|
|||
self::$loadedPubSubTool = $pubSubTool;
|
||||
}
|
||||
$pubSubTool = self::$loadedPubSubTool;
|
||||
$pubSubTool->workflow_push($message);
|
||||
$pubSubTool->workflow_push($message, $namespace);
|
||||
}
|
||||
|
||||
public function logError($message)
|
||||
|
|
|
@ -16,6 +16,12 @@ class Module_push_zmq extends WorkflowBaseModule
|
|||
{
|
||||
parent::__construct();
|
||||
$this->params = [
|
||||
[
|
||||
'type' => 'input',
|
||||
'label' => 'Namespace',
|
||||
'default' => '',
|
||||
'placeholder' => 'A namespace in the ZMQ topic'
|
||||
],
|
||||
[
|
||||
'type' => 'input',
|
||||
'label' => 'Content',
|
||||
|
@ -28,10 +34,15 @@ class Module_push_zmq extends WorkflowBaseModule
|
|||
public function exec(array $node, WorkflowRoamingData $roamingData): bool
|
||||
{
|
||||
parent::exec($node, $roamingData);
|
||||
$params = $this->getParams($node);
|
||||
$params = $this->getParamsWithValues($node);
|
||||
// $this->push_zmq([
|
||||
// 'Module_push_zmq has passed option' => $params['Content']['value']
|
||||
// ]);
|
||||
debug($params);
|
||||
$this->push_zmq([
|
||||
'Module_push_zmq has passed option' => $params['Content']['value']
|
||||
]);
|
||||
'content' => $params['Content']['value'],
|
||||
'pass_along' => $roamingData->getData(),
|
||||
], $params['Namespace']['value']);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,9 @@ class Module_if extends WorkflowBaseModule
|
|||
$ifScope = $params['Scope']['value'];
|
||||
$ifFilter = json_decode($params['Matching Conditions']['value'], true);
|
||||
$matchingUUID = $this->getMatchingUUID($roamingData->getUser(), $ifScope, $roamingData->getData(), $ifFilter);
|
||||
if (!empty($matchingUUID)) {
|
||||
$this->propagateConditions($roamingData, $ifScope, $matchingUUID);
|
||||
}
|
||||
return !empty($matchingUUID);
|
||||
}
|
||||
|
||||
|
@ -52,14 +55,42 @@ class Module_if extends WorkflowBaseModule
|
|||
$this->logError(__('Unknown model %s', $model));
|
||||
return [];
|
||||
}
|
||||
$loadedMode = ClassRegistry::init($model);
|
||||
if (empty($user) || empty($data['uuid'])) {
|
||||
$loadedModel = ClassRegistry::init($model);
|
||||
if (empty($user)) {
|
||||
return [];
|
||||
}
|
||||
$filters['uuid'] = $data['uuid'];
|
||||
$final = $loadedMode->restSearch($user, 'json', $filters);
|
||||
$events = json_decode($final->intoString(), true)['response'];
|
||||
$matchingUUID = Hash::extract($events, '{n}.Event.uuid');
|
||||
if ($model == 'Event') {
|
||||
if (!empty($data['Event.uuid'])) {
|
||||
$filters['uuid'] = $data['Event.uuid'];
|
||||
}
|
||||
$filters['metadata'] = true;
|
||||
} elseif ($model == 'Attribute') {
|
||||
if (!empty($data['Event.uuid'])) {
|
||||
$filters['eventid'] = $data['Event.uuid'];
|
||||
}
|
||||
if (!empty($data['Attribute.uuid'])) {
|
||||
$filters['uuid'] = $data['Attribute.uuid'];
|
||||
}
|
||||
}
|
||||
$final = $loadedModel->restSearch($user, 'json', $filters);
|
||||
$result = json_decode($final->intoString(), true)['response'];
|
||||
$matchingUUID = [];
|
||||
if ($model == 'Event') {
|
||||
$matchingUUID = Hash::extract($result, '{n}.Event.uuid');
|
||||
} elseif ($model == 'Attribute') {
|
||||
$matchingUUID = Hash::extract($result, 'Attribute.{n}.uuid');
|
||||
}
|
||||
return $matchingUUID;
|
||||
}
|
||||
|
||||
public function propagateConditions(WorkflowRoamingData $roamingData, $scope, array $matchingUUID)
|
||||
{
|
||||
$data = $roamingData->getData();
|
||||
if ($scope == 'Event') {
|
||||
$data['Event.uuid'] = $matchingUUID;
|
||||
} elseif ($scope == 'Attribute') {
|
||||
$data['Attribute.uuid'] = $matchingUUID;
|
||||
}
|
||||
$roamingData->setData($data);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue