Added translation support for Notifications and Privacy Bar

Bryan Roe committed Jan 14, 2022 at 15:54 UTC 545ffe3a81dee304c77050d24626db47f291aa22
2 files changed +46 -18
agents/meshcore.js
+36 -16
@@ -100,7 +100,7 @@ function getCoreTranslation()
100 {
101 try
102 {
103 - var lang = require('util-language').current;
103 + var lang = require('util-language').current;
104 if (coretranslations[lang] == null) { lang = lang.split('-')[0]; }
105 if (coretranslations[lang] == null) { lang = 'en'; }
106 if (coretranslations[lang] != null) { ret = coretranslations[lang]; }
@@ -114,6 +114,11 @@ function getCoreTranslation()
114 setDefaultCoreTranslation(ret, 'terminalConsent', '{0} requesting remote terminal access. Grant access?');
115 setDefaultCoreTranslation(ret, 'desktopConsent', '{0} requesting remote desktop access. Grant access?');
116 setDefaultCoreTranslation(ret, 'fileConsent', '{0} requesting remote file Access. Grant access?');
117 + setDefaultCoreTranslation(ret, 'terminalNotify', '{0} started a remote terminal session.');
118 + setDefaultCoreTranslation(ret, 'desktopNotify', '{0} started a remote desktop session.');
119 + setDefaultCoreTranslation(ret, 'fileNotify', '{0} started a remote file session.');
120 + setDefaultCoreTranslation(ret, 'privacyBar', 'Sharing desktop with: {0}');
121 +
122 return (ret);
123 }
124 var currentTranslation = getCoreTranslation();
@@ -1057,7 +1062,7 @@ function handleServerCommand(data) {
1062 tunnel.rights = data.rights;
1063 tunnel.consent = data.consent;
1064 if (global._MSH && _MSH().LocalConsent != null) { tunnel.consent |= parseInt(_MSH().LocalConsent); }
1060 - tunnel.privacybartext = data.privacybartext ? data.privacybartext : "Sharing desktop with: {0}";
1065 + tunnel.privacybartext = data.privacybartext ? data.privacybartext : currentTranslation['privacyBar'];
1066 tunnel.username = data.username + (data.guestname ? (' - ' + data.guestname) : '');
1067 tunnel.realname = (data.realname ? data.realname : data.username) + (data.guestname ? (' - ' + data.guestname) : '');
1068 tunnel.guestname = data.guestname;
@@ -2274,10 +2279,13 @@ function onTunnelData(data) {
2279 }
2280
2281 // Toast Notification, if required
2277 - if (this.ws.httprequest.consent && (this.ws.httprequest.consent & 2)) {
2282 + if (this.ws.httprequest.consent && (this.ws.httprequest.consent & 2))
2283 + {
2284 // User Notifications is required
2279 - var notifyMessage = this.ws.httprequest.username + " started a remote terminal session.", notifyTitle = "MeshCentral";
2280 - if (this.ws.httprequest.soptions != null) {
2285 + var notifyMessage = currentTranslation['terminalNotify'].replace('{0}', this.ws.httprequest.username);
2286 + var notifyTitle = "MeshCentral";
2287 + if (this.ws.httprequest.soptions != null)
2288 + {
2289 if (this.ws.httprequest.soptions.notifyTitle != null) { notifyTitle = this.ws.httprequest.soptions.notifyTitle; }
2290 if (this.ws.httprequest.soptions.notifyMsgTerminal != null) { notifyMessage = this.ws.httprequest.soptions.notifyMsgTerminal.replace('{0}', this.ws.httprequest.realname).replace('{1}', this.ws.httprequest.username); }
2291 }
@@ -2506,10 +2514,13 @@ function onTunnelData(data) {
2514 this.ws._consentpromise = null;
2515 MeshServerLogEx(30, null, "Starting remote desktop after local user accepted (" + this.ws.httprequest.remoteaddr + ")", this.ws.httprequest);
2516 this.ws.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: null, msgid: 0 }));
2509 - if (this.ws.httprequest.consent && (this.ws.httprequest.consent & 1)) {
2517 + if (this.ws.httprequest.consent && (this.ws.httprequest.consent & 1))
2518 + {
2519 // User Notifications is required
2511 - var notifyMessage = this.ws.httprequest.realname + " started a remote desktop session.", notifyTitle = "MeshCentral";
2512 - if (this.ws.httprequest.soptions != null) {
2520 + var notifyMessage = currentTranslation['desktopNotify'].replace('{0}', this.ws.httprequest.realname);
2521 + var notifyTitle = "MeshCentral";
2522 + if (this.ws.httprequest.soptions != null)
2523 + {
2524 if (this.ws.httprequest.soptions.notifyTitle != null) { notifyTitle = this.ws.httprequest.soptions.notifyTitle; }
2525 if (this.ws.httprequest.soptions.notifyMsgDesktop != null) { notifyMessage = this.ws.httprequest.soptions.notifyMsgDesktop.replace('{0}', this.ws.httprequest.realname).replace('{1}', this.ws.httprequest.username); }
2526 }
@@ -2559,7 +2570,8 @@ function onTunnelData(data) {
2570 if (this.httprequest.consent && (this.httprequest.consent & 1)) {
2571 // User Notifications is required
2572 MeshServerLogEx(35, null, "Started remote desktop with toast notification (" + this.httprequest.remoteaddr + ")", this.httprequest);
2562 - var notifyMessage = this.httprequest.realname + " started a remote desktop session.", notifyTitle = "MeshCentral";
2573 + var notifyMessage = currentTranslation['desktopNotify'].replace('{0}', this.ws.httprequest.realname);
2574 + var notifyTitle = "MeshCentral";
2575 if (this.httprequest.soptions != null) {
2576 if (this.httprequest.soptions.notifyTitle != null) { notifyTitle = this.httprequest.soptions.notifyTitle; }
2577 if (this.httprequest.soptions.notifyMsgDesktop != null) { notifyMessage = this.httprequest.soptions.notifyMsgDesktop.replace('{0}', this.httprequest.realname).replace('{1}', this.httprequest.username); }
@@ -2638,7 +2650,8 @@ function onTunnelData(data) {
2650 };
2651
2652 // Perform notification if needed. Toast messages may not be supported on all platforms.
2641 - if (this.httprequest.consent && (this.httprequest.consent & 32)) {
2653 + if (this.httprequest.consent && (this.httprequest.consent & 32))
2654 + {
2655 // User Consent Prompt is required
2656 // Send a console message back using the console channel, "\n" is supported.
2657 this.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: "Waiting for user to grant access...", msgid: 1 }));
@@ -2700,8 +2713,10 @@ function onTunnelData(data) {
2713 this.ws.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: null }));
2714 if (this.ws.httprequest.consent && (this.ws.httprequest.consent & 4)) {
2715 // User Notifications is required
2703 - var notifyMessage = this.ws.httprequest.realname + " started a remote file session.", notifyTitle = "MeshCentral";
2704 - if (this.ws.httprequest.soptions != null) {
2716 + var notifyMessage = currentTranslation['fileNotify'].replace('{0}', this.ws.httprequest.realname);
2717 + var notifyTitle = "MeshCentral";
2718 + if (this.ws.httprequest.soptions != null)
2719 + {
2720 if (this.ws.httprequest.soptions.notifyTitle != null) { notifyTitle = this.ws.httprequest.soptions.notifyTitle; }
2721 if (this.ws.httprequest.soptions.notifyMsgFiles != null) { notifyMessage = this.ws.httprequest.soptions.notifyMsgFiles.replace('{0}', this.ws.httprequest.realname).replace('{1}', this.ws.httprequest.username); }
2722 }
@@ -2715,13 +2730,18 @@ function onTunnelData(data) {
2730 MeshServerLogEx(41, null, "Failed to start remote files after local user rejected (" + this.ws.httprequest.remoteaddr + ")", this.ws.httprequest);
2731 this.ws.end(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: e.toString(), msgid: 2 }));
2732 });
2718 - } else {
2733 + }
2734 + else
2735 + {
2736 // User Consent Prompt is not required
2720 - if (this.httprequest.consent && (this.httprequest.consent & 4)) {
2737 + if (this.httprequest.consent && (this.httprequest.consent & 4))
2738 + {
2739 // User Notifications is required
2740 MeshServerLogEx(42, null, "Started remote files with toast notification (" + this.httprequest.remoteaddr + ")", this.httprequest);
2723 - var notifyMessage = this.httprequest.realname + " started a remote file session.", notifyTitle = "MeshCentral";
2724 - if (this.httprequest.soptions != null) {
2741 + var notifyMessage = currentTranslation['fileNotify'].replace('{0}', this.ws.httprequest.realname);
2742 + var notifyTitle = "MeshCentral";
2743 + if (this.httprequest.soptions != null)
2744 + {
2745 if (this.httprequest.soptions.notifyTitle != null) { notifyTitle = this.httprequest.soptions.notifyTitle; }
2746 if (this.httprequest.soptions.notifyMsgFiles != null) { notifyMessage = this.httprequest.soptions.notifyMsgFiles.replace('{0}', this.httprequest.realname).replace('{1}', this.httprequest.username); }
2747 }
agents/modules_meshcore/coretranslations.json
+10 -2
@@ -5,7 +5,11 @@
5 "autoAllowForFive": "Auto accept all connections for next 5 minutes",
6 "terminalConsent": "{0} requesting remote terminal access. Grant access?",
7 "desktopConsent": "{0} requesting remote desktop access. Grant access?",
8 - "fileConsent": "{0} requesting remote file Access. Grant access?"
8 + "fileConsent": "{0} requesting remote file Access. Grant access?",
9 + "terminalNotify": "{0} started a remote terminal session.",
10 + "desktopNotify": "{0} started a remote desktop session.",
11 + "fileNotify": "{0} started a remote file session.",
12 + "privacyBar": "Sharing desktop with: {0}"
13 },
14 "cs": {
15 "allow": "Dovolit",
@@ -41,7 +45,11 @@
45 },
46 "ko": {
47 "allow": "허용하다",
44 - "deny": "거부"
48 + "deny": "거부하다",
49 + "terminalNotify": "원격 터미널 세션이 시작되었습니다: {0}",
50 + "desktopNotify": "원격 데스크톱 세션이 시작되었습니다: {0}",
51 + "fileNotify": "원격 파일 전송 세션이 시작되었습니다: {0}",
52 + "privacyBar": "다음과 데스크탑 공유: {0}"
53 },
54 "nl": {
55 "allow": "Toestaan",