Updated translation support for KVM/Files/Terminal

Bryan Roe committed Jan 12, 2022 at 23:44 UTC 8fe748b4f3faa401f10d0dec43deb23b9e663eb4
1 file changed +48 -10
agents/meshcore.js
+48 -10
@@ -1,5 +1,5 @@
1 /*
2 -Copyright 2018-2021 Intel Corporation
2 +Copyright 2018-2022 Intel Corporation
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
@@ -87,6 +87,33 @@ if (require('MeshAgent').ARCHID == null) {
87 }
88 if (id != null) { Object.defineProperty(require('MeshAgent'), 'ARCHID', { value: id }); }
89 }
90 +
91 +function setDefaultCoreTranslation(obj, field, value)
92 +{
93 + if (obj[field] == null || obj[field] == '') { obj[field] = value; }
94 +}
95 +
96 +function getCoreTranslation()
97 +{
98 + var ret = {};
99 + var lang = require('util-language').current;
100 + if (global.coretranslations != null)
101 + {
102 + if (coretranslations[lang] == null) { lang = lang.split('-')[0]; }
103 + if (coretranslations[lang] == null) { lang = 'en'; }
104 + if (coretranslations[lang] != null) { ret = coretranslations[lang]; }
105 + }
106 +
107 + setDefaultCoreTranslation(ret, 'allow', 'Allow');
108 + setDefaultCoreTranslation(ret, 'deny', 'Deny');
109 + setDefaultCoreTranslation(ret, 'autoAllowForFive', 'Auto accept all connections for next 5 minutes');
110 + setDefaultCoreTranslation(ret, 'terminalConsent', '{0} requesting remote terminal access. Grant access?');
111 + setDefaultCoreTranslation(ret, 'desktopConsent', '{0} requesting remote desktop access. Grant access?');
112 + setDefaultCoreTranslation(ret, 'fileConsent', '{0} requesting remote file Access. Grant access?');
113 + return (ret);
114 +}
115 +var currentTranslation = getCoreTranslation();
116 +
117 function lockDesktop(uid)
118 {
119 switch (process.platform)
@@ -2038,8 +2065,11 @@ function onTunnelData(data) {
2065 // Perform User-Consent if needed.
2066 if (this.httprequest.consent && (this.httprequest.consent & 16)) {
2067 this.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: "Waiting for user to grant access...", msgid: 1 }));
2041 - var consentMessage = this.httprequest.username + " requesting remote terminal access. Grant access?", consentTitle = 'MeshCentral';
2042 - if (this.httprequest.soptions != null) {
2068 + var consentMessage = currentTranslation['terminalConsent'].replace('{0}', this.httprequest.realname).replace('{1}', this.httprequest.username);
2069 + var consentTitle = 'MeshCentral';
2070 +
2071 + if (this.httprequest.soptions != null)
2072 + {
2073 if (this.httprequest.soptions.consentTitle != null) { consentTitle = this.httprequest.soptions.consentTitle; }
2074 if (this.httprequest.soptions.consentMsgTerminal != null) { consentMessage = this.httprequest.soptions.consentMsgTerminal.replace('{0}', this.httprequest.realname).replace('{1}', this.httprequest.username); }
2075 }
@@ -2060,9 +2090,10 @@ function onTunnelData(data) {
2090 ipr.consentTitle = consentTitle;
2091 ipr.consentMessage = consentMessage;
2092 ipr.username = this.httprequest.realname;
2093 + ipr.translations = { Allow: currentTranslation['allow'], Deny: currentTranslation['deny'], Auto: currentTranslation['autoAllowForFive'], Caption: consentMessage };
2094 this.httprequest.tpromise._consent = ipr.then(function (img)
2095 {
2065 - this.consent = require('win-userconsent').create(this.consentTitle, this.consentMessage, this.username, { b64Image: img.split(',').pop(), timeout: 30000 });
2096 + this.consent = require('win-userconsent').create(this.consentTitle, this.consentMessage, this.username, { b64Image: img.split(',').pop(), timeout: 30000, translations: this.translations });
2097 this.__childPromise.close = this.consent.close.bind(this.consent);
2098 return (this.consent);
2099 });
@@ -2409,8 +2440,10 @@ function onTunnelData(data) {
2440 // User Consent Prompt is required
2441 // Send a console message back using the console channel, "\n" is supported.
2442 this.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: "Waiting for user to grant access...", msgid: 1 }));
2412 - var consentMessage = this.httprequest.realname + " requesting remote desktop access. Grant access?", consentTitle = 'MeshCentral';
2413 - if (this.httprequest.soptions != null) {
2443 + var consentMessage = currentTranslation['desktopConsent'].replace('{0}', this.httprequest.realname).replace('{1}', this.httprequest.username);
2444 + var consentTitle = 'MeshCentral';
2445 + if (this.httprequest.soptions != null)
2446 + {
2447 if (this.httprequest.soptions.consentTitle != null) { consentTitle = this.httprequest.soptions.consentTitle; }
2448 if (this.httprequest.soptions.consentMsgDesktop != null) { consentMessage = this.httprequest.soptions.consentMsgDesktop.replace('{0}', this.httprequest.realname).replace('{1}', this.httprequest.username); }
2449 }
@@ -2433,9 +2466,10 @@ function onTunnelData(data) {
2466 ipr.consentMessage = consentMessage;
2467 ipr.tsid = tsid;
2468 ipr.username = this.httprequest.realname;
2469 + ipr.translation = { Allow: currentTranslation['allow'], Deny: currentTranslation['deny'], Auto: currentTranslation['autoAllowForFive'], Caption: consentMessage };
2470 pr = ipr.then(function (img)
2471 {
2438 - this.consent = require('win-userconsent').create(this.consentTitle, this.consentMessage, this.username, { b64Image: img.split(',').pop(), uid: this.tsid, timeout: 30000 });
2472 + this.consent = require('win-userconsent').create(this.consentTitle, this.consentMessage, this.username, { b64Image: img.split(',').pop(), uid: this.tsid, timeout: 30000, translations: this.translation });
2473 this.__childPromise.close = this.consent.close.bind(this.consent);
2474 return (this.consent);
2475 });
@@ -2604,8 +2638,11 @@ function onTunnelData(data) {
2638 // User Consent Prompt is required
2639 // Send a console message back using the console channel, "\n" is supported.
2640 this.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: "Waiting for user to grant access...", msgid: 1 }));
2607 - var consentMessage = this.httprequest.realname + " requesting remote file Access. Grant access?", consentTitle = 'MeshCentral';
2608 - if (this.httprequest.soptions != null) {
2641 + var consentMessage = currentTranslation['fileConsent'].replace('{0}', this.httprequest.realname).replace('{1}', this.httprequest.username);
2642 + var consentTitle = 'MeshCentral';
2643 +
2644 + if (this.httprequest.soptions != null)
2645 + {
2646 if (this.httprequest.soptions.consentTitle != null) { consentTitle = this.httprequest.soptions.consentTitle; }
2647 if (this.httprequest.soptions.consentMsgFiles != null) { consentMessage = this.httprequest.soptions.consentMsgFiles.replace('{0}', this.httprequest.realname).replace('{1}', this.httprequest.username); }
2648 }
@@ -2627,9 +2664,10 @@ function onTunnelData(data) {
2664 ipr.consentTitle = consentTitle;
2665 ipr.consentMessage = consentMessage;
2666 ipr.username = this.httprequest.realname;
2667 + ipr.translations = { Allow: currentTranslation['allow'], Deny: currentTranslation['deny'], Auto: currentTranslation['autoAllowForFive'], Caption: consentMessage };
2668 pr = ipr.then(function (img)
2669 {
2632 - this.consent = require('win-userconsent').create(this.consentTitle, this.consentMessage, this.username, { b64Image: img.split(',').pop(), timeout: 30000 });
2670 + this.consent = require('win-userconsent').create(this.consentTitle, this.consentMessage, this.username, { b64Image: img.split(',').pop(), timeout: 30000, translations: this.translations });
2671 this.__childPromise.close = this.consent.close.bind(this.consent);
2672 return (this.consent);
2673 });