mirror of https://github.com/MISP/MISP
First version or REST API to export data
parent
67d3a9f9d2
commit
bf8ae66e9c
|
@ -93,6 +93,7 @@ Configure::write('CyDefSIG.footer', 'Powered by CyDefSIG © Belgian Defense
|
||||||
|
|
||||||
|
|
||||||
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('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
|
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'));
|
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
|
* Load all plugin routes. See the CakePlugin documentation on
|
||||||
* how to customize the loading of plugin routes.
|
* how to customize the loading of plugin routes.
|
||||||
|
|
|
@ -15,9 +15,10 @@ class EventsController extends AppController {
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public $components = array('Security', 'Email');
|
public $components = array('Security', 'Email', 'RequestHandler');
|
||||||
public $paginate = array(
|
public $paginate = array(
|
||||||
'limit' => 60,
|
'limit' => 60,
|
||||||
|
'maxLimit' => 9999, // LATER we will bump here on a problem once we have more than 9999 events
|
||||||
'order' => array(
|
'order' => array(
|
||||||
'Event.date' => 'DESC'
|
'Event.date' => 'DESC'
|
||||||
)
|
)
|
||||||
|
@ -79,7 +80,7 @@ class EventsController extends AppController {
|
||||||
|
|
||||||
$relatedAttributes = array();
|
$relatedAttributes = array();
|
||||||
$this->loadModel('Attribute');
|
$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) {
|
foreach ($this->Event->data['Attribute'] as $attribute) {
|
||||||
$relatedAttributes[$attribute['id']] = $this->Attribute->getRelatedAttributes($attribute, $fields);
|
$relatedAttributes[$attribute['id']] = $this->Attribute->getRelatedAttributes($attribute, $fields);
|
||||||
}
|
}
|
||||||
|
@ -97,7 +98,7 @@ class EventsController extends AppController {
|
||||||
$find_params = array(
|
$find_params = array(
|
||||||
'conditions' => array('OR' => array('Event.id' => $relatedEventsIds)), //array of conditions
|
'conditions' => array('OR' => array('Event.id' => $relatedEventsIds)), //array of conditions
|
||||||
'recursive' => 0, //int
|
'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
|
'order' => array('Event.date DESC'), //string or array defining order
|
||||||
);
|
);
|
||||||
$relatedEvents = $this->Event->find('all', $find_params);
|
$relatedEvents = $this->Event->find('all', $find_params);
|
||||||
|
@ -549,7 +550,7 @@ class EventsController extends AppController {
|
||||||
$conditions = array();
|
$conditions = array();
|
||||||
}
|
}
|
||||||
// do not expose all the data like user_id, ...
|
// 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')) {
|
if ('true' == Configure::read('CyDefSIG.showorg')) {
|
||||||
$fields[] = 'Event.org';
|
$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