Removed the js title bubble for related events

- Removed javascripts based title bubble showing the event info in related
  events / attributes and in the search attribute view.

- Replaced it with values provided by extra cake queries as the delay for
  fetching the info field through a js rest request was annoyingly slow

- some coding standards
pull/63/head
Andras Iklody 2013-03-08 13:16:02 +01:00
parent 0e18aa099b
commit 019e976783
9 changed files with 352 additions and 387 deletions

View File

@ -53,7 +53,10 @@ class AttributesController extends AppController {
array( array(
'Event.org =' => $this->Auth->user('org'), 'Event.org =' => $this->Auth->user('org'),
'AND' => array( 'AND' => array(
array('Attribute.distribution !=' => 'Your organization only'), array('OR' => array(
array('Attribute.private !=' => 1),
array('Attribute.cluster =' => 1),
)),
array('OR' => array( array('OR' => array(
array('Event.private !=' => 1), array('Event.private !=' => 1),
array('Event.cluster =' => 1), array('Event.cluster =' => 1),
@ -568,7 +571,7 @@ class AttributesController extends AppController {
// enabling / disabling the distribution field in the edit view based on whether user's org == orgc in the event // enabling / disabling the distribution field in the edit view based on whether user's org == orgc in the event
$this->Event->read(); $this->Event->read();
if(!$this->_isRest()) { if (!$this->_isRest()) {
$canEditDist = false; $canEditDist = false;
if ($this->Event->data['Event']['orgc'] == $this->_checkOrg()) { if ($this->Event->data['Event']['orgc'] == $this->_checkOrg()) {
$this->set('canEditDist', true); $this->set('canEditDist', true);
@ -758,14 +761,14 @@ class AttributesController extends AppController {
$keywordArrayElement = '%' . trim($keywordArrayElement) . '%'; $keywordArrayElement = '%' . trim($keywordArrayElement) . '%';
if ($keywordArrayElement != '%%') array_push($temp, array('Attribute.value LIKE' => $keywordArrayElement)); if ($keywordArrayElement != '%%') array_push($temp, array('Attribute.value LIKE' => $keywordArrayElement));
if ($i == 1 && $saveWord != '') $keyWordText = $saveWord; if ($i == 1 && $saveWord != '') $keyWordText = $saveWord;
else if (($i > 1 && $i < 10) && $saveWord != '') $keyWordText = $keyWordText .', '. $saveWord; else if (($i > 1 && $i < 10) && $saveWord != '') $keyWordText = $keyWordText . ', ' . $saveWord;
else if ($i == 10 && $saveWord != '') $keyWordText = $keyWordText . ' and several other keywords'; else if ($i == 10 && $saveWord != '') $keyWordText = $keyWordText . ' and several other keywords';
$i++; $i++;
} }
$this->set('keywordSearch', $keyWordText); $this->set('keywordSearch', $keyWordText);
if (!empty($temp)){ if (!empty($temp)) {
if (count($temp) == 1) { if (count($temp) == 1) {
$conditions['Attribute.value LIKE'] = '%'.$keyWordText.'%'; $conditions['Attribute.value LIKE'] = '%' . $keyWordText . '%';
} else { } else {
$conditions['OR'] = $temp; $conditions['OR'] = $temp;
} }
@ -780,12 +783,12 @@ class AttributesController extends AppController {
if (!is_numeric($saveWord) || $saveWord < 1) continue; if (!is_numeric($saveWord) || $saveWord < 1) continue;
array_push($temp, array('Attribute.event_id !=' => $keywordArrayElement)); array_push($temp, array('Attribute.event_id !=' => $keywordArrayElement));
if ($i == 1 && $saveWord != '') $keyWordText2 = $saveWord; if ($i == 1 && $saveWord != '') $keyWordText2 = $saveWord;
else if (($i > 1 && $i < 10) && $saveWord != '') $keyWordText2 = $keyWordText2 .', '. $saveWord; else if (($i > 1 && $i < 10) && $saveWord != '') $keyWordText2 = $keyWordText2 . ', ' . $saveWord;
else if ($i == 10 && $saveWord != '') $keyWordText2 = $keyWordText2 . ' and several other events'; else if ($i == 10 && $saveWord != '') $keyWordText2 = $keyWordText2 . ' and several other events';
$i++; $i++;
} }
$this->set('keywordSearch2', $keyWordText2); $this->set('keywordSearch2', $keyWordText2);
if (!empty($temp)){ if (!empty($temp)) {
if (count($temp) == 1) { if (count($temp) == 1) {
$conditions['Attribute.event_id !='] = $keyWordText2; $conditions['Attribute.event_id !='] = $keyWordText2;
} else { } else {
@ -825,9 +828,9 @@ class AttributesController extends AppController {
foreach ($keywordArray as $keywordArrayElement) { foreach ($keywordArray as $keywordArrayElement) {
$keywordArrayElement = trim($keywordArrayElement); $keywordArrayElement = trim($keywordArrayElement);
if ($attribute['Attribute']['type'] == 'malware-sample' || $attribute['Attribute']['type'] == 'link' || $attribute['Attribute']['type'] == 'attachment') { if ($attribute['Attribute']['type'] == 'malware-sample' || $attribute['Attribute']['type'] == 'link' || $attribute['Attribute']['type'] == 'attachment') {
$attribute['Attribute']['valueNoScript'] = preg_replace('%'.$keywordArrayElement.'%i', $keywordArrayElement, $attribute['Attribute']['value']); $attribute['Attribute']['valueNoScript'] = preg_replace('%' . $keywordArrayElement . '%i', $keywordArrayElement, $attribute['Attribute']['value']);
} }
$attribute['Attribute']['value'] = preg_replace('%'.$keywordArrayElement.'%i', '<span style="color:red">'.$keywordArrayElement.'</span>', $attribute['Attribute']['value']); $attribute['Attribute']['value'] = preg_replace('%' . $keywordArrayElement . '%i', '<span style="color:red">' . $keywordArrayElement . '</span>', $attribute['Attribute']['value']);
} }
} }
$this->set('attributes', $attributes); $this->set('attributes', $attributes);

View File

@ -181,6 +181,7 @@ class EventsController extends AppController {
$relatedAttributes = array(); $relatedAttributes = array();
$this->loadModel('Attribute'); $this->loadModel('Attribute');
$this->loadModel('Event');
if ('db' == Configure::read('CyDefSIG.correlation')) { if ('db' == Configure::read('CyDefSIG.correlation')) {
$this->loadModel('Correlation'); $this->loadModel('Correlation');
$fields = array('Correlation.event_id', 'Correlation.attribute_id', 'Correlation.date'); $fields = array('Correlation.event_id', 'Correlation.attribute_id', 'Correlation.date');
@ -225,19 +226,31 @@ class EventsController extends AppController {
// This is a lot faster (only additional query) than $this->Event->getRelatedEvents() // This is a lot faster (only additional query) than $this->Event->getRelatedEvents()
$relatedEventIds = array(); $relatedEventIds = array();
$relatedEventDates = array(); $relatedEventDates = array();
$relatedEventInfos = array();
$relatedEvents = array(); $relatedEvents = array();
foreach ($relatedAttributes as &$relatedAttribute) { foreach ($relatedAttributes as &$relatedAttribute) {
if (null == $relatedAttribute) continue; if (null == $relatedAttribute) continue;
foreach ($relatedAttribute as &$item) { foreach ($relatedAttribute as &$item) {
$relatedEventsIds[] = $item['Attribute']['event_id']; $relatedEventsIds[] = $item['Attribute']['event_id'];
$relatedEventsDates[$item['Attribute']['event_id']] = $item['Attribute']['date']; $relatedEventsDates[$item['Attribute']['event_id']] = $item['Attribute']['date'];
$temp = $this->Event->find('first', array(
'conditions' => array('Event.id' => $item['Attribute']['event_id']),
'fields' => array('info'),
'recursive' => 0,
));
$item['Attribute']['event_info'] = $temp['Event']['info'];
$relatedEventInfos[$item['Attribute']['event_id']] = $temp['Event']['info'];
} }
} }
if (isset($relatedEventsDates)) { if (isset($relatedEventsDates)) {
foreach ($relatedEventsDates as $key => $relatedEventsDate) { foreach ($relatedEventsDates as $key => $relatedEventsDate) {
$relatedEvents[] = array('Event' => array('id' => $key, 'date' => $relatedEventsDate)); $relatedEvents[] = array('Event' => array('id' => $key, 'date' => $relatedEventsDate));
} }
$i = 0;
foreach ($relatedEventInfos as $info) {
$relatedEvents[$i]['Event']['info'] = $info;
$i++;
}
} }
usort($relatedEvents, array($this, 'compareRelatedEvents')); usort($relatedEvents, array($this, 'compareRelatedEvents'));
} }
@ -280,7 +293,7 @@ class EventsController extends AppController {
$findParams = array( $findParams = array(
'conditions' => array('OR' => array('Event.id' => $relatedEventsIds)), //array of conditions 'conditions' => array('OR' => array('Event.id' => $relatedEventsIds)), //array of conditions
'recursive' => 0, //int 'recursive' => 0, //int
'fields' => array('Event.id', 'Event.date', 'Event.uuid'), //array of field names 'fields' => array('Event.id', 'Event.date', 'Event.uuid', 'Event.info'), //array of field names
'order' => array('Event.date DESC'), //string or array defining order 'order' => array('Event.date DESC'), //string or array defining order
); );
$relatedEvents = $this->Event->find('all', $findParams); $relatedEvents = $this->Event->find('all', $findParams);
@ -312,7 +325,6 @@ class EventsController extends AppController {
} }
} }
$this->set('event', $event); $this->set('event', $event);
$this->set('relatedEvents', $relatedEvents); $this->set('relatedEvents', $relatedEvents);
$this->set('categories', $this->Attribute->validate['category']['rule'][1]); $this->set('categories', $this->Attribute->validate['category']['rule'][1]);
@ -522,7 +534,7 @@ class EventsController extends AppController {
} }
} }
if (!$this->_isRest()) { if (!$this->_isRest()) {
if ($this->Event->data['Event']['org'] != $this->_checkOrg()){ if ($this->Event->data['Event']['org'] != $this->_checkOrg()) {
// throw new MethodNotAllowedException(); // throw new MethodNotAllowedException();
$this->Session->setFlash(__('Invalid event.')); $this->Session->setFlash(__('Invalid event.'));
$this->redirect(array('controller' => 'events', 'action' => 'index')); $this->redirect(array('controller' => 'events', 'action' => 'index'));
@ -1297,7 +1309,7 @@ class EventsController extends AppController {
$params = array('conditions' => $conditions, $params = array('conditions' => $conditions,
'recursive' => 1, 'recursive' => 1,
'fields' => $fields, 'fields' => $fields,
'contain' =>array( 'contain' => array(
'Attribute' => array( 'Attribute' => array(
'fields' => $fieldsAtt, 'fields' => $fieldsAtt,
'conditions' => $conditionsAttributes, 'conditions' => $conditionsAttributes,
@ -1486,7 +1498,6 @@ class EventsController extends AppController {
$this->loadModel('Attribute'); $this->loadModel('Attribute');
//restricting to non-private or same org if the user is not a site-admin. //restricting to non-private or same org if the user is not a site-admin.
$conditions['AND'] = array('Attribute.type' => $type); $conditions['AND'] = array('Attribute.type' => $type);
if (!$this->isSiteAdmin()) { if (!$this->isSiteAdmin()) {
@ -1499,7 +1510,6 @@ class EventsController extends AppController {
$conditions['OR'] = $temp; $conditions['OR'] = $temp;
} }
$params = array( $params = array(
'conditions' => $conditions, //array of conditions 'conditions' => $conditions, //array of conditions
'recursive' => 0, //int 'recursive' => 0, //int

View File

@ -383,7 +383,6 @@ class Attribute extends AppModel {
$this->data['Attribute']['value1'] = $total; $this->data['Attribute']['value1'] = $total;
$this->data['Attribute']['value2'] = ''; $this->data['Attribute']['value2'] = '';
} }
//}
} }
// always return true after a beforeSave() // always return true after a beforeSave()
return true; return true;

View File

@ -15,6 +15,7 @@ class Regexp extends AppModel {
'change' => 'full' 'change' => 'full'
), ),
); );
/** /**
* Use table * Use table
* *
@ -23,6 +24,7 @@ class Regexp extends AppModel {
public $useTable = 'regexp'; public $useTable = 'regexp';
// this checks whether the regexp would fail and if yes, the entry is blocked from being entered. // this checks whether the regexp would fail and if yes, the entry is blocked from being entered.
public function beforeValidate($options = array()) { public function beforeValidate($options = array()) {
$test = preg_replace($this->data['Regexp']['regexp'], 'success', $this->data['Regexp']['regexp']); $test = preg_replace($this->data['Regexp']['regexp'], 'success', $this->data['Regexp']['regexp']);
if ($test == null) return false; if ($test == null) return false;

View File

@ -1,19 +1,3 @@
<script>
function getTitle(incInt, id){
if (document.getElementById(incInt).title == "Loading event info..."){
$.ajax({
type: 'GET',
url: "/events/"+id+".xml",
dataType: 'xml',
async:true,
success:function(result){
var returnData = $(result).find("info").text();
document.getElementById(incInt).title=returnData;
},
});
};
}
</script>
<div class="attributes index"> <div class="attributes index">
<h2><?php echo __('Attributes');?></h2> <h2><?php echo __('Attributes');?></h2>
<?php <?php
@ -41,7 +25,7 @@ foreach ($attributes as $attribute): ?>
<tr> <tr>
<td class="short"> <td class="short">
<?php <?php
echo "<div id = \"" . $attribute['Attribute']['id'] . "\" onMouseOver=getTitle(" . $attribute['Attribute']['id'] . "," . $attribute['Event']['id'] . ") title = \"Loading event info...\">"; echo "<div id = \"" . $attribute['Attribute']['id'] . "\" title = \"".h($attribute['Event']['info'])."\">";
echo $this->Html->link($attribute['Event']['id'], array('controller' => 'events', 'action' => 'view', $attribute['Event']['id'])); echo $this->Html->link($attribute['Event']['id'], array('controller' => 'events', 'action' => 'view', $attribute['Event']['id']));
$currentCount++; $currentCount++;
?> ?>

View File

@ -1,30 +1,3 @@
<script>
function getTitle(incInt, incIntb, incIntc){
id = incInt;
type = null;
if (incIntb==0){
type = "R";
}else{
type = "A";
}
findElementString = type+id;
if (type == "A"){
findElementString += "X"+incIntc;
}
if (document.getElementById(findElementString).title == "Loading event info..."){
$.ajax({
type: 'GET',
url: "/events/"+id+".xml",
dataType: 'xml',
async:false,
success:function(result){
var returnData = $(result).find("info").text();
document.getElementById(findElementString).title=returnData;
},
});
};
}
</script>
<?php <?php
$mayModify = (($isAclModify && $event['Event']['user_id'] == $me['id']) || ($isAclModifyOrg && $event['Event']['org'] == $me['org'])); $mayModify = (($isAclModify && $event['Event']['user_id'] == $me['id']) || ($isAclModifyOrg && $event['Event']['org'] == $me['org']));
$mayPublish = ($isAclPublish && $event['Event']['org'] == $me['org']); $mayPublish = ($isAclPublish && $event['Event']['org'] == $me['org']);
@ -129,7 +102,6 @@ endif; ?>
</dd> </dd>
</dl> </dl>
<?php <?php
$passAlong = array(0, 0);
if (!empty($relatedEvents)):?> if (!empty($relatedEvents)):?>
<div class="related"> <div class="related">
<h3>Related Events</h3> <h3>Related Events</h3>
@ -138,9 +110,7 @@ if (!empty($relatedEvents)):?>
foreach ($relatedEvents as $relatedEvent): ?> foreach ($relatedEvents as $relatedEvent): ?>
<li><?php <li><?php
$linkText = $relatedEvent['Event']['date'] . ' (' . $relatedEvent['Event']['id'] . ')'; $linkText = $relatedEvent['Event']['date'] . ' (' . $relatedEvent['Event']['id'] . ')';
$currentID = $relatedEvent['Event']['id']; echo "<div \" title = \"".$relatedEvent['Event']['info']."\">";
$passAlong[0] = $relatedEvent['Event']['id'];
echo "<div id = \"R" . $currentID . "\" onMouseOver=getTitle(" . $passAlong[0] . "," . $passAlong[1] . ") title = \"Loading event info...\">";
echo $this->Html->link($linkText, array('controller' => 'events', 'action' => 'view', $relatedEvent['Event']['id'])); echo $this->Html->link($linkText, array('controller' => 'events', 'action' => 'view', $relatedEvent['Event']['id']));
?></li> ?></li>
<?php <?php
@ -178,7 +148,6 @@ if (!empty($event['Attribute'])):?>
<?php <?php
endif;?> endif;?>
</tr><?php </tr><?php
$passAlong = array(0, 1, 0);
foreach ($categories as $category): foreach ($categories as $category):
$first = 1; $first = 1;
foreach ($event['Attribute'] as $attribute): foreach ($event['Attribute'] as $attribute):
@ -224,12 +193,10 @@ if (!empty($event['Attribute'])):?>
$first = 0; $first = 0;
if (isset($relatedAttributes[$attribute['id']]) && (null != $relatedAttributes[$attribute['id']])) { if (isset($relatedAttributes[$attribute['id']]) && (null != $relatedAttributes[$attribute['id']])) {
foreach ($relatedAttributes[$attribute['id']] as $relatedAttribute) { foreach ($relatedAttributes[$attribute['id']] as $relatedAttribute) {
$passAlong[0] = $relatedAttribute['Attribute']['event_id']; echo "<span title = \"".$relatedAttribute['Attribute']['event_info']."\">";
echo "<span id = \"A" . $passAlong[0] . "X" . $passAlong[2] . "\" onMouseOver=getTitle(" . $passAlong[0] . "," . $passAlong[1] . "," . $passAlong[2] . ") title = \"Loading event info...\">";
echo $this->Html->link($relatedAttribute['Attribute']['event_id'], array('controller' => 'events', 'action' => 'view', $relatedAttribute['Attribute']['event_id'])); echo $this->Html->link($relatedAttribute['Attribute']['event_id'], array('controller' => 'events', 'action' => 'view', $relatedAttribute['Attribute']['event_id']));
echo "</span>"; echo "</span>";
echo ' '; echo ' ';
$passAlong[2]++;
} }
} }
?>&nbsp; ?>&nbsp;