mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-11-23 06:34:54 +03:00
Working on recurring device sharing links.
This commit is contained in:
parent
b352cc8409
commit
3589ddeaff
19
meshuser.js
19
meshuser.js
@ -3834,6 +3834,8 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
||||
else if ((command.end != null) && (typeof command.end != 'number')) { err = 'Invalid end time'; } // Check the end time in UTC seconds
|
||||
else if (common.validateInt(command.consent, 0, 256) == false) { err = 'Invalid flags'; } // Check the flags
|
||||
else if (common.validateInt(command.p, 1, 7) == false) { err = 'Invalid protocol'; } // Check the protocol, 1 = Terminal, 2 = Desktop, 4 = Files
|
||||
else if ((command.recurring != null) && (common.validateInt(command.recurring, 1, 2) == false)) { err = 'Invalid recurring value'; } // Check the recurring value, 1 = Daily, 2 = Weekly
|
||||
else if ((command.recurring != null) && ((command.end != null) || (command.start == null) || (command.expire == null))) { err = 'Invalid recurring command'; }
|
||||
else if ((command.expire == null) && ((command.start == null) || (command.end == null) || (command.start > command.end))) { err = 'No time specified'; } // Check that a time range is present
|
||||
else {
|
||||
if (command.nodeid.split('/').length == 1) { command.nodeid = 'node/' + domain.id + '/' + command.nodeid; }
|
||||
@ -3893,8 +3895,12 @@ 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 = null, expireTime = null;
|
||||
if (command.expire != null) {
|
||||
var publicid = getRandomPassword(), startTime = null, expireTime = null, duration = null;
|
||||
if (command.recurring) {
|
||||
// Recurring share
|
||||
startTime = command.start * 1000;
|
||||
duration = command.expire;
|
||||
} else if (command.expire != null) {
|
||||
if (command.expire !== 0) {
|
||||
// Now until expire in hours
|
||||
startTime = Date.now();
|
||||
@ -3911,6 +3917,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
||||
//var cookie = { a: 5, p: command.p, uid: user._id, gn: command.guestname, nid: node._id, cf: command.consent, pid: publicid }; // Old style sharing cookie
|
||||
var cookie = { a: 6, pid: publicid }; // New style sharing cookie
|
||||
if ((startTime != null) && (expireTime != null)) { command.start = startTime; command.expire = cookie.e = expireTime; }
|
||||
else if ((startTime != null) && (duration != null)) { command.start = startTime; }
|
||||
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; }
|
||||
|
||||
@ -3929,13 +3936,19 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
||||
// Create a device sharing database entry
|
||||
var shareEntry = { _id: 'deviceshare-' + publicid, type: 'deviceshare', xmeshid: node.meshid, 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; }
|
||||
else if ((startTime != null) && (duration != null)) { shareEntry.startTime = startTime; shareEntry.duration = duration; }
|
||||
if (command.recurring) { shareEntry.recurring = command.recurring; }
|
||||
if (command.viewOnly === true) { shareEntry.viewOnly = true; }
|
||||
parent.db.Set(shareEntry);
|
||||
|
||||
// Send out an event that we added a device share
|
||||
var targets = parent.CreateNodeDispatchTargets(node.meshid, node._id, ['server-users', user._id]);
|
||||
var event;
|
||||
if ((startTime != null) && (expireTime != null)) {
|
||||
if (command.recurring == 1) {
|
||||
event = { etype: 'node', userid: user._id, username: user.name, meshid: node.meshid, nodeid: node._id, action: 'addedDeviceShare', msg: 'Added device share ' + command.guestname + ' recurring daily.', msgid: 138, msgArgs: [command.guestname], domain: domain.id };
|
||||
} else if (command.recurring == 2) {
|
||||
event = { etype: 'node', userid: user._id, username: user.name, meshid: node.meshid, nodeid: node._id, action: 'addedDeviceShare', msg: 'Added device share ' + command.guestname + ' recurring weekly.', msgid: 139, msgArgs: [command.guestname], domain: domain.id };
|
||||
} else if ((startTime != null) && (expireTime != null)) {
|
||||
event = { etype: 'node', userid: user._id, username: user.name, meshid: node.meshid, nodeid: node._id, action: 'addedDeviceShare', msg: 'Added device share: ' + command.guestname + '.', msgid: 101, msgArgs: [command.guestname, 'DATETIME:' + startTime, 'DATETIME:' + expireTime], domain: domain.id };
|
||||
} else {
|
||||
event = { etype: 'node', userid: user._id, username: user.name, meshid: node.meshid, nodeid: node._id, action: 'addedDeviceShare', msg: 'Added device share ' + command.guestname + ' with unlimited time.', msgid: 131, msgArgs: [command.guestname], domain: domain.id };
|
||||
|
@ -3456,10 +3456,18 @@
|
||||
x += addHtmlValue("Device", node.name);
|
||||
x += addHtmlValue("Guest Name", message.guestname);
|
||||
x += addHtmlValue("User Input", message.viewOnly ? "Not allowed, view only" : "Allowed");
|
||||
if ((message.start != null) && (message.expire)) {
|
||||
if (message.start && message.expire) {
|
||||
if (message.recurring) {
|
||||
x += addHtmlValue("Start Time", printDateTime(new Date(message.start)));
|
||||
if (message.expire < 2) { x += addHtmlValue("Duration", format("{0} minute", message.expire) ); }
|
||||
else { x += addHtmlValue("Duration", format("{0} minutes", message.expire) ); }
|
||||
} else {
|
||||
x += addHtmlValue("Start Time", printDateTime(new Date(message.start)));
|
||||
x += addHtmlValue("Expire Time", printDateTime(new Date(message.expire)));
|
||||
}
|
||||
}
|
||||
if (message.recurring == 1) { x += addHtmlValue("Recurring", "Daily"); }
|
||||
if (message.recurring == 2) { x += addHtmlValue("Recurring", "Weekly"); }
|
||||
var y = [];
|
||||
if (message.consent & 0x0007) { y.push("Notify"); }
|
||||
if (message.consent & 0x0038) { y.push("Prompt"); }
|
||||
@ -7186,6 +7194,15 @@
|
||||
var type = ['', "Terminal", "Desktop", "Desktop + Terminal", "Files", "Terminal + Files", "Desktop + Files", "Desktop + Terminal + Files"][dshare.p];
|
||||
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.startTime != null) && (dshare.duration != null)) {
|
||||
if (dshare.duration < 2) {
|
||||
details = format("{0}, {1} for {2} minute", type, printFlexDateTime(new Date(dshare.startTime)), dshare.duration);
|
||||
} else {
|
||||
details = format("{0}, {1} for {2} minutes", type, printFlexDateTime(new Date(dshare.startTime)), dshare.duration);
|
||||
}
|
||||
}
|
||||
if (dshare.recurring == 1) { details += ", Reccuring daily"; }
|
||||
if (dshare.recurring == 2) { details += ", Reccuring weekly"; }
|
||||
if (((dshare.p & 2) != 0) && (dshare.viewOnly === true)) { details += ", View only desktop"; }
|
||||
if (dshare.consent != null) {
|
||||
if (dshare.consent == 0) { details += ", No Consent"; } else {
|
||||
@ -7460,7 +7477,7 @@
|
||||
var allFeatures = '<option value=7>' + "Desktop + Terminal + Files" + '</option>';
|
||||
if ((rights != 0xFFFFFFFF) && ((rights & 0x700) != 0)) { allFeatures = ''; }
|
||||
|
||||
var y = '';
|
||||
var y = '', z = '';
|
||||
if ((currentNode.agent.caps & 1) == 1) { y += (deskFull + '<option value=3>' + "Desktop, View only" + '</option>'); } // Agent is desktop capable
|
||||
if ((currentNode.agent.caps & 2) == 2) { y += fullTerm; } // Agent is terminal capable
|
||||
if ((currentNode.agent.caps & 4) == 4) { y += fullFiles; } // Agent is files capable
|
||||
@ -7475,12 +7492,18 @@
|
||||
if ((serverinfo.guestdevicesharingmaxtime == null) || ((i > 0) && (i <= serverinfo.guestdevicesharingmaxtime))) {
|
||||
y += '<option value=' + i + '>' + options[i] + '</option>';
|
||||
}
|
||||
if ((i > 0) && (i <= 720) && ((serverinfo.guestdevicesharingmaxtime == null) || ((i > 0) && (i <= serverinfo.guestdevicesharingmaxtime)))) {
|
||||
z += '<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>');
|
||||
}
|
||||
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><option value=2>' + "Recurring daily" + '</option><option value=3>' + "Recurring weekly" + '</option></select>');
|
||||
x += '<div id=d2modenow>';
|
||||
x += addHtmlValue("Expire Time", '<select id=d2inviteExpire style=float:right;width:250px>' + y + '</select>');
|
||||
x += '</div><div id=d2moderange style=display:none>';
|
||||
x += addHtmlValue("Time Range", '<input id=d2timeRangeSelector style=float:right;width:250px class=flatpickr type="text" placeholder="' + "Select Date & Time..." + '" data-id="altinput">');
|
||||
x += '</div><div id=d2moderecurring style=display:none>';
|
||||
x += addHtmlValue("Start Time", '<input id=d2timeStartSelector style=float:right;width:250px class=flatpickr type="text" placeholder="' + "Select Date & Time..." + '" data-id="altinput">');
|
||||
x += addHtmlValue("Duration", '<select id=d2inviteDuration style=float:right;width:250px>' + z + '</select>');
|
||||
x += '</div>';
|
||||
if (currentNode.agent.caps & 1) { x += addHtmlValue("User Consent", '<select id=d2userConsent style=float:right;width:250px><option value=1>' + "Prompt for consent" + '</option><option value=0>' + "Notify Only" + '</option></select>'); }
|
||||
setDialogMode(2, "Share Device", 3, showShareDeviceEx, x);
|
||||
@ -7488,12 +7511,14 @@
|
||||
var tomorrow = new Date();
|
||||
tomorrow.setDate(tomorrow.getDate() + 1);
|
||||
var rangeTime = flatpickr('#d2timeRangeSelector', { mode: 'range', enableTime: true, minDate: new Date(), defaultDate: [ new Date(), tomorrow ] });
|
||||
xxdialogTag = rangeTime;
|
||||
var startTime = flatpickr('#d2timeStartSelector', { enableTime: true, minDate: new Date(), defaultDate: new Date() });
|
||||
xxdialogTag = { range: rangeTime, start: startTime };
|
||||
}
|
||||
|
||||
function showShareDeviceValidate() {
|
||||
QV('d2modenow', Q('d2timeRange').value == 0);
|
||||
QV('d2moderange', Q('d2timeRange').value == 1);
|
||||
QV('d2moderecurring', Q('d2timeRange').value >= 2);
|
||||
var ok = true;
|
||||
if (Q('d2inviteName').value.trim().length == 0) { ok = false; }
|
||||
QE('idx_dlgOkButton', ok);
|
||||
@ -7519,8 +7544,10 @@
|
||||
|
||||
if (Q('d2timeRange').value == 0) {
|
||||
meshserver.send({ action: 'createDeviceShareLink', nodeid: currentNode._id, guestname: Q('d2inviteName').value.trim(), p: q, expire: parseInt(Q('d2inviteExpire').value), consent: consent, viewOnly: viewOnly });
|
||||
} else if (Q('d2timeRange').value == 1) {
|
||||
meshserver.send({ action: 'createDeviceShareLink', nodeid: currentNode._id, guestname: Q('d2inviteName').value.trim(), p: q, start: Math.floor(tag.range.selectedDates[0].getTime() / 1000), end: Math.floor(tag.range.selectedDates[1].getTime() / 1000), consent: consent, viewOnly: viewOnly });
|
||||
} else {
|
||||
meshserver.send({ action: 'createDeviceShareLink', nodeid: currentNode._id, guestname: Q('d2inviteName').value.trim(), p: q, start: Math.floor(tag.selectedDates[0].getTime() / 1000), end: Math.floor(tag.selectedDates[1].getTime() / 1000), consent: consent, viewOnly: viewOnly });
|
||||
meshserver.send({ action: 'createDeviceShareLink', nodeid: currentNode._id, guestname: Q('d2inviteName').value.trim(), p: q, start: Math.floor(tag.start.selectedDates[0].getTime() / 1000), expire: parseInt(Q('d2inviteDuration').value), recurring: Q('d2timeRange').value - 1, consent: consent, viewOnly: viewOnly });
|
||||
}
|
||||
}
|
||||
|
||||
@ -13378,7 +13405,9 @@
|
||||
134: "Forcibly disconnected desktop session of user {0}",
|
||||
135: "Forcibly disconnected terminal session of user {0}",
|
||||
136: "Forcibly disconnected files session of user {0}",
|
||||
137: "Forcibly disconnected routing session of user {0}"
|
||||
137: "Forcibly disconnected routing session of user {0}",
|
||||
138: "Added device share {0} recurring daily.",
|
||||
139: "Added device share {0} recurring weekly."
|
||||
};
|
||||
|
||||
// Highlights the device being hovered
|
||||
|
Loading…
Reference in New Issue
Block a user