Server fixes.

Ylian Saint-Hilaire committed Jun 17, 2019 at 15:20 UTC 4f043f7c215f07168d37dd92229a575cfe30fcea
6 files changed +62 -26
meshagent.js
+9 -3
@@ -29,7 +29,8 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
29 obj.remoteaddr = (req.ip.startsWith('::ffff:')) ? (req.ip.substring(7)) : req.ip;
30 obj.remoteaddrport = obj.remoteaddr + ':' + ws._socket.remotePort;
31 obj.nonce = parent.crypto.randomBytes(48).toString('binary');
32 - ws._socket.setKeepAlive(true, 240000); // Set TCP keep alive, 4 minutes
32 + //ws._socket.setKeepAlive(true, 240000); // Set TCP keep alive, 4 minutes
33 + if (args.agentidletimeout != 0) { ws._socket.setTimeout(args.agentidletimeout, function () { obj.close(1); }); } // Inactivity timeout of 2:30 minutes, by default agent will WebSocket ping every 2 minutes and server will pong back.
34 //obj.nodeid = null;
35 //obj.meshid = null;
36 //obj.dbNodeKey = null;
@@ -795,8 +796,13 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
796
797 // Check if we need to make an native update check
798 obj.agentExeInfo = parent.parent.meshAgentBinaries[obj.agentInfo.agentId];
798 - const corename = parent.parent.meshAgentsArchitectureNumbers[obj.agentInfo.agentId].core;
799 - if (corename == null) { obj.send(common.ShortToStr(10) + common.ShortToStr(0)); } // MeshCommand_CoreModule, ask mesh agent to clear the core
799 + var corename = null;
800 + if (parent.parent.meshAgentsArchitectureNumbers[obj.agentInfo.agentId] != null) {
801 + corename = parent.parent.meshAgentsArchitectureNumbers[obj.agentInfo.agentId].core;
802 + } else {
803 + // MeshCommand_CoreModule, ask mesh agent to clear the core
804 + obj.send(common.ShortToStr(10) + common.ShortToStr(0));
805 + }
806
807 if ((obj.agentExeInfo != null) && (obj.agentExeInfo.update == true)) {
808 // Ask the agent for it's executable binary hash
meshcentral.js
+1
@@ -604,6 +604,7 @@ function CreateMeshCentralServer(config, args) {
604 if (obj.args.mpsaliasport != null && (typeof obj.args.mpsaliasport != 'number')) obj.args.mpsaliasport = null;
605 if (obj.args.notls == null && obj.args.redirport == null) obj.args.redirport = 80;
606 if (obj.args.minifycore === 0) obj.args.minifycore = false;
607 + if (typeof args.agentidletimeout != 'number') { args.agentidletimeout = 150000; } else { args.agentidletimeout *= 1000 } // Default agent idle timeout is 2m, 30sec.
608
609 // Setup a site administrator
610 if ((obj.args.admin) && (typeof obj.args.admin == 'string')) {
package.json
+1 -1
@@ -1,6 +1,6 @@
1 {
2 "name": "meshcentral",
3 - "version": "0.3.6-n",
3 + "version": "0.3.6-o",
4 "keywords": [
5 "Remote Management",
6 "Intel AMT",
sample-config.json
+1
@@ -23,6 +23,7 @@
23 "_SelfUpdate": true,
24 "_AgentPing": 60,
25 "_AgentPong": 60,
26 + "_AgentIdleTimeout": 150,
27 "_AllowHighQualityDesktop": true,
28 "_UserAllowedIP": "127.0.0.1,192.168.1.0/24",
29 "_UserBlockedIP": "127.0.0.1,::1,192.168.0.100",
views/default-min.handlebars
+25 -11
@@ -8909,16 +8909,23 @@ var QRCode;!function(){function a(a){this.mode=c.MODE_8BIT_BYTE,this.data=a,this
8909 flag = Q('aginsSelect').value;
8910 if (parseInt(flag) >= 5) { name = name.toLowerCase(); } else { name += '.exe'; }
8911 }
8912 - try { xdr = new XDomainRequest(); } catch (e) { }
8913 - if (!xdr) xdr = new XMLHttpRequest();
8914 - xdr.open("GET", window.location.href + path + flag);
8915 - xdr.timeout = 15000;
8916 - xdr.responseType = "blob";
8917 - xdr.onprogress = function (x) { /*console.log(x);*/ };
8918 - xdr.onload = function (e) { saveAs(new Blob([e.target.response], { type: "application/octet-stream" }), name); if (xxdialogTag == 'fileDownload') { setDialogMode(0); } };
8919 - xdr.onerror = function () { if (xxdialogTag == 'fileDownload') { setDialogMode(0); } alert('Agent downloads timeout.'); };
8920 - xdr.ontimeout = function () { if (xxdialogTag == 'fileDownload') { setDialogMode(0); } alert('Unable to download agent.'); };
8921 - xdr.send();
8912 +
8913 + if (args.filedownloadtab == 1) {
8914 + // Open a new tab with download
8915 + window.open(window.location.origin + '/' + path + flag, '_blank');
8916 + } else {
8917 + // Background download & save
8918 + try { xdr = new XDomainRequest(); } catch (e) { }
8919 + if (!xdr) xdr = new XMLHttpRequest();
8920 + xdr.open("GET", window.location.origin + '/' + path + flag);
8921 + xdr.timeout = 15000;
8922 + xdr.responseType = "blob";
8923 + xdr.onprogress = function (x) { /*console.log(x);*/ };
8924 + xdr.onload = function (e) { saveAs(new Blob([e.target.response], { type: "application/octet-stream" }), name); if (xxdialogTag == 'fileDownload') { setDialogMode(0); } };
8925 + xdr.onerror = function () { if (xxdialogTag == 'fileDownload') { setDialogMode(0); } alert('Agent downloads timeout.'); };
8926 + xdr.ontimeout = function () { if (xxdialogTag == 'fileDownload') { setDialogMode(0); } alert('Unable to download agent.'); };
8927 + xdr.send();
8928 + }
8929 }
8930
8931 function addAgentToMeshClick() {
@@ -10047,6 +10054,11 @@ var QRCode;!function(){function a(a){this.mode=c.MODE_8BIT_BYTE,this.data=a,this
10054
10055 // Update the web page title
10056 if ((currentNode) && (xxcurrentView >= 10) && (xxcurrentView < 20)) { document.title = decodeURIComponent("{{{extitle}}}") + ' - ' + currentNode.name; } else { document.title = decodeURIComponent("{{{extitle}}}"); }
10057 +
10058 + // Clear user consent status if present
10059 + p11clearConsoleMsg();
10060 + p12clearConsoleMsg();
10061 + p13clearConsoleMsg();
10062 }
10063 setupDesktop(); // Always refresh the desktop, even if we are on the same device, we need to do some canvas switching.
10064 if (!panel) panel = 10;
@@ -10529,6 +10541,7 @@ var QRCode;!function(){function a(a){this.mode=c.MODE_8BIT_BYTE,this.data=a,this
10541 function autoConnectDesktop(e) { if (autoConnectDesktopTimer == null) { autoConnectDesktopTimer = setInterval(connectDesktop, 100); } else { clearInterval(autoConnectDesktopTimer); autoConnectDesktopTimer = null; } }
10542
10543 function connectDesktop(e, contype) {
10544 + p11clearConsoleMsg();
10545 if (desktop == null) {
10546 desktopNode = currentNode;
10547 if (contype == 2) {
@@ -11122,6 +11135,7 @@ var QRCode;!function(){function a(a){this.mode=c.MODE_8BIT_BYTE,this.data=a,this
11135 function autoConnectTerminal(e) { if (autoConnectTerminalTimer == null) { autoConnectTerminalTimer = setInterval(connectTerminal, 100); } else { clearInterval(autoConnectTerminalTimer); autoConnectTerminalTimer = null; } }
11136
11137 function connectTerminal(e, contype) {
11138 + p12clearConsoleMsg();
11139 if (!terminal) {
11140 if (contype == 2) {
11141 // Setup the Intel AMT terminal
@@ -11156,7 +11170,6 @@ var QRCode;!function(){function a(a){this.mode=c.MODE_8BIT_BYTE,this.data=a,this
11170 terminal.attemptWebRTC = attemptWebRTC;
11171 terminal.onStateChanged = onTerminalStateChange;
11172 terminal.onConsoleMessageChange = function () {
11159 - console.log('terminal.consoleMessage', terminal.consoleMessage);
11173 p12clearConsoleMsg();
11174 if (terminal.consoleMessage) {
11175 QH('p12TermConsoleMsg', EscapeHtml(terminal.consoleMessage).split('\n').join('<br />'));
@@ -11278,6 +11291,7 @@ var QRCode;!function(){function a(a){this.mode=c.MODE_8BIT_BYTE,this.data=a,this
11291 function autoConnectFiles(e) { if (autoConnectFilesTimer == null) { autoConnectFilesTimer = setInterval(connectFiles, 100); } else { clearInterval(autoConnectFilesTimer); autoConnectFilesTimer = null; } }
11292
11293 function connectFiles(e) {
11294 + p13clearConsoleMsg();
11295 if (!files) {
11296 // Setup a mesh agent files
11297 files = CreateAgentRedirect(meshserver, CreateRemoteFiles(p13gotFiles), serverPublicNamePort, authCookie, domainUrl);
views/default.handlebars
+25 -11
@@ -2861,16 +2861,23 @@
2861 flag = Q('aginsSelect').value;
2862 if (parseInt(flag) >= 5) { name = name.toLowerCase(); } else { name += '.exe'; }
2863 }
2864 - try { xdr = new XDomainRequest(); } catch (e) { }
2865 - if (!xdr) xdr = new XMLHttpRequest();
2866 - xdr.open("GET", window.location.href + path + flag);
2867 - xdr.timeout = 15000;
2868 - xdr.responseType = "blob";
2869 - xdr.onprogress = function (x) { /*console.log(x);*/ };
2870 - xdr.onload = function (e) { saveAs(new Blob([e.target.response], { type: "application/octet-stream" }), name); if (xxdialogTag == 'fileDownload') { setDialogMode(0); } };
2871 - xdr.onerror = function () { if (xxdialogTag == 'fileDownload') { setDialogMode(0); } alert('Agent downloads timeout.'); };
2872 - xdr.ontimeout = function () { if (xxdialogTag == 'fileDownload') { setDialogMode(0); } alert('Unable to download agent.'); };
2873 - xdr.send();
2864 +
2865 + if (args.filedownloadtab == 1) {
2866 + // Open a new tab with download
2867 + window.open(window.location.origin + '/' + path + flag, '_blank');
2868 + } else {
2869 + // Background download & save
2870 + try { xdr = new XDomainRequest(); } catch (e) { }
2871 + if (!xdr) xdr = new XMLHttpRequest();
2872 + xdr.open("GET", window.location.origin + '/' + path + flag);
2873 + xdr.timeout = 15000;
2874 + xdr.responseType = "blob";
2875 + xdr.onprogress = function (x) { /*console.log(x);*/ };
2876 + xdr.onload = function (e) { saveAs(new Blob([e.target.response], { type: "application/octet-stream" }), name); if (xxdialogTag == 'fileDownload') { setDialogMode(0); } };
2877 + xdr.onerror = function () { if (xxdialogTag == 'fileDownload') { setDialogMode(0); } alert('Agent downloads timeout.'); };
2878 + xdr.ontimeout = function () { if (xxdialogTag == 'fileDownload') { setDialogMode(0); } alert('Unable to download agent.'); };
2879 + xdr.send();
2880 + }
2881 }
2882
2883 function addAgentToMeshClick() {
@@ -3999,6 +4006,11 @@
4006
4007 // Update the web page title
4008 if ((currentNode) && (xxcurrentView >= 10) && (xxcurrentView < 20)) { document.title = decodeURIComponent("{{{extitle}}}") + ' - ' + currentNode.name; } else { document.title = decodeURIComponent("{{{extitle}}}"); }
4009 +
4010 + // Clear user consent status if present
4011 + p11clearConsoleMsg();
4012 + p12clearConsoleMsg();
4013 + p13clearConsoleMsg();
4014 }
4015 setupDesktop(); // Always refresh the desktop, even if we are on the same device, we need to do some canvas switching.
4016 if (!panel) panel = 10;
@@ -4481,6 +4493,7 @@
4493 function autoConnectDesktop(e) { if (autoConnectDesktopTimer == null) { autoConnectDesktopTimer = setInterval(connectDesktop, 100); } else { clearInterval(autoConnectDesktopTimer); autoConnectDesktopTimer = null; } }
4494
4495 function connectDesktop(e, contype) {
4496 + p11clearConsoleMsg();
4497 if (desktop == null) {
4498 desktopNode = currentNode;
4499 if (contype == 2) {
@@ -5074,6 +5087,7 @@
5087 function autoConnectTerminal(e) { if (autoConnectTerminalTimer == null) { autoConnectTerminalTimer = setInterval(connectTerminal, 100); } else { clearInterval(autoConnectTerminalTimer); autoConnectTerminalTimer = null; } }
5088
5089 function connectTerminal(e, contype) {
5090 + p12clearConsoleMsg();
5091 if (!terminal) {
5092 if (contype == 2) {
5093 // Setup the Intel AMT terminal
@@ -5108,7 +5122,6 @@
5122 terminal.attemptWebRTC = attemptWebRTC;
5123 terminal.onStateChanged = onTerminalStateChange;
5124 terminal.onConsoleMessageChange = function () {
5111 - console.log('terminal.consoleMessage', terminal.consoleMessage);
5125 p12clearConsoleMsg();
5126 if (terminal.consoleMessage) {
5127 QH('p12TermConsoleMsg', EscapeHtml(terminal.consoleMessage).split('\n').join('<br />'));
@@ -5230,6 +5243,7 @@
5243 function autoConnectFiles(e) { if (autoConnectFilesTimer == null) { autoConnectFilesTimer = setInterval(connectFiles, 100); } else { clearInterval(autoConnectFilesTimer); autoConnectFilesTimer = null; } }
5244
5245 function connectFiles(e) {
5246 + p13clearConsoleMsg();
5247 if (!files) {
5248 // Setup a mesh agent files
5249 files = CreateAgentRedirect(meshserver, CreateRemoteFiles(p13gotFiles), serverPublicNamePort, authCookie, domainUrl);