mirror of https://github.com/MISP/MISP
chg: [eventFiltering] WIP - Integrating new filtering behavior into
Modelpull/4076/head
parent
c89a6ed9fe
commit
1b3de72883
|
@ -44,6 +44,8 @@ class EventsController extends AppController
|
|||
$this->Auth->allow('stix');
|
||||
$this->Auth->allow('stix2');
|
||||
|
||||
$this->Security->unlockedActions[] = 'viewEventAttributes';
|
||||
|
||||
// TODO Audit, activate logable in a Controller
|
||||
if (count($this->uses) && $this->{$this->modelClass}->Behaviors->attached('SysLogLogable')) {
|
||||
$this->{$this->modelClass}->setUserData($this->activeUser);
|
||||
|
@ -999,26 +1001,35 @@ class EventsController extends AppController
|
|||
|
||||
public function viewEventAttributes($id, $all = false)
|
||||
{
|
||||
if (isset($this->params['named']['focus'])) {
|
||||
$this->set('focus', $this->params['named']['focus']);
|
||||
$paramArray = array('searchFor', 'attributeFilter', 'proposal', 'correlation', 'warning', 'deleted', 'includeRelatedTags', 'distribution', 'taggedAttributes', 'galaxyAttachedAttributes', 'objectType', 'attributeType', 'focus', 'extended', 'overrideLimit', 'filterColumnsOverwrite');
|
||||
$filterData = array(
|
||||
'request' => $this->request,
|
||||
'paramArray' => $paramArray,
|
||||
'named_params' => $this->params['named']
|
||||
);
|
||||
$exception = false;
|
||||
$filters = $this->_harvestParameters($filterData, $exception);
|
||||
|
||||
if (isset($filters['focus'])) {
|
||||
$this->set('focus', $filters['focus']);
|
||||
}
|
||||
$conditions = array('eventid' => $id);
|
||||
if (isset($this->params['named']['extended'])) {
|
||||
if (isset($filters['extended'])) {
|
||||
$conditions['extended'] = 1;
|
||||
$this->set('extended', 1);
|
||||
} else {
|
||||
$this->set('extended', 0);
|
||||
}
|
||||
if (!empty($this->params['named']['overrideLimit'])) {
|
||||
if (!empty($filters['overrideLimit'])) {
|
||||
$conditions['overrideLimit'] = 1;
|
||||
}
|
||||
if (isset($this->params['named']['deleted']) && $this->params['named']['deleted']) {
|
||||
if (isset($filters['deleted']) && $filters['deleted']) {
|
||||
$conditions['deleted'] = 1;
|
||||
}
|
||||
$conditions['includeFeedCorrelations'] = true;
|
||||
$conditions['includeAllTags'] = true;
|
||||
$conditions['includeGranularCorrelations'] = 1;
|
||||
if (!empty($this->params['named']['includeRelatedTags'])) {
|
||||
if (!empty($filters['includeRelatedTags'])) {
|
||||
$this->set('includeRelatedTags', 1);
|
||||
$conditions['includeRelatedTags'] = 1;
|
||||
} else {
|
||||
|
@ -1030,54 +1041,9 @@ class EventsController extends AppController
|
|||
}
|
||||
$event = $results[0];
|
||||
|
||||
if (isset($this->params['named']['searchFor'])) {
|
||||
// filtering on specific columns is specified
|
||||
if (!empty($this->params['named']['filterColumnsOverwrite'])) {
|
||||
$filterColumns = $this->params['named']['filterColumnsOverwrite'];
|
||||
$filterValue = array_map('trim', explode(",", $filterColumns));
|
||||
} else {
|
||||
$filterColumns = empty(Configure::read('MISP.event_view_filter_fields')) ? 'id, uuid, value, comment, type, category, Tag.name' : Configure::read('MISP.event_view_filter_fields');
|
||||
$filterValue = array_map('trim', explode(",", $filterColumns));
|
||||
$validFilters = array('id', 'uuid', 'value', 'comment', 'type', 'category', 'Tag.name');
|
||||
foreach ($filterValue as $k => $v) {
|
||||
if (!in_array($v, $validFilters)) {
|
||||
unset($filterValue[$k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// search in all attributes
|
||||
foreach ($event['Attribute'] as $k => $attribute) {
|
||||
if (!$this->__valueInFieldAttribute($attribute, $filterValue, $this->params['named']['searchFor'])) {
|
||||
unset($event['Attribute'][$k]);
|
||||
}
|
||||
}
|
||||
$event['Attribute'] = array_values($event['Attribute']);
|
||||
|
||||
// search in all attributes
|
||||
foreach ($event['ShadowAttribute'] as $k => $proposals) {
|
||||
if (!$this->__valueInFieldAttribute($proposals, $filterValue, $this->params['named']['searchFor'])) {
|
||||
unset($event['ShadowAttribute'][$k]);
|
||||
}
|
||||
}
|
||||
$event['ShadowAttribute'] = array_values($event['ShadowAttribute']);
|
||||
|
||||
// search for all attributes in object
|
||||
foreach ($event['Object'] as $k => $object) {
|
||||
foreach ($object['Attribute'] as $k2 => $attribute) {
|
||||
if (!$this->__valueInFieldAttribute($attribute, $filterValue, $this->params['named']['searchFor'])) {
|
||||
unset($event['Object'][$k]['Attribute'][$k2]);
|
||||
}
|
||||
}
|
||||
if (count($event['Object'][$k]['Attribute']) == 0) {
|
||||
// remove object if empty
|
||||
unset($event['Object'][$k]);
|
||||
} else {
|
||||
$event['Object'][$k]['Attribute'] = array_values($event['Object'][$k]['Attribute']);
|
||||
}
|
||||
}
|
||||
$event['Object'] = array_values($event['Object']);
|
||||
$this->set('passedArgsArray', array('all' => $this->params['named']['searchFor']));
|
||||
if (isset($filters['searchFor']) && $filters['searchFor'] !== '') {
|
||||
$this->applyQueryString($event, $filters['searchFor']);
|
||||
$this->set('passedArgsArray', array('all' => $filters['searchFor']));
|
||||
}
|
||||
$emptyEvent = (empty($event['Object']) && empty($event['Attribute']));
|
||||
$this->set('emptyEvent', $emptyEvent);
|
||||
|
@ -1104,10 +1070,13 @@ class EventsController extends AppController
|
|||
}
|
||||
}
|
||||
if (empty($this->passedArgs['sort'])) {
|
||||
$this->passedArgs['sort'] = 'timestamp';
|
||||
$this->passedArgs['direction'] = 'desc';
|
||||
// $this->passedArgs['sort'] = 'timestamp';
|
||||
// $this->passedArgs['direction'] = 'desc';
|
||||
$filters['sort'] = 'timestamp';
|
||||
$filters['direction'] = 'desc';
|
||||
}
|
||||
$params = $this->Event->rearrangeEventForView($event, $this->passedArgs, $all);
|
||||
// $params = $this->Event->rearrangeEventForView($event, $this->passedArgs, $all);
|
||||
$params = $this->Event->rearrangeEventForView($event, $filters, $all);
|
||||
$this->params->params['paging'] = array($this->modelClass => $params);
|
||||
// workaround to get the event dates in to the attribute relations
|
||||
$relatedDates = array();
|
||||
|
@ -1159,9 +1128,10 @@ class EventsController extends AppController
|
|||
$cortex_modules = $this->Module->getEnabledModules($this->Auth->user(), false, 'Cortex');
|
||||
$this->set('cortex_modules', $cortex_modules);
|
||||
}
|
||||
$this->set('deleted', (!empty($this->params['named']['deleted'])) ? 1 : 0);
|
||||
$this->set('deleted', (!empty($filters['deleted'])) ? 1 : 0);
|
||||
$this->set('typeGroups', array_keys($this->Event->Attribute->typeGroupings));
|
||||
$this->set('attributeFilter', isset($this->params['named']['attributeFilter']) ? $this->params['named']['attributeFilter'] : 'all');
|
||||
$this->set('attributeFilter', isset($filters['attributeFilter']) ? $filters['attributeFilter'] : 'all');
|
||||
$this->set('filters', $filters);
|
||||
$this->disableCache();
|
||||
$this->layout = 'ajax';
|
||||
$this->loadModel('Sighting');
|
||||
|
@ -1183,6 +1153,15 @@ class EventsController extends AppController
|
|||
|
||||
private function __viewUI($event, $continue, $fromEvent)
|
||||
{
|
||||
$paramArray = array('searchFor', 'attributeFilter', 'proposal', 'correlation', 'warning', 'deleted', 'includeRelatedTags', 'distribution', 'taggedAttributes', 'galaxyAttachedAttributes', 'objectType', 'attributeType', 'focus', 'extended', 'overrideLimit', 'filterColumnsOverwrite');
|
||||
$filterData = array(
|
||||
'request' => $this->request,
|
||||
'paramArray' => $paramArray,
|
||||
'named_params' => $this->params['named']
|
||||
);
|
||||
$exception = false;
|
||||
$filters = $this->_harvestParameters($filterData, $exception);
|
||||
|
||||
$this->loadModel('GalaxyCluster');
|
||||
if (!$this->_isRest()) {
|
||||
//$attack = $this->GalaxyCluster->Galaxy->constructAttackReport($event);
|
||||
|
@ -1287,8 +1266,10 @@ class EventsController extends AppController
|
|||
}
|
||||
}
|
||||
}
|
||||
$passedArgs = array('sort' => 'timestamp', 'direction' => 'desc');
|
||||
$params = $this->Event->rearrangeEventForView($event, $passedArgs);
|
||||
// $passedArgs = array('sort' => 'timestamp', 'direction' => 'desc');
|
||||
$filters['sort'] = 'timestamp';
|
||||
$filters['direction'] = 'desc';
|
||||
$params = $this->Event->rearrangeEventForView($event, $filters);
|
||||
$this->params->params['paging'] = array($this->modelClass => $params);
|
||||
$this->set('event', $event);
|
||||
$dataForView = array(
|
||||
|
@ -1366,6 +1347,7 @@ class EventsController extends AppController
|
|||
));
|
||||
$this->set('orgTable', $orgTable);
|
||||
$this->set('currentUri', $attributeUri);
|
||||
$this->set('filters', $filters);
|
||||
$this->set('mitreAttackGalaxyId', $this->Event->GalaxyCluster->Galaxy->getMitreAttackGalaxyId());
|
||||
}
|
||||
|
||||
|
@ -1438,6 +1420,10 @@ class EventsController extends AppController
|
|||
$results[0]['User']['email'] = $this->User->field('email', array('id' => $results[0]['Event']['user_id']));
|
||||
}
|
||||
$event = $results[0];
|
||||
if (isset($this->params['named']['searchFor']) && $this->params['named']['searchFor'] !== '') {
|
||||
$this->applyQueryString($event, $this->params['named']['searchFor']);
|
||||
}
|
||||
|
||||
if ($this->_isRest()) {
|
||||
$this->set('event', $event);
|
||||
}
|
||||
|
@ -1533,6 +1519,54 @@ class EventsController extends AppController
|
|||
$this->redirect(array('controller' => 'events', 'action' => 'view', $eventId, true, $eventId));
|
||||
}
|
||||
|
||||
private function applyQueryString(&$event, $searchFor, $filterColumnsOverwrite=false) {
|
||||
// filtering on specific columns is specified
|
||||
if ($filterColumnsOverwrite !== false) {
|
||||
$filterValue = array_map('trim', explode(",", $filterColumnsOverwrite));
|
||||
} else {
|
||||
$filterColumnsOverwrite = empty(Configure::read('MISP.event_view_filter_fields')) ? 'id, uuid, value, comment, type, category, Tag.name' : Configure::read('MISP.event_view_filter_fields');
|
||||
$filterValue = array_map('trim', explode(",", $filterColumnsOverwrite));
|
||||
$validFilters = array('id', 'uuid', 'value', 'comment', 'type', 'category', 'Tag.name');
|
||||
foreach ($filterValue as $k => $v) {
|
||||
if (!in_array($v, $validFilters)) {
|
||||
unset($filterValue[$k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// search in all attributes
|
||||
foreach ($event['Attribute'] as $k => $attribute) {
|
||||
if (!$this->__valueInFieldAttribute($attribute, $filterValue, $searchFor)) {
|
||||
unset($event['Attribute'][$k]);
|
||||
}
|
||||
}
|
||||
$event['Attribute'] = array_values($event['Attribute']);
|
||||
|
||||
// search in all attributes
|
||||
foreach ($event['ShadowAttribute'] as $k => $proposals) {
|
||||
if (!$this->__valueInFieldAttribute($proposals, $filterValue, $searchFor)) {
|
||||
unset($event['ShadowAttribute'][$k]);
|
||||
}
|
||||
}
|
||||
$event['ShadowAttribute'] = array_values($event['ShadowAttribute']);
|
||||
|
||||
// search for all attributes in object
|
||||
foreach ($event['Object'] as $k => $object) {
|
||||
foreach ($object['Attribute'] as $k2 => $attribute) {
|
||||
if (!$this->__valueInFieldAttribute($attribute, $filterValue, $searchFor)) {
|
||||
unset($event['Object'][$k]['Attribute'][$k2]);
|
||||
}
|
||||
}
|
||||
if (count($event['Object'][$k]['Attribute']) == 0) {
|
||||
// remove object if empty
|
||||
unset($event['Object'][$k]);
|
||||
} else {
|
||||
$event['Object'][$k]['Attribute'] = array_values($event['Object'][$k]['Attribute']);
|
||||
}
|
||||
}
|
||||
$event['Object'] = array_values($event['Object']);
|
||||
}
|
||||
|
||||
private function __removeChildren(&$pivot, $id)
|
||||
{
|
||||
if ($pivot['id'] == $id) {
|
||||
|
|
|
@ -4368,17 +4368,34 @@ class Event extends AppModel
|
|||
) {
|
||||
$attribute['objectType'] = 'attribute';
|
||||
$include = true;
|
||||
if ($filterType && !in_array($filterType, array('proposal', 'correlation', 'warning'))) {
|
||||
if (!in_array($attribute['type'], $this->Attribute->typeGroupings[$filterType])) {
|
||||
if ($filterType) {
|
||||
/* proposal */
|
||||
if ($filterType['proposal'] == 0) { // `both`
|
||||
// pass, do not consider as `both` is selected
|
||||
} else if ($filterType['proposal'] == 1 && empty($attribute['ShadowAttribute'])) { // `include only`
|
||||
$include = false;
|
||||
} else if ($filterType['proposal'] == 2 && !empty($attribute['ShadowAttribute'])) { // `exclude`
|
||||
$include = false;
|
||||
}
|
||||
/* correlation */
|
||||
if ($filterType['correlation'] == 0) { // `both`
|
||||
// pass, do not consider as `both` is selected
|
||||
} else if ($filterType['correlation'] == 1 && !in_array($attribute['id'], $correlatedAttributes)) { // `include only`
|
||||
$include = false;
|
||||
} else if ($filterType['correlation'] == 2 && in_array($attribute['id'], $correlatedAttributes)) { // `exclude`
|
||||
$include = false;
|
||||
}
|
||||
|
||||
/* TypeGroupings */
|
||||
if (
|
||||
$filterType['attributeFilter'] != 'all'
|
||||
&& isset($this->Attribute->typeGroupings[$filterType['attributeFilter']])
|
||||
&& !in_array($attribute['type'], $this->Attribute->typeGroupings[$filterType['attributeFilter']])
|
||||
) {
|
||||
$include = false;
|
||||
}
|
||||
}
|
||||
if ($filterType === 'proposal' && empty($attribute['ShadowAttribute'])) {
|
||||
$include = false;
|
||||
}
|
||||
if ($filterType === 'correlation' && !in_array($attribute['id'], $correlatedAttributes)) {
|
||||
$include = false;
|
||||
}
|
||||
|
||||
if (!empty($attribute['ShadowAttribute'])) {
|
||||
$temp = array();
|
||||
foreach ($attribute['ShadowAttribute'] as $k => $proposal) {
|
||||
|
@ -4396,8 +4413,14 @@ class Event extends AppModel
|
|||
$attribute['ShadowAttribute'] = $temp;
|
||||
}
|
||||
$attribute = $this->__prepareGenericForView($attribute, $eventWarnings, $warningLists);
|
||||
if ($filterType === 'warning') {
|
||||
if (empty($attribute['warnings']) && empty($attribute['validationIssue'])) {
|
||||
|
||||
/* warning */
|
||||
if ($filterType) {
|
||||
if ($filterType['warning'] == 0) { // `both`
|
||||
// pass, do not consider as `both` is selected
|
||||
} else if ($filterType['warning'] == 1 && empty($attribute['warnings']) && empty($attribute['validationIssue'])) { // `include only`
|
||||
$include = false;
|
||||
} else if ($filterType['warning'] == 2 && !(empty($attribute['warnings']) && empty($attribute['validationIssue']))) { // `exclude`
|
||||
$include = false;
|
||||
}
|
||||
}
|
||||
|
@ -4417,18 +4440,34 @@ class Event extends AppModel
|
|||
$proposal['objectType'] = 'proposal';
|
||||
}
|
||||
|
||||
$include = true;
|
||||
if ($filterType === 'correlation' && !in_array($proposal['id'], $correlatedShadowAttributes)) {
|
||||
$include = $filterType['proposal'] != 2;
|
||||
|
||||
/* correlation */
|
||||
if ($filterType['correlation'] == 0) { // `both`
|
||||
// pass, do not consider as `both` is selected
|
||||
} else if ($filterType['correlation'] == 1 && !in_array($proposal['id'], $correlatedShadowAttributes)) { // `include only`
|
||||
$include = false;
|
||||
} else if ($filterType['correlation'] == 2 && in_array($proposal['id'], $correlatedShadowAttributes)) { // `exclude`
|
||||
$include = false;
|
||||
}
|
||||
if ($filterType && !in_array($filterType, array('proposal', 'correlation', 'warning'))) {
|
||||
if (!in_array($proposal['type'], $this->Attribute->typeGroupings[$filterType])) {
|
||||
$include = false;
|
||||
}
|
||||
|
||||
/* TypeGroupings */
|
||||
if (
|
||||
$filterType['attributeFilter'] != 'all'
|
||||
&& isset($this->Attribute->typeGroupings[$filterType['attributeFilter']])
|
||||
&& !in_array($proposal['type'], $this->Attribute->typeGroupings[$filterType['attributeFilter']])
|
||||
) {
|
||||
$include = false;
|
||||
}
|
||||
$proposal = $this->__prepareGenericForView($proposal, $eventWarnings, $warningLists);
|
||||
if ($filterType === 'warning') {
|
||||
if (empty($proposal['warnings'])) {
|
||||
|
||||
/* warning */
|
||||
if ($filterType) {
|
||||
if ($filterType['warning'] == 0) { // `both`
|
||||
// pass, do not consider as `both` is selected
|
||||
} else if ($filterType['warning'] == 1 && empty($proposal['warnings']) && empty($proposal['validationIssue'])) { // `include only`
|
||||
$include = false;
|
||||
} else if ($filterType['warning'] == 2 && !(empty($proposal['warnings']) && empty($proposal['validationIssue']))) { // `exclude`
|
||||
$include = false;
|
||||
}
|
||||
}
|
||||
|
@ -4446,10 +4485,8 @@ class Event extends AppModel
|
|||
$object['category'] = $object['meta-category'];
|
||||
$proposal['objectType'] = 'object';
|
||||
// filters depend on child objects
|
||||
$include = empty($filterType) || $filterType == 'object' || $object['meta-category'] === $filterType;
|
||||
if ($filterType === 'correlation' || $filterType === 'proposal') {
|
||||
$include = $this->__checkObjectByFilter($object, $filterType, $correlatedAttributes, $correlatedShadowAttributes);
|
||||
}
|
||||
$include = $this->__checkObjectByFilter($object, $filterType, $correlatedAttributes, $correlatedShadowAttributes);
|
||||
|
||||
if (!empty($object['Attribute'])) {
|
||||
$temp = array();
|
||||
foreach ($object['Attribute'] as $k => $proposal) {
|
||||
|
@ -4467,59 +4504,84 @@ class Event extends AppModel
|
|||
}
|
||||
$object['Attribute'] = $temp;
|
||||
}
|
||||
if ($filterType === 'warning') {
|
||||
$include = $this->__checkObjectByFilter($object, $filterType, $correlatedAttributes, $correlatedShadowAttributes);
|
||||
}
|
||||
|
||||
return array('include' => $include, 'data' => $object);
|
||||
}
|
||||
|
||||
private function __checkObjectByFilter($object, $filterType, $correlatedAttributes, $correlatedShadowAttributes)
|
||||
{
|
||||
$include = false;
|
||||
switch ($filterType) {
|
||||
case 'warning':
|
||||
if (!empty($object['Attribute'])) {
|
||||
foreach ($object['Attribute'] as $k => $attribute) {
|
||||
if (!empty($attribute['warnings'])) {
|
||||
$include = true;
|
||||
}
|
||||
if (!empty($attribute['ShadowAttribute'])) {
|
||||
foreach ($attribute['ShadowAttribute'] as $shadowAttribute) {
|
||||
if (!empty($shadowAttribute['warnings'])) {
|
||||
$include = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'correlation':
|
||||
if (!empty($object['Attribute'])) {
|
||||
foreach ($object['Attribute'] as $k => $attribute) {
|
||||
if (in_array($attribute['id'], $correlatedAttributes)) {
|
||||
$include = true;
|
||||
} else {
|
||||
if (!empty($attribute['ShadowAttribute'])) {
|
||||
foreach ($attribute['ShadowAttribute'] as $k => $shadowAttribute) {
|
||||
if (in_array($shadowAttribute['id'], $correlatedShadowAttributes)) {
|
||||
$include = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'proposal':
|
||||
if (!empty($object['Attribute'])) {
|
||||
foreach ($object['Attribute'] as $k => $attribute) {
|
||||
if (!empty($attribute['ShadowAttribute'])) {
|
||||
$include = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
$include = true;
|
||||
|
||||
if (empty($object['Attribute'])) { // reject empty object
|
||||
$include = false;
|
||||
return $include;
|
||||
}
|
||||
|
||||
/* proposal */
|
||||
if ($filterType['proposal'] == 0) { // `both`
|
||||
// pass, do not consider as `both` is selected
|
||||
} else if ($filterType['proposal'] == 1 || $filterType['proposal'] == 2) {
|
||||
$flagKeep = false;
|
||||
foreach ($object['Attribute'] as $k => $attribute) { // check if object contains at least 1 proposal
|
||||
if (!empty($attribute['ShadowAttribute'])) {
|
||||
$flagKeep = true && ($filterType['proposal'] == 1); // do not keep if proposal are excluded
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$flagKeep) {
|
||||
$include = false;
|
||||
return $include;
|
||||
}
|
||||
}
|
||||
|
||||
/* warning */
|
||||
if ($filterType['warning'] == 0) { // `both`
|
||||
// pass, do not consider as `both` is selected
|
||||
} else if ($filterType['warning'] == 1 || $filterType['warning'] == 2) {
|
||||
$flagKeep = false;
|
||||
foreach ($object['Attribute'] as $k => $attribute) { // check if object contains at least 1 warning
|
||||
if (!empty($attribute['warnings'])) {
|
||||
$flagKeep = true && ($filterType['warning'] == 1); // do not keep if warning are excluded
|
||||
}
|
||||
if (!$flagKeep && !empty($attribute['ShadowAttribute'])) {
|
||||
foreach ($attribute['ShadowAttribute'] as $shadowAttribute) {
|
||||
if (!empty($shadowAttribute['warnings'])) {
|
||||
$flagKeep = true && ($filterType['warning'] == 1); // do not keep if warning are excluded
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$flagKeep) {
|
||||
$include = false;
|
||||
return $include;
|
||||
}
|
||||
}
|
||||
|
||||
/* correlation */
|
||||
if ($filterType['correlation'] == 0) { // `both`
|
||||
// pass, do not consider as `both` is selected
|
||||
} else if ($filterType['correlation'] == 1 || $filterType['correlation'] == 2) {
|
||||
$flagKeep = false;
|
||||
foreach ($object['Attribute'] as $k => $attribute) { // check if object contains at least 1 warning
|
||||
if (in_array($attribute['id'], $correlatedAttributes)) {
|
||||
$flagKeep = true && ($filterType['warning'] == 1); // do not keep if warning are excluded
|
||||
}
|
||||
if (!$flagKeep && !empty($attribute['ShadowAttribute'])) {
|
||||
foreach ($attribute['ShadowAttribute'] as $k => $shadowAttribute) {
|
||||
if (in_array($shadowAttribute['id'], $correlatedShadowAttributes)) {
|
||||
$flagKeep = true && ($filterType['warning'] == 1); // do not keep if warning are excluded
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$flagKeep) {
|
||||
$include = false;
|
||||
return $include;
|
||||
}
|
||||
}
|
||||
|
||||
return $include;
|
||||
}
|
||||
|
||||
|
@ -4566,14 +4628,17 @@ class Event extends AppModel
|
|||
unset($event['Event'][$k]);
|
||||
}
|
||||
}
|
||||
$filterType = false;
|
||||
if (isset($passedArgs['attributeFilter'])) {
|
||||
if (in_array($passedArgs['attributeFilter'], array_keys($this->Attribute->typeGroupings)) || in_array($passedArgs['attributeFilter'], array('proposal', 'correlation', 'warning'))) {
|
||||
$filterType = $passedArgs['attributeFilter'];
|
||||
} else {
|
||||
unset($passedArgs['attributeFilter']);
|
||||
}
|
||||
$filterType = array(
|
||||
'attributeFilter' => isset($passedArgs['attributeFilter']) ? $passedArgs['attributeFilter'] : 'all',
|
||||
'proposal' => isset($passedArgs['proposal']) ? $passedArgs['proposal'] : 0,
|
||||
'correlation' => isset($passedArgs['correlation']) ? $passedArgs['correlation'] : 0,
|
||||
'warning' => isset($passedArgs['warning']) ? $passedArgs['warning'] : 0
|
||||
);
|
||||
// update proposal, correlation and warning accordingly
|
||||
if (in_array($filterType['attributeFilter'], array('proposal', 'correlation', 'warning'))) {
|
||||
$filterType[$filterType['attributeFilter']] = 1;
|
||||
}
|
||||
|
||||
$eventArray = array();
|
||||
$eventWarnings = array();
|
||||
$correlatedAttributes = isset($event['RelatedAttribute']) ? array_keys($event['RelatedAttribute']) : array();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<div id="eventFilteringQBWrapper" style="padding: 5px; display: none; border: 1px solid #dddddd; border-bottom: 0px;">
|
||||
<div id="eventFilteringQB"></div>
|
||||
<div style="display: flex; justify-content: flex-end">
|
||||
<input id="eventFilteringQBLinkInput" class="form-control"></input>
|
||||
<input id="eventFilteringQBLinkInput" class="form-control" style="width: 500px;"></input>
|
||||
<button id="eventFilteringQBLinkCopy" type="button" class="btn btn-inverse" style="margin-right: 5px; margin-left: 5px;" onclick="clickMessage(this);"> <i class="fa fa-clipboard"></i> Copy to clipboard </button>
|
||||
<button id="eventFilteringQBSubmit" type="button" class="btn btn-inverse" style=""> <i class="fa fa-filter"></i> Filter </button>
|
||||
</div>
|
||||
|
@ -165,46 +165,46 @@ function triggerEventFilteringTool(clicked) {
|
|||
2: "Attributes with galaxy"
|
||||
}
|
||||
},
|
||||
{
|
||||
"input": "select",
|
||||
"type": "string",
|
||||
"operators": [
|
||||
"equal",
|
||||
],
|
||||
"unique": false,
|
||||
"id": "objectType",
|
||||
"label": "Object Types",
|
||||
<?php
|
||||
$object_types = array();
|
||||
foreach ($event['objects'] as $k => $object) {
|
||||
if ($object['objectType'] == 'object') {
|
||||
$object_types[$object['name']] = $object['name'];
|
||||
}
|
||||
}
|
||||
ksort($object_types);
|
||||
?>
|
||||
"values": <?php echo json_encode($object_types); ?>
|
||||
},
|
||||
{
|
||||
"input": "select",
|
||||
"type": "string",
|
||||
"operators": [
|
||||
"equal",
|
||||
],
|
||||
"unique": false,
|
||||
"id": "attributeType",
|
||||
"label": "Attribute Types",
|
||||
<?php
|
||||
$attribute_types = array();
|
||||
foreach ($event['objects'] as $k => $attribute) {
|
||||
if ($attribute['objectType'] == 'attribute') {
|
||||
$attribute_types[$attribute['type']] = $attribute['type'];
|
||||
}
|
||||
}
|
||||
ksort($attribute_types);
|
||||
?>
|
||||
"values": <?php echo json_encode($attribute_types); ?>
|
||||
},
|
||||
// {
|
||||
// "input": "select",
|
||||
// "type": "string",
|
||||
// "operators": [
|
||||
// "equal",
|
||||
// ],
|
||||
// "unique": false,
|
||||
// "id": "objectType",
|
||||
// "label": "Object Types",
|
||||
// <?php
|
||||
// $object_types = array();
|
||||
// foreach ($event['objects'] as $k => $object) {
|
||||
// if ($object['objectType'] == 'object') {
|
||||
// $object_types[$object['name']] = $object['name'];
|
||||
// }
|
||||
// }
|
||||
// ksort($object_types);
|
||||
// ?>
|
||||
// "values": <?php //echo json_encode($object_types); ?>
|
||||
// },
|
||||
// {
|
||||
// "input": "select",
|
||||
// "type": "string",
|
||||
// "operators": [
|
||||
// "equal",
|
||||
// ],
|
||||
// "unique": false,
|
||||
// "id": "attributeType",
|
||||
// "label": "Attribute Types",
|
||||
// <?php
|
||||
// $attribute_types = array();
|
||||
// foreach ($event['objects'] as $k => $attribute) {
|
||||
// if ($attribute['objectType'] == 'attribute') {
|
||||
// $attribute_types[$attribute['type']] = $attribute['type'];
|
||||
// }
|
||||
// }
|
||||
// ksort($attribute_types);
|
||||
// ?>
|
||||
// "values": <?php //echo json_encode($attribute_types); ?>
|
||||
// },
|
||||
{
|
||||
"input": "text",
|
||||
"type": "string",
|
||||
|
@ -230,80 +230,85 @@ function triggerEventFilteringTool(clicked) {
|
|||
rules: [
|
||||
{
|
||||
field: 'searchFor',
|
||||
id: 'searchFor'
|
||||
id: 'searchFor',
|
||||
value: "<?php echo isset($filters['searchFor']) ? $filters['searchFor'] : ''; ?>"
|
||||
},
|
||||
{
|
||||
field: 'attributeFilter',
|
||||
id: 'attributeFilter',
|
||||
value: '<?php echo !isset($filteringData['category']) ? 'all' : h($filteringData['category']) ?>'
|
||||
<?php if (isset($filters['attributeFilter'])): ?>
|
||||
value: "<?php echo in_array($filters['attributeFilter'], array('all', 'network', 'financial', 'file')) ? $filters['attributeFilter'] : 'all'; ?>"
|
||||
<?php else: ?>
|
||||
value: "<?php echo 'all'; ?>"
|
||||
<?php endif; ?>
|
||||
},
|
||||
{
|
||||
field: 'proposal',
|
||||
id: 'proposal',
|
||||
value: 0,
|
||||
value: <?php echo isset($filters['proposal']) ? $filters['proposal'] : 0; ?>
|
||||
},
|
||||
{
|
||||
field: 'correlation',
|
||||
id: 'correlation',
|
||||
value: 0,
|
||||
value: <?php echo isset($filters['correlation']) ? $filters['correlation'] : 0; ?>
|
||||
},
|
||||
{
|
||||
field: 'warning',
|
||||
id: 'warning',
|
||||
value: 0,
|
||||
value: <?php echo isset($filters['warning']) ? $filters['warning'] : 0; ?>
|
||||
},
|
||||
{
|
||||
field: 'deleted',
|
||||
id: 'deleted',
|
||||
value: 0,
|
||||
value: <?php echo isset($filters['deleted']) ? $filters['deleted'] : 0; ?>
|
||||
},
|
||||
{
|
||||
field: 'includeRelatedTags',
|
||||
id: 'includeRelatedTags',
|
||||
value: 0,
|
||||
value: <?php echo isset($filters['includeRelatedTags']) ? $filters['includeRelatedTags'] : 0; ?>
|
||||
},
|
||||
{
|
||||
field: 'distribution',
|
||||
id: 'distribution',
|
||||
operator: 'in',
|
||||
value: [0, 1, 2, 3, 4],
|
||||
value: <?php echo isset($filters['distribution']) ? json_encode($filters['distribution']) : json_encode(array(0, 1, 2, 3, 4)); ?>
|
||||
},
|
||||
{
|
||||
field: 'taggedAttributes',
|
||||
id: 'taggedAttributes',
|
||||
value: 0,
|
||||
value: <?php echo isset($filters['taggedAttributes']) ? $filters['taggedAttributes'] : 0; ?>
|
||||
},
|
||||
{
|
||||
field: 'galaxyAttachedAttributes',
|
||||
id: 'galaxyAttachedAttributes',
|
||||
value: 0,
|
||||
value: <?php echo isset($filters['galaxyAttachedAttributes']) ? $filters['galaxyAttachedAttributes'] : 0; ?>
|
||||
},
|
||||
{
|
||||
condition: 'OR',
|
||||
not: false,
|
||||
flags: {
|
||||
no_add_group: true,
|
||||
condition_readonly: true,
|
||||
},
|
||||
rules: [{
|
||||
field: 'objectType',
|
||||
id: 'objectType',
|
||||
value: '<?php reset($object_types); echo key($object_types); ?>',
|
||||
}]
|
||||
},
|
||||
{
|
||||
condition: 'OR',
|
||||
not: false,
|
||||
flags: {
|
||||
no_add_group: true,
|
||||
condition_readonly: true,
|
||||
},
|
||||
rules: [{
|
||||
field: 'attributeType',
|
||||
id: 'attributeType',
|
||||
value: '<?php reset($attribute_types); echo key($attribute_types); ?>',
|
||||
}]
|
||||
}
|
||||
// {
|
||||
// condition: 'OR',
|
||||
// not: false,
|
||||
// flags: {
|
||||
// no_add_group: true,
|
||||
// condition_readonly: true,
|
||||
// },
|
||||
// rules: [{
|
||||
// field: 'objectType',
|
||||
// id: 'objectType',
|
||||
// value: '<?php //reset($object_types); echo key($object_types); ?>',
|
||||
// }]
|
||||
// },
|
||||
// {
|
||||
// condition: 'OR',
|
||||
// not: false,
|
||||
// flags: {
|
||||
// no_add_group: true,
|
||||
// condition_readonly: true,
|
||||
// },
|
||||
// rules: [{
|
||||
// field: 'attributeType',
|
||||
// id: 'attributeType',
|
||||
// value: '<?php //reset($attribute_types); echo key($attribute_types); ?>',
|
||||
// }]
|
||||
// }
|
||||
],
|
||||
flags: {
|
||||
no_add_group: true,
|
||||
|
@ -319,7 +324,7 @@ function triggerEventFilteringTool(clicked) {
|
|||
},
|
||||
};
|
||||
|
||||
|
||||
var filters = <?php echo json_encode($filters); ?>;
|
||||
var $wrapper = $('#eventFilteringQBWrapper');
|
||||
var $ev = $('#eventFilteringQB');
|
||||
var querybuilderTool = $ev.queryBuilder(qbOptions);
|
||||
|
@ -373,6 +378,10 @@ function triggerEventFilteringTool(clicked) {
|
|||
var url = "";
|
||||
Object.keys(res).forEach(function(k) {
|
||||
var v = res[k];
|
||||
if (Array.isArray(v)) {
|
||||
// v = JSON.stringify(v);
|
||||
v = v.join('||');
|
||||
}
|
||||
url += "/" + k + ":" + v;
|
||||
});
|
||||
return url;
|
||||
|
@ -394,10 +403,13 @@ function triggerEventFilteringTool(clicked) {
|
|||
function performQuery(rules) {
|
||||
var res = cleanRules(rules);
|
||||
|
||||
var url = "/events/viewEventAttributes/<?php echo h($event['Event']['id']); ?>" + buildURL(res);
|
||||
// var url = "/events/viewEventAttributes/<?php echo h($event['Event']['id']); ?>" + buildURL(res);
|
||||
var url = "/events/viewEventAttributes/<?php echo h($event['Event']['id']); ?>";
|
||||
|
||||
$.ajax({
|
||||
type:"get",
|
||||
type:"post",
|
||||
url: url,
|
||||
data: res,
|
||||
beforeSend: function (XMLHttpRequest) {
|
||||
$(".loading").show();
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue