mirror of https://github.com/MISP/MISP
chg: More progress on the galaxies
parent
0280fad3e6
commit
d891e0e652
|
@ -86,4 +86,75 @@ class GalaxiesController extends AppController {
|
|||
$this->set('galaxy', $galaxy);
|
||||
}
|
||||
}
|
||||
|
||||
public function selectGalaxy($event_id) {
|
||||
$galaxies = $this->Galaxy->find('all', array('recursive' => -1));
|
||||
$this->set('galaxies', $galaxies);
|
||||
$this->set('event_id', $event_id);
|
||||
$this->render('ajax/galaxy_choice');
|
||||
}
|
||||
|
||||
public function selectCluster($event_id) {
|
||||
$selectGalaxy = isset($this->request->data['Galaxy']['id']) ? $this->request->data['Galaxy']['id'] : false;
|
||||
$conditions = array();
|
||||
if ($selectGalaxy) {
|
||||
$conditions = array('GalaxyCluster.galaxy_id' => $selectGalaxy);
|
||||
}
|
||||
$data = $this->Galaxy->GalaxyCluster->find('all', array(
|
||||
'conditions' => $conditions,
|
||||
'fields' => array('value', 'description', 'source'),
|
||||
'contain' => array('GalaxyElement' => array('conditions' => array('GalaxyElement.key' => 'synonyms'))),
|
||||
'recursive' => -1
|
||||
));
|
||||
$clusters = array();
|
||||
$lookup_table = array();
|
||||
foreach ($data as $k => $cluster) {
|
||||
$cluster['GalaxyCluster']['synonyms_string'] = array();
|
||||
foreach ($cluster['GalaxyElement'] as $element) {
|
||||
$cluster['GalaxyCluster']['synonyms_string'][] = $element['value'];
|
||||
if (isset($lookup_table[$element['value']])) {
|
||||
$lookup_table[$element['value']][] = $cluster['GalaxyCluster']['id'];
|
||||
} else {
|
||||
$lookup_table[$element['value']] = array($cluster['GalaxyCluster']['id']);
|
||||
}
|
||||
}
|
||||
$cluster['GalaxyCluster']['synonyms_string'] = implode(', ', $cluster['GalaxyCluster']['synonyms_string']);
|
||||
unset($cluster['GalaxyElement']);
|
||||
$clusters[$cluster['GalaxyCluster']['value']] = $cluster['GalaxyCluster'];
|
||||
ksort($clusters);
|
||||
if (isset($lookup_table[$cluster['GalaxyCluster']['value']])) {
|
||||
$lookup_table[$cluster['GalaxyCluster']['value']][] = $cluster['GalaxyCluster']['id'];
|
||||
} else {
|
||||
$lookup_table[$cluster['GalaxyCluster']['value']] = array($cluster['GalaxyCluster']['id']);
|
||||
}
|
||||
}
|
||||
$this->set('clusters', $clusters);
|
||||
$this->set('event_id', $event_id);
|
||||
$this->set('lookup_table', $lookup_table);
|
||||
$this->render('ajax/cluster_choice');
|
||||
}
|
||||
|
||||
public function attachClusterToEvent($event_id) {
|
||||
$cluster_id = $this->request->data['Galaxy']['target_id'];
|
||||
$cluster = $this->Galaxy->GalaxyCluster->find('first', array('recursive' => -1, 'conditions' => array('id' => $cluster_id), 'fields' => array('tag_name')));
|
||||
$this->loadModel('Tag');
|
||||
$tag_id = $this->Tag->captureTag(array('name' => $cluster['GalaxyCluster']['tag_name'], 'colour' => '#0088cc'), $this->Auth->user());
|
||||
if ($tag_id === false) {
|
||||
throw new MethodNotAllowedException('Could not attach cluster.');
|
||||
}
|
||||
$this->Tag->EventTag->create();
|
||||
$existingTag = $this->Tag->EventTag->find('first', array('conditions' => array('event_id' => $event_id, 'tag_id' => $tag_id)));
|
||||
if (!empty($existingTag)) {
|
||||
$this->Session->setFlash('Cluster already attached.');
|
||||
$this->redirect($this->referer());
|
||||
}
|
||||
$result = $this->Tag->EventTag->save(array('event_id' => $event_id, 'tag_id' => $tag_id));
|
||||
if ($result) {
|
||||
$this->Session->setFlash('Cluster attached');
|
||||
$this->redirect($this->referer());
|
||||
} else {
|
||||
$this->Session->setFlash('Cluster could not be attached');
|
||||
$this->redirect($this->referer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -352,6 +352,11 @@ class TagsController extends AppController {
|
|||
unset($expanded[$banned_tag]);
|
||||
}
|
||||
}
|
||||
foreach ($options as $k => $v) {
|
||||
if (substr($v, 0, strlen('misp-galaxy:')) === 'misp-galaxy:') {
|
||||
unset($options[$k]);
|
||||
}
|
||||
}
|
||||
$this->set('event_id', $event_id);
|
||||
$this->set('options', $options);
|
||||
$this->set('expanded', $expanded);
|
||||
|
|
|
@ -113,7 +113,7 @@ class Tag extends AppModel {
|
|||
$tag = array(
|
||||
'name' => $tag['name'],
|
||||
'colour' => $tag['colour'],
|
||||
'exportable' => $tag['exportable'],
|
||||
'exportable' => isset($tag['exportable']) ? $tag['exportable'] : 0,
|
||||
'org_id' => 0
|
||||
);
|
||||
$this->save($tag);
|
||||
|
@ -151,7 +151,7 @@ class Tag extends AppModel {
|
|||
return $colour;
|
||||
}
|
||||
|
||||
public function quickAdd($name, $colour = false) {
|
||||
public function quickAdd($name, $colour = false, $returnId = false) {
|
||||
$this->create();
|
||||
if ($colour === false) $colour = $this->random_color();
|
||||
$data = array(
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
$fixed_fields = array('decription', 'source', 'authors');
|
||||
foreach ($event['Galaxy'] as $galaxy):
|
||||
?>
|
||||
<div class="useCursorPointer">
|
||||
<div>
|
||||
<span title="<?php echo isset($galaxy['description']) ? h($galaxy['description']) : h($galaxy['name']);?>" class="bold blue" style="font-size:14px;">
|
||||
<?php echo h($galaxy['name']); ?>
|
||||
</span>
|
||||
|
@ -69,8 +69,7 @@ $(document).ready(function () {
|
|||
});
|
||||
$('.delete-cluster').click(function() {
|
||||
var tagName = $(this).data('tag-name');
|
||||
alert(tagName);
|
||||
removeTag($id = false, $tag_id = false, $galaxy = false)
|
||||
removeTag($id = false, $tag_id = false, $galaxy = false);
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -225,16 +225,16 @@
|
|||
</div>
|
||||
<br />
|
||||
<div class="toggleButtons">
|
||||
<button class="btn btn-inverse toggle-left btn.active qet toggle-button" id="pivots_toggle" data-toggle-type="pivots">
|
||||
<button class="btn btn-inverse toggle-left btn.active qet galaxy-toggle-button" id="pivots_toggle" data-toggle-type="pivots">
|
||||
<span class="icon-minus icon-white" style="vertical-align:top;"></span>Pivots
|
||||
</button>
|
||||
<button class="btn btn-inverse toggle qet toggle-button" id="galaxies_toggle" data-toggle-type="galaxies">
|
||||
<button class="btn btn-inverse toggle qet galaxy-toggle-button" id="galaxies_toggle" data-toggle-type="galaxies">
|
||||
<span class="icon-minus icon-white" style="vertical-align:top;"></span>Galaxy
|
||||
</button>
|
||||
<button class="btn btn-inverse toggle qet toggle-button" id="attributes_toggle" data-toggle-type="attributes">
|
||||
<button class="btn btn-inverse toggle qet galaxy-toggle-button" id="attributes_toggle" data-toggle-type="attributes">
|
||||
<span class="icon-minus icon-white" style="vertical-align:top;"></span>Attributes
|
||||
</button>
|
||||
<button class="btn btn-inverse toggle-right qet toggle-button" id="discussions_toggle" data-toggle-type="discussions">
|
||||
<button class="btn btn-inverse toggle-right qet galaxy-toggle-button" id="discussions_toggle" data-toggle-type="discussions">
|
||||
<span class="icon-minus icon-white" style="vertical-align:top;"></span>Discussion
|
||||
</button>
|
||||
</div>
|
||||
|
@ -244,7 +244,9 @@
|
|||
<?php if (sizeOf($allPivots) > 1) echo $this->element('pivot'); ?>
|
||||
</div>
|
||||
<div id="galaxies_div" class="info_container" style="width:33%">
|
||||
<h4 class="blue">Galaxies</h4>
|
||||
<h4 class="blue">Galaxies
|
||||
<span class="useCursorPointer blue bold" id="addGalaxy" data-event-id="<?php echo h($event['Event']['id']); ?>">+</span>
|
||||
</h4>
|
||||
<?php echo $this->element('galaxyQuickView', array()); ?>
|
||||
</div>
|
||||
<div id="attributes_div">
|
||||
|
@ -259,27 +261,13 @@
|
|||
var showContext = false;
|
||||
$(document).ready(function () {
|
||||
popoverStartup();
|
||||
|
||||
$("th, td, dt, div, span, li").tooltip({
|
||||
'placement': 'top',
|
||||
'container' : 'body',
|
||||
delay: { show: 500, hide: 100 }
|
||||
});
|
||||
var toggles = ['discussions', 'attributes', 'pivots', 'galaxies'];
|
||||
$('.toggle-button').click(function() {
|
||||
var element = $(this).data('toggle-type');
|
||||
if ($(this).children('span').hasClass('icon-minus')) {
|
||||
$(this).children('span').addClass('icon-plus');
|
||||
$(this).children('span').removeClass('icon-minus');
|
||||
$('#' + element + '_div').hide();
|
||||
} else {
|
||||
$(this).children('span').removeClass('icon-plus');
|
||||
$(this).children('span').addClass('icon-minus');
|
||||
$('#' + element + '_div').show();
|
||||
}
|
||||
});
|
||||
// $.get("/events/viewEventAttributes/<?php echo $event['Event']['id']; ?>", function(data) {
|
||||
// $("#attributes_div").html(data);
|
||||
// });
|
||||
|
||||
$.get("/threads/view/<?php echo $event['Event']['id']; ?>/true", function(data) {
|
||||
$("#discussions_div").html(data);
|
||||
});
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
<div class="popover_choice select_cluster">
|
||||
<legend>Select Cluster</legend>
|
||||
<div class="hidden">
|
||||
<?php
|
||||
echo $this->Form->create('Galaxy', array('url' => '/galaxies/attachClusterToEvent/' . $event_id, 'style' => 'margin:0px;'));
|
||||
echo $this->Form->input('target_id', array('type' => 'text'));
|
||||
echo $this->Form->end();
|
||||
?>
|
||||
</div>
|
||||
<div style="text-align:right;width:100%;" class="select_tag_search">
|
||||
<input id="clusterFilterField" style="width:100%;border:0px;padding:0px;" placeholder="search clusters..."/>
|
||||
</div>
|
||||
<div class="popover_choice_main" id ="popover_choice_main">
|
||||
<table style="width:100%;">
|
||||
<?php
|
||||
foreach ($clusters as $k => $cluster):
|
||||
$title = isset($cluster['description']) ? $cluster['description'] : $cluster['value'];
|
||||
?>
|
||||
<tr id="field_<?php echo h($cluster['id']); ?>" style="border-bottom:1px solid black;" class="templateChoiceButton filterableButton">
|
||||
<td class="clusterSelectChoice" data-event-id="<?php echo h($event_id); ?>" data-cluster-id="<?php echo h($cluster['id']); ?>" style="padding-left:10px;padding-right:10px; text-align:center;width:100%;" title="<?php echo 'Synonyms: ' . h($cluster['synonyms_string']); ?>"><?php echo h($cluster['value']); ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
<tr style="border-bottom:1px solid black;" class="templateChoiceButton">
|
||||
<td class="clusterSelectBack" style="padding-left:10px;padding-right:10px; text-align:center;width:100%;" data-event-id="<?php echo h($event_id); ?>" title="Select Galaxy">Back to Galaxy Selection</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="templateChoiceButton templateChoiceButtonLast" onClick="cancelPopoverForm();">Cancel</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
var lookup_table = <?php echo json_encode($lookup_table); ?>;
|
||||
$(document).ready(function() {
|
||||
resizePopoverBody();
|
||||
$("#clusterFilterField").focus();
|
||||
});
|
||||
|
||||
$('.clusterSelectBack').click(function() {
|
||||
getPopup($(this).data('event-id'), 'galaxies', 'selectGalaxy');
|
||||
});
|
||||
|
||||
$('.clusterSelectChoice').click(function() {
|
||||
quickSubmitGalaxyForm($(this).data('event-id'), $(this).data('cluster-id'));
|
||||
});
|
||||
$('#clusterFilterField').keyup(function() {
|
||||
var filterString = $("#clusterFilterField").val().toLowerCase();
|
||||
$('.filterableButton').hide();
|
||||
$.each(lookup_table, function(index, value) {
|
||||
var found = false;
|
||||
if (index.toLowerCase().indexOf(filterString) != -1) {
|
||||
$.each(value, function(k, v) {
|
||||
$('#field_' + v).show();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
$(window).resize(function() {
|
||||
resizePopoverBody();
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,25 @@
|
|||
<div class="popover_choice select_galaxy_source">
|
||||
<legend>Select Cluster Source</legend>
|
||||
<div class="popover_choice_main" id ="popover_choice_main">
|
||||
<table style="width:100%;">
|
||||
<tr style="border-bottom:1px solid black;" class="templateChoiceButton">
|
||||
<td style="padding-left:10px;padding-right:10px; text-align:center;width:100%;" onClick="getPopup('<?php echo h($event_id); ?>/0', 'galaxies', 'selectCluster');">All Galaxies</td>
|
||||
</tr>
|
||||
<?php foreach ($galaxies as $galaxy): ?>
|
||||
<tr style="border-bottom:1px solid black;" class="templateChoiceButton">
|
||||
<td style="padding-left:10px;padding-right:10px; text-align:center;width:100%;" onClick="getPopup('<?php echo h($event_id); ?>/<?php echo h($galaxy['Galaxy']['id']);?>', 'galaxies', 'selectCluster');">Galaxy: <?php echo h($galaxy['Galaxy']['name']); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</div>
|
||||
<div class="templateChoiceButton templateChoiceButtonLast" onClick="cancelPopoverForm();">Cancel</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
resizePopoverBody();
|
||||
});
|
||||
|
||||
$(window).resize(function() {
|
||||
resizePopoverBody();
|
||||
});
|
||||
</script>
|
|
@ -2688,3 +2688,26 @@ function selectAllInbetween(last, current) {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
$('.galaxy-toggle-button').click(function() {
|
||||
var element = $(this).data('toggle-type');
|
||||
if ($(this).children('span').hasClass('icon-minus')) {
|
||||
$(this).children('span').addClass('icon-plus');
|
||||
$(this).children('span').removeClass('icon-minus');
|
||||
$('#' + element + '_div').hide();
|
||||
} else {
|
||||
$(this).children('span').removeClass('icon-plus');
|
||||
$(this).children('span').addClass('icon-minus');
|
||||
$('#' + element + '_div').show();
|
||||
}
|
||||
});
|
||||
|
||||
$('#addGalaxy').click(function() {
|
||||
getPopup($(this).data('event-id'), 'galaxies', 'selectGalaxy');
|
||||
});
|
||||
|
||||
function quickSubmitGalaxyForm(event_id, cluster_id) {
|
||||
$('#GalaxyTargetId').val(cluster_id);
|
||||
$('#GalaxySelectClusterForm').submit();
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue