mirror of https://github.com/MISP/MISP
chg: [decayingTool] Improved related type retreival and improved UI -
WiPpull/5032/head
parent
38a7f511d7
commit
cdec345c4c
|
@ -6,13 +6,6 @@ class DecayingModelMappingController extends AppController
|
|||
{
|
||||
public $components = array('Security' ,'RequestHandler');
|
||||
|
||||
public $belongsTo = array(
|
||||
'DecayingModel' => array(
|
||||
'className' => 'DecayingModel',
|
||||
'foreignKey' => 'id'
|
||||
)
|
||||
);
|
||||
|
||||
public $paginate = array(
|
||||
'limit' => 50,
|
||||
'order' => array(
|
||||
|
|
|
@ -72,7 +72,7 @@ class AppModel extends Model
|
|||
7 => false, 8 => false, 9 => false, 10 => false, 11 => false, 12 => false,
|
||||
13 => false, 14 => false, 15 => false, 18 => false, 19 => false, 20 => false,
|
||||
21 => false, 22 => false, 23 => false, 24 => false, 25 => false, 26 => false,
|
||||
27 => false, 28 => false, 29 => false, 30 => false, 31 => false, 32 => false
|
||||
27 => false, 28 => false, 29 => false, 30 => false, 31 => false
|
||||
);
|
||||
|
||||
public function afterSave($created, $options = array())
|
||||
|
@ -1110,11 +1110,9 @@ class AppModel extends Model
|
|||
`version` varchar(255) COLLATE utf8_bin NOT NULL
|
||||
PRIMARY KEY (id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
||||
break;
|
||||
case 32:
|
||||
$sqlArray[] = "CREATE TABLE IF NOT EXISTS decaying_model_mappings (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`org_id` int(11) NOT NULL,
|
||||
`org_id` int(11),
|
||||
`attribute_type` varchar(255) COLLATE utf8_bin NOT NULL,
|
||||
`model_id` int(11) NOT NULL,
|
||||
PRIMARY KEY (id)
|
||||
|
|
|
@ -29,6 +29,8 @@ class DecayingModel extends AppModel
|
|||
$decoded = array();
|
||||
}
|
||||
$results[$k]['DecayingModel']['attribute_types'] = $decoded;
|
||||
} else {
|
||||
$results[$k]['DecayingModel']['attribute_types'] = array();
|
||||
}
|
||||
if (!empty($v['DecayingModel']['ref'])) {
|
||||
$decoded = json_decode($v['DecayingModel']['ref'], true);
|
||||
|
@ -105,10 +107,13 @@ class DecayingModel extends AppModel
|
|||
if ($force || $new_model['version'] > $existing_model['version']) {
|
||||
$new_model['id'] = $existing_model['id'];
|
||||
$this->save($new_model);
|
||||
$this->DecayingModelMapping->resetMappingFromDefaultModel($new_model);
|
||||
}
|
||||
} else {
|
||||
$this->create();
|
||||
$this->save($new_model);
|
||||
$new_model['id'] = $this->Model->id;
|
||||
$this->DecayingModelMapping->resetMappingFromDefaultModel($new_model);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -142,7 +147,11 @@ class DecayingModel extends AppModel
|
|||
return false;
|
||||
}
|
||||
|
||||
//if the user is a site admin, return the template without question
|
||||
if ($full) {
|
||||
$decayingModel['DecayingModel']['attribute_types'] = $this->DecayingModelMapping->getAssociatedTypes($user, $decayingModel['DecayingModel']['id']);
|
||||
}
|
||||
|
||||
//if the user is a site admin, return the model without question
|
||||
if ($user['Role']['perm_site_admin']) {
|
||||
return $decayingModel;
|
||||
}
|
||||
|
|
|
@ -24,55 +24,81 @@ class DecayingModelMapping extends AppModel
|
|||
);
|
||||
|
||||
public $belongsTo = array(
|
||||
'DecayingModel',
|
||||
'Attribute'
|
||||
);
|
||||
|
||||
private $__default_type_mapping = array(
|
||||
'domain|ip' => 10,
|
||||
'ip-dst' => 10,
|
||||
'ip-dst|port' => 10,
|
||||
'ip-src' => 10,
|
||||
'ip-src|port' => 10,
|
||||
'DecayingModel' => array(
|
||||
'className' => 'DecayingModel',
|
||||
'foreignKey' => 'id'
|
||||
)
|
||||
);
|
||||
|
||||
private $__default_type_mapping_reverse = array();
|
||||
// private $default_type_mapping_reverse = array_flip($this->__default_type_mapping);
|
||||
|
||||
private function __setup() {
|
||||
foreach ($this->__default_type_mapping as $type => $model_id) {
|
||||
if (!isset($this->__default_type_mapping_reverse[$model_id])) {
|
||||
$this->__default_type_mapping_reverse[$model_id] = array();
|
||||
}
|
||||
$this->__default_type_mapping_reverse[$model_id][] = $type;
|
||||
}
|
||||
// foreach ($this->__default_type_mapping as $type => $model_id) {
|
||||
// if (!isset($this->__default_type_mapping_reverse[$model_id])) {
|
||||
// $this->__default_type_mapping_reverse[$model_id] = array();
|
||||
// }
|
||||
// $this->__default_type_mapping_reverse[$model_id][] = $type;
|
||||
// }
|
||||
}
|
||||
|
||||
public function injectDefaultMapping(&$associated_types, $model_id) {
|
||||
$associated_types = array_merge($associated_types, $this->__default_type_mapping_reverse[$model_id]);
|
||||
// Delete all DEFAULT mapping associated to the model and re-create them
|
||||
public function resetMappingFromDefaultModel($new_model) {
|
||||
$this->deleteAll(array(
|
||||
'DecayingModelMapping.org_id' => null,
|
||||
'model_id' => $new_model['id']
|
||||
));
|
||||
|
||||
foreach ($new_model['attribute_types'] as $type) {
|
||||
$this->create();
|
||||
$to_save = array(
|
||||
'attribute_type' => $type,
|
||||
'model_id' => $new_model['id']
|
||||
);
|
||||
$this->save($to_save);
|
||||
}
|
||||
}
|
||||
|
||||
public function getAssociatedTypes($user, $model_id) {
|
||||
$this->__setup();
|
||||
$decaying_model = $this->DecayingModel->checkAuthorisation($user, $model_id);
|
||||
if (!$decaying_model) {
|
||||
$decaying_model = $this->DecayingModel->find('first', array(
|
||||
'conditions' => array('id' => $model_id),
|
||||
'recursive' => -1,
|
||||
));
|
||||
if (empty($decaying_model)) {
|
||||
$associated_types = array();
|
||||
} else {
|
||||
$conditions = array(
|
||||
'org_id' => $user['Organisation']['id'],
|
||||
'model_id' => $model_id
|
||||
);
|
||||
$associated_types = $this->find('all', array(
|
||||
'conditions' => $conditions,
|
||||
$decaying_model = $decaying_model['DecayingModel'];
|
||||
$associated_types = $decaying_model['attribute_types'];
|
||||
$temp = $this->find('list', array(
|
||||
'conditions' => array(
|
||||
'OR' => array(
|
||||
'org_id' => $user['Organisation']['id'],
|
||||
'org_id' => NULL,
|
||||
),
|
||||
'model_id' => $model_id
|
||||
),
|
||||
'recursive' => -1,
|
||||
'fields' => array('attribute_type')
|
||||
));
|
||||
$this->injectDefaultMapping($associated_types, $model_id);
|
||||
// if (!empty($associated_types)) {
|
||||
// $associated_types = $associated_types[0];
|
||||
// }
|
||||
$associated_types = array_unique(array_merge($associated_types, $temp));
|
||||
}
|
||||
return $associated_types;
|
||||
}
|
||||
|
||||
public function getAssociatedModels($user, $attribute_type) {
|
||||
$associated_models = $this->find('all', array(
|
||||
'conditions' => array(
|
||||
'OR' => array(
|
||||
'org_id' => $user['Organisation']['id'],
|
||||
'org_id' => NULL,
|
||||
),
|
||||
'model_id' => $attribute_type
|
||||
),
|
||||
'recursive' => -1,
|
||||
'fields' => array('attribute_type')
|
||||
));
|
||||
return $associated_models;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
<div class="span6" style="margin-bottom: 20px;">
|
||||
<?php foreach ($parameters as $param => $config): ?>
|
||||
<div class="input-prepend input-append">
|
||||
<span class="add-on" data-toggle="tooltip" data-placement="left" style="min-width: 100px;" title="<?php echo isset($config['info']) ? h($config['info']) : ''?>">
|
||||
<span class="add-on param-name" data-toggle="tooltip" data-placement="left" style="min-width: 100px;" title="<?php echo isset($config['info']) ? h($config['info']) : ''?>">
|
||||
<?php echo h($config['name']) . (isset($config['greek']) ? ' <strong>'.h($config['greek']).'</strong>' : ''); ?>
|
||||
</span>
|
||||
<input id="input_<?php echo h($param); ?>" class="input-mini" type="number" min=0 step=<?php echo h($config['step']); ?> value=<?php echo h($config['value']); ?> oninput="refreshGraph(this);" ></input>
|
||||
|
@ -107,6 +107,7 @@
|
|||
<table class="table table-striped table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th rowspan="2">ID</th>
|
||||
<th rowspan="2">Model Name</th>
|
||||
<th rowspan="2">Org id</th>
|
||||
<th rowspan="2">Description</th>
|
||||
|
@ -122,6 +123,7 @@
|
|||
<tbody id="modelTableBody">
|
||||
<?php foreach ($savedModels as $k => $model): ?>
|
||||
<tr id="modelId_<?php echo h($model['DecayingModel']['id']); ?>">
|
||||
<td class="DMId"><a href="<?php echo $baseurl; ?>/decayingModel/view/<?php echo h($model['DecayingModel']['id']); ?>"><?php echo h($model['DecayingModel']['id']); ?></a></td>
|
||||
<td class="DMName"><?php echo h($model['DecayingModel']['name']); ?></td>
|
||||
<td class="DMOrg"><?php echo $this->OrgImg->getOrgImg(array('name' => $model['DecayingModel']['org_id'], 'size' => 24)); ?> </td>
|
||||
<td class="DMDescription"><?php echo h($model['DecayingModel']['description']); ?></td>
|
||||
|
|
|
@ -1053,6 +1053,10 @@ li .generic-picker-item-element-check {
|
|||
z-index:-111;
|
||||
}
|
||||
|
||||
span.success {
|
||||
background-color: #d0e9c6 !important;
|
||||
}
|
||||
|
||||
.ajaxMessage {
|
||||
display:none;
|
||||
margin-left:10px;
|
||||
|
|
|
@ -288,15 +288,17 @@
|
|||
|
||||
/* MODEL TABLE */
|
||||
loadModel: function(clicked) {
|
||||
var that = this;
|
||||
var $clicked = $(clicked);
|
||||
var tr = $clicked.closest('tr');
|
||||
var parameters = {
|
||||
tau: parseFloat(tr.find('td.DMParameterTau')[0].innerHTML),
|
||||
delta: parseFloat(tr.find('td.DMParameterDelta')[0].innerHTML),
|
||||
threshold: parseInt(tr.find('td.DMParameterThreshold')[0].innerHTML)
|
||||
tau: parseFloat(tr.find('td.DMParameterTau').text()),
|
||||
delta: parseFloat(tr.find('td.DMParameterDelta').text()),
|
||||
threshold: parseInt(tr.find('td.DMParameterThreshold').text())
|
||||
};
|
||||
var name = tr.find('td.DMName')[0].innerHTML;
|
||||
var desc = tr.find('td.DMDescription')[0].innerHTML;
|
||||
var name = tr.find('td.DMName').text();
|
||||
var desc = tr.find('td.DMDescription').text();
|
||||
var model_id = tr.find('td.DMId').text();
|
||||
|
||||
$('#input_Tau').val(parameters.tau);
|
||||
$('#input_Tau').data('multiplier', $('#input_Tau').val()/this.options.TICK_NUM);
|
||||
|
@ -307,6 +309,10 @@
|
|||
$form.find('[name="description"]').val(desc);
|
||||
this.refreshInfoCells(parameters.threshold);
|
||||
this.redrawGraph();
|
||||
// highlight attribute types
|
||||
$.getJSON('/decayingModelMapping/viewAssociatedTypes/' + model_id, function(j) {
|
||||
that.highlightAttributeType(j);
|
||||
});
|
||||
},
|
||||
retreiveData: function() {
|
||||
var $form = $('#saveForm')
|
||||
|
@ -394,12 +400,14 @@
|
|||
delete data['description'];
|
||||
var $rows = $('#modelTableBody').find('tr');
|
||||
$rows.removeClass('success');
|
||||
$('div.input-prepend > span.param-name').removeClass('success');
|
||||
$rows.each(function(i) {
|
||||
var rowData = that.getDataFromRow($(this));
|
||||
delete rowData['name'];
|
||||
delete rowData['description'];
|
||||
if (that.simpleCompareObject(data, rowData)) {
|
||||
$(this).addClass('success');
|
||||
$('div.input-prepend > span.param-name').addClass('success');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
@ -432,11 +440,11 @@
|
|||
/* TYPE TABLE */
|
||||
toggleCB: function(clicked, force) {
|
||||
var $clicked = $(clicked);
|
||||
var cb = $clicked.first().find('input');
|
||||
var $cb = $clicked.first().find('input');
|
||||
if (force === undefined) {
|
||||
cb.prop('checked', !cb.is(':checked'));
|
||||
$cb.prop('checked', !$cb.is(':checked'));
|
||||
} else {
|
||||
cb.prop('checked', force);
|
||||
$cb.prop('checked', force);
|
||||
}
|
||||
},
|
||||
filterTableType: function(table, searchString) {
|
||||
|
@ -454,7 +462,7 @@
|
|||
// show only matching elements
|
||||
var $cells = $table.find('tbody > tr > td.isFilteringField');
|
||||
$cells.each(function() {
|
||||
if ($(this).text().indexOf(searchString) != -1) {
|
||||
if ($(this).text().trim().indexOf(searchString) != -1) {
|
||||
$(this).parent().filter('.isNotToIDS').forceClass('hidden', !$('#table_toggle_all_type').is(':checked'));
|
||||
$(this).parent().filter('.isObject').forceClass('hidden', !$('#table_toggle_objects').is(':checked'));
|
||||
$(this).parent().filter(':not(".isObject, .isNotToIDS")').forceClass('hidden', false);
|
||||
|
@ -462,6 +470,22 @@
|
|||
});
|
||||
}
|
||||
},
|
||||
highlightAttributeType: function(types) {
|
||||
var that = this;
|
||||
var $checkboxes = $('#attributeTypeTableBody').find('input[type="checkbox"]');
|
||||
$checkboxes.prop('checked', false);
|
||||
var $row = $($checkboxes).closest('tr');
|
||||
$row.removeClass('info');
|
||||
|
||||
var $cells = $('#table_attribute_type').find('tbody > tr > td.isFilteringField');
|
||||
$cells.each(function() {
|
||||
var value = $(this).text().trim();
|
||||
if (types.includes(value)) {
|
||||
that.toggleCB($(this).parent(), true);
|
||||
$(this).parent().forceClass('info', true)
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/* UTIL */
|
||||
refreshInfoCells: function() {
|
||||
|
@ -580,7 +604,7 @@ $(document).ready(function() {
|
|||
$('#checkAll').change(function() {
|
||||
var $checkboxes = $('#attributeTypeTableBody').find('input[type="checkbox"]');
|
||||
$checkboxes.prop('checked', this.checked);
|
||||
$row = $($checkboxes).closest('tr');
|
||||
var $row = $($checkboxes).closest('tr');
|
||||
$row.toggleClass('info', this.checked);
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue