From 019e976783e01b83d75f2605e57caa844aea9f9a Mon Sep 17 00:00:00 2001 From: Andras Iklody Date: Fri, 8 Mar 2013 13:16:02 +0100 Subject: [PATCH] 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 --- app/Controller/AttributesController.php | 21 +- app/Controller/EventsController.php | 24 +- app/Model/Attribute.php | 23 +- app/Model/Regexp.php | 2 + app/Model/Role.php | 214 ++++++------- app/Model/User.php | 2 +- app/View/Attributes/event.ctp | 398 ++++++++++++------------ app/View/Attributes/index.ctp | 18 +- app/View/Events/view.ctp | 37 +-- 9 files changed, 352 insertions(+), 387 deletions(-) diff --git a/app/Controller/AttributesController.php b/app/Controller/AttributesController.php index b0608049d..8c5d99d1c 100755 --- a/app/Controller/AttributesController.php +++ b/app/Controller/AttributesController.php @@ -53,7 +53,10 @@ class AttributesController extends AppController { array( 'Event.org =' => $this->Auth->user('org'), 'AND' => array( - array('Attribute.distribution !=' => 'Your organization only'), + array('OR' => array( + array('Attribute.private !=' => 1), + array('Attribute.cluster =' => 1), + )), array('OR' => array( array('Event.private !=' => 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 $this->Event->read(); - if(!$this->_isRest()) { + if (!$this->_isRest()) { $canEditDist = false; if ($this->Event->data['Event']['orgc'] == $this->_checkOrg()) { $this->set('canEditDist', true); @@ -758,14 +761,14 @@ class AttributesController extends AppController { $keywordArrayElement = '%' . trim($keywordArrayElement) . '%'; if ($keywordArrayElement != '%%') 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 > 1 && $i < 10) && $saveWord != '') $keyWordText = $keyWordText . ', ' . $saveWord; else if ($i == 10 && $saveWord != '') $keyWordText = $keyWordText . ' and several other keywords'; $i++; } $this->set('keywordSearch', $keyWordText); - if (!empty($temp)){ + if (!empty($temp)) { if (count($temp) == 1) { - $conditions['Attribute.value LIKE'] = '%'.$keyWordText.'%'; + $conditions['Attribute.value LIKE'] = '%' . $keyWordText . '%'; } else { $conditions['OR'] = $temp; } @@ -780,12 +783,12 @@ class AttributesController extends AppController { if (!is_numeric($saveWord) || $saveWord < 1) continue; array_push($temp, array('Attribute.event_id !=' => $keywordArrayElement)); 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'; $i++; } $this->set('keywordSearch2', $keyWordText2); - if (!empty($temp)){ + if (!empty($temp)) { if (count($temp) == 1) { $conditions['Attribute.event_id !='] = $keyWordText2; } else { @@ -825,9 +828,9 @@ class AttributesController extends AppController { foreach ($keywordArray as $keywordArrayElement) { $keywordArrayElement = trim($keywordArrayElement); 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', ''.$keywordArrayElement.'', $attribute['Attribute']['value']); + $attribute['Attribute']['value'] = preg_replace('%' . $keywordArrayElement . '%i', '' . $keywordArrayElement . '', $attribute['Attribute']['value']); } } $this->set('attributes', $attributes); diff --git a/app/Controller/EventsController.php b/app/Controller/EventsController.php index e6f43eb5f..0747cf8aa 100755 --- a/app/Controller/EventsController.php +++ b/app/Controller/EventsController.php @@ -181,6 +181,7 @@ class EventsController extends AppController { $relatedAttributes = array(); $this->loadModel('Attribute'); + $this->loadModel('Event'); if ('db' == Configure::read('CyDefSIG.correlation')) { $this->loadModel('Correlation'); $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() $relatedEventIds = array(); $relatedEventDates = array(); + $relatedEventInfos = array(); $relatedEvents = array(); foreach ($relatedAttributes as &$relatedAttribute) { if (null == $relatedAttribute) continue; foreach ($relatedAttribute as &$item) { $relatedEventsIds[] = $item['Attribute']['event_id']; $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)) { foreach ($relatedEventsDates as $key => $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')); } @@ -280,7 +293,7 @@ class EventsController extends AppController { $findParams = array( 'conditions' => array('OR' => array('Event.id' => $relatedEventsIds)), //array of conditions '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 ); $relatedEvents = $this->Event->find('all', $findParams); @@ -312,7 +325,6 @@ class EventsController extends AppController { } } $this->set('event', $event); - $this->set('relatedEvents', $relatedEvents); $this->set('categories', $this->Attribute->validate['category']['rule'][1]); @@ -522,7 +534,7 @@ class EventsController extends AppController { } } if (!$this->_isRest()) { - if ($this->Event->data['Event']['org'] != $this->_checkOrg()){ + if ($this->Event->data['Event']['org'] != $this->_checkOrg()) { // throw new MethodNotAllowedException(); $this->Session->setFlash(__('Invalid event.')); $this->redirect(array('controller' => 'events', 'action' => 'index')); @@ -1297,7 +1309,7 @@ class EventsController extends AppController { $params = array('conditions' => $conditions, 'recursive' => 1, 'fields' => $fields, - 'contain' =>array( + 'contain' => array( 'Attribute' => array( 'fields' => $fieldsAtt, 'conditions' => $conditionsAttributes, @@ -1486,7 +1498,6 @@ class EventsController extends AppController { $this->loadModel('Attribute'); - //restricting to non-private or same org if the user is not a site-admin. $conditions['AND'] = array('Attribute.type' => $type); if (!$this->isSiteAdmin()) { @@ -1499,7 +1510,6 @@ class EventsController extends AppController { $conditions['OR'] = $temp; } - $params = array( 'conditions' => $conditions, //array of conditions 'recursive' => 0, //int diff --git a/app/Model/Attribute.php b/app/Model/Attribute.php index a2f0ce5e0..8ea155e1f 100755 --- a/app/Model/Attribute.php +++ b/app/Model/Attribute.php @@ -371,19 +371,18 @@ class Attribute extends AppModel { $compositeTypes = $this->getCompositeTypes(); // explode composite types in value1 and value2 //if (!isset($this->data['Attribute']['value1'])) { - $pieces = explode('|', $this->data['Attribute']['value']); - if (in_array($this->data['Attribute']['type'], $compositeTypes)) { - if (2 != count($pieces)) { - throw new InternalErrorException('Composite type, but value not explodable'); - } - $this->data['Attribute']['value1'] = $pieces[0]; - $this->data['Attribute']['value2'] = $pieces[1]; - } else { - $total = implode('|', $pieces); - $this->data['Attribute']['value1'] = $total; - $this->data['Attribute']['value2'] = ''; + $pieces = explode('|', $this->data['Attribute']['value']); + if (in_array($this->data['Attribute']['type'], $compositeTypes)) { + if (2 != count($pieces)) { + throw new InternalErrorException('Composite type, but value not explodable'); } - //} + $this->data['Attribute']['value1'] = $pieces[0]; + $this->data['Attribute']['value2'] = $pieces[1]; + } else { + $total = implode('|', $pieces); + $this->data['Attribute']['value1'] = $total; + $this->data['Attribute']['value2'] = ''; + } } // always return true after a beforeSave() return true; diff --git a/app/Model/Regexp.php b/app/Model/Regexp.php index c8bcf1ea3..a19714d12 100755 --- a/app/Model/Regexp.php +++ b/app/Model/Regexp.php @@ -15,6 +15,7 @@ class Regexp extends AppModel { 'change' => 'full' ), ); + /** * Use table * @@ -23,6 +24,7 @@ class Regexp extends AppModel { public $useTable = 'regexp'; // this checks whether the regexp would fail and if yes, the entry is blocked from being entered. + public function beforeValidate($options = array()) { $test = preg_replace($this->data['Regexp']['regexp'], 'success', $this->data['Regexp']['regexp']); if ($test == null) return false; diff --git a/app/Model/Role.php b/app/Model/Role.php index 939ecab2c..469f40e5e 100755 --- a/app/Model/Role.php +++ b/app/Model/Role.php @@ -1,112 +1,112 @@ - array( - 'notempty' => array( - 'rule' => array('notempty'), - //'message' => 'Your custom message here', - //'allowEmpty' => false, - //'required' => false, - //'last' => false, // Stop validation after this rule - //'on' => 'create', // Limit validation to 'create' or 'update' operations - ), - ), - ); - -/** - * hasMany associations - * - * @var array - */ - public $hasMany = array( - 'User' => array( - 'className' => 'User', - 'foreignKey' => 'role_id', - 'dependent' => false, - 'conditions' => '', - 'fields' => '', - 'order' => '', - 'limit' => '', - 'offset' => '', - 'exclusive' => '', - 'finderQuery' => '', - 'counterQuery' => '' - ) - ); - -/** - * TODO ACL: 1: be requester to CakePHP ACL system - * - * @var unknown_type - */ - public $actsAs = array( - 'Acl' => array('type' => 'requester'), - 'MagicTools.OrphansProtectable', - 'Trim', + array( + 'notempty' => array( + 'rule' => array('notempty'), + //'message' => 'Your custom message here', + //'allowEmpty' => false, + //'required' => false, + //'last' => false, // Stop validation after this rule + //'on' => 'create', // Limit validation to 'create' or 'update' operations + ), + ), + ); + +/** + * hasMany associations + * + * @var array + */ + public $hasMany = array( + 'User' => array( + 'className' => 'User', + 'foreignKey' => 'role_id', + 'dependent' => false, + 'conditions' => '', + 'fields' => '', + 'order' => '', + 'limit' => '', + 'offset' => '', + 'exclusive' => '', + 'finderQuery' => '', + 'counterQuery' => '' + ) + ); + +/** + * TODO ACL: 1: be requester to CakePHP ACL system + * + * @var unknown_type + */ + public $actsAs = array( + 'Acl' => array('type' => 'requester'), + 'MagicTools.OrphansProtectable', + 'Trim', 'SysLogLogable.SysLogLogable' => array( // TODO Audit, logable 'roleModel' => 'Role', 'roleKey' => 'role_id', 'change' => 'full' - ), - ); - -/** - * TODO ACL: 2: hook Role into CakePHP ACL system (so link to aros) - */ - public function parentNode() { - return null; - } - -/** - * Virtual field - * - * @var array - */ - public $virtualFields = array( - 'permission' => "IF (Role.perm_add && Role.perm_modify && Role.perm_publish, '3', IF (Role.perm_add && Role.perm_modify_org, '2', IF (Role.perm_add, '1', '0')))", - ); - - public function beforeSave($options = array()) { - switch ($this->data['Role']['permission']) { - case '0': - $this->data['Role']['perm_add'] = false; - $this->data['Role']['perm_modify'] = false; - $this->data['Role']['perm_modify_org'] = false; - $this->data['Role']['perm_publish'] = false; - break; - case '1': - $this->data['Role']['perm_add'] = true; - $this->data['Role']['perm_modify'] = true; // SHOULD BE true - $this->data['Role']['perm_modify_org'] = false; - $this->data['Role']['perm_publish'] = false; - break; - case '2': - $this->data['Role']['perm_add'] = true; - $this->data['Role']['perm_modify'] = true; - $this->data['Role']['perm_modify_org'] = true; - $this->data['Role']['perm_publish'] = false; - break; - case '3': - $this->data['Role']['perm_add'] = true; - $this->data['Role']['perm_modify'] = true; // ? - $this->data['Role']['perm_modify_org'] = true; // ? - $this->data['Role']['perm_publish'] = true; - break; - default: - break; - } - return true; - } + ), + ); + +/** + * TODO ACL: 2: hook Role into CakePHP ACL system (so link to aros) + */ + public function parentNode() { + return null; + } + +/** + * Virtual field + * + * @var array + */ + public $virtualFields = array( + 'permission' => "IF (Role.perm_add && Role.perm_modify && Role.perm_publish, '3', IF (Role.perm_add && Role.perm_modify_org, '2', IF (Role.perm_add, '1', '0')))", + ); + + public function beforeSave($options = array()) { + switch ($this->data['Role']['permission']) { + case '0': + $this->data['Role']['perm_add'] = false; + $this->data['Role']['perm_modify'] = false; + $this->data['Role']['perm_modify_org'] = false; + $this->data['Role']['perm_publish'] = false; + break; + case '1': + $this->data['Role']['perm_add'] = true; + $this->data['Role']['perm_modify'] = true; // SHOULD BE true + $this->data['Role']['perm_modify_org'] = false; + $this->data['Role']['perm_publish'] = false; + break; + case '2': + $this->data['Role']['perm_add'] = true; + $this->data['Role']['perm_modify'] = true; + $this->data['Role']['perm_modify_org'] = true; + $this->data['Role']['perm_publish'] = false; + break; + case '3': + $this->data['Role']['perm_add'] = true; + $this->data['Role']['perm_modify'] = true; // ? + $this->data['Role']['perm_modify_org'] = true; // ? + $this->data['Role']['perm_publish'] = true; + break; + default: + break; + } + return true; + } } \ No newline at end of file diff --git a/app/Model/User.php b/app/Model/User.php index 083b7c45b..f506a125e 100755 --- a/app/Model/User.php +++ b/app/Model/User.php @@ -236,7 +236,7 @@ class User extends AppModel { public $actsAs = array( 'Acl' => array( // TODO ACL, + 'enabled' => false 'type' => 'requester', - 'enabled' => false + 'enabled' => false ), 'SysLogLogable.SysLogLogable' => array( // TODO Audit, logable 'userModel' => 'User', diff --git a/app/View/Attributes/event.ctp b/app/View/Attributes/event.ctp index bd66059a6..102dea8fc 100755 --- a/app/View/Attributes/event.ctp +++ b/app/View/Attributes/event.ctp @@ -1,200 +1,200 @@ -
-
-
  • Form->postLink('Publish Event', array('controller' => 'events', 'action' => 'alert', $event['Event']['id']), null, 'Are you sure this event is complete and everyone should be informed?'); - echo $this->Form->postLink('Publish (no email)', array('controller' => 'events', 'action' => 'publish', $event['Event']['id']), null, 'Publish but do NOT send alert email? Only for minor changes!'); - ?>
-
  • Not published
- -
  • Html->link(__('Contact reporter', true), array('controller' => 'events', 'action' => 'contact', $event['Event']['id'])); ?>
-
- - - -

Event

-
-
ID
-
- -   -
-
Org
-
- -   -
-
Email
-
- -   -
-
Date
-
- -   -
- >Risk -
- -   -
-
Distribution
-
- -   -
- -
Info
-
- -   -
-
- - - - -
- -
- +
+
+
  • Form->postLink('Publish Event', array('controller' => 'events', 'action' => 'alert', $event['Event']['id']), null, 'Are you sure this event is complete and everyone should be informed?'); + echo $this->Form->postLink('Publish (no email)', array('controller' => 'events', 'action' => 'publish', $event['Event']['id']), null, 'Publish but do NOT send alert email? Only for minor changes!'); + ?>
+
  • Not published
+ +
  • Html->link(__('Contact reporter', true), array('controller' => 'events', 'action' => 'contact', $event['Event']['id'])); ?>
+
+ + + +

Event

+
+
ID
+
+ +   +
+
Org
+
+ +   +
+
Email
+
+ +   +
+
Date
+
+ +   +
+ >Risk +
+ +   +
+
Distribution
+
+ +   +
+ +
Info
+
+ +   +
+
+ + + + +
+ +
+
    +
  • Html->link(__('Add Attribute', true), array('controller' => 'attributes', 'action' => 'add', $event['Event']['id']));?>
  • +
  • Html->link(__('Add Attachment', true), array('controller' => 'attributes', 'action' => 'add_attachment', $event['Event']['id']));?>
  • +
  • Html->link(__('Edit Event', true), array('controller' => 'events', 'action' => 'edit', $event['Event']['id'])); ?>
  • +
  • Form->postLink(__('Delete Event'), array('controller' => 'events', 'action' => 'delete', $event['Event']['id']), null, __('Are you sure you want to delete # %s?', $event['Event']['id'])); ?>
  • +
  •  
  • + element('actions_menu'); ?> +
\ No newline at end of file diff --git a/app/View/Attributes/index.ctp b/app/View/Attributes/index.ctp index a5a91a0f0..be7dc776a 100755 --- a/app/View/Attributes/index.ctp +++ b/app/View/Attributes/index.ctp @@ -1,19 +1,3 @@ -

"; + echo "
"; echo $this->Html->link($attribute['Event']['id'], array('controller' => 'events', 'action' => 'view', $attribute['Event']['id'])); $currentCount++; ?> diff --git a/app/View/Events/view.ctp b/app/View/Events/view.ctp index 342362b85..278764a47 100755 --- a/app/View/Events/view.ctp +++ b/app/View/Events/view.ctp @@ -1,30 +1,3 @@ -