mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-11-22 12:52:50 +03:00
Fixed Server Peering, now requires SessionKey.
This commit is contained in:
parent
a6f3ec7b7f
commit
ddb429fcce
@ -1497,6 +1497,7 @@ function CreateMeshCentralServer(config, args) {
|
||||
obj.multiServer = require('./multiserver.js').CreateMultiServer(obj, obj.args);
|
||||
if (obj.multiServer != null) {
|
||||
if ((obj.db.databaseType != 3) || (obj.db.changeStream != true)) { console.log("ERROR: Multi-server support requires use of MongoDB with ReplicaSet and ChangeStream enabled."); process.exit(0); return; }
|
||||
if (typeof obj.args.sessionkey != 'string') { console.log("ERROR: Multi-server support requires \"SessionKey\" be set in the settings section of config.json, same key for all servers."); process.exit(0); return; }
|
||||
obj.serverId = obj.multiServer.serverid;
|
||||
for (var serverid in obj.config.peers.servers) { obj.peerConnectivityByNode[serverid] = {}; }
|
||||
}
|
||||
@ -1506,7 +1507,7 @@ function CreateMeshCentralServer(config, args) {
|
||||
|
||||
// Set the session length to 60 minutes if not set and set a random key if needed
|
||||
if ((obj.args.sessiontime != null) && ((typeof obj.args.sessiontime != 'number') || (obj.args.sessiontime < 1))) { delete obj.args.sessiontime; }
|
||||
if (!obj.args.sessionkey) { obj.args.sessionkey = buf.toString('hex').toUpperCase(); }
|
||||
if (typeof obj.args.sessionkey != 'string') { obj.args.sessionkey = buf.toString('hex').toUpperCase(); }
|
||||
|
||||
// Create MQTT Broker to hook into webserver and mpsserver
|
||||
if ((typeof obj.config.settings.mqtt == 'object') && (typeof obj.config.settings.mqtt.auth == 'object') && (typeof obj.config.settings.mqtt.auth.keyid == 'string') && (typeof obj.config.settings.mqtt.auth.key == 'string')) { obj.mqttbroker = require("./mqttbroker.js").CreateMQTTBroker(obj, obj.db, obj.args); }
|
||||
|
@ -463,7 +463,7 @@ module.exports.CreateMultiServer = function (parent, args) {
|
||||
// Process a message coming from a peer server
|
||||
obj.ProcessPeerServerMessage = function (server, peerServerId, msg) {
|
||||
var userid, i;
|
||||
//console.log('ProcessPeerServerMessage', peerServerId, msg);
|
||||
//console.log('ProcessPeerServerMessage', peerServerId, msg.action);
|
||||
switch (msg.action) {
|
||||
case 'mqtt': {
|
||||
if ((obj.parent.mqttbroker != null) && (msg.nodeid != null)) { obj.parent.mqttbroker.publishNoPeers(msg.nodeid, msg.topic, msg.message); } // Dispatch in the MQTT broker
|
||||
@ -531,7 +531,7 @@ module.exports.CreateMultiServer = function (parent, args) {
|
||||
if (peerServerId > obj.parent.serverId) {
|
||||
// We must initiate the connection to the peer
|
||||
userid = null;
|
||||
if (rsession.peer1.req.session != null) { userid = rsession.peer1.req.session.userid; } // TODO: Seems like there is a race condition here, need to investigate.
|
||||
if (rsession.peer1.user != null) { userid = rsession.peer1.user._id; }
|
||||
obj.createPeerRelay(rsession.peer1.ws, rsession.peer1.req, peerServerId, userid);
|
||||
delete obj.parent.webserver.wsrelays[msg.id];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user