mirror of https://github.com/MISP/MISP
Version negotiation
parent
62094989c9
commit
ee3e2b0007
|
@ -757,4 +757,18 @@ class ServersController extends AppController {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The server responds with its current version
|
||||
public function getVersion() {
|
||||
if (!$this->Auth->user('Role')['perm_sync']) throw new MethodNotAllowedException('Only accessible by sync users');
|
||||
App::uses('Folder', 'Utility');
|
||||
$file = new File (ROOT . DS . 'VERSION.json', true);
|
||||
$version_json = $file->read();
|
||||
$file->close();
|
||||
return new CakeResponse(array('body'=> $version_json));
|
||||
}
|
||||
|
||||
public function checkVersionCompatibility($id) {
|
||||
debug($this->Server->checkVersionCompatibility($id));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1189,4 +1189,25 @@ class Server extends AppModel {
|
|||
return array('status' => 3);
|
||||
}
|
||||
}
|
||||
|
||||
public function checkVersionCompatibility($id, $HttpSocket = false) {
|
||||
App::uses('Folder', 'Utility');
|
||||
$file = new File (ROOT . DS . 'VERSION.json', true);
|
||||
$version_array = json_decode($file->read());
|
||||
$file->close();
|
||||
|
||||
$server = $this->find('first', array('conditions' => array('Server.id' => $id)));
|
||||
if (!$HttpSocket) {
|
||||
App::uses('SyncTool', 'Tools');
|
||||
$syncTool = new SyncTool();
|
||||
$HttpSocket = $syncTool->setupHttpSocket($server);
|
||||
}
|
||||
$uri = $server['Server']['url'] . '/servers/getVersion';
|
||||
try {
|
||||
$response = $HttpSocket->get($uri);
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
return (json_decode($response));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue