From aba9dc4e88143d15b907b07e8be35f224be031f1 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Mon, 17 Jun 2019 17:17:23 -0700 Subject: [PATCH] Server fixes and webapp trace support. --- meshcentral.js | 1 + public/scripts/meshcentral.js | 9 ++++++++- views/default-min.handlebars | 17 +++++++++++------ views/default-mobile-min.handlebars | 2 +- views/default.handlebars | 8 +++----- webserver.js | 8 +++++++- 6 files changed, 31 insertions(+), 14 deletions(-) diff --git a/meshcentral.js b/meshcentral.js index 8b8df868..bc99000f 100644 --- a/meshcentral.js +++ b/meshcentral.js @@ -1473,6 +1473,7 @@ function CreateMeshCentralServer(config, args) { 24: { id: 24, localname: 'meshagent_arm-linaro', rname: 'meshagent', desc: 'Linux ARM Linaro', update: true, amt: false, platform: 'linux', core: 'linux-noamt', rcore: 'linux-recovery', arcore: 'linux-agentrecovery' }, 25: { id: 25, localname: 'meshagent_armhf', rname: 'meshagent', desc: 'Linux ARM - HardFloat', update: true, amt: false, platform: 'linux', core: 'linux-noamt', rcore: 'linux-recovery', arcore: 'linux-agentrecovery' }, // "armv6l" and "armv7l" 26: { id: 26, localname: 'meshagent_arm64', rname: 'meshagent', desc: 'Linux ARMv8-64', update: true, amt: false, platform: 'linux', core: 'linux-noamt', rcore: 'linux-recovery', arcore: 'linux-agentrecovery' }, // "aarch64" + 30: { id: 30, localname: 'meshagent_freebsd64', rname: 'meshagent', desc: 'FreeBSD x86-64', update: true, amt: false, platform: 'freebsd', core: 'linux-noamt', rcore: 'linux-recovery', arcore: 'linux-agentrecovery' }, // FreeBSD x64 10003: { id: 3, localname: 'MeshService.exe', rname: 'meshagent.exe', desc: 'Windows x86-32 service', update: true, amt: true, platform: 'win32', core: 'windows-amt', rcore: 'linux-recovery', arcore: 'linux-agentrecovery' }, // Unsigned version of the Windows MeshAgent x86 10004: { id: 4, localname: 'MeshService64.exe', rname: 'meshagent.exe', desc: 'Windows x86-64 service', update: true, amt: true, platform: 'win32', core: 'windows-amt', rcore: 'linux-recovery', arcore: 'linux-agentrecovery' } // Unsigned version of the Windows MeshAgent x64 }; diff --git a/public/scripts/meshcentral.js b/public/scripts/meshcentral.js index 73cc13ee..08188510 100644 --- a/public/scripts/meshcentral.js +++ b/public/scripts/meshcentral.js @@ -10,6 +10,7 @@ var MeshServerCreateControl = function (domain, authCookie) { obj.connectstate = 0; obj.pingTimer = null; obj.authCookie = authCookie; + obj.trace = false; obj.xxStateChange = function (newstate, errCode) { if (obj.State == newstate) return; @@ -46,10 +47,16 @@ var MeshServerCreateControl = function (domain, authCookie) { try { message = JSON.parse(e.data); } catch (e) { return; } if ((typeof message != 'object') || (message.action == 'pong')) { return; } if (message.action == 'close') { if (message.msg) { console.log(message.msg); } obj.Stop(message.cause); return; } + if (obj.trace) { console.log('RECV', message); } if (obj.onMessage) obj.onMessage(obj, message); }; - obj.send = function (x) { if (obj.socket != null && obj.connectstate == 1) { obj.socket.send(JSON.stringify(x)); } } + obj.send = function (x) { + if (obj.socket != null && obj.connectstate == 1) { + if (obj.trace) { console.log('SEND', x); } + obj.socket.send(JSON.stringify(x)); + } + } return obj; } diff --git a/views/default-min.handlebars b/views/default-min.handlebars index 2cacedff..67f364f4 100644 --- a/views/default-min.handlebars +++ b/views/default-min.handlebars @@ -111,6 +111,7 @@ var MeshServerCreateControl = function (domain, authCookie) { obj.connectstate = 0; obj.pingTimer = null; obj.authCookie = authCookie; + obj.trace = false; obj.xxStateChange = function (newstate, errCode) { if (obj.State == newstate) return; @@ -147,10 +148,16 @@ var MeshServerCreateControl = function (domain, authCookie) { try { message = JSON.parse(e.data); } catch (e) { return; } if ((typeof message != 'object') || (message.action == 'pong')) { return; } if (message.action == 'close') { if (message.msg) { console.log(message.msg); } obj.Stop(message.cause); return; } + if (obj.trace) { console.log('RECV', message); } if (obj.onMessage) obj.onMessage(obj, message); }; - obj.send = function (x) { if (obj.socket != null && obj.connectstate == 1) { obj.socket.send(JSON.stringify(x)); } } + obj.send = function (x) { + if (obj.socket != null && obj.connectstate == 1) { + if (obj.trace) { console.log('SEND', x); } + obj.socket.send(JSON.stringify(x)); + } + } return obj; } @@ -7061,6 +7068,7 @@ var QRCode;!function(){function a(a){this.mode=c.MODE_8BIT_BYTE,this.data=a,this meshserver = MeshServerCreateControl(domainUrl, authCookie); meshserver.onStateChanged = onStateChanged; meshserver.onMessage = onMessage; + meshserver.trace = (args.trace == 1); meshserver.Start(); // Setup page controls @@ -7077,7 +7085,6 @@ var QRCode;!function(){function a(a){this.mode=c.MODE_8BIT_BYTE,this.data=a,this for (var j = 1; j < 5; j++) { Q('devViewButton' + j).classList.remove('viewSelectorSel'); } Q('devViewButton' + Q('viewselect').value).classList.add('viewSelectorSel'); - // Setup upload drag & drop Q('p5filetable').addEventListener("drop", p5fileDragDrop, false); Q('p5filetable').addEventListener("dragover", p5fileDragOver, false); @@ -7350,7 +7357,6 @@ var QRCode;!function(){function a(a){this.mode=c.MODE_8BIT_BYTE,this.data=a,this } function onMessage(server, message) { - if (args.trace == 1) { console.log('MSG:', message); } switch (message.action) { case 'serverstats': { updateGeneralServerStats(message); @@ -8771,8 +8777,7 @@ var QRCode;!function(){function a(a){this.mode=c.MODE_8BIT_BYTE,this.data=a,this x += addHtmlValue('Link Expiration', ''); x += ''; setDialogMode(2, "Invite", 3, performAgentInvite, x, meshid); - d2ChangedInviteType(); - validateAgentInvite(); + if (features & 64) { d2ChangedInviteType(); } else { validateAgentInvite(); } d2RequestInvitationLink(); } @@ -8783,7 +8788,7 @@ var QRCode;!function(){function a(a){this.mode=c.MODE_8BIT_BYTE,this.data=a,this function d2ChangedInviteType() { QV('urlInviteDiv', Q('d2InviteType').value == 0); QV('d2agentexpirediv', Q('agentInviteNameOs').value == 4); - if (features & 64) { QV('emailInviteDiv', Q('d2InviteType').value == 1); } + QV('emailInviteDiv', Q('d2InviteType').value == 1); validateAgentInvite(); } diff --git a/views/default-mobile-min.handlebars b/views/default-mobile-min.handlebars index 66eac647..8ac47c0a 100644 --- a/views/default-mobile-min.handlebars +++ b/views/default-mobile-min.handlebars @@ -1 +1 @@ - {{{title}}}
{{{title}}}
{{{title2}}}
\ No newline at end of file + {{{title}}}
{{{title}}}
{{{title2}}}
\ No newline at end of file diff --git a/views/default.handlebars b/views/default.handlebars index 263c7bf7..2610314f 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -1013,6 +1013,7 @@ meshserver = MeshServerCreateControl(domainUrl, authCookie); meshserver.onStateChanged = onStateChanged; meshserver.onMessage = onMessage; + meshserver.trace = (args.trace == 1); meshserver.Start(); // Setup page controls @@ -1029,7 +1030,6 @@ for (var j = 1; j < 5; j++) { Q('devViewButton' + j).classList.remove('viewSelectorSel'); } Q('devViewButton' + Q('viewselect').value).classList.add('viewSelectorSel'); - // Setup upload drag & drop Q('p5filetable').addEventListener("drop", p5fileDragDrop, false); Q('p5filetable').addEventListener("dragover", p5fileDragOver, false); @@ -1302,7 +1302,6 @@ } function onMessage(server, message) { - if (args.trace == 1) { console.log('MSG:', message); } switch (message.action) { case 'serverstats': { updateGeneralServerStats(message); @@ -2723,8 +2722,7 @@ x += addHtmlValue('Link Expiration', ''); x += ''; setDialogMode(2, "Invite", 3, performAgentInvite, x, meshid); - d2ChangedInviteType(); - validateAgentInvite(); + if (features & 64) { d2ChangedInviteType(); } else { validateAgentInvite(); } d2RequestInvitationLink(); } @@ -2735,7 +2733,7 @@ function d2ChangedInviteType() { QV('urlInviteDiv', Q('d2InviteType').value == 0); QV('d2agentexpirediv', Q('agentInviteNameOs').value == 4); - if (features & 64) { QV('emailInviteDiv', Q('d2InviteType').value == 1); } + QV('emailInviteDiv', Q('d2InviteType').value == 1); validateAgentInvite(); } diff --git a/webserver.js b/webserver.js index 3844fee0..fe86e449 100644 --- a/webserver.js +++ b/webserver.js @@ -1722,7 +1722,13 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) { if (splitUrl.length > 1) { urlArgs = '?' + splitUrl[1]; } if ((splitUrl.length > 0) && (splitUrl[0].length > 1)) { urlName = splitUrl[0].substring(1).toLowerCase(); } if ((urlName == null) || (domain.redirects[urlName] == null) || (urlName[0] == '_')) { res.sendStatus(404); return; } - res.redirect(domain.redirects[urlName] + urlArgs + getQueryPortion(req)); + if (domain.redirects[urlName] == '~showversion') { + // Show the current version + res.end('MeshCentral v' + obj.parent.currentVer); + } else { + // Perform redirection + res.redirect(domain.redirects[urlName] + urlArgs + getQueryPortion(req)); + } } // Take a "user/domain/userid/path/file" format and return the actual server disk file path if access is allowed