chg: [wip] local tools integration

feature-scoped-element
iglocska 2021-06-11 14:27:22 +02:00
parent 551ca0d83f
commit 2e9b306f46
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
6 changed files with 40 additions and 1 deletions

View File

@ -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');
}

View File

@ -76,7 +76,6 @@ class CommonConnectorTools
'created' => time(),
'modified' => time()
];
debug($entry);
$data = $remoteToolConnections->patchEntity($data, $entry);
$remoteToolConnections->save($data);
} else {

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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'),

View File

@ -0,0 +1,13 @@
<?php
$tools = $this->Hash->extract($row, 'local_tools');
$output = [];
foreach ($tools as $tool) {
$output[] = sprintf(
'<a href="/localTools/view/%s">%s</a>: %s',
h($tool['id']),
h($tool['name']),
h($tool['status'])
);
}
echo implode('<br />', $output);
?>