MISP/app/Lib/Dashboard/RecentSightingsWidget.php

69 lines
2.3 KiB
PHP

<?php
class RecentSightingsWidget
{
public $title = 'Recent Sightings';
public $render = 'SimpleList';
public $width = 8;
public $height = 6;
public $params = array(
'limit' => 'Maximum amount of sightings to return',
'last' => 'Limit sightings to last 1d, 12h, ...'
);
public $description = 'Widget showing information on recent sightings';
public $cacheLifetime = false;
public $autoRefreshDelay = 30;
public $placeholder =
'{
"limit": "10",
"last": "1d",
}';
public function handler($user, $options = array())
{
$params = array(
'last' => empty($options['last']) ? "1d" : $options['last'],
'limit' => empty($options['limit']) ? "10" : $options['limit']
);
$last = $params['last'];
$limit = $params['limit'];
/** @var Sighting $Sighting */
$Sighting = ClassRegistry::init('Sighting');
$filters = array('last' => $last, 'includeAttribute' => 'true', 'includeEvent' => 'true');
$data = array();
$count = 0;
foreach (JsonTool::decode($Sighting->restSearch($user, 'json', $filters)->intoString())['response'] as $el) {
$sighting = $el['Sighting'];
$event = $sighting['Event'];
$attribute = $sighting['Attribute'];
if ($sighting['type'] == 0) $type = "Sighting";
elseif ($sighting['type'] == 1) $type = "False positive";
else $type = "Expiration";
$output = $attribute['value'] . " (id: " . $attribute['id'] . ") in " . $event['info'] . " (id: " . $event['id'] . ")";
$data[] = array( 'title' => $type, 'value' => $output,
'html' => sprintf(
' (Event <a href="%s%s">%s</a>)',
Configure::read('MISP.baseurl') . '/events/view/', $event['id'],
$event['id']
)
);
++$count;
if ($count >= $limit ) break;
}
return $data;
}
public function checkPermissions($user)
{
if (empty($user['Role']['perm_site_admin'])) {
return false;
}
return true;
}
}