diff --git a/src/Controller/LocalToolsController.php b/src/Controller/LocalToolsController.php index 9d4a20c..61f6e92 100644 --- a/src/Controller/LocalToolsController.php +++ b/src/Controller/LocalToolsController.php @@ -205,6 +205,9 @@ class LocalToolsController extends AppController { $this->loadModel('Broods'); $tools = $this->Broods->queryLocalTools($id); + foreach ($tools as $k => $tool) { + $tools[$k]['local_tools'] = $this->LocalTools->appendLocalToolConnections($id, $tool); + } if ($this->ParamHandler->isRest()) { return $this->RestResponse->viewData($tools, 'json'); } diff --git a/src/Lib/default/local_tool_connectors/CommonConnectorTools.php b/src/Lib/default/local_tool_connectors/CommonConnectorTools.php index b4924ee..acfc2e3 100644 --- a/src/Lib/default/local_tool_connectors/CommonConnectorTools.php +++ b/src/Lib/default/local_tool_connectors/CommonConnectorTools.php @@ -76,7 +76,6 @@ class CommonConnectorTools 'created' => time(), 'modified' => time() ]; - debug($entry); $data = $remoteToolConnections->patchEntity($data, $entry); $remoteToolConnections->save($data); } else { diff --git a/src/Lib/default/local_tool_connectors/MispConnector.php b/src/Lib/default/local_tool_connectors/MispConnector.php index 5a7467a..d86afad 100644 --- a/src/Lib/default/local_tool_connectors/MispConnector.php +++ b/src/Lib/default/local_tool_connectors/MispConnector.php @@ -579,6 +579,12 @@ class MispConnector extends CommonConnectorTools public function finaliseConnection(array $params): bool { + $params['sync_connection'] = $this->addServer([ + 'authkey' => $params['remote_tool']['authkey'], + 'url' => $params['remote_tool']['url'], + 'name' => $params['remote_tool']['name'], + 'remote_org_id' => $params['misp_organisation']['id'] + ]); return true; } diff --git a/src/Model/Table/LocalToolsTable.php b/src/Model/Table/LocalToolsTable.php index ee6e1ac..9cfc48f 100644 --- a/src/Model/Table/LocalToolsTable.php +++ b/src/Model/Table/LocalToolsTable.php @@ -223,4 +223,17 @@ class LocalToolsTable extends AppTable //'message' => ]; } + + public function appendLocalToolConnections(int $brood_id, array $tool): array + { + $remoteToolConnections = \Cake\ORM\TableRegistry::getTableLocator()->get('RemoteToolConnections'); + $connections = $remoteToolConnections->find()->where(['remote_tool_id' => $tool['id'], 'brood_id' => $brood_id])->toArray(); + $local_tools = []; + foreach ($connections as $k => $connection) { + $temp = $this->find()->where(['id' => $connection['local_tool_id']])->select(['id', 'name'])->enableHydration(false)->first(); + $temp['status'] = $connection['status']; + $local_tools[] = $temp; + } + return $local_tools; + } } diff --git a/templates/LocalTools/brood_tools.php b/templates/LocalTools/brood_tools.php index 9b73ae9..d069eca 100644 --- a/templates/LocalTools/brood_tools.php +++ b/templates/LocalTools/brood_tools.php @@ -29,6 +29,11 @@ echo $this->element('genericElements/IndexTable/index_table', [ [ 'name' => __('Description'), 'data_path' => 'description', + ], + [ + 'name' => __('Connected Local Tools'), + 'data_path' => 'local_tool', + 'element' => 'local_tools_status' ] ], 'title' => __('Local tools made available by the remote Cerebrate'), diff --git a/templates/element/genericElements/IndexTable/Fields/local_tools_status.php b/templates/element/genericElements/IndexTable/Fields/local_tools_status.php new file mode 100644 index 0000000..0d6e0b1 --- /dev/null +++ b/templates/element/genericElements/IndexTable/Fields/local_tools_status.php @@ -0,0 +1,13 @@ +Hash->extract($row, 'local_tools'); + $output = []; + foreach ($tools as $tool) { + $output[] = sprintf( + '%s: %s', + h($tool['id']), + h($tool['name']), + h($tool['status']) + ); + } + echo implode('
', $output); +?>