mirror of https://github.com/MISP/MISP
Merge pull request #7658 from JakubOnderka/compatiblity-check-log
chg: [internal] Create log entry for compatibility checkpull/7848/head
commit
86effcf41f
|
@ -923,7 +923,7 @@ class Event extends AppModel
|
|||
return 'The distribution level of this event blocks it from being pushed.';
|
||||
}
|
||||
|
||||
$push = $this->Server->checkVersionCompatibility($server, false, $HttpSocket);
|
||||
$push = $this->Server->checkVersionCompatibility($server, false);
|
||||
if (empty($push['canPush'])) {
|
||||
return 'The remote user is not a sync user - the upload of the event has been blocked.';
|
||||
}
|
||||
|
|
|
@ -1662,7 +1662,7 @@ class GalaxyCluster extends AppModel
|
|||
{
|
||||
$this->Server = ClassRegistry::init('Server');
|
||||
$this->Log = ClassRegistry::init('Log');
|
||||
$push = $this->Server->checkVersionCompatibility($server, false, $HttpSocket);
|
||||
$push = $this->Server->checkVersionCompatibility($server, false);
|
||||
if (empty($push['canPush']) && empty($push['canPushGalaxyCluster'])) {
|
||||
return __('The remote user does not have the permission to manipulate galaxies - the upload of the galaxy clusters has been blocked.');
|
||||
}
|
||||
|
|
|
@ -2481,61 +2481,47 @@ class Server extends AppModel
|
|||
return ['status' => 1, 'content-encoding' => $contentEncoding];
|
||||
}
|
||||
|
||||
public function checkVersionCompatibility(array $server, $user = array(), $HttpSocket = false)
|
||||
/**
|
||||
* @param array $server
|
||||
* @param array $user
|
||||
* @param ServerSyncTool|null $serverSync
|
||||
* @return array|string
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function checkVersionCompatibility(array $server, $user = [], ServerSyncTool $serverSync = null)
|
||||
{
|
||||
// for event publishing when we don't have a user.
|
||||
if (empty($user)) {
|
||||
$user = array('Organisation' => array('name' => 'SYSTEM'), 'email' => 'SYSTEM', 'id' => 0);
|
||||
$user = 'SYSTEM';
|
||||
}
|
||||
$localVersion = $this->checkMISPVersion();
|
||||
$HttpSocket = $this->setupHttpSocket($server, $HttpSocket);
|
||||
$request = $this->setupSyncRequest($server);
|
||||
$uri = $server['Server']['url'] . '/servers/getVersion';
|
||||
|
||||
$serverSync = $serverSync ? $serverSync : new ServerSyncTool($server, $this->setupSyncRequest($server));
|
||||
|
||||
try {
|
||||
$response = $HttpSocket->get($uri, '', $request);
|
||||
$remoteVersion = $serverSync->info();
|
||||
} catch (Exception $e) {
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
if (!isset($response) || $response->code != '200') {
|
||||
$this->Log = ClassRegistry::init('Log');
|
||||
$this->Log->create();
|
||||
if (isset($response->code)) {
|
||||
$title = 'Error: Connection to the server has failed.' . (isset($response->code) ? ' Returned response code: ' . $response->code : '');
|
||||
$this->logException("Connection to the server {$server['Server']['id']} has failed", $e);
|
||||
|
||||
if ($e instanceof HttpSocketHttpException) {
|
||||
$title = 'Error: Connection to the server has failed. Returned response code: ' . $e->getCode();
|
||||
} else {
|
||||
$title = 'Error: Connection to the server has failed. The returned exception\'s error message was: ' . $error;
|
||||
$title = 'Error: Connection to the server has failed. The returned exception\'s error message was: ' . $e->getMessage();
|
||||
}
|
||||
$this->Log->save(array(
|
||||
'org' => $user['Organisation']['name'],
|
||||
'model' => 'Server',
|
||||
'model_id' => $server['Server']['id'],
|
||||
'email' => $user['email'],
|
||||
'action' => 'error',
|
||||
'user_id' => $user['id'],
|
||||
'title' => $title
|
||||
));
|
||||
$this->loadLog()->createLogEntry($user, 'error', 'Server', $server['Server']['id'], $title);
|
||||
return $title;
|
||||
}
|
||||
$remoteVersion = $this->jsonDecode($response->body);
|
||||
|
||||
$canPush = isset($remoteVersion['perm_sync']) ? $remoteVersion['perm_sync'] : false;
|
||||
$canSight = isset($remoteVersion['perm_sighting']) ? $remoteVersion['perm_sighting'] : false;
|
||||
$supportEditOfGalaxyCluster = isset($remoteVersion['perm_galaxy_editor']);
|
||||
$canEditGalaxyCluster = isset($remoteVersion['perm_galaxy_editor']) ? $remoteVersion['perm_galaxy_editor'] : false;
|
||||
$remoteVersion = explode('.', $remoteVersion['version']);
|
||||
if (!isset($remoteVersion[0])) {
|
||||
$this->Log = ClassRegistry::init('Log');
|
||||
$this->Log->create();
|
||||
$message = __('Error: Server didn\'t send the expected response. This may be because the remote server version is outdated.');
|
||||
$this->Log->save(array(
|
||||
'org' => $user['Organisation']['name'],
|
||||
'model' => 'Server',
|
||||
'model_id' => $server['Server']['id'],
|
||||
'email' => $user['email'],
|
||||
'action' => 'error',
|
||||
'user_id' => $user['id'],
|
||||
'title' => $message,
|
||||
));
|
||||
$this->loadLog()->createLogEntry($user, 'error', 'Server', $server['Server']['id'], $message);
|
||||
return $message;
|
||||
}
|
||||
$localVersion = $this->checkMISPVersion();
|
||||
$response = false;
|
||||
$success = false;
|
||||
$issueLevel = "warning";
|
||||
|
@ -2569,17 +2555,7 @@ class Server extends AppModel
|
|||
}
|
||||
|
||||
if ($response !== false) {
|
||||
$this->Log = ClassRegistry::init('Log');
|
||||
$this->Log->create();
|
||||
$this->Log->save(array(
|
||||
'org' => $user['Organisation']['name'],
|
||||
'model' => 'Server',
|
||||
'model_id' => $server['Server']['id'],
|
||||
'email' => $user['email'],
|
||||
'action' => $issueLevel,
|
||||
'user_id' => $user['id'],
|
||||
'title' => ucfirst($issueLevel) . ': ' . $response,
|
||||
));
|
||||
$this->loadLog()->createLogEntry($user, $issueLevel, 'Server', $server['Server']['id'], ucfirst($issueLevel) . ': ' . $response);
|
||||
}
|
||||
return [
|
||||
'success' => $success,
|
||||
|
|
Loading…
Reference in New Issue