mirror of https://github.com/MISP/MISP
Merge branch 'event_recovery' of github.com:MISP/MISP into event_recovery
commit
d7b93b46ab
|
@ -381,4 +381,21 @@ class EventShell extends AppShell
|
|||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function recoverEvent()
|
||||
{
|
||||
$this->ConfigLoad->execute();
|
||||
$jobId = $this->args[0];
|
||||
$id = $this->args[1];
|
||||
$job = $this->Job->read(null, $jobId);
|
||||
$job['Job']['progress'] = 1;
|
||||
$job['Job']['date_modified'] = date("Y-m-d H:i:s");
|
||||
$job['Job']['message'] = __('Recovering event %s', $id);
|
||||
$this->Job->save($job);
|
||||
$result = $this->Event->recoverEvent($id);
|
||||
$job['Job']['progress'] = 100;
|
||||
$job['Job']['date_modified'] = date("Y-m-d H:i:s");
|
||||
$job['Job']['message'] = __('Recovery complete. Event #%s recovered, using %s log entries.', $id, $result);
|
||||
$this->Job->save($job);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -203,9 +203,11 @@ class ACLComponent extends Component
|
|||
'pushEventToKafka' => array('perm_publish_kafka'),
|
||||
'pushProposals' => array('perm_sync'),
|
||||
'queryEnrichment' => array('perm_add'),
|
||||
'recoverEvent' => array('perm_site_admin'),
|
||||
'removePivot' => array('*'),
|
||||
'removeTag' => array('perm_tagger'),
|
||||
'reportValidationIssuesEvents' => array(),
|
||||
'restoreDeletedEvents' => array('perm_site_admin'),
|
||||
'restSearch' => array('*'),
|
||||
'saveFreeText' => array('perm_add'),
|
||||
'stix' => array('*'),
|
||||
|
|
|
@ -5607,7 +5607,11 @@ class EventsController extends AppController
|
|||
public function restoreDeletedEvents($force = false)
|
||||
{
|
||||
$startDate = '2020-07-31 00:00:00';
|
||||
$endDate = date('Y-m-d H:i:s', time());
|
||||
$this->loadModel('AdminSetting');
|
||||
$endDate = date('Y-m-d H:i:s', $this->AdminSetting->getSetting('fix_login'));
|
||||
if (empty($endDate)) {
|
||||
$endDate = date('Y-m-d H:i:s', time());
|
||||
}
|
||||
$this->loadModel('Log');
|
||||
$redis = $this->Event->setupRedis();
|
||||
if ($force || ($redis && !$redis->exists('misp:event_recovery'))) {
|
||||
|
@ -5626,29 +5630,75 @@ class EventsController extends AppController
|
|||
|
||||
public function recoverEvent($id, $mock = false)
|
||||
{
|
||||
if ($this->request->is('post')) {
|
||||
$this->loadModel('Log');
|
||||
$result = $this->Log->recoverDeletedEvent($id, $mock);
|
||||
$message = __('Recovery complete. Event #%s recovered, using %s log entries.', $id, $result);
|
||||
if ($this->_isRest()) {
|
||||
if ($mock) {
|
||||
$results = $this->Log->mockLog;
|
||||
} else {
|
||||
$results = $this->Event->fetchEvent($this->Auth->user(), ['eventid' => $id]);
|
||||
}
|
||||
return $this->RestResponse->viewData($results, $this->response->type());
|
||||
} else {
|
||||
$this->Flash->success(__('Recovery complete. Event #%s recovered, using %s log entries.', $id, $result));
|
||||
}
|
||||
} else {
|
||||
if ($this->_isRest()) {
|
||||
} else {
|
||||
$this->Flash->error(__('This action is only accessible via POST requests.'));
|
||||
}
|
||||
if (!Configure::read('MISP.background_jobs')) {
|
||||
throw new MethodNotAllowedException(__('Workers must be enabled to use this feature'));
|
||||
}
|
||||
if ($mock) {
|
||||
if ($this->request->is('post')) {
|
||||
$this->loadModel('Log');
|
||||
$result = $this->Log->recoverDeletedEvent($id, $mock);
|
||||
$message = __('Recovery complete. Event #%s recovered, using %s log entries.', $id, $result);
|
||||
if ($this->_isRest()) {
|
||||
if ($mock) {
|
||||
$results = $this->Log->mockLog;
|
||||
} else {
|
||||
$results = $this->Event->fetchEvent($this->Auth->user(), ['eventid' => $id]);
|
||||
}
|
||||
return $this->RestResponse->viewData($results, $this->response->type());
|
||||
} else {
|
||||
$this->Flash->success($message);
|
||||
}
|
||||
} else {
|
||||
$message = __('This action is only accessible via POST requests.');
|
||||
if ($this->_isRest()) {
|
||||
return $this->RestResponse->viewData(array('message' => $message, 'error' => true), $this->response->type());
|
||||
} else {
|
||||
$this->Flash->error($message);
|
||||
}
|
||||
$this->redirect(['action' => 'restoreDeletedEvents']);
|
||||
}
|
||||
$this->set('data', $this->Log->mockLog);
|
||||
} else {
|
||||
if ($this->request->is('post')) {
|
||||
$job_type = 'recover_event';
|
||||
$function = 'recoverEvent';
|
||||
$message = __('Bootstraping recovering of event %s', $id);
|
||||
$job = ClassRegistry::init('Job');
|
||||
$job->create();
|
||||
$data = array(
|
||||
'worker' => $this->Event->__getPrioWorkerIfPossible(),
|
||||
'job_type' => $job_type,
|
||||
'job_input' => sprintf('Event ID: %s', $id),
|
||||
'status' => 0,
|
||||
'retries' => 0,
|
||||
'org_id' => 0,
|
||||
'org' => 'ADMIN',
|
||||
'message' => $message
|
||||
);
|
||||
$job->save($data);
|
||||
$jobId = $job->id;
|
||||
$process_id = CakeResque::enqueue(
|
||||
'prio',
|
||||
'EventShell',
|
||||
array($function, $jobId, $id),
|
||||
true
|
||||
);
|
||||
$job->saveField('process_id', $process_id);
|
||||
|
||||
$message = __('Recover event job queued. Job ID: %s', $jobId);
|
||||
if ($this->_isRest()) {
|
||||
return $this->RestResponse->viewData(array('message' => $message), $this->response->type());
|
||||
} else {
|
||||
$this->Flash->success($message);
|
||||
}
|
||||
} else {
|
||||
$message = __('This action is only accessible via POST requests.');
|
||||
if ($this->_isRest()) {
|
||||
return $this->RestResponse->viewData(array('message' => $message, 'error' => true), $this->response->type());
|
||||
} else {
|
||||
$this->Flash->error($message);
|
||||
}
|
||||
}
|
||||
$this->redirect(['action' => 'restoreDeletedEvents']);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7113,4 +7113,11 @@ class Event extends AppModel
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function recoverEvent($id)
|
||||
{
|
||||
$this->Log = ClassRegistry::init('Log');
|
||||
$result = $this->Log->recoverDeletedEvent($id);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue