mirror of https://github.com/MISP/MISP
Correctly assign tag / sharing group to event fetched from feed
parent
fe3a94d3d1
commit
3845c7442a
|
@ -12,8 +12,7 @@ class FeedsController extends AppController {
|
|||
public $paginate = array(
|
||||
'limit' => 60,
|
||||
'recursive' => -1,
|
||||
'contain' => array(
|
||||
),
|
||||
'contain' => array('Tag', 'SharingGroup'),
|
||||
'maxLimit' => 9999, // LATER we will bump here on a problem once we have more than 9999 events
|
||||
'order' => array(
|
||||
'Feed.url' => 'ASC'
|
||||
|
@ -34,6 +33,8 @@ class FeedsController extends AppController {
|
|||
*/
|
||||
public function index() {
|
||||
$this->set('feeds', $this->paginate());
|
||||
$this->loadModel('Event');
|
||||
$this->set('distributionLevels', $this->Event->distributionLevels);
|
||||
}
|
||||
|
||||
public function view($feedId) {
|
||||
|
|
|
@ -10,6 +10,17 @@ class Feed extends AppModel {
|
|||
'Containable'
|
||||
);
|
||||
|
||||
public $belongsTo = array(
|
||||
'SharingGroup' => array(
|
||||
'className' => 'SharingGroup',
|
||||
'foreignKey' => 'sharing_group_id',
|
||||
),
|
||||
'Tag' => array(
|
||||
'className' => 'Tag',
|
||||
'foreignKey' => 'tag_id',
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Validation rules
|
||||
*
|
||||
|
@ -230,6 +241,32 @@ class Feed extends AppModel {
|
|||
$event['Event']['distribution'] = $feed['Feed']['distribution'];
|
||||
$event['Event']['sharing_group_id'] = $feed['Feed']['sharing_group_id'];
|
||||
foreach ($event['Event']['Attribute'] as &$attribute) $attribute['distribution'] = 5;
|
||||
if ($feed['Feed']['tag_id']) {
|
||||
if (!isset($event['Event']['Tag'])) $event['Event']['Tag'] = array();
|
||||
$found = false;
|
||||
if (!empty($event['Event']['Tag'])) {
|
||||
foreach ($event['Event']['Tag'] as $tag) {
|
||||
if (strtolower($tag['name']) === strtolower($feed['Tag']['name'])) $found = true;
|
||||
}
|
||||
}
|
||||
if (!$found) {
|
||||
$feedTag = $this->Tag->find('first', array('conditions' => array('Tag.id' => $feed['Feed']['tag_id']), 'recursive' => -1, 'fields' => array('Tag.name', 'Tag.colour', 'Tag.exportable')));
|
||||
if (!empty($feedTag)) $event['Event']['Tag'][] = $feedTag['Tag'];
|
||||
}
|
||||
}
|
||||
if ($feed['Feed']['sharing_group_id']) {
|
||||
$sg = $this->SharingGroup->find('first', array(
|
||||
'recursive' => -1,
|
||||
'conditions' => array('SharingGroup.id' => $feed['Feed']['sharing_group_id'])
|
||||
));
|
||||
if (!empty($sg)) {
|
||||
$event['Event']['SharingGroup'] = $sg['SharingGroup'];
|
||||
} else {
|
||||
// We have an SG ID for the feed, but the SG is gone. Make the event private as a fall-back.
|
||||
$event['Event']['distribution'] = 0;
|
||||
$event['Event']['sharing_group_id'] = 0;
|
||||
}
|
||||
}
|
||||
if (!$this->__checkIfEventBlockedByFilter($event, $filterRules)) return 'blocked';
|
||||
return $event;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
<th><?php echo $this->Paginator->sort('provider');?></th>
|
||||
<th><?php echo $this->Paginator->sort('name');?></th>
|
||||
<th><?php echo $this->Paginator->sort('url');?></th>
|
||||
<th><?php echo $this->Paginator->sort('distribution');?></th>
|
||||
<th><?php echo $this->Paginator->sort('tag');?></th>
|
||||
<th><?php echo $this->Paginator->sort('enabled');?></th>
|
||||
<th class="actions"><?php echo __('Actions');?></th>
|
||||
</tr><?php
|
||||
|
@ -52,6 +54,18 @@ foreach ($feeds as $item):
|
|||
<td><?php echo h($item['Feed']['name']); ?> </td>
|
||||
<td><?php echo h($item['Feed']['provider']); ?> </td>
|
||||
<td><?php echo h($item['Feed']['url']); ?> </td>
|
||||
<td <?php if ($item['Feed']['distribution'] == 0) echo 'class="red"'; ?>>
|
||||
<?php
|
||||
echo $item['Feed']['distribution'] == 4 ? '<a href="' . $baseurl . '/sharing_groups/view/' . h($item['SharingGroup']['id']) . '">' . h($item['SharingGroup']['name']) . '</a>' : $distributionLevels[$item['Feed']['distribution']] ;
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php if ($item['Feed']['tag_id']): ?>
|
||||
<a href="<?php echo $baseurl;?>/events/index/searchtag:<?php echo h($item['Tag']['id']); ?>" class=tag style="background-color:<?php echo h($item['Tag']['colour']);?>;color:<?php echo $this->TextColour->getTextColour($item['Tag']['colour']);?>"><?php echo h($item['Tag']['name']); ?></a>
|
||||
<?php else: ?>
|
||||
|
||||
<?php endif;?>
|
||||
</td>
|
||||
<td class="short"><span class="<?php echo ($item['Feed']['enabled'] ? 'icon-ok' : 'icon-remove'); ?>"></span><span class="short <?php if (!$item['Feed']['enabled'] || empty($ruleDescription)) echo "hidden"; ?>" data-toggle="popover" title="Filter rules" data-content="<?php echo $ruleDescription; ?>"> (Rules)</span>
|
||||
<td class="short action-links">
|
||||
<?php
|
||||
|
|
Loading…
Reference in New Issue