chg: [wip] local tool interconnector, user browsing/searching added for misp connector

pull/67/head
iglocska 2021-06-28 10:45:23 +02:00
parent 3bf7f5a3e4
commit 7ed72c5469
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
4 changed files with 168 additions and 3 deletions

View File

@ -246,4 +246,34 @@ class LocalToolsController extends AppController
]); ]);
} }
} }
public function connectLocal($local_tool_id)
{
$params = [
'local_tool_id' => $local_tool_id
];
$local_tool = $this->LocalTools->fetchConnection($local_tool_id);
if ($this->request->is(['post', 'put'])) {
$postParams = $this->ParamHandler->harvestParams(['target_tool_id']);
if (empty($postParams['target_tool_id'])) {
throw new MethodNotAllowedException(__('No target tool ID supplied.'));
}
$params['target_tool_id'] = $postParams['target_tool_id'];
$result = $this->LocalTools->encodeLocalConnection($params);
// Send message to remote inbox
debug($result);
} else {
$target_tools = $this->LocalTools->findConnectable($local_tool);
debug($target_tools);
if (empty($target_tools)) {
throw new NotFoundException(__('No tools found to connect.'));
}
$this->set('data', [
'remoteCerebrate' => $remoteCerebrate,
'remoteTool' => $remoteTool,
'local_tools' => $local_tools
]);
}
}
} }

View File

@ -82,6 +82,17 @@ class MispConnector extends CommonConnectorTools
'sort', 'sort',
'direction' 'direction'
] ]
],
'usersAction' => [
'type' => 'index',
'scope' => 'child',
'params' => [
'quickFilter',
'limit',
'page',
'sort',
'direction'
]
] ]
]; ];
public $version = '0.1'; public $version = '0.1';
@ -397,6 +408,82 @@ class MispConnector extends CommonConnectorTools
} }
} }
public function usersAction(array $params): array
{
$params['validParams'] = [
'limit' => 'limit',
'page' => 'page',
'quickFilter' => 'searchall'
];
$urlParams = h($params['connection']['id']) . '/usersAction';
$response = $this->getData('/admin/users/index', $params);
$data = $response->getJson();
if (!empty($data)) {
return [
'type' => 'index',
'data' => [
'data' => $data,
'skip_pagination' => 1,
'top_bar' => [
'children' => [
[
'type' => 'search',
'button' => __('Filter'),
'placeholder' => __('Enter value to search'),
'data' => '',
'searchKey' => 'value',
'additionalUrlParams' => $urlParams,
'quickFilter' => 'value'
]
]
],
'fields' => [
[
'name' => 'Id',
'sort' => 'User.id',
'data_path' => 'User.id',
],
[
'name' => 'Organisation',
'sort' => 'Organisation.name',
'data_path' => 'Organisation.name',
],
[
'name' => 'Email',
'sort' => 'User.email',
'data_path' => 'User.email',
],
[
'name' => 'Role',
'sort' => 'Role.name',
'data_path' => 'Role.name'
]
],
'actions' => [
[
'open_modal' => '/localTools/action/' . h($params['connection']['id']) . '/editUser?id={{0}}',
'modal_params_data_path' => ['User.id'],
'icon' => 'edit',
'reload_url' => '/localTools/action/' . h($params['connection']['id']) . '/editAction'
],
[
'open_modal' => '/localTools/action/' . h($params['connection']['id']) . '/deleteUser?id={{0}}',
'modal_params_data_path' => ['User.id'],
'icon' => 'trash',
'reload_url' => '/localTools/action/' . h($params['connection']['id']) . '/serversAction'
]
],
'title' => false,
'description' => false,
'pull' => 'right'
]
];
} else {
return [];
}
}
public function organisationsAction(array $params): array public function organisationsAction(array $params): array
{ {
$params['validParams'] = [ $params['validParams'] = [
@ -631,8 +718,7 @@ class MispConnector extends CommonConnectorTools
'label' => __('Value'), 'label' => __('Value'),
'default' => h($response['value']), 'default' => h($response['value']),
'type' => 'dropdown', 'type' => 'dropdown',
'options' => $response['options'], 'options' => $response['options']
] ]
]; ];
} else { } else {
@ -648,7 +734,7 @@ class MispConnector extends CommonConnectorTools
return [ return [
'data' => [ 'data' => [
'title' => __('Modify server setting'), 'title' => __('Modify server setting'),
'description' => __('Modify setting ({0}) on connected MISP instance.', $params['setting']), 'description' => __('Modify setting ({0}) on selected MISP instance(s).', $params['setting']),
'fields' => $fields, 'fields' => $fields,
'submit' => [ 'submit' => [
'action' => $params['request']->getParam('action') 'action' => $params['request']->getParam('action')

View File

@ -95,6 +95,29 @@ class LocalToolsTable extends AppTable
return $connectors; return $connectors;
} }
public function getInterconnectors(string $name = null): array
{
$connectors = [];
$dirs = [
ROOT . '/src/Lib/default/local_tool_interconnectors',
ROOT . '/src/Lib/custom/local_tool_interconnectors'
];
foreach ($dirs as $dir) {
$dir = new Folder($dir);
$files = $dir->find('.*Interconnector\.php');
foreach ($files as $file) {
require_once($dir->pwd() . '/'. $file);
$className = substr($file, 0, -4);
$classNamespace = '\\' . $className . '\\' . $className;
$tempClass = new $classNamespace;
if (empty($name) || $tempClass->getConnectors()[0] === $name) {
$connectors[$tempClass->getConnectors()[0]][] = new $classNamespace;
}
}
}
return $connectors;
}
public function extractMeta(array $connector_classes, bool $includeConnections = false): array public function extractMeta(array $connector_classes, bool $includeConnections = false): array
{ {
$connectors = []; $connectors = [];
@ -236,4 +259,25 @@ class LocalToolsTable extends AppTable
} }
return $local_tools; return $local_tools;
} }
public function findConnectable($local_tool): array
{
$connectors = $this->getInterconnectors($local_tool['connector']);
$validTargets = [];
if (!empty($connectors)) {
foreach ($connectors[$local_tool['connector']] as $connector) {
$validTargets[$connector['connects'][1]] = 1;
}
}
}
public function fetchConnection($id): object
{
$connection = $this->find()->where(['id' => $id])->first();
if (empty($connection)) {
throw new NotFoundException(__('Local tool not found.'));
}
return $connection;
}
} }

View File

@ -60,6 +60,11 @@ echo $this->element('genericElements/IndexTable/index_table', [
'url_params_data_paths' => ['id'], 'url_params_data_paths' => ['id'],
'icon' => 'eye' 'icon' => 'eye'
], ],
[
'open_modal' => '/localTools/connectLocal/[onclick_params_data_path]',
'modal_params_data_path' => 'id',
'icon' => 'plug'
],
[ [
'open_modal' => '/localTools/edit/[onclick_params_data_path]', 'open_modal' => '/localTools/edit/[onclick_params_data_path]',
'modal_params_data_path' => 'id', 'modal_params_data_path' => 'id',