Guest device shares can now be unlimited time.

Ylian Saint-Hilaire committed Aug 31, 2021 at 13:40 UTC 715f85e7207cc6db09c7636c414645dbc18b3239
4 files changed +23 -17
meshdesktopmultiplex.js
-1
@@ -1014,7 +1014,6 @@ function CreateMeshRelayEx2(parent, ws, req, domain, user, cookie) {
1014 };
1015
1016 obj.sendAgentMessage = function (command, userid, domainid) {
1017 - console.log('sendAgentMessage');
1017 var rights, mesh;
1018 if (command.nodeid == null) return false;
1019 var user = parent.users[userid];
meshuser.js
+13 -9
@@ -4482,7 +4482,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
4482 var now = Date.now(), removed = false, okDocs = [];
4483 for (var i = 0; i < docs.length; i++) {
4484 const doc = docs[i];
4485 - if (doc.expireTime < now) {
4485 + if ((doc.expireTime != null) && (doc.expireTime < now)) {
4486 // This share is expired.
4487 parent.db.Remove(doc._id, function () { }); removed = true;
4488 } else {
@@ -4640,23 +4640,26 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
4640 if ((rights != MESHRIGHT_ADMIN) && ((rights & MESHRIGHT_REMOTEVIEWONLY) != 0)) { command.viewOnly = true; command.p = (command.p & 1); }
4641
4642 // Create cookie
4643 - var publicid = getRandomPassword(), startTime, expireTime;
4643 + var publicid = getRandomPassword(), startTime = null, expireTime = null;
4644 if (command.expire != null) {
4645 - // Now until expire in hours
4646 - startTime = Date.now();
4647 - expireTime = Date.now() + (60000 * command.expire);
4645 + if (command.expire !== 0) {
4646 + // Now until expire in hours
4647 + startTime = Date.now();
4648 + expireTime = Date.now() + (60000 * command.expire);
4649 + } else {
4650 + delete command.expire;
4651 + }
4652 } else {
4653 // Time range in seconds
4654 startTime = command.start * 1000;
4655 expireTime = command.end * 1000;
4656 }
4657
4654 - var cookie = { a: 5, p: command.p, uid: user._id, gn: command.guestname, nid: node._id, cf: command.consent, start: startTime, expire: expireTime, pid: publicid };
4658 + var cookie = { a: 5, p: command.p, uid: user._id, gn: command.guestname, nid: node._id, cf: command.consent, pid: publicid };
4659 + if ((startTime != null) && (expireTime != null)) { command.start = cookie.start = startTime; command.expire = cookie.expire = expireTime; }
4660 if (command.viewOnly === true) { cookie.vo = 1; }
4661 const inviteCookie = parent.parent.encodeCookie(cookie, parent.parent.invitationLinkEncryptionKey);
4662 if (inviteCookie == null) { if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'createDeviceShareLink', responseid: command.responseid, result: 'Unable to generate shareing cookie' })); } catch (ex) { } } return; }
4658 - command.start = startTime;
4659 - command.expire = expireTime;
4663
4664 // Create the server url
4665 var serverName = parent.getWebServerName(domain);
@@ -4670,7 +4673,8 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
4673 try { ws.send(JSON.stringify(command)); } catch (ex) { }
4674
4675 // Create a device sharing database entry
4673 - var shareEntry = { _id: 'deviceshare-' + publicid, type: 'deviceshare', nodeid: node._id, p: command.p, domain: node.domain, publicid: publicid, startTime: startTime, expireTime: expireTime, userid: user._id, guestName: command.guestname, consent: command.consent, url: url };
4676 + var shareEntry = { _id: 'deviceshare-' + publicid, type: 'deviceshare', nodeid: node._id, p: command.p, domain: node.domain, publicid: publicid, userid: user._id, guestName: command.guestname, consent: command.consent, url: url };
4677 + if ((startTime != null) && (expireTime != null)) { shareEntry.startTime = startTime; shareEntry.expireTime = expireTime; }
4678 if (command.viewOnly === true) { shareEntry.viewOnly = true; }
4679 parent.db.Set(shareEntry);
4680
views/default.handlebars
+7 -4
@@ -3354,8 +3354,10 @@
3354 x += addHtmlValue("Device", node.name);
3355 x += addHtmlValue("Guest Name", message.guestname);
3356 x += addHtmlValue("User Input", message.viewOnly ? "Not allowed, view only" : "Allowed");
3357 - x += addHtmlValue("Start Time", printDateTime(new Date(message.start)));
3358 - x += addHtmlValue("Expire Time", printDateTime(new Date(message.expire)));
3357 + if ((message.start != null) && (message.expire)) {
3358 + x += addHtmlValue("Start Time", printDateTime(new Date(message.start)));
3359 + x += addHtmlValue("Expire Time", printDateTime(new Date(message.expire)));
3360 + }
3361 var y = [];
3362 if (message.consent & 0x0007) { y.push("Notify"); }
3363 if (message.consent & 0x0038) { y.push("Prompt"); }
@@ -6919,7 +6921,8 @@
6921 var dshare = deviceShares[i];
6922 var trash = '<a href="' + dshare.url + '" rel="noreferrer noopener" target=_blank title="' + "Device Sharing Link" + '" style=cursor:pointer><img src=images/link2.png border=0 height=10 width=10></a> <a href=# onclick=\'return p30removeDeviceSharing(event,"' + encodeURIComponentEx(currentNode._id) + '","' + encodeURIComponentEx(dshare.publicid) + '","' + encodeURIComponentEx(dshare.guestName) + '")\' title="' + "Remove device sharing" + '" style=cursor:pointer><img src=images/trash.png border=0 height=10 width=10></a>';
6923 var type = ['', "Terminal", "Desktop", "Desktop + Terminal", "Files", "Terminal + Files", "Desktop + Files", "Desktop + Terminal + Files"][dshare.p];
6922 - var details = format("{0}, {1} to {2}", type, printFlexDateTime(new Date(dshare.startTime)), printFlexDateTime(new Date(dshare.expireTime)));
6924 + var details = type;
6925 + if ((dshare.startTime != null) && (dshare.expireTime != null)) { details = format("{0}, {1} to {2}", type, printFlexDateTime(new Date(dshare.startTime)), printFlexDateTime(new Date(dshare.expireTime))); }
6926 if (dshare.viewOnly === true) { details += ", View only"; }
6927 if (dshare.consent != null) {
6928 if (dshare.consent == 0) { details += ", No Consent"; } else {
@@ -7151,7 +7154,7 @@
7154 if ((currentNode.agent.caps & 7) == 7) { y += allFeatures; } // Agent is desktop + terminal + files capable
7155
7156 x += addHtmlValue("Type", '<select id=d2shareType style=float:right;width:250px onchange=showShareDeviceValidate()>' + y + '</select>');
7154 - var options = { 1 : "1 minute", 5 : "5 minutes", 10 : "10 minutes", 15 : "15 minutes", 30 : "30 minutes", 45 : "45 minutes", 60 : "60 minutes", 120 : "2 hours", 240 : "4 hours", 480 : "8 hours", 720 : "12 hours", 960 : "16 hours", 1440 : "24 hours", 2880 : "2 days", 5760 : "4 days" }
7157 + var options = { 1 : "1 minute", 5 : "5 minutes", 10 : "10 minutes", 15 : "15 minutes", 30 : "30 minutes", 45 : "45 minutes", 60 : "60 minutes", 120 : "2 hours", 240 : "4 hours", 480 : "8 hours", 720 : "12 hours", 960 : "16 hours", 1440 : "24 hours", 2880 : "2 days", 5760 : "4 days", 0 : "Unlimited" }
7158 y = '';
7159 for (var i in options) { y += '<option value=' + i + '>' + options[i] + '</option>'; }
7160 x += addHtmlValue("Validity", '<select id=d2timeRange style=float:right;width:250px onchange=showShareDeviceValidate()><option value=0>' + "Starting now" + '</option><option value=1>' + "Time range" + '</option></select>');
webserver.js
+3 -3
@@ -3480,10 +3480,10 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
3480
3481 // Check the inbound desktop sharing cookie
3482 var c = obj.parent.decodeCookie(req.query.c, obj.parent.invitationLinkEncryptionKey, 60); // 60 minute timeout
3483 - if ((c == null) || (c.a !== 5) || (typeof c.p !== 'number') || (c.p < 1) || (c.p > 7) || (typeof c.uid != 'string') || (typeof c.nid != 'string') || (typeof c.gn != 'string') || (typeof c.cf != 'number') || (typeof c.start != 'number') || (typeof c.expire != 'number') || (typeof c.pid != 'string')) { res.sendStatus(404); return; }
3483 + if ((c == null) || (c.a !== 5) || (typeof c.p !== 'number') || (c.p < 1) || (c.p > 7) || (typeof c.uid != 'string') || (typeof c.nid != 'string') || (typeof c.gn != 'string') || (typeof c.cf != 'number') || (typeof c.pid != 'string')) { res.sendStatus(404); return; }
3484
3485 // Check the expired time, expire message.
3486 - if (c.expire <= Date.now()) { render(req, res, getRenderPage((domain.sitestyle == 2) ? 'message2' : 'message', req, domain), getRenderArgs({ titleid: 2, msgid: 12, domainurl: encodeURIComponent(domain.url).replace(/'/g, '%27') }, req, domain)); return; }
3486 + if ((c.expire != null) && (c.expire <= Date.now())) { render(req, res, getRenderPage((domain.sitestyle == 2) ? 'message2' : 'message', req, domain), getRenderArgs({ titleid: 2, msgid: 12, domainurl: encodeURIComponent(domain.url).replace(/'/g, '%27') }, req, domain)); return; }
3487
3488 // Check the public id
3489 obj.db.GetAllTypeNodeFiltered([c.nid], domain.id, 'deviceshare', null, function (err, docs) {
@@ -3501,7 +3501,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
3501 var node = nodes[0];
3502
3503 // Check the start time, not yet valid message.
3504 - if ((c.start > Date.now()) || (c.start > c.expire)) { render(req, res, getRenderPage((domain.sitestyle == 2) ? 'message2' : 'message', req, domain), getRenderArgs({ titleid: 2, msgid: 11, domainurl: encodeURIComponent(domain.url).replace(/'/g, '%27') }, req, domain)); return; }
3504 + if ((c.start != null) && (c.expire != null) && ((c.start > Date.now()) || (c.start > c.expire))) { render(req, res, getRenderPage((domain.sitestyle == 2) ? 'message2' : 'message', req, domain), getRenderArgs({ titleid: 2, msgid: 11, domainurl: encodeURIComponent(domain.url).replace(/'/g, '%27') }, req, domain)); return; }
3505
3506 // Looks good, let's create the outbound session cookies.
3507 // Consent flags are 1 = Notify, 8 = Prompt, 64 = Privacy Bar.