mirror of https://github.com/MISP/MISP
Further progress
parent
255c65942e
commit
bebdde03e7
|
@ -76,6 +76,7 @@ class FeedsController extends AppController {
|
|||
else $this->Session->setFlash('Feed could not be updated.');
|
||||
} else {
|
||||
$this->request->data = $this->Feed->data;
|
||||
$this->request->data['Feed']['pull_rules'] = $this->request->data['Feed']['rules'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,6 +98,18 @@ class FeedsController extends AppController {
|
|||
$HttpSocket = $syncTool->setupHttpSocketFeed($this->Feed->data);
|
||||
$actions = $this->Feed->getNewEventUuids($this->Feed->data, $HttpSocket);
|
||||
$result = $this->Feed->downloadFromFeed($actions, $this->Feed->data, $HttpSocket, $this->Auth->user());
|
||||
|
||||
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => true, 'success' => 'Attribute added.')),'status'=>200));
|
||||
}
|
||||
}
|
||||
|
||||
public function previewIndex($feedId) {
|
||||
$this->Feed->id = $feedId;
|
||||
if (!$this->Feed->exists()) throw new NotFoundException('Invalid feed.');
|
||||
App::uses('SyncTool', 'Tools');
|
||||
$syncTool = new SyncTool();
|
||||
$this->Feed->read();
|
||||
$HttpSocket = $syncTool->setupHttpSocketFeed($this->Feed->data);
|
||||
debug($this->Feed->getManifest($this->Feed->data, $HttpSocket));
|
||||
}
|
||||
|
||||
}
|
|
@ -1853,7 +1853,7 @@ class Attribute extends AppModel {
|
|||
if (isset($options['conditions'])) $params['conditions']['AND'][] = $options['conditions'];
|
||||
if (isset($options['order'])) $params['order'] = $options['order'];
|
||||
if (isset($options['group'])) $params['group'] = $options['group'];
|
||||
if (Configure::read('MISP.unpublishedprivate')) $params['conditions']['AND'][] = array('Event.published' => 1);
|
||||
if (Configure::read('MISP.unpublishedprivate')) $params['conditions']['AND'][] = array('OR' => array('Event.published' => 1, 'Event.orgc_id' => $user['org_id']));
|
||||
$results = $this->find('all', $params);
|
||||
if (isset($options['withAttachments']) && $options['withAttachments']) {
|
||||
foreach ($results as &$attribute) {
|
||||
|
|
|
@ -1281,8 +1281,11 @@ class Event extends AppModel {
|
|||
}
|
||||
if ($event['SharingGroup']['id'] == null) unset($event['SharingGroup']);
|
||||
// unset empty event tags that got added because the tag wasn't exportable
|
||||
foreach ($event['EventTag'] as $k => &$eventTag) {
|
||||
if (empty($eventTag['Tag'])) unset ($event['EventTag'][$k]);
|
||||
if (!empty($event['EventTag'])) {
|
||||
foreach ($event['EventTag'] as $k => &$eventTag) {
|
||||
if (empty($eventTag['Tag'])) unset ($event['EventTag'][$k]);
|
||||
}
|
||||
$event['EventTag'] = array_values($event['EventTag']);
|
||||
}
|
||||
// Let's find all the related events and attach it to the event itself
|
||||
$results[$eventKey]['RelatedEvent'] = $this->getRelatedEvents($user, $event['Event']['id'], $sgsids);
|
||||
|
|
|
@ -51,25 +51,52 @@ class Feed extends AppModel {
|
|||
'fields' => array('Event.id', 'Event.uuid', 'Event.timestamp')
|
||||
));
|
||||
foreach ($events as &$event) {
|
||||
if ($event['Event']['timestamp'] < $manifest[$event['Event']['uuid']]) $result['edit'][] = array('uuid' => $event['Event']['uuid'], 'id' => $event['Event']['id']);
|
||||
if ($event['Event']['timestamp'] < $manifest[$event['Event']['uuid']]['timestamp']) $result['edit'][] = array('uuid' => $event['Event']['uuid'], 'id' => $event['Event']['id']);
|
||||
unset($manifest[$event['Event']['uuid']]);
|
||||
}
|
||||
$result['add'] = array_keys($manifest);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
public function getManifest($feed, $HttpSocket) {
|
||||
$result = array();
|
||||
$request = $this->__createFeedRequest();
|
||||
$uri = $feed['Feed']['url'] . '/manifest.json';
|
||||
$response = $HttpSocket->get($uri, '', $request);
|
||||
return json_decode($response->body, true);
|
||||
}
|
||||
|
||||
public function downloadFromFeed($actions, $feed, $HttpSocket, $user) {
|
||||
$this->Event = ClassRegistry::init('Event');
|
||||
$results = array();
|
||||
$filterRules = false;
|
||||
if (isset($feed['Feed']['rules']) && !empty($feed['Feed']['rules'])) {
|
||||
$filterRules = json_decode($feed['Feed']['rules'], true);
|
||||
}
|
||||
if (isset($actions['add']) && !empty($actions['add'])) {
|
||||
foreach ($actions['add'] as $uuid) {
|
||||
$this->__addEventFromFeed($HttpSocket, $feed, $uuid, $user);
|
||||
$result = $this->__addEventFromFeed($HttpSocket, $feed, $uuid, $user, $filterRules);
|
||||
if ($result === 'blocked') debug('blocked: ' . $uuid);
|
||||
if ($result === true) {
|
||||
$results['add']['success'] = $uuid;
|
||||
} else {
|
||||
$results['add']['fail'] = array('uuid' => $uuid, 'reason' => $result);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($actions['edit']) && !empty($actions['edit'])) {
|
||||
foreach ($actions['edit'] as $editTarget) {
|
||||
$this->__updateEventFromFeed($HttpSocket, $feed, $editTarget['uuid'], $editTarget['id'], $user);
|
||||
$result = $this->__updateEventFromFeed($HttpSocket, $feed, $editTarget['uuid'], $editTarget['id'], $user, $filterRules);
|
||||
if ($result === true) {
|
||||
$results['edit']['success'] = $uuid;
|
||||
} else {
|
||||
$results['edit']['fail'] = array('uuid' => $uuid, 'reason' => $result);
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new Exception();
|
||||
return $results;
|
||||
}
|
||||
|
||||
private function __createFeedRequest() {
|
||||
|
@ -79,12 +106,36 @@ class Feed extends AppModel {
|
|||
'header' => array(
|
||||
'Accept' => 'application/json',
|
||||
'Content-Type' => 'application/json',
|
||||
'MISP-version' => $version
|
||||
'MISP-version' => $version,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function __addEventFromFeed($HttpSocket, $feed, $uuid, $user) {
|
||||
private function __checkIfEventBlockedByFilter($event, $filterRules) {
|
||||
$fields = array('tags' => 'Tag', 'orgs' => 'Orgc');
|
||||
$prefixes = array('OR', 'NOT');
|
||||
foreach ($fields as $field => $fieldModel) {
|
||||
foreach ($prefixes as $prefix) {
|
||||
if (!empty($filterRules[$field][$prefix])) {
|
||||
$found = false;
|
||||
if (isset($event['Event'][$fieldModel]) && !empty($event['Event'][$fieldModel])) {
|
||||
if (!isset($event['Event'][$fieldModel][0])) $event['Event'][$fieldModel] = array(0 => $event['Event'][$fieldModel]);
|
||||
foreach ($event['Event'][$fieldModel] as $object) {
|
||||
foreach ($filterRules[$field][$prefix] as $temp) {
|
||||
if (stripos($object['name'], $temp) !== false) $found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($prefix === 'OR' && !$found) return false;
|
||||
if ($prefix !== 'OR' && $found) return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$filterRules) return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
private function __addEventFromFeed($HttpSocket, $feed, $uuid, $user, $filterRules) {
|
||||
$request = $this->__createFeedRequest();
|
||||
$uri = $feed['Feed']['url'] . '/' . $uuid . '.json';
|
||||
$response = $HttpSocket->get($uri, '', $request);
|
||||
|
@ -92,6 +143,7 @@ class Feed extends AppModel {
|
|||
return false;
|
||||
} else {
|
||||
$event = json_decode($response->body, true);
|
||||
if (!$this->__checkIfEventBlockedByFilter($event, $filterRules)) return 'blocked';
|
||||
if (isset($event['response'])) $event = $event['response'];
|
||||
if (isset($event[0])) $event = $event[0];
|
||||
if (!isset($event['Event']['uuid'])) return false;
|
||||
|
@ -100,7 +152,7 @@ class Feed extends AppModel {
|
|||
}
|
||||
}
|
||||
|
||||
private function __updateEventFromFeed($HttpSocket, $feed, $uuid, $eventId, $user) {
|
||||
private function __updateEventFromFeed($HttpSocket, $feed, $uuid, $eventId, $user, $filterRules) {
|
||||
debug($uuid);
|
||||
$request = $this->__createFeedRequest();
|
||||
$uri = $feed['Feed']['url'] . '/' . $uuid . '.json';
|
||||
|
@ -113,8 +165,7 @@ class Feed extends AppModel {
|
|||
if (isset($event[0])) $event = $event[0];
|
||||
if (!isset($event['Event']['uuid'])) return false;
|
||||
$this->Event = ClassRegistry::init('Event');
|
||||
debug($this->Event->_edit($event, $user, $uuid, $jobId = null));
|
||||
//return $this->Event->_edit($event, $user, $uuid, $jobId = null);
|
||||
return $this->Event->_edit($event, $user, $uuid, $jobId = null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,17 +4,21 @@
|
|||
<legend>Add MISP Feed</legend>
|
||||
<p>Add a new MISP feed source.</p>
|
||||
<?php
|
||||
echo $this->Form->input('enabled', array());
|
||||
echo $this->Form->input('name', array(
|
||||
'div' => 'input clear',
|
||||
'placeholder' => 'Feed name'
|
||||
'placeholder' => 'Feed name',
|
||||
'class' => 'form-control span6',
|
||||
));
|
||||
echo $this->Form->input('provider', array(
|
||||
'div' => 'input clear',
|
||||
'placeholder' => 'Name of the content provider'
|
||||
'placeholder' => 'Name of the content provider',
|
||||
'class' => 'form-control span6'
|
||||
));
|
||||
echo $this->Form->input('url', array(
|
||||
'div' => 'input clear',
|
||||
'placeholder' => 'URL of the feed'
|
||||
'placeholder' => 'URL of the feed',
|
||||
'class' => 'form-control span6'
|
||||
));
|
||||
echo $this->Form->input('pull_rules', array('style' => 'display:none;', 'label' => false, 'div' => false));
|
||||
?>
|
||||
|
@ -53,6 +57,7 @@ var formInfoValues = {
|
|||
var rules = {"pull": {"tags": {"OR":[], "NOT":[]}, "orgs": {"OR":[], "NOT":[]}}};
|
||||
var validOptions = ['pull'];
|
||||
var validFields = ['tags', 'orgs'];
|
||||
var modelContext = 'Feed';
|
||||
|
||||
$(document).ready(function() {
|
||||
$("#pull_modify").click(function() {
|
||||
|
|
|
@ -2,28 +2,68 @@
|
|||
<?php echo $this->Form->create('Feed');?>
|
||||
<fieldset>
|
||||
<legend>Edit MISP Feed</legend>
|
||||
<p>Edit a MISP feed source.</p>
|
||||
<p>Edit a new MISP feed source.</p>
|
||||
<?php
|
||||
echo $this->Form->input('enabled', array());
|
||||
echo $this->Form->input('name', array(
|
||||
'div' => 'input clear',
|
||||
'placeholder' => 'Feed name'
|
||||
'placeholder' => 'Feed name',
|
||||
'class' => 'form-control span6',
|
||||
));
|
||||
echo $this->Form->input('provider', array(
|
||||
'div' => 'input clear',
|
||||
'placeholder' => 'Name of the content provider'
|
||||
'placeholder' => 'Name of the content provider',
|
||||
'class' => 'form-control span6'
|
||||
));
|
||||
echo $this->Form->input('url', array(
|
||||
'div' => 'input clear',
|
||||
'placeholder' => 'URL of the feed'
|
||||
'placeholder' => 'URL of the feed',
|
||||
'class' => 'form-control span6'
|
||||
));
|
||||
echo $this->Form->input('pull_rules', array('style' => 'display:none;', 'label' => false, 'div' => false));
|
||||
?>
|
||||
</fieldset>
|
||||
<?php
|
||||
echo $this->Form->button('Add', array('class' => 'btn btn-primary'));
|
||||
echo $this->Form->end();
|
||||
?>
|
||||
<b>Filter rules:</b><br />
|
||||
<span id="pull_tags_OR" style="display:none;">Events with the following tags allowed: <span id="pull_tags_OR_text" style="color:green;"></span><br /></span>
|
||||
<span id="pull_tags_NOT" style="display:none;">Events with the following tags blocked: <span id="pull_tags_NOT_text" style="color:red;"></span><br /></span>
|
||||
<span id="pull_orgs_OR" style="display:none;">Events with the following organisations allowed: <span id="pull_orgs_OR_text" style="color:green;"></span><br /></span>
|
||||
<span id="pull_orgs_NOT" style="display:none;">Events with the following organisations blocked: <span id="pull_orgs_NOT_text" style="color:red;"></span><br /></span>
|
||||
<span id="pull_modify" class="btn btn-inverse" style="line-height:10px; padding: 4px 4px;">Modify</span><br /><br />
|
||||
<?php
|
||||
echo $this->Form->button('Edit', array('class' => 'btn btn-primary'));
|
||||
echo $this->Form->end();
|
||||
?>
|
||||
<div id="hiddenRuleForms">
|
||||
<?php echo $this->element('serverRuleElements/pull'); ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
echo $this->element('side_menu', array('menuList' => 'feeds', 'menuItem' => 'edit'));
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
//
|
||||
var formInfoValues = {
|
||||
'ServerUrl' : "The base-url to the external server you want to sync with. Example: https://foo.sig.mil.be",
|
||||
'ServerName' : "A name that will make it clear to your users what this instance is. For example: Organisation A's instance",
|
||||
'ServerOrganization' : "The organization having the external server you want to sync with. Example: BE",
|
||||
'ServerAuthkey' : "You can find the authentication key on your profile on the external server.",
|
||||
'ServerPush' : "Allow the upload of events and their attributes.",
|
||||
'ServerPull' : "Allow the download of events and their attributes from the server.",
|
||||
'ServerSubmittedCert' : "You can also upload a certificate file if the instance you are trying to connect to has its own signing authority.",
|
||||
'ServerSelfSigned' : "Click this, if you would like to allow a connection despite the other instance using a self-signed certificate (not recommended)."
|
||||
};
|
||||
|
||||
|
||||
var rules = {"pull": {"tags": {"OR":[], "NOT":[]}, "orgs": {"OR":[], "NOT":[]}}};
|
||||
var validOptions = ['pull'];
|
||||
var validFields = ['tags', 'orgs'];
|
||||
var modelContext = 'Feed';
|
||||
|
||||
$(document).ready(function() {
|
||||
ules = convertServerFilterRules(rules);
|
||||
$("#pull_modify").click(function() {
|
||||
serverRuleFormActivate('pull');
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
|
@ -22,7 +22,6 @@
|
|||
<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('rules');?></th>
|
||||
<th><?php echo $this->Paginator->sort('enabled');?></th>
|
||||
<th class="actions"><?php echo __('Actions');?></th>
|
||||
</tr><?php
|
||||
|
@ -54,9 +53,11 @@ foreach ($feeds as $item):
|
|||
<td><?php echo h($item['Feed']['provider']); ?> </td>
|
||||
<td><?php echo h($item['Feed']['url']); ?> </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"><span class="<?php echo ($item['Feed']['enabled'] ? 'icon-ok' : 'icon-remove');?>"> </span></td>
|
||||
<td class="short action-links">
|
||||
<?php echo $this->Html->link('', array('action' => 'fetchFromFeed', $item['Feed']['id']), array('class' => 'icon-download', 'title' => 'Fetch')); ?>
|
||||
<?php
|
||||
echo $this->Html->link('', array('action' => 'previewIndex', $item['Feed']['id']), array('class' => 'icon-search', 'title' => 'Explore'));
|
||||
echo $this->Html->link('', array('action' => 'fetchFromFeed', $item['Feed']['id']), array('class' => 'icon-download', 'title' => 'Fetch'));
|
||||
?>
|
||||
<a href="<?php echo $baseurl;?>/feeds/edit/<?php echo h($item['Feed']['id']); ?>"><span class="icon-edit" title="edit"> </span></a>
|
||||
<?php echo $this->Form->postLink('', array('action' => 'delete', h($item['Feed']['id'])), array('class' => 'icon-trash', 'title' => 'Delete'), __('Are you sure you want to permanently remove the feed (%s)?', h($item['Feed']['name']))); ?>
|
||||
</td>
|
||||
|
@ -79,8 +80,12 @@ endforeach; ?>
|
|||
?>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function(){
|
||||
popoverStartup();
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
echo $this->element('side_menu', array('menuList' => 'feeds', 'menuItem' => 'index'));
|
||||
?>
|
||||
?>
|
||||
|
|
|
@ -119,6 +119,7 @@ var validOptions = ['pull', 'push'];
|
|||
var validFields = ['tags', 'orgs'];
|
||||
var tags = <?php echo json_encode($allTags); ?>;
|
||||
var orgs = <?php echo json_encode($allOrganisations); ?>;
|
||||
var modelContext = 'Server';
|
||||
|
||||
$(document).ready(function() {
|
||||
serverOrgTypeChange();
|
||||
|
|
|
@ -143,6 +143,7 @@ var validFields = ['tags', 'orgs'];
|
|||
var tags = <?php echo json_encode($allTags); ?>;
|
||||
var orgs = <?php echo json_encode($allOrganisations); ?>;
|
||||
var delete_cert = false;
|
||||
var modelContext = 'Server';
|
||||
|
||||
$(document).ready(function() {
|
||||
serverOrgTypeChange();
|
||||
|
|
|
@ -2027,7 +2027,7 @@ function zeroMQServerAction(action) {
|
|||
|
||||
function convertServerFilterRules(rules) {
|
||||
validOptions.forEach(function (type) {
|
||||
container = "#Server" + type.ucfirst() + "Rules";
|
||||
container = "#"+ modelContext + type.ucfirst() + "Rules";
|
||||
if($(container).val() != '') rules[type] = JSON.parse($(container).val());
|
||||
});
|
||||
serverRuleUpdate();
|
||||
|
|
Loading…
Reference in New Issue