Fixed MeshMessenger connection issue.

This commit is contained in:
Ylian Saint-Hilaire 2020-10-01 10:30:26 -07:00
parent 974214b9e9
commit d55c102a8f
3 changed files with 51 additions and 8 deletions

View File

@ -149,7 +149,11 @@ function createMeshCore(agent) {
}; };
this._daipc = c; this._daipc = c;
c.parent = this; c.parent = this;
c.on('end', function () { this.end(); this.parent._daipc = null; }); // TODO: Must call end() on self to close the named pipe correctly. c.on('end', function () {
this.end(); // TODO: Must call end() on self to close the named pipe correctly.
this.parent._daipc = null;
if (this._registered != null) { try { mesh.SendCommand({ action: 'sessions', type: 'app', value: {} }); } catch (e) { } }
});
c.on('data', function (chunk) { c.on('data', function (chunk) {
if (chunk.length < 4) { this.unshift(chunk); return; } if (chunk.length < 4) { this.unshift(chunk); return; }
var len = chunk.readUInt32LE(0); var len = chunk.readUInt32LE(0);
@ -162,6 +166,15 @@ function createMeshCore(agent) {
try { try {
switch (data.cmd) { switch (data.cmd) {
case 'register':
if (typeof data.value == 'string') {
this._registered = data.value;
var apps = {};
apps[data.value] = 1;
try { mesh.SendCommand({ action: 'sessions', type: 'app', value: apps }); } catch (e) { }
this._send({ cmd: 'serverstate', value: meshServerConnectionState, url: require('MeshAgent').ConnectedServer });
}
break;
case 'query': case 'query':
switch (data.value) { switch (data.value) {
case 'connection': case 'connection':
@ -3572,6 +3585,16 @@ function createMeshCore(agent) {
try { mesh.SendCommand({ action: 'sessions', type: 'msg', value: tunnelUserCount.msg }); } catch (e) { } try { mesh.SendCommand({ action: 'sessions', type: 'msg', value: tunnelUserCount.msg }); } catch (e) { }
} }
} }
// Send update to the registered application
if ((obj.DAIPC._daipc != null) && (obj.DAIPC._daipc._registered != null)) {
if (state == 1) {
var apps = {};
apps[obj.DAIPC._daipc._registered] = 1;
try { mesh.SendCommand({ action: 'sessions', type: 'app', value: apps }); } catch (e) { }
}
obj.DAIPC._daipc._send({ cmd: 'serverstate', value: meshServerConnectionState, url: require('MeshAgent').ConnectedServer });
}
} }
// Update the server with the latest network interface information // Update the server with the latest network interface information

View File

@ -1378,12 +1378,15 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
case 'sessions': { case 'sessions': {
// This is a list of sessions provided by the agent // This is a list of sessions provided by the agent
if (obj.sessions == null) { obj.sessions = {}; } if (obj.sessions == null) { obj.sessions = {}; }
if (typeof command.value != null) {
if (command.type == 'kvm') { obj.sessions.kvm = command.value; } if (command.type == 'kvm') { obj.sessions.kvm = command.value; }
else if (command.type == 'terminal') { obj.sessions.terminal = command.value; } else if (command.type == 'terminal') { obj.sessions.terminal = command.value; }
else if (command.type == 'files') { obj.sessions.files = command.value; } else if (command.type == 'files') { obj.sessions.files = command.value; }
else if (command.type == 'tcp') { obj.sessions.tcp = command.value; } else if (command.type == 'tcp') { obj.sessions.tcp = command.value; }
else if (command.type == 'udp') { obj.sessions.udp = command.value; } else if (command.type == 'udp') { obj.sessions.udp = command.value; }
else if (command.type == 'msg') { obj.sessions.msg = command.value; } else if (command.type == 'msg') { obj.sessions.msg = command.value; }
else if (command.type == 'app') { obj.sessions.app = command.value; }
}
obj.updateSessions(); obj.updateSessions();
break; break;
} }

View File

@ -46,7 +46,7 @@
var userInputFocus = 0; var userInputFocus = 0;
var socket = null; // Websocket object var socket = null; // Websocket object
var state = 0; // Connection state. 0 = Disconnected, 1 = Connecting, 2 = Connected. var state = 0; // Connection state. 0 = Disconnected, 1 = Connecting, 2 = Connected.
var args = parseUriArgs(); var args = XparseUriArgs();
if (args.key && (isAlphaNumeric(args.key) == false)) { delete args.key; } if (args.key && (isAlphaNumeric(args.key) == false)) { delete args.key; }
if (args.locale && (isAlphaNumeric(args.locale) == false)) { delete args.locale; } if (args.locale && (isAlphaNumeric(args.locale) == false)) { delete args.locale; }
@ -656,6 +656,23 @@
if (socket != null) { try { socket.close(); } catch (e) { } socket = null; } if (socket != null) { try { socket.close(); } catch (e) { } socket = null; }
} }
function isSafeString3(str) { return ((typeof str == 'string') && (str.indexOf('<') == -1) && (str.indexOf('>') == -1) && (str.indexOf('&') == -1) && (str.indexOf('"') == -1) && (str.indexOf('\'') == -1) && (str.indexOf('+') == -1) && (str.indexOf('(') == -1) && (str.indexOf(')') == -1) && (str.indexOf('#') == -1) && (str.indexOf(':') == -1)) };
// Parse URL arguments, only keep safe values
function XparseUriArgs() {
var href = window.document.location.href;
if (href.endsWith('#')) { href = href.substring(0, href.length - 1); }
var name, r = {}, parsedUri = href.split(/[\?&|]/);
parsedUri.splice(0, 1);
for (var j in parsedUri) {
var arg = parsedUri[j], i = arg.indexOf('=');
name = arg.substring(0, i);
r[name] = arg.substring(i + 1);
if (!isSafeString3(r[name])) { delete r[name]; } else { var x = parseInt(r[name]); if (x == r[name]) { r[name] = x; } }
}
return r;
}
</script> </script>
</body> </body>
</html> </html>