mirror of https://github.com/MISP/MISP
new: [internal] OrgBlocklist::removeBlockedEvents
parent
cb53c030b7
commit
1a44c3885d
|
@ -1,5 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
App::uses('AppModel', 'Model');
|
App::uses('AppModel', 'Model');
|
||||||
|
|
||||||
class OrgBlocklist extends AppModel
|
class OrgBlocklist extends AppModel
|
||||||
{
|
{
|
||||||
public $useTable = 'org_blocklists';
|
public $useTable = 'org_blocklists';
|
||||||
|
@ -39,4 +40,24 @@ class OrgBlocklist extends AppModel
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $eventArray
|
||||||
|
*/
|
||||||
|
public function removeBlockedEvents(array &$eventArray)
|
||||||
|
{
|
||||||
|
$blocklistHits = $this->find('column', array(
|
||||||
|
'conditions' => array('OrgBlocklist.org_uuid' => array_unique(array_column($eventArray, 'orgc_uuid'))),
|
||||||
|
'fields' => array('OrgBlocklist.org_uuid'),
|
||||||
|
));
|
||||||
|
if (empty($blocklistHits)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$blocklistHits = array_flip($blocklistHits);
|
||||||
|
foreach ($eventArray as $k => $event) {
|
||||||
|
if (isset($blocklistHits[$event['orgc_uuid']])) {
|
||||||
|
unset($eventArray[$k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -733,7 +733,7 @@ class Server extends AppModel
|
||||||
public function getEventIdsFromServer(ServerSyncTool $serverSync, $all = false, $ignoreFilterRules = false, $scope = 'events', $force = false)
|
public function getEventIdsFromServer(ServerSyncTool $serverSync, $all = false, $ignoreFilterRules = false, $scope = 'events', $force = false)
|
||||||
{
|
{
|
||||||
if (!in_array($scope, ['events', 'sightings'], true)) {
|
if (!in_array($scope, ['events', 'sightings'], true)) {
|
||||||
throw new InvalidArgumentException("Scope mus be 'events' or 'sightings', '$scope' given.");
|
throw new InvalidArgumentException("Scope must be 'events' or 'sightings', '$scope' given.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$eventArray = $this->getEventIndexFromServer($serverSync, $ignoreFilterRules);
|
$eventArray = $this->getEventIndexFromServer($serverSync, $ignoreFilterRules);
|
||||||
|
@ -767,16 +767,7 @@ class Server extends AppModel
|
||||||
|
|
||||||
if (Configure::read('MISP.enableOrgBlocklisting') !== false) {
|
if (Configure::read('MISP.enableOrgBlocklisting') !== false) {
|
||||||
$this->OrgBlocklist = ClassRegistry::init('OrgBlocklist');
|
$this->OrgBlocklist = ClassRegistry::init('OrgBlocklist');
|
||||||
$blocklistHits = $this->OrgBlocklist->find('column', array(
|
$this->OrgBlocklist->removeBlockedEvents($eventArray);
|
||||||
'conditions' => array('OrgBlocklist.org_uuid' => array_unique(array_column($eventArray, 'orgc_uuid'))),
|
|
||||||
'fields' => array('OrgBlocklist.org_uuid'),
|
|
||||||
));
|
|
||||||
$blocklistHits = array_flip($blocklistHits);
|
|
||||||
foreach ($eventArray as $k => $event) {
|
|
||||||
if (isset($blocklistHits[$event['orgc_uuid']])) {
|
|
||||||
unset($eventArray[$k]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($eventArray as $k => $event) {
|
foreach ($eventArray as $k => $event) {
|
||||||
|
|
Loading…
Reference in New Issue