mirror of https://github.com/MISP/MISP
new: [eventgraph:viewPicture] Allow access to saved picture from the eventgraph history
parent
d7de209623
commit
a1b5141a5a
|
@ -727,6 +727,7 @@ class ACLComponent extends Component
|
|||
),
|
||||
'eventGraph' => array(
|
||||
'view' => array('*'),
|
||||
'viewPicture' => array('*'),
|
||||
'add' => array('perm_add'),
|
||||
'delete' => array('perm_modify'),
|
||||
)
|
||||
|
|
|
@ -50,6 +50,37 @@ class EventGraphController extends AppController
|
|||
return $this->RestResponse->viewData($eventGraphs, $this->response->type());
|
||||
}
|
||||
|
||||
public function viewPicture($event_id, $graph_id)
|
||||
{
|
||||
$this->loadModel('Event');
|
||||
$event = $this->Event->fetchSimpleEvent($this->Auth->user(), $event_id);
|
||||
if (empty($event)) {
|
||||
throw new NotFoundException('Invalid event');
|
||||
}
|
||||
|
||||
$conditions = [
|
||||
'EventGraph.event_id' => $event['Event']['id'],
|
||||
'EventGraph.org_id' => $this->Auth->user('org_id'),
|
||||
'EventGraph.id' => $graph_id,
|
||||
];
|
||||
$eventGraph = $this->EventGraph->find('first', array(
|
||||
'conditions' => $conditions,
|
||||
'contain' => array(
|
||||
'User' => array(
|
||||
'fields' => array(
|
||||
'User.email'
|
||||
)
|
||||
)
|
||||
)
|
||||
));
|
||||
if (empty($eventGraph)) {
|
||||
throw new MethodNotAllowedException('Invalid event graph');
|
||||
}
|
||||
$eventGraph = $eventGraph;
|
||||
$imageData = $this->EventGraph->getPictureData($eventGraph);
|
||||
return new CakeResponse(array('body' => $imageData, 'type' => 'png'));
|
||||
}
|
||||
|
||||
public function add($event_id = false)
|
||||
{
|
||||
if ($this->request->is('get')) {
|
||||
|
|
|
@ -53,4 +53,18 @@ class EventGraph extends AppModel
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getPictureData($eventGraph)
|
||||
{
|
||||
$b64 = str_replace('data:image/png;base64,', '', $eventGraph['EventGraph']['preview_img']);
|
||||
$imageDecoded = base64_decode($b64);
|
||||
$source = imagecreatefromstring($imageDecoded);
|
||||
imagesavealpha($source, true);
|
||||
ob_start();
|
||||
imagepng($source, null, 9);
|
||||
$imageData = ob_get_contents();
|
||||
ob_end_clean();
|
||||
imagedestroy($source);
|
||||
return $imageData;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue