Merge branch '2.4' of github.com:MISP/MISP into 2.4

pull/5103/head
chrisr3d 2019-09-04 16:21:37 +02:00
commit d783e0d039
5 changed files with 565 additions and 504 deletions

View File

@ -253,13 +253,19 @@ class ServerShell extends AppShell
$jobId = $this->Job->id;
}
$this->Job->read(null, $jobId);
$result = $this->Feed->cacheFeedInitiator($user, $jobId, $scope);
try {
$result = $this->Feed->cacheFeedInitiator($user, $jobId, $scope);
} catch (Exception $e) {
CakeLog::error($e->getMessage());
$result = false;
}
$this->Job->id = $jobId;
if ($result !== true) {
$message = 'Job Failed. Reason: ';
$message = 'Job failed. See logs for more details.';
$this->Job->save(array(
'id' => $jobId,
'message' => $message . $result,
'message' => $message,
'progress' => 0,
'status' => 3
));
@ -401,12 +407,26 @@ class ServerShell extends AppShell
);
$this->Job->save($data);
$jobId = $this->Job->id;
$result = $this->Feed->cacheFeedInitiator($user, $jobId, 'all');
$this->Job->save(array(
'message' => 'Job done.',
'progress' => 100,
'status' => 4
));
try {
$result = $this->Feed->cacheFeedInitiator($user, $jobId, 'all');
} catch (Exception $e) {
CakeLog::error($e->getMessage());
$result = false;
}
if ($result) {
$this->Job->save(array(
'message' => 'Job done.',
'progress' => 100,
'status' => 4
));
} else {
$this->Job->save(array(
'message' => 'Job failed. See logs for more details.',
'progress' => 100,
'status' => 3,
));
}
$this->Task->id = $task['Task']['id'];
$this->Task->saveField('message', 'Job completed at ' . date('d/m/Y - H:i:s'));
}

View File

