Added server redirection and unlimited invite URL's.
Ylian Saint-Hilaire committed
Jun 7, 2019 at 10:20 UTC
eb1c6d3a48f8ecfd7e686ac8818db55c35645bb6
6 files changed
+23
-5
meshcentral.js
+2
-2
@@ -1555,7 +1555,7 @@ function CreateMeshCentralServer(config, args) {
1555
if ((o.dtime > (timeout * 60000)) || (o.dtime < -30000)) { obj.debug(1, 'ERR: Bad cookie due to timeout'); return null; } // The cookie is only valid 120 seconds, or 30 seconds back in time (in case other server's clock is not quite right)
1556
} else {
1557
// An expire time is included in the cookie (in minutes), use this.
1558
- if ((o.dtime > (o.expire * 60000)) || (o.dtime < -30000)) { obj.debug(1, 'ERR: Bad cookie due to timeout'); return null; } // The cookie is only valid 120 seconds, or 30 seconds back in time (in case other server's clock is not quite right)
1558
+ if ((o.expire !== 0) && ((o.dtime > (o.expire * 60000)) || (o.dtime < -30000))) { obj.debug(1, 'ERR: Bad cookie due to timeout'); return null; } // The cookie is only valid 120 seconds, or 30 seconds back in time (in case other server's clock is not quite right)
1559
}
1560
return o;
1561
} catch (ex) { obj.debug(1, 'ERR: Bad AESGCM cookie due to exception: ' + ex); return null; }
@@ -1583,7 +1583,7 @@ function CreateMeshCentralServer(config, args) {
1583
if ((o.dtime > (timeout * 60000)) || (o.dtime < -30000)) { obj.debug(1, 'ERR: Bad cookie due to timeout'); return null; } // The cookie is only valid 120 seconds, or 30 seconds back in time (in case other server's clock is not quite right)
1584
} else {
1585
// An expire time is included in the cookie (in minutes), use this.
1586
- if ((o.dtime > (o.expire * 60000)) || (o.dtime < -30000)) { obj.debug(1, 'ERR: Bad cookie due to timeout'); return null; } // The cookie is only valid 120 seconds, or 30 seconds back in time (in case other server's clock is not quite right)
1586
+ if ((o.expire !== 0) && ((o.dtime > (o.expire * 60000)) || (o.dtime < -30000))) { obj.debug(1, 'ERR: Bad cookie due to timeout'); return null; } // The cookie is only valid 120 seconds, or 30 seconds back in time (in case other server's clock is not quite right)
1587
}
1588
return o;
1589
} catch (ex) { obj.debug(1, 'ERR: Bad AESSHA cookie due to exception: ' + ex); return null; }
meshuser.js
+1
-1
@@ -2501,7 +2501,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
2501
}
2502
case 'createInviteLink': {
2503
if (common.validateString(command.meshid, 8, 128) == false) break; // Check the meshid
2504
- if (common.validateInt(command.expire, 1, 99999) == false) break; // Check the expire time in hours
2504
+ if (common.validateInt(command.expire, 0, 99999) == false) break; // Check the expire time in hours
2505
if (common.validateInt(command.flags, 0, 256) == false) break; // Check the flags
2506
var mesh = parent.meshes[command.meshid];
2507
if (mesh == null) break;
package.json
+1
-1
@@ -1,6 +1,6 @@
1
{
2
"name": "meshcentral",
3
- "version": "0.3.6-d",
3
+ "version": "0.3.6-e",
4
"keywords": [
5
"Remote Management",
6
"Intel AMT",
sample-config.json
+3
@@ -46,6 +46,9 @@
46
"keepLastDaysBackup": 10,
47
"zipPassword": "MyReallySecretPassword3",
48
"_backupPath": "C:\\backups"
49
+ },
50
+ "_Redirects": {
51
+ "meshcommander": "https://www.meshcommander.com/"
52
}
53
},
54
"_domains": {
views/default.handlebars
+2
-1
@@ -1998,6 +1998,7 @@
1998
if (message.expire == 24) { t = '1 day'; }
1999
if (message.expire == 168) { t = '1 week'; }
2000
if (message.expire == 5040) { t = '1 month'; }
2001
+ if (message.expire == 0) { t = 'Unlimited'; }
2002
QH('agentInvitationLink', 'Invitation Link (' + t + ')');
2003
QV('agentInvitationLinkDiv', true);
2004
break;
@@ -2708,7 +2709,7 @@
2709
x += '</div>';
2710
}
2711
x += '<div id=urlInviteDiv>Invite someone to install the mesh agent by sharing a invitation link. This link points the user to installation instructions for the \"' + EscapeHtml(mesh.name) + '\" device group. The link is public and no account this server is needed.<br /><br />';
2711
- 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></select>');
2712
+ 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>');
2713
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>';
2714
setDialogMode(2, "Invite", 3, performAgentInvite, x, meshid);
2715
validateAgentInvite();
webserver.js
+14
@@ -1699,6 +1699,17 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
1699
}
1700
}
1701
1702
+ // Handle domain redirection
1703
+ function handleDomainRedirect(req, res) {
1704
+ const domain = checkUserIpAddress(req, res);
1705
+ if ((domain == null) || (domain.redirects == null)) { res.sendStatus(404); return; }
1706
+ var urlArgs = '', urlName = null, splitUrl = req.originalUrl.split("?");
1707
+ if (splitUrl.length > 1) { urlArgs = '?' + splitUrl[1]; }
1708
+ if ((splitUrl.length > 0) && (splitUrl[0].length > 1)) { urlName = splitUrl[0].substring(1).toLowerCase(); }
1709
+ if ((urlName == null) || (domain.redirects[urlName] == null)) { res.sendStatus(404); return; }
1710
+ res.redirect(domain.redirects[urlName] + urlArgs);
1711
+ }
1712
+
1713
// Take a "user/domain/userid/path/file" format and return the actual server disk file path if access is allowed
1714
obj.getServerFilePath = function (user, domain, path) {
1715
var splitpath = path.split('/'), serverpath = obj.path.join(obj.filespath, 'domain'), filename = '';
@@ -2716,6 +2727,9 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
2727
obj.app.get(url + 'logo.png', handleLogoRequest);
2728
obj.app.get(url + 'welcome.jpg', handleWelcomeImageRequest);
2729
2730
+ // Server redirects
2731
+ if (parent.config.domains[i].redirects) { for (var j in parent.config.domains[i].redirects) { obj.app.get(url + j, handleDomainRedirect); } }
2732
+
2733
// Server picture
2734
obj.app.get(url + 'serverpic.ashx', function (req, res) {
2735
// Check if we have "server.jpg" in the data folder, if so, use that.