Server fixes and webapp trace support.

This commit is contained in:
Ylian Saint-Hilaire 2019-06-17 17:17:23 -07:00
parent 89f37973a0
commit aba9dc4e88
6 changed files with 31 additions and 14 deletions

View File

@ -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
};

View File

@ -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;
}

View File

@ -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', '<select id=d2inviteExpire style=width:236px onchange=d2RequestInvitationLink()><option value=1>1 hour</option><option value=8>8 hours</option><option value=24>1 day</option><option value=168>1 week</option><option value=5040>1 month</option><option value=0>Unlimited</option></select>');
x += '<div id=agentInvitationLinkDiv style="text-align:center;font-size:large;margin:16px;display:none"><a id=agentInvitationLink target="_blank" href="" style=cursor:pointer></a> <img src=images/link4.png height=10 width=10 title="Copy link to clipboard" style=cursor:pointer onclick=d2CopyInviteToClip()></div></div>';
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();
}

File diff suppressed because one or more lines are too long

View File

@ -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', '<select id=d2inviteExpire style=width:236px onchange=d2RequestInvitationLink()><option value=1>1 hour</option><option value=8>8 hours</option><option value=24>1 day</option><option value=168>1 week</option><option value=5040>1 month</option><option value=0>Unlimited</option></select>');
x += '<div id=agentInvitationLinkDiv style="text-align:center;font-size:large;margin:16px;display:none"><a id=agentInvitationLink target="_blank" href="" style=cursor:pointer></a> <img src=images/link4.png height=10 width=10 title="Copy link to clipboard" style=cursor:pointer onclick=d2CopyInviteToClip()></div></div>';
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();
}

View File

@ -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