mirror of https://github.com/MISP/MISP
pull/61/head
parent
03ad7d3acd
commit
fa167bc2c8
|
@ -61,6 +61,7 @@ class AppController extends Controller {
|
|||
// REST things
|
||||
if ($this->_isRest()) {
|
||||
// disable CSRF for REST access
|
||||
if (array_key_exists('Security', $this->components))
|
||||
$this->Security->csrfCheck = false;
|
||||
|
||||
// Authenticate user with authkey in Authorization HTTP header
|
||||
|
|
|
@ -128,7 +128,7 @@ class EventsController extends AppController {
|
|||
// check if the uuid already exists
|
||||
$existingEventCount = $this->Event->find('count', array('conditions' => array('Event.uuid'=>$this->request->data['Event']['uuid'])));
|
||||
if ($existingEventCount > 0) {
|
||||
throw new InternalErrorException('Event already exists'); // TODO throw errors a clean way using XML
|
||||
throw new MethodNotAllowedException('Event already exists'); // TODO throw errors a clean way using XML
|
||||
}
|
||||
|
||||
// Workaround for different structure in XML/array than what CakePHP expects
|
||||
|
|
|
@ -176,27 +176,39 @@ class ServersController extends AppController {
|
|||
$this->Server->read(null, $id);
|
||||
|
||||
if ("full"==$full) {
|
||||
// TODO full push
|
||||
throw new NotFoundException('Sorry, this is not yet implemented');
|
||||
$lastpushedid = 0;
|
||||
|
||||
} else {
|
||||
$lastpushedid = $this->Server->data['Server']['lastpushedid'];
|
||||
}
|
||||
$find_params = array(
|
||||
'conditions' => array(
|
||||
'Event.id >' => $this->Server->data['Server']['lastpushedid'],
|
||||
'Event.id >' => $lastpushedid,
|
||||
'Event.private' => 0,
|
||||
'Event.published' =>1
|
||||
), //array of conditions
|
||||
'recursive' => 1, //int
|
||||
'fields' => array('Event.*'), //array of field names
|
||||
// 'order' => array('Event.id ASC'), //string or array defining order
|
||||
);
|
||||
$events = $this->Event->find('all', $find_params);
|
||||
|
||||
// FIXME now all events are uploaded, even if they exist on the remote server. No merging is done
|
||||
// FIXME file attachments are not synced
|
||||
$lastpushedid = $this->Server->data['Server']['lastpushedid'];
|
||||
$successes = array();
|
||||
$fails = array();
|
||||
|
||||
$HttpSocket = new HttpSocket();
|
||||
$uri = $this->Server->data['Server']['url'].'/events';
|
||||
$request = array(
|
||||
'header' => array(
|
||||
'Authorization' => $this->Server->data['Server']['authkey'],
|
||||
'Accept' => 'application/xml',
|
||||
'Content-Type' => 'application/xml',
|
||||
//'Connection' => 'keep-alive' // LATER followup cakephp ticket 2854 about this problem http://cakephp.lighthouseapp.com/projects/42648-cakephp/tickets/2854
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
foreach ($events as $event) {
|
||||
// TODO try to do this using a separate EventsController
|
||||
// $eventsController = new EventsController();
|
||||
|
@ -238,20 +250,10 @@ class ServersController extends AppController {
|
|||
$xmlObject = Xml::fromArray($xmlArray, array('format' => 'tags'));
|
||||
$eventsXml = $xmlObject->asXML();
|
||||
// do a REST POST request with the server
|
||||
$HttpSocket = new HttpSocket();
|
||||
$uri = $this->Server->data['Server']['url'].'/events';
|
||||
$request = array(
|
||||
'header' => array(
|
||||
'Authorization' => $this->Server->data['Server']['authkey'],
|
||||
'Accept' => 'application/xml',
|
||||
'Content-Type' => 'application/xml'
|
||||
)
|
||||
);
|
||||
$data = $eventsXml;
|
||||
// LATER validate HTTPS SSL certificate
|
||||
$response = $HttpSocket->post($uri, $data, $request);
|
||||
if ($response->isOk()) {
|
||||
debug('OK for event '.$event['Event']['id']);
|
||||
$successes[] = $event['Event']['id'];
|
||||
}
|
||||
else {
|
||||
|
@ -264,8 +266,6 @@ class ServersController extends AppController {
|
|||
$this->set('fails', $fails);
|
||||
// increment lastid based on the highest ID seen
|
||||
$this->Server->saveField('lastpushedid', $lastpushedid);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private function _testXmlArrayProblem() {
|
||||
|
|
Loading…
Reference in New Issue