Guest device shares can now be unlimited time.

This commit is contained in:
Ylian Saint-Hilaire 2021-08-31 13:40:03 -07:00
parent 80d29262f9
commit 715f85e720
4 changed files with 23 additions and 17 deletions

View File

@ -1014,7 +1014,6 @@ function CreateMeshRelayEx2(parent, ws, req, domain, user, cookie) {
};
obj.sendAgentMessage = function (command, userid, domainid) {
console.log('sendAgentMessage');
var rights, mesh;
if (command.nodeid == null) return false;
var user = parent.users[userid];

View File

@ -4482,7 +4482,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
var now = Date.now(), removed = false, okDocs = [];
for (var i = 0; i < docs.length; i++) {
const doc = docs[i];
if (doc.expireTime < now) {
if ((doc.expireTime != null) && (doc.expireTime < now)) {
// This share is expired.
parent.db.Remove(doc._id, function () { }); removed = true;
} else {
@ -4640,23 +4640,26 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
if ((rights != MESHRIGHT_ADMIN) && ((rights & MESHRIGHT_REMOTEVIEWONLY) != 0)) { command.viewOnly = true; command.p = (command.p & 1); }
// Create cookie
var publicid = getRandomPassword(), startTime, expireTime;
var publicid = getRandomPassword(), startTime = null, expireTime = null;
if (command.expire != null) {
// Now until expire in hours
startTime = Date.now();
expireTime = Date.now() + (60000 * command.expire);
if (command.expire !== 0) {
// Now until expire in hours
startTime = Date.now();
expireTime = Date.now() + (60000 * command.expire);
} else {
delete command.expire;
}
} else {
// Time range in seconds
startTime = command.start * 1000;
expireTime = command.end * 1000;
}
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 };
var cookie = { a: 5, p: command.p, uid: user._id, gn: command.guestname, nid: node._id, cf: command.consent, pid: publicid };
if ((startTime != null) && (expireTime != null)) { command.start = cookie.start = startTime; command.expire = cookie.expire = expireTime; }
if (command.viewOnly === true) { cookie.vo = 1; }
const inviteCookie = parent.parent.encodeCookie(cookie, parent.parent.invitationLinkEncryptionKey);
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; }
command.start = startTime;
command.expire = expireTime;
// Create the server url
var serverName = parent.getWebServerName(domain);
@ -4670,7 +4673,8 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
try { ws.send(JSON.stringify(command)); } catch (ex) { }
// Create a device sharing database entry
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 };
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 };
if ((startTime != null) && (expireTime != null)) { shareEntry.startTime = startTime; shareEntry.expireTime = expireTime; }
if (command.viewOnly === true) { shareEntry.viewOnly = true; }
parent.db.Set(shareEntry);

View File

@ -3354,8 +3354,10 @@
x += addHtmlValue("Device", node.name);
x += addHtmlValue("Guest Name", message.guestname);
x += addHtmlValue("User Input", message.viewOnly ? "Not allowed, view only" : "Allowed");
x += addHtmlValue("Start Time", printDateTime(new Date(message.start)));
x += addHtmlValue("Expire Time", printDateTime(new Date(message.expire)));
if ((message.start != null) && (message.expire)) {
x += addHtmlValue("Start Time", printDateTime(new Date(message.start)));
x += addHtmlValue("Expire Time", printDateTime(new Date(message.expire)));
}
var y = [];
if (message.consent & 0x0007) { y.push("Notify"); }
if (message.consent & 0x0038) { y.push("Prompt"); }
@ -6919,7 +6921,8 @@
var dshare = deviceShares[i];
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>';
var type = ['', "Terminal", "Desktop", "Desktop + Terminal", "Files", "Terminal + Files", "Desktop + Files", "Desktop + Terminal + Files"][dshare.p];
var details = format("{0}, {1} to {2}", type, printFlexDateTime(new Date(dshare.startTime)), printFlexDateTime(new Date(dshare.expireTime)));
var details = type;
if ((dshare.startTime != null) && (dshare.expireTime != null)) { details = format("{0}, {1} to {2}", type, printFlexDateTime(new Date(dshare.startTime)), printFlexDateTime(new Date(dshare.expireTime))); }
if (dshare.viewOnly === true) { details += ", View only"; }
if (dshare.consent != null) {
if (dshare.consent == 0) { details += ", No Consent"; } else {
@ -7151,7 +7154,7 @@
if ((currentNode.agent.caps & 7) == 7) { y += allFeatures; } // Agent is desktop + terminal + files capable
x += addHtmlValue("Type", '<select id=d2shareType style=float:right;width:250px onchange=showShareDeviceValidate()>' + y + '</select>');
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" }
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" }
y = '';
for (var i in options) { y += '<option value=' + i + '>' + options[i] + '</option>'; }
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>');

View File

@ -3480,10 +3480,10 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
// Check the inbound desktop sharing cookie
var c = obj.parent.decodeCookie(req.query.c, obj.parent.invitationLinkEncryptionKey, 60); // 60 minute timeout
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; }
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; }
// Check the expired time, expire message.
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; }
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; }
// Check the public id
obj.db.GetAllTypeNodeFiltered([c.nid], domain.id, 'deviceshare', null, function (err, docs) {
@ -3501,7 +3501,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
var node = nodes[0];
// Check the start time, not yet valid message.
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; }
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; }
// Looks good, let's create the outbound session cookies.
// Consent flags are 1 = Notify, 8 = Prompt, 64 = Privacy Bar.