mirror of https://github.com/MISP/MISP
ichg: [analyst-note:pull] Continuation of adding support of PULL sync filtering rule - WiP
parent
b928e8241b
commit
a8607c54dd
|
@ -256,7 +256,24 @@ class AnalystDataController extends AppController
|
|||
if ($this->request->is('post')) {
|
||||
$filters = $this->request->data;
|
||||
}
|
||||
$allData = $this->AnalystData->indexMinimal($this->Auth->user(), $filters);
|
||||
$options = [];
|
||||
$acceptedFilters = ['orgc_uuid', ];
|
||||
foreach ($acceptedFilters as $filterName) {
|
||||
if (!empty($filters[$filterName])) {
|
||||
$filterValue = $filters[$filterName];
|
||||
if (!is_array($filterValue)) {
|
||||
$filterValue = [$filterValue];
|
||||
}
|
||||
foreach ($filterValue as $entry) {
|
||||
if ($entry[0] === '!') {
|
||||
$options[]['AND'][] = ["{$filterName} !=" => substr($entry, 1)];
|
||||
} else {
|
||||
$options['OR'][] = [$filterName => $entry];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$allData = $this->AnalystData->indexMinimal($this->Auth->user(), $options);
|
||||
|
||||
return $this->RestResponse->viewData($allData, $this->response->type());
|
||||
}
|
||||
|
|
|
@ -780,9 +780,25 @@ class AnalystData extends AppModel
|
|||
$this->Server = ClassRegistry::init('Server');
|
||||
$this->AnalystData = ClassRegistry::init('AnalystData');
|
||||
try {
|
||||
$filterRules = $this->Server->filterRuleToParameter($serverSync->server()['Server']['pull_rules']);
|
||||
if (!empty($filterRules['org']) && !$serverSync->isSupported(ServerSyncTool::FEATURE_ORG_RULE)) {
|
||||
$filterRules['org'] = implode('|', $filterRules['org']);
|
||||
$filterRules = ['orgc_uuid' => []];
|
||||
$pullRules = $this->jsonDecode($serverSync->server()['Server']['pull_rules']);
|
||||
if (!empty($pullRules['orgs']['OR'])) {
|
||||
$orgsOR = $this->AnalystData->Orgc->find('column', [
|
||||
'recursive' => -1,
|
||||
'conditions' => ['name' => $pullRules['orgs']['OR']],
|
||||
'fields' => ['uuid'],
|
||||
]);
|
||||
$filterRules['orgc_uuid'] = $orgsOR;
|
||||
}
|
||||
if (!empty($pullRules['orgs']['NOT'])) {
|
||||
$orgsNOT = $this->AnalystData->Orgc->find('column', [
|
||||
'recursive' => -1,
|
||||
'conditions' => ['name' => $pullRules['orgs']['NOT']],
|
||||
'fields' => ['uuid'],
|
||||
]);
|
||||
$filterRules['orgc_uuid'] = array_merge($filterRules['orgc_uuid'], array_map(function($orgUUID) {
|
||||
return '!' . $orgUUID;
|
||||
}, $orgsNOT));
|
||||
}
|
||||
$remoteData = $serverSync->fetchIndexMinimal($filterRules);
|
||||
} catch (Exception $e) {
|
||||
|
|
Loading…
Reference in New Issue