mirror of https://github.com/MISP/MISP
Update to the attribute search
- Use ! to exclude terms in the value/id/org fields - org search works the same way as value / id now, you can enter several terms separated by a newline. Also, adding ! infront of a term will exclude the organisation from the results - sub string search for organisationspull/217/head
parent
12e36671bc
commit
24ebbcca5c
|
@ -644,6 +644,7 @@ class AttributesController extends AppController {
|
|||
$this->set('keywordSearch', $keyword);
|
||||
$keyWordText = null;
|
||||
$keyWordText2 = null;
|
||||
$keyWordText3 = null;
|
||||
$this->set('typeSearch', $type);
|
||||
$this->set('isSearch', 1);
|
||||
$this->set('categorySearch', $category);
|
||||
|
@ -656,10 +657,17 @@ class AttributesController extends AppController {
|
|||
$this->set('keywordArray', $keywordArray);
|
||||
$i = 1;
|
||||
$temp = array();
|
||||
$temp2 = array();
|
||||
foreach ($keywordArray as $keywordArrayElement) {
|
||||
$saveWord = trim($keywordArrayElement);
|
||||
$keywordArrayElement = '%' . trim($keywordArrayElement) . '%';
|
||||
if ($keywordArrayElement != '%%') array_push($temp, array('Attribute.value LIKE' => $keywordArrayElement));
|
||||
if ($keywordArrayElement != '%%') {
|
||||
if ($keywordArrayElement[1] == '!') {
|
||||
array_push($temp2, array('Attribute.value NOT LIKE' => '%' . substr($keywordArrayElement, 2)));
|
||||
} else {
|
||||
array_push($temp, array('Attribute.value LIKE' => $keywordArrayElement));
|
||||
}
|
||||
}
|
||||
if ($i == 1 && $saveWord != '') $keyWordText = $saveWord;
|
||||
else if (($i > 1 && $i < 10) && $saveWord != '') $keyWordText = $keyWordText . ', ' . $saveWord;
|
||||
else if ($i == 10 && $saveWord != '') $keyWordText = $keyWordText . ' and several other keywords';
|
||||
|
@ -667,12 +675,12 @@ class AttributesController extends AppController {
|
|||
}
|
||||
$this->set('keywordSearch', $keyWordText);
|
||||
if (!empty($temp)) {
|
||||
if (count($temp) == 1) {
|
||||
$conditions['Attribute.value LIKE'] = '%' . $keyWordText . '%';
|
||||
} else {
|
||||
$conditions['OR'] = $temp;
|
||||
}
|
||||
$conditions['AND']['OR'] = $temp;
|
||||
}
|
||||
if (!empty($temp2)) {
|
||||
$conditions['AND'][] = $temp2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// event IDs to be excluded
|
||||
|
@ -682,8 +690,12 @@ class AttributesController extends AppController {
|
|||
$temp = array();
|
||||
foreach ($keywordArray2 as $keywordArrayElement) {
|
||||
$saveWord = trim($keywordArrayElement);
|
||||
if (!is_numeric($saveWord) || $saveWord < 1) continue;
|
||||
array_push($temp, array('Attribute.event_id !=' => $keywordArrayElement));
|
||||
if (empty($saveWord)) continue;
|
||||
if ($saveWord[0] == '!') {
|
||||
$temp[] = array('Attribute.event_id !=' => substr($saveWord, 1));
|
||||
} else {
|
||||
$temp['OR'][] = array('Attribute.event_id =' => $saveWord);
|
||||
}
|
||||
if ($i == 1 && $saveWord != '') $keyWordText2 = $saveWord;
|
||||
else if (($i > 1 && $i < 10) && $saveWord != '') $keyWordText2 = $keyWordText2 . ', ' . $saveWord;
|
||||
else if ($i == 10 && $saveWord != '') $keyWordText2 = $keyWordText2 . ' and several other events';
|
||||
|
@ -691,11 +703,7 @@ class AttributesController extends AppController {
|
|||
}
|
||||
$this->set('keywordSearch2', $keyWordText2);
|
||||
if (!empty($temp)) {
|
||||
if (count($temp) == 1) {
|
||||
$conditions['Attribute.event_id !='] = $keyWordText2;
|
||||
} else {
|
||||
$conditions['AND'] = $temp;
|
||||
}
|
||||
$conditions['AND'][] = $temp;
|
||||
}
|
||||
}
|
||||
if ($type != 'ALL') {
|
||||
|
@ -705,10 +713,27 @@ class AttributesController extends AppController {
|
|||
$conditions['Attribute.category ='] = $category;
|
||||
}
|
||||
// organisation search field
|
||||
if (isset($org) && $org != '') {
|
||||
$org = trim($org);
|
||||
$this->set('orgSearch', $org);
|
||||
$conditions['Event.orgc ='] = $org;
|
||||
$i = 0;
|
||||
$temp = array();
|
||||
if (isset($org)) {
|
||||
$orgArray = explode("\n", $org);
|
||||
foreach ($orgArray as $orgArrayElement) {
|
||||
$saveWord = trim($orgArrayElement);
|
||||
if (empty($saveWord)) continue;
|
||||
if ($saveWord[0] == '!') {
|
||||
$temp[] = array('Event.orgc NOT LIKE ' => '%' . substr($saveWord, 1) . '%');
|
||||
} else {
|
||||
$temp['OR'][] = array('Event.orgc LIKE ' => '%' . $saveWord . '%');
|
||||
}
|
||||
}
|
||||
if ($i == 1 && $saveWord != '') $keyWordText3 = $saveWord;
|
||||
else if (($i > 1 && $i < 10) && $saveWord != '') $keyWordText3 = $keyWordText3 . ', ' . $saveWord;
|
||||
else if ($i == 10 && $saveWord != '') $keyWordText3 = $keyWordText3 . ' and several other organisations';
|
||||
$i++;
|
||||
$this->set('orgSearch', $keyWordText3);
|
||||
if (!empty($temp)) {
|
||||
$conditions['AND'][] = $temp;
|
||||
}
|
||||
}
|
||||
$this->Attribute->recursive = 0;
|
||||
$this->paginate = array(
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
if ($isSearch == 1) {
|
||||
echo "<h4>Results for all attributes";
|
||||
if ($keywordSearch != null) echo " with the value containing \"<b>" . h($keywordSearch) . "</b>\"";
|
||||
if ($keywordSearch2 != null) echo " excluding the events \"<b>" . h($keywordSearch2) . "</b>\"";
|
||||
if ($keywordSearch2 != null) echo " from the events \"<b>" . h($keywordSearch2) . "</b>\"";
|
||||
if ($categorySearch != "ALL") echo " of category \"<b>" . h($categorySearch) . "</b>\"";
|
||||
if ($typeSearch != "ALL") echo " of type \"<b>" . h($typeSearch) . "</b>\"";
|
||||
if (isset($orgSearch) && $orgSearch != '' && $orgSearch != null) echo " created by the organisation \"<b>" . h($orgSearch) . "</b>\"";
|
||||
|
|
|
@ -2,16 +2,18 @@
|
|||
<?php echo $this->Form->create('Attribute');?>
|
||||
<fieldset>
|
||||
<legend>Search Attribute</legend>
|
||||
You can search for attributes based on contained expression within the value, event ID, submiting organisation, category and type. <br />For the value, event ID and organisation, you can enter several search terms by entering each term as a new line. To exclude things from a result, use the NOT operator (!) infront of the term.<br/><br />
|
||||
<?php
|
||||
echo $this->Form->input('keyword', array('type' => 'textarea', 'label' => 'Containing the following expressions', 'div' => 'clear', 'class' => 'input-xxlarge'));
|
||||
echo $this->Form->input('keyword2', array('type' => 'textarea', 'label' => 'Excluding the following events', 'div' => 'clear', 'class' => 'input-xxlarge'));
|
||||
echo $this->Form->input('keyword2', array('type' => 'textarea', 'label' => 'Being attributes of the following event IDs', 'div' => 'clear', 'class' => 'input-xxlarge'));
|
||||
?>
|
||||
<?php
|
||||
if ('true' == Configure::read('CyDefSIG.showorg') || $isAdmin)
|
||||
echo $this->Form->input('org', array(
|
||||
'type' => 'text',
|
||||
'label' => 'From the following organisation',
|
||||
'div' => 'input clear'));
|
||||
'type' => 'textarea',
|
||||
'label' => 'From the following organisation(s)',
|
||||
'div' => 'input clear',
|
||||
'class' => 'input-xxlarge'));
|
||||
?>
|
||||
<?php
|
||||
echo $this->Form->input('type', array(
|
||||
|
|
Loading…
Reference in New Issue