mirror of https://github.com/MISP/MISP
First version or REST API to export data
parent
67d3a9f9d2
commit
bf8ae66e9c
|
@ -92,7 +92,8 @@ Configure::write('CyDefSIG.footer', 'Powered by CyDefSIG © Belgian Defense
|
|||
//Configure::write('CyDefSIG.logo', '/img/logo_big.gif');
|
||||
|
||||
|
||||
Configure::write('CyDefSIG.showorg', 'false'); // show the name of the organisation that uploaded the data
|
||||
Configure::write('CyDefSIG.showorg', 'false'); // show the name of the organisation that uploaded the data
|
||||
Configure::write('CyDefSIG.serversync', 'true'); // enable features related to syncing with other CyDefSIG instances
|
||||
Configure::write('CyDefSIG.email', 'no-reply@sig.mil.be'); // email from for all the mails
|
||||
|
||||
Configure::write('GnuPG.onlyencrypted', 'true'); // only allow encrypted email, do not allow plaintext mails
|
||||
|
|
|
@ -27,6 +27,11 @@
|
|||
*/
|
||||
Router::connect('/', array('controller' => 'events', 'action' => 'index'));
|
||||
|
||||
|
||||
// Activate REST
|
||||
Router::mapResources(array('events', 'attributes'));
|
||||
Router::parseExtensions('xml');
|
||||
|
||||
/**
|
||||
* Load all plugin routes. See the CakePlugin documentation on
|
||||
* how to customize the loading of plugin routes.
|
||||
|
|
|
@ -15,9 +15,10 @@ class EventsController extends AppController {
|
|||
* @var array
|
||||
*/
|
||||
|
||||
public $components = array('Security', 'Email');
|
||||
public $components = array('Security', 'Email', 'RequestHandler');
|
||||
public $paginate = array(
|
||||
'limit' => 60,
|
||||
'maxLimit' => 9999, // LATER we will bump here on a problem once we have more than 9999 events
|
||||
'order' => array(
|
||||
'Event.date' => 'DESC'
|
||||
)
|
||||
|
@ -79,7 +80,7 @@ class EventsController extends AppController {
|
|||
|
||||
$relatedAttributes = array();
|
||||
$this->loadModel('Attribute');
|
||||
$fields = array('Attribute.id', 'Attribute.event_id');
|
||||
$fields = array('Attribute.id', 'Attribute.event_id', 'Attribute.uuid');
|
||||
foreach ($this->Event->data['Attribute'] as $attribute) {
|
||||
$relatedAttributes[$attribute['id']] = $this->Attribute->getRelatedAttributes($attribute, $fields);
|
||||
}
|
||||
|
@ -97,7 +98,7 @@ class EventsController extends AppController {
|
|||
$find_params = array(
|
||||
'conditions' => array('OR' => array('Event.id' => $relatedEventsIds)), //array of conditions
|
||||
'recursive' => 0, //int
|
||||
'fields' => array('Event.id', 'Event.date'), //array of field names
|
||||
'fields' => array('Event.id', 'Event.date', 'Event.uuid'), //array of field names
|
||||
'order' => array('Event.date DESC'), //string or array defining order
|
||||
);
|
||||
$relatedEvents = $this->Event->find('all', $find_params);
|
||||
|
@ -549,7 +550,7 @@ class EventsController extends AppController {
|
|||
$conditions = array();
|
||||
}
|
||||
// do not expose all the data like user_id, ...
|
||||
$fields = array('Event.id', 'Event.date', 'Event.risk', 'Event.info', 'Event.uuid', 'Event.published');
|
||||
$fields = array('Event.id', 'Event.date', 'Event.risk', 'Event.info', 'Event.published', 'Event.uuid');
|
||||
if ('true' == Configure::read('CyDefSIG.showorg')) {
|
||||
$fields[] = 'Event.org';
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
$xmlArray = array();
|
||||
foreach ($events as $key => $event) {
|
||||
// rearrange things to be compatible with the Xml::fromArray()
|
||||
$events[$key] = $events[$key]['Event'];
|
||||
|
||||
// cleanup the array from things we do not want to expose
|
||||
unset($events[$key]['User']);
|
||||
unset($events[$key]['Event']);
|
||||
unset($events[$key]['user_id']);
|
||||
// hide the private field is we are not in serversync mode
|
||||
if ('true' != Configure::read('CyDefSIG.serversync')) {
|
||||
unset($events[$key]['private']);
|
||||
}
|
||||
// hide the org field is we are not in showorg mode
|
||||
if ('true' != Configure::read('CyDefSIG.showorg') && !$isAdmin) {
|
||||
unset($events[$key]['org']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// display the XML to the user
|
||||
$xmlArray['CyDefSIG']['event'] = $events;
|
||||
$xmlObject = Xml::fromArray($xmlArray, array('format' => 'tags'));
|
||||
echo $xmlObject->asXML();
|
||||
?><!--
|
||||
Please note that this XML page is a representation of the /events/index page.
|
||||
Because the /events/index page is paginated you will have a limited number of results.
|
||||
|
||||
You can for example ask: /events/index/limit:999.xml to get the 999 first records.
|
||||
(A maximum has been set to 9999)
|
||||
|
||||
|
||||
To export all the events at once, with their attributes, use the export functionality.
|
||||
-->
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
$xmlArray = array();
|
||||
// rearrange things to be compatible with the Xml::fromArray()
|
||||
$event['Event']['attribute'] = $event['Attribute'];
|
||||
unset($event['Attribute']);
|
||||
|
||||
// cleanup the array from things we do not want to expose
|
||||
unset($event['Event']['user_id']);
|
||||
// hide the private fields is we are not in serversync mode
|
||||
if ('true' != Configure::read('CyDefSIG.serversync')) {
|
||||
unset($event['Event']['private']);
|
||||
foreach($event['Event']['attribute'] as $key => $value) {
|
||||
unset($event['Event']['attribute'][$key]['private']);
|
||||
}
|
||||
}
|
||||
// hide the org field is we are not in showorg mode
|
||||
if ('true' != Configure::read('CyDefSIG.showorg') && !$isAdmin) {
|
||||
unset($event['Event']['org']);
|
||||
}
|
||||
|
||||
// build up a list of the related events
|
||||
foreach ($relatedEvents as $relatedEvent) {
|
||||
$event['Event']['relatedevent'][] = $relatedEvent['Event'];
|
||||
}
|
||||
|
||||
// display the XML to the user
|
||||
$xmlArray['CyDefSIG']['event'][] = $event['Event'];
|
||||
$xmlObject = Xml::fromArray($xmlArray, array('format' => 'tags'));
|
||||
echo $xmlObject->asXML();
|
Loading…
Reference in New Issue