diff --git a/app/Controller/AppController.php b/app/Controller/AppController.php index f004cdd90..01970a732 100755 --- a/app/Controller/AppController.php +++ b/app/Controller/AppController.php @@ -40,6 +40,8 @@ class AppController extends Controller { public $defaultModel = ''; + public $debugMode = false; + public function __construct($id = false, $table = null, $ds = null) { parent::__construct($id, $table, $ds); @@ -128,6 +130,12 @@ class AppController extends Controller { $this->set('isAclAudit', false); $this->set('isAclAuth', false); } + if (Configure::read('debug')) { + $this->debugMode = 'debugOn'; + } else { + $this->debugMode = 'debugOff'; + } + $this->set('debugMode', $this->debugMode); } public $userRole = null; diff --git a/app/Controller/AttributesController.php b/app/Controller/AttributesController.php index 148df2598..caac7d333 100755 --- a/app/Controller/AttributesController.php +++ b/app/Controller/AttributesController.php @@ -77,9 +77,7 @@ class AttributesController extends AppController { public function index() { $this->Attribute->recursive = 0; $this->set('isSearch', 0); - $this->set('attributes', $this->paginate()); - $this->set('attrDescriptions', $this->Attribute->fieldDescriptions); $this->set('typeDefinitions', $this->Attribute->typeDefinitions); $this->set('categoryDefinitions', $this->Attribute->categoryDefinitions); diff --git a/app/Controller/EventsController.php b/app/Controller/EventsController.php index 348482688..9a326ebb8 100755 --- a/app/Controller/EventsController.php +++ b/app/Controller/EventsController.php @@ -1186,7 +1186,7 @@ class EventsController extends AppController { $gpg = new Crypt_GPG(array('homedir' => Configure::read('GnuPG.homedir'))); // , 'debug' => true $gpg->addSignKey(Configure::read('GnuPG.email'), Configure::read('GnuPG.password')); $bodySigned = $gpg->sign($body, Crypt_GPG::SIGN_MODE_CLEAR); - + $bodySigned = $body; // Add the GPG key of the user as attachment // LATER sign the attached GPG key if ($this->Auth->user('gpgkey') != null) { @@ -1224,6 +1224,7 @@ class EventsController extends AppController { // prepare the email $this->Email->from = Configure::read('CyDefSIG.email'); + $this->Email->replyTo = $this->Auth->user('email'); $this->Email->to = $reporter['User']['email']; $this->Email->subject = "[" . Configure::read('CyDefSIG.name') . "] Need info about event " . $id . " - TLP Amber"; //$this->Email->delivery = 'debug'; // do not really send out mails, only display it on the screen diff --git a/app/Controller/RegexpController.php b/app/Controller/RegexpController.php index 64c726eae..ec9d9045a 100755 --- a/app/Controller/RegexpController.php +++ b/app/Controller/RegexpController.php @@ -83,19 +83,20 @@ class RegexpController extends AppController { */ public function admin_clean() { if($this->Auth->User('org') != 'ADMIN') $this->redirect(array('controller' => 'regexp', 'action' => 'index', 'admin' => false)); - $this->regexpAll('Attribute', 'value'); - $this->regexpAll('Event', 'info'); + $allRegexp = $this->Regexp->find('all'); + $this->regexpAll('Attribute', 'value', $allRegexp); + $this->regexpAll('Event', 'info', $allRegexp); $this->redirect(array('action' => 'index')); } - public function regexpAll($Model, $Field) { + public function regexpAll($Model, $Field, $allRegexp) { if($this->Auth->User('org') != 'ADMIN') $this->redirect(array('controller' => 'regexp', 'action' => 'index', 'admin' => false)); $deletable = array(); $this->loadModel($Model); $all = $this->{$Model}->find('all', array('recursive' => -1)); foreach ($all as $item) { - $result = $this->replaceSpecific($item[$Model][$Field]); + $result = $this->__replaceSpecific($item[$Model][$Field], $allRegexp); if (!$result) { $deletable[] = $item[$Model]['id']; } else { @@ -109,10 +110,9 @@ class RegexpController extends AppController { } } - public function replaceSpecific($origString) { + private function __replaceSpecific($origString, $allRegexp = null) { if($this->Auth->User('org') != 'ADMIN') $this->redirect(array('controller' => 'regexp', 'action' => 'index', 'admin' => false)); $returnValue = true; - $allRegexp = $this->Regexp->find('all'); // TODO REGEXP INIT LOAD ARRAY foreach ($allRegexp as $regexp) { if (strlen($regexp['Regexp']['replacement']) && strlen($regexp['Regexp']['regexp'])) { $origString = preg_replace($regexp['Regexp']['regexp'], $regexp['Regexp']['replacement'], $origString); @@ -120,10 +120,9 @@ class RegexpController extends AppController { if (!strlen($regexp['Regexp']['replacement']) && preg_match($regexp['Regexp']['regexp'], $origString)) { App::uses('SessionComponent', 'Controller/Component'); SessionComponent::setFlash('Blacklisted value!'); - $returnValue = false; + return false; } } return $returnValue; } - } \ No newline at end of file diff --git a/app/Model/Attribute.php b/app/Model/Attribute.php index 8bc2ceeab..1d68bb23e 100755 --- a/app/Model/Attribute.php +++ b/app/Model/Attribute.php @@ -22,7 +22,7 @@ class Attribute extends AppModel { 'change' => 'full'), 'Trim', 'Containable', - 'Regexp' => array('fields' => array('value', 'value2')), + 'Regexp' => array('fields' => array('value')), 'Blacklist' => array('fields' => array('value')) ); diff --git a/app/Model/Behavior/RegexpBehavior.php b/app/Model/Behavior/RegexpBehavior.php index 37e323032..4dc1618b1 100755 --- a/app/Model/Behavior/RegexpBehavior.php +++ b/app/Model/Behavior/RegexpBehavior.php @@ -5,8 +5,6 @@ App::uses('Regexp', 'Model'); /** * Behavior to regexp all string fields in a model * - * @author noud - * */ class RegexpBehavior extends ModelBehavior { @@ -30,8 +28,6 @@ class RegexpBehavior extends ModelBehavior { * @param $options */ public function beforeValidate(Model $Model, $options = array()) { - $returnValue = true; - // process some.. $returnValue = $this->regexpStringFields($Model); return $returnValue; } @@ -44,14 +40,20 @@ class RegexpBehavior extends ModelBehavior { */ public function regexpStringFields(Model $Model) { $returnValue = true; + $regexp = new Regexp(); + $allRegexp = $regexp->find('all'); + // Go through all the fields from the validated model foreach ($Model->data[$Model->name] as $key => $field) { - if (in_array($key, $this->settings[$Model->alias]['fields']) && is_string($field)) { - $returnValue = $this->replaceWindowsSpecific($Model, $field); + // if a field is marked for regexp checks, do a regexp check + if (in_array($key, $this->settings[$Model->alias]['fields'])) { + $returnValue = $this->__replaceWindowsSpecific($Model, $field, $allRegexp); + // if replaceWindowsSpecific returns false, it means that we ran into a blacklisted value. Return false to let the validation fail. + if (!$returnValue) return false; + // if it wasn't false, change the value to the replacement $Model->data[$Model->name][$key] = $returnValue; } } - if ($returnValue != false) $returnValue = true; - return $returnValue; + return true; } /** @@ -61,21 +63,17 @@ class RegexpBehavior extends ModelBehavior { * * @return string */ - public function replaceWindowsSpecific(Model $Model, $string) { - $returnValue = $string; - $regexp = new Regexp(); - $allRegexp = $regexp->find('all'); // TODO INIT LOAD ARRAY + private function __replaceWindowsSpecific(Model $Model, $string, $allRegexp) { foreach ($allRegexp as $regexp) { - if (strlen($regexp['Regexp']['replacement'] && strlen($regexp['Regexp']['regexp']))) { + if (isset($regexp['Regexp']['replacement']) && isset($regexp['Regexp']['regexp'])) { $string = preg_replace($regexp['Regexp']['regexp'], $regexp['Regexp']['replacement'], $string); - $returnValue = $string; } - if (!strlen($regexp['Regexp']['replacement']) && preg_match($regexp['Regexp']['regexp'], $string)) { + if (!isset($regexp['Regexp']['replacement']) && preg_match($regexp['Regexp']['regexp'], $string)) { App::uses('SessionComponent', 'Controller/Component'); - SessionComponent::setFlash('Blacklisted value!'); + SessionComponent::setFlash('Blacklisted value (blocked through a regular expression entry)!'); return false; } } - return $returnValue; + return $string; } } diff --git a/app/webroot/css/main.css b/app/webroot/css/main.css index 1e3172e17..bffe669f5 100755 --- a/app/webroot/css/main.css +++ b/app/webroot/css/main.css @@ -152,7 +152,6 @@ div.view { div.actions { float:left; width:10%; - position:fixed; } div.actions h3 { padding-top:0;