chg: [UI] Make feed event preview nicer

pull/7184/head
Jakub Onderka 2021-03-09 23:01:52 +01:00
parent 2f1efc4561
commit 42f78580df
3 changed files with 72 additions and 83 deletions

View File

@ -606,26 +606,30 @@ class FeedsController extends AppController
public function previewIndex($feedId)
{
$this->Feed->id = $feedId;
if (!$this->Feed->exists()) {
$feed = $this->Feed->find('first', [
'conditions' => ['id' => $feedId],
'recursive' => -1,
]);
if (empty($feed)) {
throw new NotFoundException(__('Invalid feed.'));
}
$this->Feed->read();
if (!empty($this->Feed->data['Feed']['settings'])) {
$this->Feed->data['Feed']['settings'] = json_decode($this->Feed->data['Feed']['settings'], true);
if (!empty($feed['Feed']['settings'])) {
$feed['Feed']['settings'] = json_decode($feed['Feed']['settings'], true);
}
$params = array();
if ($this->request->is('post')) {
$params = $this->request->data['Feed'];
}
if ($this->Feed->data['Feed']['source_format'] == 'misp') {
return $this->__previewIndex($this->Feed->data, $params);
} elseif (in_array($this->Feed->data['Feed']['source_format'], array('freetext', 'csv'))) {
return $this->__previewFreetext($this->Feed->data);
if ($feed['Feed']['source_format'] === 'misp') {
return $this->__previewIndex($feed, $params);
} elseif (in_array($feed['Feed']['source_format'], ['freetext', 'csv'], true)) {
return $this->__previewFreetext($feed);
} else {
throw new Exception("Invalid feed format `{$feed['Feed']['source_format']}`.");
}
}
private function __previewIndex($feed, $filterParams = array())
private function __previewIndex(array $feed, $filterParams = array())
{
$urlparams = '';
App::uses('CustomPaginationTool', 'Tools');
@ -703,7 +707,7 @@ class FeedsController extends AppController
$this->set('passedArgsArray', $passedArgs);
}
private function __previewFreetext($feed)
private function __previewFreetext(array $feed)
{
if (isset($this->passedArgs['page'])) {
$currentPage = $this->passedArgs['page'];
@ -758,13 +762,15 @@ class FeedsController extends AppController
public function previewEvent($feedId, $eventUuid, $all = false)
{
$this->Feed->id = $feedId;
if (!$this->Feed->exists()) {
$feed = $this->Feed->find('first', [
'conditions' => ['id' => $feedId],
'recursive' => -1,
]);
if (empty($feed)) {
throw new NotFoundException(__('Invalid feed.'));
}
$this->Feed->read();
try {
$event = $this->Feed->downloadEventFromFeed($this->Feed->data, $eventUuid);
$event = $this->Feed->downloadEventFromFeed($feed, $eventUuid);
} catch (Exception $e) {
throw new Exception(__('Could not download the selected Event'), 0, $e);
}
@ -781,11 +787,11 @@ class FeedsController extends AppController
$params = $this->Event->rearrangeEventForView($event, $this->passedArgs, $all);
$this->params->params['paging'] = array('Feed' => $params);
$this->set('event', $event);
$this->set('feed', $this->Feed->data);
$this->set('feed', $feed);
$this->loadModel('Event');
$dataForView = array(
'Attribute' => array('attrDescriptions' => 'fieldDescriptions', 'distributionDescriptions' => 'distributionDescriptions', 'distributionLevels' => 'distributionLevels'),
'Event' => array('eventDescriptions' => 'fieldDescriptions', 'analysisLevels' => 'analysisLevels')
'Attribute' => array('attrDescriptions' => 'fieldDescriptions', 'distributionDescriptions' => 'distributionDescriptions', 'distributionLevels' => 'distributionLevels'),
'Event' => array('eventDescriptions' => 'fieldDescriptions', 'analysisLevels' => 'analysisLevels')
);
foreach ($dataForView as $m => $variables) {
if ($m === 'Event') {

View File

@ -1,71 +1,56 @@
<?php
$tableData = [
['key' => __('UUID'), 'value' => $event['Event']['uuid'], 'class' => 'quickSelect'],
['key' => Configure::read('MISP.showorgalternate') ? __('Source Organisation') : __('Org'), 'value' => $event['Orgc']['name']],
];
if (Configure::read('MISP.tagging')) {
ob_start();
if (!empty($event['Tag'])): foreach ($event['Tag'] as $tag): ?>
<span style="padding-right:0;">
<span class="tagFirstHalf" style="background-color:<?= h($tag['colour']);?>;color:<?= $this->TextColour->getTextColour($tag['colour']);?>"><?= h($tag['name']); ?></span>
</span>
<?php endforeach; endif;
$tags = ob_get_clean();
$tableData[] = ['key' => __('Tags'), 'html' => $tags];
}
$tableData[] = ['key' => __('Date'), 'html' => $this->Time->time($event['Event']['date'])];
$tableData[] = [
'key' => __('Threat Level'),
'key_title' => $eventDescriptions['threat_level_id']['desc'],
'value' => $threatLevels[$event['Event']['threat_level_id']],
'value_class' => 'threat-level-' . strtolower($threatLevels[$event['Event']['threat_level_id']]),
];
$tableData[] = [
'key' => __('Analysis'),
'key_title' => $eventDescriptions['analysis']['desc'],
'value' => $analysisLevels[$event['Event']['analysis']],
];
$tableData[] = [
'key' => __('Info'),
'value' => $event['Event']['info']
];
$tableData[] = [
'key' => __('Published'),
'class' => $event['Event']['published'] == 0 ? 'background-red bold not-published' : 'published',
'class_value' => $event['Event']['published'] == 0 ? '' : 'green',
'html' => $event['Event']['published'] == 0 ? __('No') : sprintf('<span class="green bold">%s</span>', __('Yes')),
];
$tableData[] = [
'key' => __('Last change'),
'html' => $this->Time->time($event['Event']['timestamp']),
];
?>
<div class="events view">
<?php
$title = $event['Event']['info'];
if (strlen($title) > 58) $title = substr($title, 0, 55) . '...';
?>
<h4 class="visibleDL notPublished" ><?php echo __('You are currently viewing an event from a feed (%s by %s)', h($feed['Feed']['name']), h($feed['Feed']['provider']));?></h4>
<h4 class="visibleDL notPublished" ><?= __('You are currently viewing an event from a feed (%s by %s)', h($feed['Feed']['name']), h($feed['Feed']['provider']));?></h4>
<div class="row-fluid">
<div class="span8">
<h2><?php echo nl2br(h($title)); ?></h2>
<dl>
<dt><?php echo __('UUID');?></dt>
<dd><?php echo h($event['Event']['uuid']); ?></dd>
<dt><?php echo Configure::read('MISP.showorgalternate') ? __('Source Organisation') : __('Org')?></dt>
<dd><?php echo h($event['Orgc']['name']); ?></dd>
<?php if (Configure::read('MISP.tagging')): ?>
<dt><?php echo __('Tags');?></dt>
<dd class="eventTagContainer">
<?php if (!empty($event['Tag'])) foreach ($event['Tag'] as $tag): ?>
<span style="padding-right:0px;">
<span class="tagFirstHalf" style="background-color:<?php echo isset($tag['colour']) ? h($tag['colour']) : 'red';?>;color:<?php echo $this->TextColour->getTextColour(isset($tag['colour']) ? h($tag['colour']) : 'red'); ?>"><?php echo h($tag['name']); ?></span>
</span>
<?php endforeach; ?>&nbsp;
</dd>
<?php endif; ?>
<dt><?php echo __('Date');?></dt>
<dd>
<?php echo h($event['Event']['date']); ?>
&nbsp;
</dd>
<dt title="<?php echo $eventDescriptions['threat_level_id']['desc'];?>"><?php echo __('Threat Level');?></dt>
<dd>
<?php
echo h($threatLevels[$event['Event']['threat_level_id']]);
?>
&nbsp;
</dd>
<dt title="<?php echo $eventDescriptions['analysis']['desc'];?>"><?php echo __('Analysis');?></dt>
<dd>
<?php echo h($analysisLevels[$event['Event']['analysis']]); ?>
&nbsp;
</dd>
<dt><?php echo __('Info');?></dt>
<dd style="word-wrap: break-word;">
<?php echo nl2br(h($event['Event']['info'])); ?>
&nbsp;
</dd>
<?php
$published = '';
$notPublished = 'style="display:none;"';
if ($event['Event']['published'] == 0) {
$published = 'style="display:none;"';
$notPublished = '';
}
?>
<dt class="published" <?php echo $published;?>><?php echo __('Published');?></dt>
<dd class="published green" <?php echo $published;?>><?php echo __('Yes');?></dd>
<?php
if ($isAclPublish) :
?>
<dt class="visibleDL notPublished" <?php echo $notPublished;?>><?php echo __('Published');?></dt>
<dd class="visibleDL notPublished" <?php echo $notPublished;?>><?php echo __('No');?></dd>
<?php
else:
?>
<dt class="notPublished" <?php echo $notPublished;?>><?php echo __('Published');?></dt>
<dd class="notPublished red" <?php echo $notPublished;?>><?php echo __('No');?></dd>
<?php endif; ?>
</dl>
<?= $this->element('genericElements/viewMetaTable', array('table_data' => $tableData)); ?>
</div>
<?php if (!empty($event['RelatedEvent'])):?>
@ -96,12 +81,10 @@
<?php echo $this->element('Feeds/eventattribute'); ?>
</div>
</div>
<?php
echo $this->element('/genericElements/SideMenu/side_menu', array('menuList' => 'feeds', 'menuItem' => 'previewEvent', 'id' => $event['Event']['uuid']));
?>
<?= $this->element('/genericElements/SideMenu/side_menu', array('menuList' => 'feeds', 'menuItem' => 'previewEvent', 'id' => $event['Event']['uuid'])); ?>
<script type="text/javascript">
// tooltips
$(document).ready(function () {
$(function () {
$("th, td, dt, div, span, li").tooltip({
'placement': 'top',
'container' : 'body',

View File

@ -57,7 +57,7 @@ $tableData[] = [
if (strlen($title) > 58) $title = substr($title, 0, 55) . '...';
$serverName = $server['Server']['name'] ? '"' . $server['Server']['name'] . '" (' . $server['Server']['url'] . ')' : '"' . $server['Server']['url'] . '"';
?>
<h4 class="visibleDL notPublished" ><?php echo __('You are currently viewing an event on the remote instance %s ', h($serverName));?></h4>
<h4 class="visibleDL notPublished"><?php echo __('You are currently viewing an event on the remote instance %s ', h($serverName));?></h4>
<div class="row-fluid">
<div class="span8">
<h2><?php echo nl2br(h($title)); ?></h2>