id = Inflector::underscore($misp_module_config['name']); $this->name = $misp_module_config['name']; $this->description = $misp_module_config['meta']['description']; if (!empty($misp_module_config['meta']['icon'])) { $this->icon = $misp_module_config['meta']['icon']; } if (!empty($misp_module_config['meta']['icon_class'])) { $this->icon_class = $misp_module_config['meta']['icon_class']; } if (!empty($misp_module_config['meta']['inputs'])) { $this->inputs = (int)$misp_module_config['meta']['inputs']; } if (!empty($misp_module_config['meta']['outputs'])) { $this->inputs = (int)$misp_module_config['meta']['outputs']; } if (!empty($misp_module_config['meta']['config']['blocking'])) { $this->blocking = !empty($misp_module_config['meta']['config']['blocking']); } if (!empty($misp_module_config['meta']['config']['expect_misp_core_format'])) { $this->expect_misp_core_format = !empty($misp_module_config['meta']['config']['expect_misp_core_format']); } if (!empty($misp_module_config['meta']['config']['support_filters'])) { $this->support_filters = !empty($misp_module_config['meta']['config']['support_filters']); } if (!empty($misp_module_config['meta']['config'])) { foreach ($misp_module_config['meta']['config']['params'] as $paramName => $moduleParam) { $this->params[] = $this->translateParams($paramName, $moduleParam); } } $this->Module = ClassRegistry::init('Module'); } public function exec(array $node, WorkflowRoamingData $roamingData, array &$errors=[]): bool { parent::exec($node, $roamingData); $postData = ['module' => $this->name]; $rData = $roamingData->getData(); $postData['data'] = $rData; if ($this->support_filters) { $filters = $this->getFilters($node); $extracted = $this->extractData($rData, $filters['selector']); if ($extracted === false) { return false; } $filteredItems = $this->getItemsMatchingCondition($extracted, $filters['value'], $filters['operator'], $filters['path']); $postData['filteredItems'] = !empty($filteredItems) ? $filteredItems : $rData; } $postData['params'] = $this->getIndexedParamsWithValues($node); $params = $this->getParamsWithValues($node); $matchingData = []; foreach ($params as $param) { if (!empty($param['_isHashPath'])) { $matchingData[$param['label']] = !empty($param['value']) ? $this->extractData($rData, $param['value']) : $rData; } } if (!empty($matchingData)) { $postData['matchingData'] = $matchingData; } $query = $this->Module->queryModuleServer($postData, false, 'Action', false, $postData['data']); if (!empty($query['error'])) { $errors[] = $query['error']; return false; } return true; } // FIXME: We might want to align the module config with what's currently supported protected function translateParams($paramName, $moduleParam): array { $param = []; $param['label'] = $paramName; $param['placeholder'] = $moduleParam['value'] ?? ''; if ($moduleParam['type'] == 'hash_path') { $param['type'] = 'input'; $param['_isHashPath'] = true; } elseif ($moduleParam['type'] == 'large_string') { $param['type'] = 'input'; } else { $param['type'] = 'input'; } return $param; } }