Added user consent config options, #3692

Ylian Saint-Hilaire committed Feb 22, 2022 at 12:32 UTC e160f8e73f56aaffdd80ab4b90e7ddbe11bd55b7
6 files changed +41 -33
agents/meshcore.js
+23 -31
@@ -1025,18 +1025,15 @@ function handleServerCommand(data) {
1025 tunnel.realname = (data.realname ? data.realname : data.username) + (data.guestname ? (' - ' + data.guestname) : '');
1026 tunnel.guestname = data.guestname;
1027 tunnel.userid = data.userid;
1028 -
1029 - if (server_check_consentTimer(tunnel.userid)) {
1030 - sendConsoleText('Deleting Consent Requirement');
1031 - tunnel.consent = (tunnel.consent & -57);
1032 - }
1033 -
1028 + if (server_check_consentTimer(tunnel.userid)) { tunnel.consent = (tunnel.consent & -57); } // Deleting Consent Requirement
1029 tunnel.desktopviewonly = data.desktopviewonly;
1030 tunnel.remoteaddr = data.remoteaddr;
1031 tunnel.state = 0;
1032 tunnel.url = xurl;
1033 tunnel.protocol = 0;
1034 tunnel.soptions = data.soptions;
1035 + tunnel.consentTimeout = (tunnel.soptions && tunnel.soptions.consentTimeout) ? tunnel.soptions.consentTimeout : 30;
1036 + tunnel.consentAutoAccept = (tunnel.soptions && (tunnel.soptions.consentAutoAccept === true));
1037 tunnel.tcpaddr = data.tcpaddr;
1038 tunnel.tcpport = data.tcpport;
1039 tunnel.udpaddr = data.udpaddr;
@@ -2068,28 +2065,25 @@ function onTunnelData(data) {
2065 }
2066 if (process.platform == 'win32') {
2067 var enhanced = false;
2071 - try {
2072 - require('win-userconsent');
2073 - enhanced = true;
2074 - } catch (ex) { }
2068 + try { require('win-userconsent'); enhanced = true; } catch (ex) { }
2069 if (enhanced) {
2070 var ipr = server_getUserImage(this.httprequest.userid);
2071 ipr.consentTitle = consentTitle;
2072 ipr.consentMessage = consentMessage;
2073 + ipr.consentTimeout = this.httprequest.consentTimeout;
2074 + ipr.consentAutoAccept = this.httprequest.consentAutoAccept; // TODO: If true, consent timeout must accept.
2075 ipr.username = this.httprequest.realname;
2076 ipr.translations = { Allow: currentTranslation['allow'], Deny: currentTranslation['deny'], Auto: currentTranslation['autoAllowForFive'], Caption: consentMessage };
2077 this.httprequest.tpromise._consent = ipr.then(function (img) {
2082 - this.consent = require('win-userconsent').create(this.consentTitle, this.consentMessage, this.username, { b64Image: img.split(',').pop(), timeout: 30000, translations: this.translations, background: color_options.background, foreground: color_options.foreground });
2078 + this.consent = require('win-userconsent').create(this.consentTitle, this.consentMessage, this.username, { b64Image: img.split(',').pop(), timeout: this.consentTimeout * 1000, translations: this.translations, background: color_options.background, foreground: color_options.foreground });
2079 this.__childPromise.close = this.consent.close.bind(this.consent);
2080 return (this.consent);
2081 });
2082 + } else {
2083 + this.httprequest.tpromise._consent = require('message-box').create(consentTitle, consentMessage, this.consentTimeout);
2084 }
2087 - else {
2088 - this.httprequest.tpromise._consent = require('message-box').create(consentTitle, consentMessage, 30);
2089 - }
2090 - }
2091 - else {
2092 - this.httprequest.tpromise._consent = require('message-box').create(consentTitle, consentMessage, 30);
2085 + } else {
2086 + this.httprequest.tpromise._consent = require('message-box').create(consentTitle, consentMessage, this.consentTimeout);
2087 }
2088 this.httprequest.tpromise._consent.retPromise = this.httprequest.tpromise;
2089 this.httprequest.tpromise._consent.then(
@@ -2428,29 +2422,28 @@ function onTunnelData(data) {
2422 var pr;
2423 if (process.platform == 'win32') {
2424 var enhanced = false;
2431 - try {
2432 - require('win-userconsent');
2433 - enhanced = true;
2434 - } catch (ex) { }
2425 + try { require('win-userconsent'); enhanced = true; } catch (ex) { }
2426 if (enhanced) {
2427 var ipr = server_getUserImage(this.httprequest.userid);
2428 ipr.consentTitle = consentTitle;
2429 ipr.consentMessage = consentMessage;
2430 + ipr.consentTimeout = this.httprequest.consentTimeout;
2431 + ipr.consentAutoAccept = this.httprequest.consentAutoAccept; // TODO: If true, consent timeout must accept.
2432 ipr.tsid = tsid;
2433 ipr.username = this.httprequest.realname;
2434 ipr.translation = { Allow: currentTranslation['allow'], Deny: currentTranslation['deny'], Auto: currentTranslation['autoAllowForFive'], Caption: consentMessage };
2435 pr = ipr.then(function (img) {
2443 - this.consent = require('win-userconsent').create(this.consentTitle, this.consentMessage, this.username, { b64Image: img.split(',').pop(), uid: this.tsid, timeout: 30000, translations: this.translation, background: color_options.background, foreground: color_options.foreground });
2436 + this.consent = require('win-userconsent').create(this.consentTitle, this.consentMessage, this.username, { b64Image: img.split(',').pop(), uid: this.tsid, timeout: this.consentTimeout * 1000, translations: this.translation, background: color_options.background, foreground: color_options.foreground });
2437 this.__childPromise.close = this.consent.close.bind(this.consent);
2438 return (this.consent);
2439 });
2440 }
2441 else {
2449 - pr = require('message-box').create(consentTitle, consentMessage, 30, null, tsid);
2442 + pr = require('message-box').create(consentTitle, consentMessage, this.consentTimeout, null, tsid);
2443 }
2444 }
2445 else {
2453 - pr = require('message-box').create(consentTitle, consentMessage, 30, null, tsid);
2446 + pr = require('message-box').create(consentTitle, consentMessage, this.consentTimeout, null, tsid);
2447 }
2448 pr.ws = this;
2449 this.pause();
@@ -2612,26 +2605,25 @@ function onTunnelData(data) {
2605 var pr;
2606 if (process.platform == 'win32') {
2607 var enhanced = false;
2615 - try {
2616 - require('win-userconsent');
2617 - enhanced = true;
2618 - } catch (ex) { }
2608 + try { require('win-userconsent'); enhanced = true; } catch (ex) { }
2609 if (enhanced) {
2610 var ipr = server_getUserImage(this.httprequest.userid);
2611 ipr.consentTitle = consentTitle;
2612 ipr.consentMessage = consentMessage;
2613 + ipr.consentTimeout = this.httprequest.consentTimeout;
2614 + ipr.consentAutoAccept = this.httprequest.consentAutoAccept; // TODO: If true, consent timeout must accept.
2615 ipr.username = this.httprequest.realname;
2616 ipr.translations = { Allow: currentTranslation['allow'], Deny: currentTranslation['deny'], Auto: currentTranslation['autoAllowForFive'], Caption: consentMessage };
2617 pr = ipr.then(function (img) {
2626 - this.consent = require('win-userconsent').create(this.consentTitle, this.consentMessage, this.username, { b64Image: img.split(',').pop(), timeout: 30000, translations: this.translations, background: color_options.background, foreground: color_options.foreground });
2618 + this.consent = require('win-userconsent').create(this.consentTitle, this.consentMessage, this.username, { b64Image: img.split(',').pop(), timeout: this.consentTimeout * 1000, translations: this.translations, background: color_options.background, foreground: color_options.foreground });
2619 this.__childPromise.close = this.consent.close.bind(this.consent);
2620 return (this.consent);
2621 });
2622 } else {
2631 - pr = require('message-box').create(consentTitle, consentMessage, 30, null);
2623 + pr = require('message-box').create(consentTitle, consentMessage, this.consentTimeout, null);
2624 }
2625 } else {
2634 - pr = require('message-box').create(consentTitle, consentMessage, 30, null);
2626 + pr = require('message-box').create(consentTitle, consentMessage, this.consentTimeout, null);
2627 }
2628 pr.ws = this;
2629 this.pause();
meshcentral-config-schema.json
+3 -1
@@ -492,7 +492,9 @@
492 "Title": { "type": "string" },
493 "Desktop": { "type": "string" },
494 "Terminal": { "type": "string" },
495 - "Files": { "type": "string" }
495 + "Files": { "type": "string" },
496 + "consentTimeout": { "type": "integer", "default": 30, "description": "How long in seconds to show the user consent dialog box." },
497 + "autoAcceptOnTimeout": { "type": "boolean", "default": false, "description": "If true, user consent is accepted after the timeout." }
498 }
499 },
500 "notificationMessages": {
meshdesktopmultiplex.js
+2
@@ -1339,6 +1339,8 @@ function CreateMeshRelayEx2(parent, ws, req, domain, user, cookie) {
1339 if (typeof domain.consentmessages.desktop == 'string') { command.soptions.consentMsgDesktop = domain.consentmessages.desktop; }
1340 if (typeof domain.consentmessages.terminal == 'string') { command.soptions.consentMsgTerminal = domain.consentmessages.terminal; }
1341 if (typeof domain.consentmessages.files == 'string') { command.soptions.consentMsgFiles = domain.consentmessages.files; }
1342 + if ((typeof domain.consentmessages.consenttimeout == 'number') && (domain.consentmessages.consenttimeout > 0)) { command.soptions.consentTimeout = domain.consentmessages.consenttimeout; }
1343 + if (domain.consentmessages.autoacceptontimeout === true) { command.soptions.consentAutoAccept = true; }
1344 }
1345 if (typeof domain.notificationmessages == 'object') {
1346 if (typeof domain.notificationmessages.title == 'string') { command.soptions.notifyTitle = domain.notificationmessages.title; }
meshrelay.js
+8
@@ -882,6 +882,8 @@ function CreateMeshRelayEx(parent, ws, req, domain, user, cookie) {
882 if (typeof domain.consentmessages.desktop == 'string') { command.soptions.consentMsgDesktop = domain.consentmessages.desktop; }
883 if (typeof domain.consentmessages.terminal == 'string') { command.soptions.consentMsgTerminal = domain.consentmessages.terminal; }
884 if (typeof domain.consentmessages.files == 'string') { command.soptions.consentMsgFiles = domain.consentmessages.files; }
885 + if ((typeof domain.consentmessages.consenttimeout == 'number') && (domain.consentmessages.consenttimeout > 0)) { command.soptions.consentTimeout = domain.consentmessages.consenttimeout; }
886 + if (domain.consentmessages.autoacceptontimeout === true) { command.soptions.consentAutoAccept = true; }
887 }
888 if (typeof domain.notificationmessages == 'object') {
889 if (typeof domain.notificationmessages.title == 'string') { command.soptions.notifyTitle = domain.notificationmessages.title; }
@@ -918,6 +920,8 @@ function CreateMeshRelayEx(parent, ws, req, domain, user, cookie) {
920 if (typeof domain.consentmessages.desktop == 'string') { command.soptions.consentMsgDesktop = domain.consentmessages.desktop; }
921 if (typeof domain.consentmessages.terminal == 'string') { command.soptions.consentMsgTerminal = domain.consentmessages.terminal; }
922 if (typeof domain.consentmessages.files == 'string') { command.soptions.consentMsgFiles = domain.consentmessages.files; }
923 + if ((typeof domain.consentmessages.consenttimeout == 'number') && (domain.consentmessages.consenttimeout > 0)) { command.soptions.consentTimeout = domain.consentmessages.consenttimeout; }
924 + if (domain.consentmessages.autoacceptontimeout === true) { command.soptions.consentAutoAccept = true; }
925 }
926 if (typeof domain.notificationmessages == 'object') {
927 if (typeof domain.notificationmessages.title == 'string') { command.soptions.notifyTitle = domain.notificationmessages.title; }
@@ -934,6 +938,8 @@ function CreateMeshRelayEx(parent, ws, req, domain, user, cookie) {
938 if (typeof domain.consentmessages.desktop == 'string') { command.soptions.consentMsgDesktop = domain.consentmessages.desktop; }
939 if (typeof domain.consentmessages.terminal == 'string') { command.soptions.consentMsgTerminal = domain.consentmessages.terminal; }
940 if (typeof domain.consentmessages.files == 'string') { command.soptions.consentMsgFiles = domain.consentmessages.files; }
941 + if ((typeof domain.consentmessages.consenttimeout == 'number') && (domain.consentmessages.consenttimeout > 0)) { command.soptions.consentTimeout = domain.consentmessages.consenttimeout; }
942 + if (domain.consentmessages.autoacceptontimeout === true) { command.soptions.consentAutoAccept = true; }
943 }
944 if (typeof domain.notificationmessages == 'object') {
945 if (typeof domain.notificationmessages.title == 'string') { command.soptions.notifyTitle = domain.notificationmessages.title; }
@@ -983,6 +989,8 @@ function CreateMeshRelayEx(parent, ws, req, domain, user, cookie) {
989 if (typeof domain.consentmessages.desktop == 'string') { command.soptions.consentMsgDesktop = domain.consentmessages.desktop; }
990 if (typeof domain.consentmessages.terminal == 'string') { command.soptions.consentMsgTerminal = domain.consentmessages.terminal; }
991 if (typeof domain.consentmessages.files == 'string') { command.soptions.consentMsgFiles = domain.consentmessages.files; }
992 + if ((typeof domain.consentmessages.consenttimeout == 'number') && (domain.consentmessages.consenttimeout > 0)) { command.soptions.consentTimeout = domain.consentmessages.consenttimeout; }
993 + if (domain.consentmessages.autoacceptontimeout === true) { command.soptions.consentAutoAccept = true; }
994 }
995 if (typeof domain.notificationmessages == 'object') {
996 if (typeof domain.notificationmessages.title == 'string') { command.soptions.notifyTitle = domain.notificationmessages.title; }
meshuser.js
+2
@@ -868,6 +868,8 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
868 if (typeof domain.consentmessages.desktop == 'string') { command.soptions.consentMsgDesktop = domain.consentmessages.desktop; }
869 if (typeof domain.consentmessages.terminal == 'string') { command.soptions.consentMsgTerminal = domain.consentmessages.terminal; }
870 if (typeof domain.consentmessages.files == 'string') { command.soptions.consentMsgFiles = domain.consentmessages.files; }
871 + if ((typeof domain.consentmessages.consenttimeout == 'number') && (domain.consentmessages.consenttimeout > 0)) { command.soptions.consentTimeout = domain.consentmessages.consenttimeout; }
872 + if (domain.consentmessages.autoacceptontimeout === true) { command.soptions.consentAutoAccept = true; }
873 }
874 if (typeof domain.notificationmessages == 'object') {
875 if (typeof domain.notificationmessages.title == 'string') { command.soptions.notifyTitle = domain.notificationmessages.title; }
sample-config-advanced.json
+3 -1
@@ -236,7 +236,9 @@
236 "title": "MeshCentral",
237 "desktop": "{0} requesting remote desktop access. Grant access?",
238 "terminal": "{0} requesting remote terminal access. Grant access?",
239 - "files": "{0} requesting remote files access. Grant access?"
239 + "files": "{0} requesting remote files access. Grant access?",
240 + "consentTimeout": 30,
241 + "autoAcceptOnTimeout": false
242 },
243 "_notificationMessages": {
244 "title": "MeshCentral",