chg: [MISP connector] added bulk org pull

pull/163/head
iglocska 2023-11-30 11:44:38 +01:00
parent be64a186e0
commit d3f08205fb
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
1 changed files with 33 additions and 8 deletions

View File

@ -907,6 +907,12 @@ class MispConnector extends CommonConnectorTools
'reload_url' => '/localTools/action/' . h($params['connection']['id']) . '/organisationsAction', 'reload_url' => '/localTools/action/' . h($params['connection']['id']) . '/organisationsAction',
'popover_url' => '/localTools/action/' . h($params['connection']['id']) . '/fetchSelectedOrganisationsAction' 'popover_url' => '/localTools/action/' . h($params['connection']['id']) . '/fetchSelectedOrganisationsAction'
], ],
[
'text' => __('Fetch all organisations'),
'html' => '<i class="fas fa-download"></i> ',
'reload_url' => '/localTools/action/' . h($params['connection']['id']) . '/organisationsAction',
'popover_url' => '/localTools/action/' . h($params['connection']['id']) . '/fetchSelectedOrganisationsAction?ids=all'
],
[ [
'text' => __('Push organisations'), 'text' => __('Push organisations'),
'html' => '<i class="fas fa-upload"></i> ', 'html' => '<i class="fas fa-upload"></i> ',
@ -1190,23 +1196,42 @@ class MispConnector extends CommonConnectorTools
return [ return [
'data' => [ 'data' => [
'title' => __('Fetch organisations'), 'title' => __('Fetch organisations'),
'description' => __('Fetch and create/update the selected {0} organisations from MISP?', count($ids)), 'description' => is_array($ids) ?
__('Fetch and create/update the selected {0} organisations from MISP?', count($ids)) :
__('Fetch and create/update ALL organisations from MISP?'),
'submit' => [ 'submit' => [
'action' => $params['request']->getParam('action') 'action' => $params['request']->getParam('action')
], ],
'url' => ['controller' => 'localTools', 'action' => 'action', $params['connection']['id'], 'fetchSelectedOrganisationsAction'] 'url' => is_array($ids) ?
['controller' => 'localTools', 'action' => 'action', $params['connection']['id'], 'fetchSelectedOrganisationsAction'] :
['controller' => 'localTools', 'action' => 'action', $params['connection']['id'], 'fetchSelectedOrganisationsAction?ids=all']
] ]
]; ];
} elseif ($params['request']->is(['post'])) { } elseif ($params['request']->is(['post'])) {
$successes = 0; $successes = 0;
$errors = 0; $errors = 0;
foreach ($ids as $id) { if (!is_array($ids) && $ids === 'all') {
$response = $this->getData('/organisations/view/' . $id, $params); $response = $this->getData('/organisations/index/scope:all', $params);
$result = $this->captureOrganisation($response->getJson()['Organisation']);
if ($response->getStatusCode() == 200) { if ($response->getStatusCode() == 200) {
$successes++; $orgs = $response->getJson();
} else { foreach ($orgs as $org) {
$errors++; $result = $this->captureOrganisation($org['Organisation']);
if ($result) {
$successes++;
} else {
$errors++;
}
}
}
} else {
foreach ($ids as $id) {
$response = $this->getData('/organisations/view/' . $id, $params);
$result = $this->captureOrganisation($response->getJson()['Organisation']);
if ($response->getStatusCode() == 200) {
$successes++;
} else {
$errors++;
}
} }
} }
if ($successes) { if ($successes) {