mirror of https://github.com/MISP/MISP
new: Added a POST server connection test
- hopefully it should help debug some issuespull/2076/head
parent
6fcad27dae
commit
3fbfe08f87
|
@ -46,7 +46,7 @@ class AppController extends Controller {
|
|||
|
||||
public $helpers = array('Utility');
|
||||
|
||||
private $__jsVersion = '1';
|
||||
private $__jsVersion = '2';
|
||||
public $pyMispVersion = '2.4.68';
|
||||
public $phpmin = '5.6.5';
|
||||
public $phprec = '7.0.0';
|
||||
|
|
|
@ -1145,6 +1145,20 @@ class ServersController extends AppController {
|
|||
$this->render('ajax/fetch_servers_for_sg');
|
||||
}
|
||||
|
||||
public function postTest() {
|
||||
if ($this->request->is('post')) {
|
||||
$headers = getallheaders();
|
||||
$result = array();
|
||||
$result['body'] = $this->request->data;
|
||||
$result['headers']['Content-type'] = isset($headers['Content-type']) ? $headers['Content-type'] : 0;
|
||||
$result['headers']['Accept'] = isset($headers['Accept']) ? $headers['Accept'] : 0;
|
||||
$result['headers']['Authorization'] = isset($headers['Authorization']) ? 'OK' : 0;
|
||||
return new CakeResponse(array('body'=> json_encode($result)));
|
||||
} else {
|
||||
throw new MethodNotAllowedException('Invalid request, expecting a POST request.');
|
||||
}
|
||||
}
|
||||
|
||||
public function testConnection($id = false) {
|
||||
if (!$this->Auth->user('Role')['perm_sync'] && !$this->Auth->user('Role')['perm_site_admin']) throw new MethodNotAllowedException('You don\'t have permission to do that.');
|
||||
$this->Server->id = $id;
|
||||
|
@ -1163,6 +1177,10 @@ class ServersController extends AppController {
|
|||
$mismatch = false;
|
||||
$newer = false;
|
||||
$parts = array('major', 'minor', 'hotfix');
|
||||
if ($version[0] == 2 && $version[1] == 4 && $version[2] > 68) {
|
||||
$post = $this->Server->runPOSTTest($id);
|
||||
}
|
||||
$testPost = false;
|
||||
foreach ($parts as $k => $v) {
|
||||
if (!$mismatch) {
|
||||
if ($version[$k] > $local_version[$v]) {
|
||||
|
@ -1185,7 +1203,7 @@ class ServersController extends AppController {
|
|||
return new CakeResponse(array('body'=> json_encode($result)));
|
||||
}
|
||||
}
|
||||
return new CakeResponse(array('body'=> json_encode(array('status' => 1, 'local_version' => implode('.', $local_version), 'version' => implode('.', $version), 'mismatch' => $mismatch, 'newer' => $newer))));
|
||||
return new CakeResponse(array('body'=> json_encode(array('status' => 1, 'local_version' => implode('.', $local_version), 'version' => implode('.', $version), 'mismatch' => $mismatch, 'newer' => $newer, 'post' => isset($post) ? $post : 'too old'))));
|
||||
} else {
|
||||
$result['status'] = 3;
|
||||
}
|
||||
|
|
|
@ -2553,6 +2553,48 @@ class Server extends AppModel {
|
|||
}
|
||||
}
|
||||
|
||||
public function runPOSTtest($id) {
|
||||
$server = $this->find('first', array('conditions' => array('Server.id' => $id)));
|
||||
App::uses('SyncTool', 'Tools');
|
||||
$syncTool = new SyncTool();
|
||||
$HttpSocket = $syncTool->setupHttpSocket($server);
|
||||
$request = array(
|
||||
'header' => array(
|
||||
'Authorization' => $server['Server']['authkey'],
|
||||
'Accept' => 'application/json',
|
||||
'Content-Type' => 'application/json',
|
||||
)
|
||||
);
|
||||
$uri = $server['Server']['url'] . '/servers/postTest';
|
||||
try {
|
||||
$response = $HttpSocket->post($uri, json_encode(array('testString' => '##comma##')), $request);
|
||||
$response = json_decode($response, true);
|
||||
} catch (Exception $e) {
|
||||
$this->Log = ClassRegistry::init('Log');
|
||||
$this->Log->create();
|
||||
$this->Log->save(array(
|
||||
'org' => 'SYSTEM',
|
||||
'model' => 'Server',
|
||||
'model_id' => $id,
|
||||
'email' => 'SYSTEM',
|
||||
'action' => 'error',
|
||||
'user_id' => 0,
|
||||
'title' => 'Error: POST connection test failed. Reason: ' . json_encode($e->getMessage()),
|
||||
));
|
||||
return 8;
|
||||
}
|
||||
if (!isset($response['body']['testString']) || $response['body']['testString'] !== '##comma##') {
|
||||
return 9;
|
||||
}
|
||||
$headers = array('Accept', 'Content-type');
|
||||
foreach ($headers as $header) {
|
||||
if (!isset($response['headers'][$header]) || $response['headers'][$header] != 'application/json') {
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function checkVersionCompatibility($id, $user = array(), $HttpSocket = false) {
|
||||
// for event publishing when we don't have a user.
|
||||
if (empty($user)) $user = array('Organisation' => array('name' => 'SYSTEM'), 'email' => 'SYSTEM', 'id' => 0);
|
||||
|
|
|
@ -2261,10 +2261,27 @@ function testConnection(id) {
|
|||
else status_message = "Remote outdated, notify admin!"
|
||||
colours.status = 'class="' + issue_colour + '"';
|
||||
}
|
||||
if (result.post != false) {
|
||||
var post_colour = "red";
|
||||
if (result.post == 1) {
|
||||
post_colour = "green";
|
||||
post_result = "Received sent package";
|
||||
} else if (result.post == 8) {
|
||||
post_result = "Could not POST message";
|
||||
} else if (result.post == 9) {
|
||||
post_result = "Invalid headers";
|
||||
} else if (result.post == 10) {
|
||||
post_result = "Invalid body";
|
||||
} else {
|
||||
post_colour = "orange";
|
||||
post_result = "Remote too old for this test";
|
||||
}
|
||||
}
|
||||
resultDiv = '<div>Local version: <span ' + colours.local + '>' + result.local_version + '</span><br />';
|
||||
resultDiv += '<div>Remote version: <span ' + colours.remote + '>' + result.version + '</span><br />';
|
||||
resultDiv += '<div>Status: <span ' + colours.status + '>' + status_message + '</span><br />';
|
||||
resultDiv += '<div>Compatiblity: <span class="' + compatibility_colour + '">' + compatibility + '</span><br />';
|
||||
resultDiv += '<div>POST test: <span class="' + post_colour + '">' + post_result + '</span><br />';
|
||||
$("#connection_test_" + id).html(resultDiv);
|
||||
//$("#connection_test_" + id).html('<span class="green bold" title="Connection established, correct response received.">OK</span>');
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue