fix: Some cleanup of the attribute filtering

pull/2547/head
iglocska 2017-10-05 11:59:59 +02:00
parent 66a43f5511
commit cd9fe1883e
5 changed files with 69 additions and 79 deletions

View File

@ -46,7 +46,7 @@ class AppController extends Controller {
public $helpers = array('Utility');
private $__queryVersion = '20';
private $__queryVersion = '21';
public $pyMispVersion = '2.4.80';
public $phpmin = '5.6.5';
public $phprec = '7.0.16';

View File

@ -715,20 +715,20 @@ class EventsController extends AppController {
}
/*
* Search for a value in an attribut in specific field.
* $arr : (array) an attribut
* $fiels : (array) list of key in attribut which search in
* Search for a value on an attribute level for a specific field.
* $attribute : (array) an attribute
* $fields : (array) list of keys in attribute to search in
* $searchValue : Value to search
* return : true if match
* returns true on match
*/
private function __valueInFieldAttribut($arr, $fields, $searchValue) {
foreach($arr as $k => $v){ // look in attributes line
if(is_string($v)) {
foreach($fields as $filterV){
if(strpos(".", $filterV) === false) { // check sub array after
private function __valueInFieldAttribute($attribute, $fields, $searchValue) {
foreach ($attribute as $k => $v){ // look in attributes line
if (is_string($v)) {
foreach ($fields as $field){
if (strpos(".", $field) === false) { // check sub array after
// check for key in attribut
if(isset($arr[$filterV])){
$temp_value = strtolower($arr[$filterV]);
if (isset($attribute[$field])) {
$temp_value = strtolower($attribute[$field]);
$temp_search = strtolower($searchValue);
if(strpos($temp_value, $temp_search) !==false) {
return true;
@ -736,17 +736,17 @@ class EventsController extends AppController {
}
}
}
}else{
} else {
// check for tag in attribut maybe for other thing later
if($k === 'AttributeTag'){
foreach($v as $tag) {
foreach($fields as $filterV){
if(strpos(strtolower($filterV), "tag.") !== false) { // check sub array
$tagKey = explode('tag.', strtolower($filterV))[1];
if(isset($tag['Tag'][$tagKey])){
foreach ($v as $tag) {
foreach ($fields as $field) {
if (strpos(strtolower($field), "tag.") !== false) { // check sub array
$tagKey = explode('tag.', strtolower($field))[1];
if (isset($tag['Tag'][$tagKey])) {
$temp_value = strtolower($tag['Tag'][$tagKey]);
$temp_search = strtolower($searchValue);
if(strpos($temp_value, $temp_search) !==false) {
if (strpos($temp_value, $temp_search) !==false) {
return true;
}
}
@ -758,7 +758,7 @@ class EventsController extends AppController {
}
return false;
}
public function viewEventAttributes($id, $all = false) {
if (isset($this->params['named']['focus'])) {
$this->set('focus', $this->params['named']['focus']);
@ -770,58 +770,50 @@ class EventsController extends AppController {
$results = $this->Event->fetchEvent($this->Auth->user(), $conditions);
if (empty($results)) throw new NotFoundException('Invalid event');
$event = $results[0];
$filterValue = false;
if(
Configure::read('MISP.Attributes_Values_Filter_In_Event') &&
strlen(Configure::read('MISP.Attributes_Values_Filter_In_Event')) > 0){
$filterValue = true;
}
$attributeFilterOnInput = false;
if(
isset($this->params['named']['attributeFilter']) &&
$this->params['named']['attributeFilter'] === 'value'){
$attributeFilterOnInput = true;
}
$searchFor = false;
if (
isset($this->params['named']['searchFor']) &&
strlen($this->params['named']['searchFor']) > 0){
$searchFor = true;
}
if($filterValue && $attributeFilterOnInput && $searchFor){
$filterValue = array_map('trim', explode(",", Configure::read('MISP.Attributes_Values_Filter_In_Event')));
if (!empty($this->params['named']['searchFor'])) {
$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
$simpleAttributes = $event['Attribute'];
foreach($simpleAttributes as $attrK => $attrV){
$attrMatched = $this->__valueInFieldAttribut($attrV,$filterValue,$this->params['named']['searchFor']);
if(!$attrMatched) unset($simpleAttributes[$attrK]);
foreach ($event['Attribute'] as $k => $attribute) {
if (!$this->__valueInFieldAttribute($attribute, $filterValue, $this->params['named']['searchFor'])) {
unset($event['Attribute'][$k]);
}
}
$event['Attribute'] = array_values($simpleAttributes);
$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
$attributesObjects = $event['Object'];
foreach($attributesObjects as $objK => $objV){
$simpleAttributes = $objV['Attribute'];
foreach($simpleAttributes as $attrK => $attrV){
$attrMatched = $this->__valueInFieldAttribut($attrV,$filterValue,$this->params['named']['searchFor']);
if(!$attrMatched) unset($simpleAttributes[$attrK]);
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($simpleAttributes) > 0){
$attributesObjects[$objK]['Attribute'] = array_values($simpleAttributes);
}else{
if (count($event['Object'][$k]['Attribute']) == 0){
// remove object if empty
unset($attributesObjects[$objK]);
unset($event['Object'][$k]);
} else {
$event['Object'][$k]['Attribute'] = array_values($event['Object'][$k]['Attribute']);
}
}
$event['Object'] = array_values($attributesObjects);
unset($simpleAttributes);
unset($attributesObjects);
$event['Object'] = array_values($event['Object']);
$this->set('passedArgsArray', array('all' => $this->params['named']['searchFor']));
}
// else{
// throw new NotFoundException('Go to administration setting to check if your fieds to filter on is not empty.');
// }
$emptyEvent = (empty($event['Object']) && empty($event['Attribute']));
$this->set('emptyEvent', $emptyEvent);
$params = $this->Event->rearrangeEventForView($event, $this->passedArgs, $all);

View File

@ -793,9 +793,9 @@ class Server extends AppModel {
'type' => 'string',
'redacted' => true
),
'Attributes_Values_Filter_In_Event' => array(
'level' => 1,
'description' => 'Specify wich field to filter on when you serch in an event. "value" will search in "Attribute.value and Object.Attribute.value". Default value are : "id, uuid, value, comment, type, category, Tag.name"',
'event_view_filter_fields' => array(
'level' => 2,
'description' => 'Specify which fields to filter on when you search on the event view. Default values are : "id, uuid, value, comment, type, category, Tag.name"',
'value' => 'id, uuid, value, comment, type, category, Tag.name',
'errorMessage' => '',
'test' => null,

View File

@ -115,15 +115,6 @@
<?php if (Configure::read('Plugin.Sightings_enable')): ?>
<span id="multi-sighting-button" title="Sightings display for selected attributes" role="button" tabindex="0" aria-label="Sightings display for selected attributes" class="hidden icon-wrench mass-select useCursorPointer sightings_advanced_add" data-object-id="selected" data-object-context="attribute"></span>
<?php endif; ?>
<?php if ($filtered):?>
<div class='attribute_filter_text attribute_filter_text_active'>
<?php foreach ($passedArgsArray as $k => $v):?>
<span><?php echo h(ucfirst($k)) . " : " . h($v); ?></span>
<?php endforeach; ?>
<span tabindex="0" aria-label="Show all attributes" title="Remove filters" role="button" onClick="filterAttributes('all', '<?php echo h($event['Event']['id']); ?>');" class='icon-remove'>
</span>
</div>
<?php endif;?>
</div>
<div class="tabMenu tabMenuToolsBlock noPrint">
<?php if ($mayModify): ?>
@ -147,10 +138,12 @@
<div id="filter_deleted" title="Include deleted attributes" role="button" tabindex="0" aria-label="Include deleted attributes" class="attribute_filter_text<?php if ($deleted) echo '_active'; ?>" onClick="toggleDeletedAttributes('<?php echo Router::url( $this->here, true );?>');">Include deleted attributes</div>
<?php endif; ?>
<div id="show_context" title="Show attribute context fields" role="button" tabindex="0" aria-label="Show attribute context fields" class="attribute_filter_text" onClick="toggleContextFields();">Show context fields</div>
<div title="input filter" tabindex="0" aria-label="input filter" class="attribute_filter_text">
<span id="attributesFilterButton" role="button" tabindex="0" aria-label="Filter on attributes value"
onClick="filterAttributes('value', '<?php echo h($event['Event']['id']); ?>');"></span>
<input type="text" id="attributesFilterField" style="height:20px;padding:0px;margin:0px;" class="form-control"></input>
<div title="input filter" tabindex="0" aria-label="input filter" class="attribute_filter_text" style="padding-top:0px;">
<input type="text" id="attributesFilterField" style="height:20px;padding:0px;margin:0px;" class="form-control" data-eventid="<?php echo h($event['Event']['id']); ?>"></input>
<span id="attributesFilterButton" role="button" class="icon-search" tabindex="0" aria-label="Filter on attributes value" onClick="filterAttributes('value', '<?php echo h($event['Event']['id']); ?>');"></span>
<?php if ($filtered):?>
<span tabindex="0" aria-label="Show all attributes" title="Remove filters" role="button" onClick="filterAttributes('all', '<?php echo h($event['Event']['id']); ?>');" class='icon-remove'></span>
<?php endif;?>
</div>
</div>
@ -339,6 +332,12 @@ attributes or the appropriate distribution level. If you think there is a mistak
genericPopup(url, '#screenshot_box');
});
});
$('#attributesFilterField').bind("keydown", function(e) {
var eventid = $('#attributesFilterField').data("eventid");
if ((e.keyCode == 13 || e.keyCode == 10)) {
filterAttributes('value', eventid);
}
});
$('.hex-value-convert').click(function() {
var val = $(this).parent().children(':first-child').text();
if ($(this).parent().children(':first-child').attr('data-original-title') == 'Hexadecimal representation') {

View File

@ -3222,7 +3222,6 @@ $('.add_object_attribute_row').click(function() {
$('.quickToggleCheckbox').toggle(function() {
var url = $(this).data('checkbox-url');
});
(function(){