mirror of https://github.com/MISP/MISP
Regexp changes, UI changes
- first cleanup of regexp - some changes left off from the UI changes that were not in the views themselvespull/217/head
parent
1b79963ce8
commit
eeac31bee8
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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'))
|
||||
);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -152,7 +152,6 @@ div.view {
|
|||
div.actions {
|
||||
float:left;
|
||||
width:10%;
|
||||
position:fixed;
|
||||
}
|
||||
div.actions h3 {
|
||||
padding-top:0;
|
||||
|
|
Loading…
Reference in New Issue