@ -520,7 +520,13 @@ class FeedsController extends AppController
$this->Flash->info(__('Feed is currently not enabled. Make sure you enable it.'));
$this->redirect(array('action' => 'previewIndex', $feedId));
}
$result = $this->Feed->downloadAndSaveEventFromFeed($this->Feed->data, $eventUuid, $this->Auth->user());
try {
$result = $this->Feed->downloadAndSaveEventFromFeed($this->Feed->data, $eventUuid, $this->Auth->user());
} catch (Exception $e) {
$this->Flash->error(__('Download failed.') . ' ' . $e->getMessage());
$this->redirect(array('action' => 'previewIndex', $feedId));
}
if (isset($result['action'])) {
if ($result['result']) {
if ($result['action'] == 'add') {
@ -579,11 +585,13 @@ class FeedsController extends AppController
App::uses('SyncTool', 'Tools');
$syncTool = new SyncTool();
$HttpSocket = $syncTool->setupHttpSocketFeed($feed);
$events = $this->Feed->getManifest($feed, $HttpSocket);
if (!is_array($events)) {
$this->Flash->info($events);
try {
$events = $this->Feed->getManifest($feed, $HttpSocket);
} catch (Exception $e) {
$this->Flash->error("Could not fetch manifest for feed: {$e->getMessage()}");
$this->redirect(array('controller' => 'feeds', 'action' => 'index'));
}
if (!empty($this->params['named']['searchall'])) {
foreach ($events as $uuid => $event) {
$found = false;
@ -672,10 +680,10 @@ class FeedsController extends AppController
$HttpSocket = $syncTool->setupHttpSocketFeed($feed);
$params = array();
// params is passed as reference here, the pagination happens in the method, which isn't ideal but considering the performance gains here it's worth it
$resultArray = $this->Feed->getFreetextFeed($feed, $HttpSocket, $feed['Feed']['source_format'], $currentPage, 60, $params);
// we want false as a valid option for the split fetch, but we don't want it for the preview
if (!is_array($resultArray)) {
$this->Flash->info($resultArray);
try {
$resultArray = $this->Feed->getFreetextFeed($feed, $HttpSocket, $feed['Feed']['source_format'], $currentPage, 60, $params);
} catch (Exception $e) {
$this->Flash->error("Could not fetch feed: {$e->getMessage()}");
$this->redirect(array('controller' => 'feeds', 'action' => 'index'));
}
$this->params->params['paging'] = array($this->modelClass => $params);
@ -721,7 +729,12 @@ class FeedsController extends AppController
throw new MethodNotAllowedException(__('Invalid feed type.'));
}
$HttpSocket = $syncTool->setupHttpSocketFeed($feed);
$resultArray = $this->Feed->getFreetextFeed($feed, $HttpSocket, $feed['Feed']['source_format'], $currentPage);
try {
$resultArray = $this->Feed->getFreetextFeed($feed, $HttpSocket, $feed['Feed']['source_format'], $currentPage);
} catch (Exception $e) {
$this->Flash->error("Could not fetch feed: {$e->getMessage()}");
$this->redirect(array('controller' => 'feeds', 'action' => 'index'));
}
// we want false as a valid option for the split fetch, but we don't want it for the preview
if ($resultArray == false) {
$resultArray = array();
@ -755,7 +768,11 @@ class FeedsController extends AppController
throw new NotFoundException(__('Invalid feed.'));
}
$this->Feed->read();
$event = $this->Feed->downloadEventFromFeed($this->Feed->data, $eventUuid, $this->Auth->user());
try {
$event = $this->Feed->downloadEventFromFeed($this->Feed->data, $eventUuid, $this->Auth->user());
} catch (Exception $e) {
throw new Exception(__('Could not download the selected Event'), 0, $e);
}
if ($this->_isRest()) {
return $this->RestResponse->viewData($event, $this->response->type());
}
@ -858,11 +875,11 @@ class FeedsController extends AppController
$feed['Feed']['settings'] = json_decode($feed['Feed']['settings'], true);
}
$data = json_decode($this->request->data['Feed']['data'], true);
$result = $this->Feed->saveFreetextFeedData($feed, $data, $this->Auth->user());
if ($result === true) {
try {
$this->Feed->saveFreetextFeedData($feed, $data, $this->Auth->user());
$this->Flash->success(__('Data pulled.'));
} else {
$this->Flash->error(__('Could not pull the selected data. Reason: %s', $result));
} catch (Exception $e) {
$this->Flash->error(__('Could not pull the selected data. Reason: %s', $e->getMessage()));
}
$this->redirect(array('controller' => 'feeds', 'action' => 'index'));
}

File diff suppressed because it is too large Load Diff

View File

@ -1049,50 +1049,46 @@ class User extends AppModel
App::uses('SyncTool', 'Tools');
$syncTool = new SyncTool();
$HttpSocket = $syncTool->setupHttpSocket();
$response = $HttpSocket->get('https://pgp.circl.lu/pks/lookup?search=' . $email . '&op=index&fingerprint=on');
$response = $HttpSocket->get('https://pgp.circl.lu/pks/lookup?search=' . urlencode($email) . '&op=index&fingerprint=on&options=mr');
if ($response->code != 200) {
return $response->code;
}
$string = str_replace(array("\r", "\n"), "", $response->body);
$result = preg_match_all('/<pre>pub(.*?)<\/pre>/', $string, $matches);
$results = $this->__extractPGPInfo($matches[1]);
return $results;
return $this->__extractPGPInfo($response->body);
}
private function __extractPGPInfo($lines)
private function __extractPGPInfo($body)
{
$extractionRules = array(
'key_id' => array('regex' => '/\">(.*?)<\/a>/', 'all' => false, 'alternate' => false),
'date' => array('regex' => '/([0-9]{4}\-[0-9]{2}\-[0-9]{2})/', 'all' => false, 'alternate' => false),
'fingerprint' => array('regex' => '/Fingerprint=(.*)$/m', 'all' => false, 'alternate' => false),
'uri' => array('regex' => '/<a href=\"(.*?)\">/', 'all' => false, 'alternate' => false),
'address' => array('regex' => '/<a href="\/pks\/lookup\?op=vindex[^>]*>([^\<]*)<\/a>(.*)Fingerprint/s', 'all' => true, 'alternate' => true),
);
$final = array();
$lines = explode("\n", $body);
foreach ($lines as $line) {
if (strpos($line, 'KEY REVOKED')) {
continue;
$parts = explode(":", $line);
if ($parts[0] === 'pub') {
if (!empty($temp)) {
$final[] = $temp;
$temp = array();
}
if (strpos($parts[6], 'r') !== false || strpos($parts[6], 'd') !== false || strpos($parts[6], 'e') !== false) {
continue; // skip if key is expired, revoked or disabled
}
$temp = array(
'fingerprint' => chunk_split($parts[1], 4, ' '),
'key_id' => substr($parts[1], -8),
'date' => date('Y-m-d', $parts[4]),
'uri' => 'pks/lookup?op=get&search=0x' . $parts[1],
);
} else if ($parts[0] === 'uid' && !empty($temp)) {
$temp['address'] = urldecode($parts[1]);
}
$temp = array();
foreach ($extractionRules as $ruleName => $rule) {
if ($rule['all']) {
preg_match_all($rule['regex'], $line, ${$ruleName});
} else {
preg_match($rule['regex'], $line, ${$ruleName});
}
if ($rule['alternate'] && isset(${$ruleName}[2]) && trim(${$ruleName}[2][0]) != '') {
$temp[$ruleName] = ${$ruleName}[2];
} else {
$temp[$ruleName] = ${$ruleName}[1];
}
if ($rule['all']) {
$temp[$ruleName] = $temp[$ruleName][0];
}
$temp[$ruleName] = html_entity_decode($temp[$ruleName]);
}
$temp['address'] = preg_replace('/\s{2,}/', PHP_EOL, trim($temp['address']));
}
if (!empty($temp)) {
$final[] = $temp;
}
return $final;
}

View File

@ -67,21 +67,3 @@ $disabledBtnText = $updateLocked ? 'title="' . __('An action is already in progr
<?php
echo $this->element('/genericElements/SideMenu/side_menu', array('menuList' => 'admin', 'menuItem' => 'adminTools'));
?>
<script type="text/javascript">
$(document).ready(function(){
$('.submitButtonToUpdateProgress').click(function() {
var form = $(this).closest("form");
$.ajax({
data: form.serialize(),
cache: false,
timeout: 100,
complete: function (data, textStatus) {
window.location.href = $('#btnShowProgress').prop('href');
},
type:"post",
url: form.prop('action')
});
});
});
</script>