mirror of https://github.com/MISP/MISP
auto-upload when publish event
parent
efa590de23
commit
747c211723
|
@ -270,6 +270,49 @@ class EventsController extends AppController {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Uploads this specific event to all remote servers
|
||||
* TODO move this to a helper or
|
||||
*/
|
||||
function _uploadEventToServers($id) {
|
||||
// make sure we have all the data of the Event
|
||||
$this->Event->id=$id;
|
||||
$this->Event->recursive=1;
|
||||
$this->Event->read();
|
||||
|
||||
// get a list of the servers
|
||||
$this->loadModel('Server');
|
||||
$servers = $this->Server->find('all', array(
|
||||
'conditions' => array('Server.push' => true)
|
||||
));
|
||||
|
||||
// iterate over the servers and upload the event
|
||||
if(empty($servers))
|
||||
return;
|
||||
|
||||
App::uses('HttpSocket', 'Network/Http');
|
||||
$HttpSocket = new HttpSocket();
|
||||
foreach ($servers as $server) {
|
||||
$this->Event->uploadEventToServer($this->Event->data, $server, $HttpSocket);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs all the actions required to publish an event
|
||||
*
|
||||
* @param unknown_type $id
|
||||
*/
|
||||
function _publish($id) {
|
||||
$this->Event->id = $id;
|
||||
$this->Event->recursive = 0;
|
||||
//$this->Event->read();
|
||||
|
||||
// update the DB to set the published flag
|
||||
$this->Event->saveField('published', 1);
|
||||
|
||||
// upload the event to remote servers
|
||||
$this->_uploadEventToServers($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Publishes the event without sending an alert email
|
||||
|
@ -279,17 +322,13 @@ class EventsController extends AppController {
|
|||
if (!$this->Event->exists()) {
|
||||
throw new NotFoundException(__('Invalid event'));
|
||||
}
|
||||
|
||||
// only allow publish for own events verified by isAuthorized
|
||||
|
||||
// only allow form submit CSRF protection.
|
||||
if ($this->request->is('post') || $this->request->is('put')) {
|
||||
|
||||
$this->Event->id = $id;
|
||||
$this->Event->read();
|
||||
|
||||
// only allow publish for own events verified by isAuthorized
|
||||
|
||||
// update the DB to set the published flag
|
||||
$this->Event->saveField('published', 1);
|
||||
if ($this->request->is('post') || $this->request->is('put')) {
|
||||
// Performs all the actions required to publish an event
|
||||
$this->_publish($id);
|
||||
|
||||
// redirect to the view event page
|
||||
$this->Session->setFlash(__('Event published, but NO mail sent to any participants.', true));
|
||||
|
@ -312,17 +351,10 @@ class EventsController extends AppController {
|
|||
|
||||
// only allow form submit CSRF protection.
|
||||
if ($this->request->is('post') || $this->request->is('put')) {
|
||||
$this->Event->read();
|
||||
// fetch the event and build the body
|
||||
if (1 == $this->Event->data['Event']['published']) {
|
||||
$this->Session->setFlash(__('Everyone has already been published for this event. To alert again, first edit this event.', true), 'default', array(), 'error');
|
||||
$this->redirect(array('action' => 'view', $id));
|
||||
}
|
||||
|
||||
// send out the email
|
||||
if ($this->_sendAlertEmail($id)) {
|
||||
// update the DB to set the published flag
|
||||
$this->Event->saveField('published', 1);
|
||||
if ($this->_sendAlertEmail($id)) {
|
||||
// Performs all the actions required to publish an event
|
||||
$this->_publish($id);
|
||||
|
||||
// redirect to the view event page
|
||||
$this->Session->setFlash(__('Email sent to all participants.', true));
|
||||
|
|
|
@ -206,11 +206,14 @@ class Event extends AppModel {
|
|||
|
||||
|
||||
/**
|
||||
* Uploads the event and the associated Attributes to another instance
|
||||
* Uploads the event and the associated Attributes to another Server
|
||||
*
|
||||
* @return bool true if success, error message if failed
|
||||
*/
|
||||
function uploadEventToServer($event, $server, $HttpSocket=null) {
|
||||
if (true ==$event['Event']['private']) // never upload private events
|
||||
return "Event is private and non exportable";
|
||||
|
||||
$url = $server['Server']['url'];
|
||||
$authkey = $server['Server']['authkey'];
|
||||
if (null == $HttpSocket) {
|
||||
|
@ -275,6 +278,11 @@ class Event extends AppModel {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Download a specific event from a Server
|
||||
*
|
||||
* @return array|NULL
|
||||
*/
|
||||
function downloadEventFromServer($event_id, $server, $HttpSocket=null) {
|
||||
$url = $server['Server']['url'];
|
||||
$authkey = $server['Server']['authkey'];
|
||||
|
@ -298,13 +306,13 @@ class Event extends AppModel {
|
|||
return $xml_array['response'];
|
||||
}
|
||||
else {
|
||||
// parse the XML response and keep the reason why it failed
|
||||
// TODO parse the XML response and keep the reason why it failed
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of event_ids that are present on the server
|
||||
* Get an array of event_ids that are present on the remote server
|
||||
* @return array of event_ids
|
||||
*/
|
||||
function getEventIdsFromServer($server, $HttpSocket=null) {
|
||||
|
@ -340,4 +348,7 @@ class Event extends AppModel {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -93,4 +93,6 @@ class Server extends AppModel {
|
|||
public function isOwnedByOrg($serverid, $org) {
|
||||
return $this->field('id', array('id' => $serverid, 'org' => $org)) === $serverid;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue