Added maximum device guest sharing time, #3431

Ylian Saint-Hilaire committed Jan 9, 2022 at 17:15 UTC 92fe9642d09b39ddbc71987411ba8041f67a067e
3 files changed +28 -6
meshcentral-config-schema.json
+8 -1
@@ -318,7 +318,14 @@
318 "hide": { "type": "integer", "default": 0, "description": "Sum of: 1 = Hide header, 2 = Hide tab, 4 = Hide footer, 8 = Hide title, 16 = Hide left bar, 32 = Hide back buttons" },
319 "footer": { "type": "string", "default": null, "description": "This is a HTML string displayed at the bottom of the web page when a user is logged in." },
320 "loginfooter": { "type": "string", "default": null, "description": "This is a HTML string displayed at the bottom of the web page when a user is not logged in." },
321 - "guestDeviceSharing": { "type": "boolean", "default": true, "description": "When set to false, the desktop/terminal sharing link feature is not available." },
321 + "guestDeviceSharing": {
322 + "type": [ "boolean", "object" ],
323 + "default": true,
324 + "description": "When set to false, the desktop/terminal sharing link feature is not available.",
325 + "properties": {
326 + "maxSessionTime": { "type": "number", "description": "When set, limits the maximum length of a guest session, in minutes." }
327 + }
328 + },
329 "autoRemoveInactiveDevices": { "type": "integer", "default": 0, "minimum": 0, "maximum": 2000, "description": "Number of days a device can be inactive before it's removed. 0 disables this feature. Device group setting will override this value." },
330 "deviceSearchBarServerAndClientName": { "type": "boolean", "default": false, "description": "When set to true, the devices search box will match on both the server name and client name of a device." },
331 "agentSelfGuestSharing": {
meshuser.js
+15 -4
@@ -559,7 +559,11 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
559 serverinfo.magenturl = 'mc://' + agentServerName + ((agentHttpsPort != 443) ? (':' + agentHttpsPort) : '') + ((xdomain != '') ? ('/' + xdomain) : '');
560 serverinfo.domainsuffix = xdomain;
561
562 - if (domain.guestdevicesharing === false) { serverinfo.guestdevicesharing = false; }
562 + if (domain.guestdevicesharing === false) { serverinfo.guestdevicesharing = false; } else {
563 + if (typeof domain.guestdevicesharing == 'object') {
564 + if (typeof domain.guestdevicesharing.maxsessiontime == 'number') { serverinfo.guestdevicesharingmaxtime = domain.guestdevicesharing.maxsessiontime; }
565 + }
566 + }
567 if (typeof domain.userconsentflags == 'number') { serverinfo.consent = domain.userconsentflags; }
568 if ((typeof domain.usersessionidletimeout == 'number') && (domain.usersessionidletimeout > 0)) { serverinfo.timeout = (domain.usersessionidletimeout * 60 * 1000); }
569 if (user.siteadmin === SITERIGHT_ADMIN) {
@@ -3949,9 +3953,9 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
3953 else if (command.nodeid.indexOf('/') == -1) { command.nodeid = 'node/' + domain.id + '/' + command.nodeid; }
3954 else if ((command.nodeid.split('/').length != 3) || (command.nodeid.split('/')[1] != domain.id)) { err = 'Invalid domain'; } // Invalid domain, operation only valid for current domain
3955 if (common.validateString(command.guestname, 1, 128) == false) { err = 'Invalid guest name'; } // Check the guest name
3952 - else if ((command.expire != null) && (typeof command.expire != 'number')) { err = 'Invalid expire time'; } // Check the expire time in hours
3953 - else if ((command.start != null) && (typeof command.start != 'number')) { err = 'Invalid start time'; } // Check the start time in seconds
3954 - else if ((command.end != null) && (typeof command.end != 'number')) { err = 'Invalid end time'; } // Check the end time in seconds
3956 + else if ((command.expire != null) && (typeof command.expire != 'number')) { err = 'Invalid expire time'; } // Check the expire time in minutes
3957 + else if ((command.start != null) && (typeof command.start != 'number')) { err = 'Invalid start time'; } // Check the start time in UTC seconds
3958 + else if ((command.end != null) && (typeof command.end != 'number')) { err = 'Invalid end time'; } // Check the end time in UTC seconds
3959 else if (common.validateInt(command.consent, 0, 256) == false) { err = 'Invalid flags'; } // Check the flags
3960 else if (common.validateInt(command.p, 1, 7) == false) { err = 'Invalid protocol'; } // Check the protocol, 1 = Terminal, 2 = Desktop, 4 = Files
3961 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
@@ -3967,6 +3971,13 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
3971 break;
3972 }
3973
3974 + // Correct maximum session length if needed
3975 + if ((typeof domain.guestdevicesharing == 'object') && (typeof domain.guestdevicesharing.maxsessiontime == 'number') && (domain.guestdevicesharing.maxsessiontime > 0)) {
3976 + const maxtime = domain.guestdevicesharing.maxsessiontime;
3977 + if ((command.expire != null) && (command.expire > maxtime)) { command.expire = maxtime; }
3978 + if ((command.start != null) && (command.end != null)) { if ((command.end - command.start) > (maxtime * 60)) { command.end = (command.start + (maxtime * 60)); } }
3979 + }
3980 +
3981 // Get the device rights
3982 parent.GetNodeWithRights(domain, user, command.nodeid, function (node, rights, visible) {
3983 // If node not found or we don't have remote control, reject.
views/default.handlebars
+5 -1
@@ -7471,7 +7471,11 @@
7471 x += addHtmlValue("Type", '<select id=d2shareType style=float:right;width:250px onchange=showShareDeviceValidate()>' + y + '</select>');
7472 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" }
7473 y = '';
7474 - for (var i in options) { y += '<option value=' + i + '>' + options[i] + '</option>'; }
7474 + for (var i in options) {
7475 + if ((serverinfo.guestdevicesharingmaxtime == null) || ((i > 0) && (i <= serverinfo.guestdevicesharingmaxtime))) {
7476 + y += '<option value=' + i + '>' + options[i] + '</option>';
7477 + }
7478 + }
7479 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>');
7480 x += '<div id=d2modenow>';
7481 x += addHtmlValue("Expire Time", '<select id=d2inviteExpire style=float:right;width:250px>' + y + '</select>');