diff --git a/app/Config/bootstrap.php b/app/Config/bootstrap.php index e664e20e0..f90385867 100644 --- a/app/Config/bootstrap.php +++ b/app/Config/bootstrap.php @@ -2,7 +2,7 @@ /** * This file is loaded automatically by the app/webroot/index.php file after core.php * - * This file should load/create any application wide configuration settings, such as + * This file should load/create any application wide configuration settings, such as * Caching, Logging, loading additional configuration files. * * You should also use this file to include any files that provide global functions/constants @@ -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 diff --git a/app/Config/routes.php b/app/Config/routes.php index 44e92b11e..adb4e6a4d 100644 --- a/app/Config/routes.php +++ b/app/Config/routes.php @@ -27,8 +27,13 @@ */ 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. */ CakePlugin::routes(); diff --git a/app/Controller/EventsController.php b/app/Controller/EventsController.php index ae955a45a..c4424a215 100644 --- a/app/Controller/EventsController.php +++ b/app/Controller/EventsController.php @@ -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'; } diff --git a/app/View/Events/xml/index.ctp b/app/View/Events/xml/index.ctp new file mode 100644 index 000000000..02d30c843 --- /dev/null +++ b/app/View/Events/xml/index.ctp @@ -0,0 +1,35 @@ + $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(); +?> \ No newline at end of file diff --git a/app/View/Events/xml/view.ctp b/app/View/Events/xml/view.ctp new file mode 100755 index 000000000..242200010 --- /dev/null +++ b/app/View/Events/xml/view.ctp @@ -0,0 +1,29 @@ + $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();