From 94c37871da7f70f23042872408122c92010303e2 Mon Sep 17 00:00:00 2001 From: iglocska Date: Sat, 19 Sep 2020 18:35:15 +0200 Subject: [PATCH] fix: [recovery] various fixes - to_ids fixed - background processing made optional - first/last seen format conversion altering the data's format for the recovery script fixed - added capture of object first/last seen to the recovery script --- app/Controller/EventsController.php | 8 ++++---- app/Model/Log.php | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/Controller/EventsController.php b/app/Controller/EventsController.php index 8b6f087ac..7daeef897 100644 --- a/app/Controller/EventsController.php +++ b/app/Controller/EventsController.php @@ -5630,7 +5630,7 @@ class EventsController extends AppController public function recoverEvent($id, $mock = false) { - if ($mock) { + if ($mock || !Configure::read('MISP.background_jobs')) { if ($this->request->is('post')) { $this->loadModel('Log'); $result = $this->Log->recoverDeletedEvent($id, $mock); @@ -5648,6 +5648,9 @@ class EventsController extends AppController return $this->RestResponse->viewData($results, $this->response->type()); } else { $this->Flash->success($message); + if (!$mock) { + $this->redirect(['action' => 'restoreDeletedEvents']); + } } } else { $message = __('This action is only accessible via POST requests.'); @@ -5660,9 +5663,6 @@ class EventsController extends AppController } $this->set('data', $this->Log->mockLog); } else { - if (!Configure::read('MISP.background_jobs')) { - throw new MethodNotAllowedException(__('Workers must be enabled to use this feature')); - } if ($this->request->is('post')) { $job_type = 'recover_event'; $function = 'recoverEvent'; diff --git a/app/Model/Log.php b/app/Model/Log.php index 391e91182..61fe02471 100644 --- a/app/Model/Log.php +++ b/app/Model/Log.php @@ -848,10 +848,14 @@ class Log extends AppModel switch($logEntry['action']) { case 'add': $logEntry['data'] = $this->Attribute->UTCToISODatetime(['Attribute' => $logEntry['data']], 'Attribute'); + $logEntry['data'] = $logEntry['data']['Attribute']; if (!empty($this->mockRecovery)) { $this->mockLog[] = ['model' => 'Attribute', 'action' => 'add', 'data' => $logEntry['data']]; } else { $this->Attribute->create(); + if (!isset($logEntry['data']['to_ids'])) { + $logEntry['data']['to_ids'] = 0; + } $this->Attribute->save($logEntry['data']); } break; @@ -862,6 +866,7 @@ class Log extends AppModel ]); if (!empty($attribute)) { $logEntry['data'] = $this->Attribute->UTCToISODatetime(['Attribute' => $logEntry['data']], 'Attribute'); + $logEntry['data'] = $logEntry['data']['Attribute']; foreach ($logEntry['data'] as $field => $value) { $attribute['Attribute'][$field] = $value; } @@ -1057,6 +1062,8 @@ class Log extends AppModel } switch($logEntry['action']) { case 'add': + $logEntry['data'] = $this->MispObject->Attribute->UTCToISODatetime(['Object' => $logEntry['data']], 'Object'); + $logEntry['data'] = $logEntry['data']['Object']; if (!empty($this->mockRecovery)) { $this->mockLog[] = ['model' => 'MispObject', 'action' => 'add', 'data' => $logEntry['data']]; } else { @@ -1065,6 +1072,8 @@ class Log extends AppModel } break; case 'edit': + $logEntry['data'] = $this->MispObject->Attribute->UTCToISODatetime(['Object' => $logEntry['data']], 'Object'); + $logEntry['data'] = $logEntry['data']['Object']; $object = $this->MispObject->find('first', [ 'recursive' => -1, 'conditions' => ['Object.id' => $logEntry['model_id']]