mirror of https://github.com/MISP/MISP
chg: [UI] Add object reference cleanup
parent
fc0ceb8206
commit
dca9803865
|
@ -9,10 +9,10 @@ class ObjectReferencesController extends AppController
|
|||
public $components = array('RequestHandler', 'Session');
|
||||
|
||||
public $paginate = array(
|
||||
'limit' => 20,
|
||||
'order' => array(
|
||||
'ObjectReference.id' => 'desc'
|
||||
),
|
||||
'limit' => 20,
|
||||
'order' => array(
|
||||
'ObjectReference.id' => 'desc'
|
||||
),
|
||||
);
|
||||
|
||||
public function add($objectId = false)
|
||||
|
@ -23,7 +23,7 @@ class ObjectReferencesController extends AppController
|
|||
}
|
||||
}
|
||||
if (empty($objectId)) {
|
||||
throw new MethodNotAllowedException('No object defined.');
|
||||
throw new NotFoundException('No object defined.');
|
||||
}
|
||||
if (Validation::uuid($objectId)) {
|
||||
$conditions = ['Object.uuid' => $objectId];
|
||||
|
@ -91,65 +91,63 @@ class ObjectReferencesController extends AppController
|
|||
} else {
|
||||
if ($this->_isRest()) {
|
||||
return $this->RestResponse->describe('ObjectReferences', 'add', false, $this->response->type());
|
||||
} else {
|
||||
$events = $this->ObjectReference->Object->Event->find('all', array(
|
||||
'conditions' => array(
|
||||
'OR' => array(
|
||||
'Event.id' => $object['Event']['id'],
|
||||
'AND' => array(
|
||||
'Event.uuid' => $object['Event']['extends_uuid'],
|
||||
$this->ObjectReference->Object->Event->createEventConditions($this->Auth->user())
|
||||
)
|
||||
),
|
||||
}
|
||||
|
||||
$events = $this->ObjectReference->Object->Event->find('all', array(
|
||||
'conditions' => array(
|
||||
'OR' => array(
|
||||
'Event.id' => $object['Event']['id'],
|
||||
'AND' => array(
|
||||
'Event.uuid' => $object['Event']['extends_uuid'],
|
||||
$this->ObjectReference->Object->Event->createEventConditions($this->Auth->user())
|
||||
)
|
||||
),
|
||||
'recursive' => -1,
|
||||
'fields' => array('Event.id'),
|
||||
'contain' => array(
|
||||
),
|
||||
'recursive' => -1,
|
||||
'fields' => array('Event.id'),
|
||||
'contain' => array(
|
||||
'Attribute' => array(
|
||||
'conditions' => array('Attribute.deleted' => 0, 'Attribute.object_id' => 0),
|
||||
'fields' => array('Attribute.id', 'Attribute.uuid', 'Attribute.type', 'Attribute.category', 'Attribute.value', 'Attribute.to_ids')
|
||||
),
|
||||
'Object' => array(
|
||||
'conditions' => array('NOT' => array('Object.id' => $object['Object']['id']), 'Object.deleted' => 0),
|
||||
'fields' => array('Object.id', 'Object.uuid', 'Object.name', 'Object.meta-category'),
|
||||
'Attribute' => array(
|
||||
'conditions' => array('Attribute.deleted' => 0, 'Attribute.object_id' => 0),
|
||||
'conditions' => array('Attribute.deleted' => 0),
|
||||
'fields' => array('Attribute.id', 'Attribute.uuid', 'Attribute.type', 'Attribute.category', 'Attribute.value', 'Attribute.to_ids')
|
||||
),
|
||||
'Object' => array(
|
||||
'conditions' => array('NOT' => array('Object.id' => $object['Object']['id']), 'Object.deleted' => 0),
|
||||
'fields' => array('Object.id', 'Object.uuid', 'Object.name', 'Object.meta-category'),
|
||||
'Attribute' => array(
|
||||
'conditions' => array('Attribute.deleted' => 0),
|
||||
'fields' => array('Attribute.id', 'Attribute.uuid', 'Attribute.type', 'Attribute.category', 'Attribute.value', 'Attribute.to_ids')
|
||||
)
|
||||
)
|
||||
)
|
||||
));
|
||||
if (!empty($events)) {
|
||||
$event = $events[0];
|
||||
}
|
||||
for ($i=1; $i < count($events); $i++) {
|
||||
$event['Attribute'] = array_merge($event['Attribute'], $events[$i]['Attribute']);
|
||||
$event['Object'] = array_merge($event['Object'], $events[$i]['Object']);
|
||||
}
|
||||
$toRearrange = array('Attribute', 'Object');
|
||||
foreach ($toRearrange as $d) {
|
||||
if (!empty($event[$d])) {
|
||||
$temp = array();
|
||||
foreach ($event[$d] as $data) {
|
||||
$temp[$data['uuid']] = $data;
|
||||
}
|
||||
$event[$d] = $temp;
|
||||
}
|
||||
}
|
||||
$this->loadModel('ObjectRelationship');
|
||||
$relationships = $this->ObjectRelationship->find('column', array(
|
||||
'recursive' => -1,
|
||||
'fields' => ['name'],
|
||||
));
|
||||
$relationships = array_combine($relationships, $relationships);
|
||||
$relationships['custom'] = 'custom';
|
||||
ksort($relationships);
|
||||
$this->set('relationships', $relationships);
|
||||
$this->set('event', $event);
|
||||
$this->set('objectId', $object['Object']['id']);
|
||||
$this->layout = false;
|
||||
$this->render('ajax/add');
|
||||
)
|
||||
));
|
||||
$event = $events[0];
|
||||
for ($i = 1; $i < count($events); $i++) {
|
||||
$event['Attribute'] = array_merge($event['Attribute'], $events[$i]['Attribute']);
|
||||
$event['Object'] = array_merge($event['Object'], $events[$i]['Object']);
|
||||
}
|
||||
$toRearrange = array('Attribute', 'Object');
|
||||
foreach ($toRearrange as $d) {
|
||||
if (!empty($event[$d])) {
|
||||
$temp = array();
|
||||
foreach ($event[$d] as $data) {
|
||||
$temp[$data['uuid']] = $data;
|
||||
}
|
||||
$event[$d] = $temp;
|
||||
}
|
||||
}
|
||||
$this->loadModel('ObjectRelationship');
|
||||
$relationships = $this->ObjectRelationship->find('column', array(
|
||||
'recursive' => -1,
|
||||
'fields' => ['name'],
|
||||
));
|
||||
$relationships = array_combine($relationships, $relationships);
|
||||
$relationships['custom'] = 'custom';
|
||||
ksort($relationships);
|
||||
$this->set('relationships', $relationships);
|
||||
$this->set('event', $event);
|
||||
$this->set('objectId', $object['Object']['id']);
|
||||
$this->layout = false;
|
||||
$this->render('ajax/add');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ class ObjectTemplateElement extends AppModel
|
|||
}
|
||||
$json_fields = array('categories', 'values_list', 'sane_default');
|
||||
foreach ($json_fields as $field) {
|
||||
$this->data['ObjectTemplateElement'][$field] = empty($this->data['ObjectTemplateElement'][$field]) ? '[]' : json_encode($this->data['ObjectTemplateElement'][$field]);
|
||||
$this->data['ObjectTemplateElement'][$field] = empty($this->data['ObjectTemplateElement'][$field]) ? '[]' : JsonTool::encode($this->data['ObjectTemplateElement'][$field]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
'div' => false
|
||||
));
|
||||
?>
|
||||
<div id="" class="hidden">
|
||||
<div class="hidden">
|
||||
<label for="ObjectReferenceRelationshipTypeSelect"><?php echo __('Relationship type');?></label>
|
||||
<?php
|
||||
echo $this->Form->input('relationship_type', array(
|
||||
|
@ -44,7 +44,7 @@
|
|||
'style' => 'width:320px;'
|
||||
));
|
||||
?>
|
||||
<br />
|
||||
<br>
|
||||
|
||||
<?php
|
||||
$items = array();
|
||||
|
@ -115,7 +115,6 @@
|
|||
);
|
||||
echo $this->element('generic_picker', array('items' => $items, 'options' => $options));
|
||||
?>
|
||||
|
||||
</div>
|
||||
<div class="span6">
|
||||
<label for="selectedData"><?php echo __('Target Details');?></label>
|
||||
|
@ -146,7 +145,7 @@
|
|||
</div>
|
||||
<script type="text/javascript">
|
||||
var targetEvent = <?php echo json_encode($event); ?>;
|
||||
$(document).ready(function() {
|
||||
$(function() {
|
||||
$('#ObjectReferenceReferencedUuid').on('input', function() {
|
||||
objectReferenceInput();
|
||||
});
|
||||
|
@ -160,4 +159,3 @@
|
|||
$('#ObjectReferenceRelationshipTypeSelect').chosen({ width: "100%" });
|
||||
});
|
||||
</script>
|
||||
<?php echo $this->Js->writeBuffer(); // Write cached scripts
|
||||
|
|
|
@ -13,6 +13,10 @@ if (!String.prototype.startsWith) {
|
|||
}
|
||||
|
||||
function escapeHtml(unsafe) {
|
||||
if (typeof unsafe === "boolean" || typeof unsafe === "number") {
|
||||
return unsafe;
|
||||
}
|
||||
|
||||
return unsafe
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
|
@ -4527,38 +4531,43 @@ function add_basic_auth() {
|
|||
}
|
||||
|
||||
function changeObjectReferenceSelectOption(selected, additionalData) {
|
||||
var keys = {
|
||||
"uuid": "UUID",
|
||||
"category": "Category",
|
||||
"type": "Type",
|
||||
"value": "Value",
|
||||
"to_ids": "To IDS",
|
||||
"name": "Name",
|
||||
"meta-category": "Meta category",
|
||||
};
|
||||
|
||||
var uuid = selected;
|
||||
var type = additionalData.itemOptions[uuid].type;
|
||||
$('#ObjectReferenceReferencedUuid').val(uuid);
|
||||
if (type == "Attribute") {
|
||||
$('#targetData').html("");
|
||||
var $targetData = $('#targetData');
|
||||
if (type === "Attribute") {
|
||||
$targetData.html("");
|
||||
for (var k in targetEvent[type][uuid]) {
|
||||
if ($.inArray(k, ['uuid', 'category', 'type', 'value', 'to_ids']) !== -1) {
|
||||
$('#targetData').append('<div><span id="' + uuid + '_' + k + '_key" class="bold"></span>: <span id="' + uuid + '_' + k + '_data"></span></div>');
|
||||
$('#' + uuid + '_' + k + '_key').text(k);
|
||||
$('#' + uuid + '_' + k + '_data').text(targetEvent[type][uuid][k]);
|
||||
$targetData.append('<div><span class="bold">' + keys[k] + '</span>: ' + escapeHtml(targetEvent[type][uuid][k]) + '</div>');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$('#targetData').html("");
|
||||
$targetData.html("");
|
||||
for (var k in targetEvent[type][uuid]) {
|
||||
if (k == 'Attribute') {
|
||||
$('#targetData').append('<br /><div><span id="header" class="bold">Attributes:</span>');
|
||||
for (attribute in targetEvent[type][uuid]['Attribute']) {
|
||||
for (k2 in targetEvent[type][uuid]['Attribute'][attribute]) {
|
||||
if (k === 'Attribute') {
|
||||
$targetData.append('<br><div><span id="header" class="bold">Attributes:</span>');
|
||||
for (var attribute in targetEvent[type][uuid]['Attribute']) {
|
||||
for (var k2 in targetEvent[type][uuid]['Attribute'][attribute]) {
|
||||
if ($.inArray(k2, ['category', 'type', 'value', 'to_ids']) !== -1) {
|
||||
$('#targetData').append('<div class="indent"><span id="' + targetEvent[type][uuid]['Attribute'][attribute]['uuid'] + '_' + k2 + '_key" class="bold"></span>: <span id="' + targetEvent[type][uuid]['Attribute'][attribute]['uuid'] + '_' + k2 + '_data"></span></div>');
|
||||
$('#' + targetEvent[type][uuid]['Attribute'][attribute]['uuid'] + '_' + k2 + '_key').text(k2);
|
||||
$('#' + targetEvent[type][uuid]['Attribute'][attribute]['uuid'] + '_' + k2 + '_data').text(targetEvent[type][uuid]['Attribute'][attribute][k2]);
|
||||
$targetData.append('<div class="indent"><span class="bold">' + keys[k2] + '</span>: ' + escapeHtml(targetEvent[type][uuid]['Attribute'][attribute][k2]) + '</div>');
|
||||
}
|
||||
}
|
||||
$('#targetData').append('<br />');
|
||||
$targetData.append('<br>');
|
||||
}
|
||||
} else {
|
||||
if ($.inArray(k, ['name', 'uuid', 'meta-category']) !== -1) {
|
||||
$('#targetData').append('<div><span id="' + uuid + '_' + k + '_key" class="bold"></span>: <span id="' + uuid + '_' + k + '_data"></span></div>');
|
||||
$('#' + uuid + '_' + k + '_key').text(k);
|
||||
$('#' + uuid + '_' + k + '_data').text(targetEvent[type][uuid][k]);
|
||||
$targetData.append('<div><span class="bold">' + keys[k] + '</span>: ' + escapeHtml(targetEvent[type][uuid][k]) + '</div>');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue