From a2aed9e772cef0ea43eba756475a41a9a27e95eb Mon Sep 17 00:00:00 2001 From: Simon Smith Date: Fri, 19 Jan 2024 02:56:54 +0000 Subject: [PATCH] show rdp port on button and set rdpport in console (#5708) * add rdpport to console Signed-off-by: si458 * add port number to rdp connect button Signed-off-by: si458 --------- Signed-off-by: si458 --- agents/meshcore.js | 40 +++++++++++++++++++++++++++++++++++++++- views/default.handlebars | 1 + 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/agents/meshcore.js b/agents/meshcore.js index 1c6284e8..ca0f2d46 100644 --- a/agents/meshcore.js +++ b/agents/meshcore.js @@ -3767,7 +3767,7 @@ function processConsoleCommand(cmd, args, rights, sessionid) { if (require('os').dns != null) { availcommands += ',dnsinfo'; } try { require('linux-dhcp'); availcommands += ',dhcp'; } catch (ex) { } if (process.platform == 'win32') { - availcommands += ',cs,wpfhwacceleration,uac,volumes'; + availcommands += ',cs,wpfhwacceleration,uac,volumes,rdpport'; if (bcdOK()) { availcommands += ',safemode'; } if (require('notifybar-desktop').DefaultPinned != null) { availcommands += ',privacybar'; } try { require('win-utils'); availcommands += ',taskbar'; } catch (ex) { } @@ -4051,6 +4051,44 @@ function processConsoleCommand(cmd, args, rights, sessionid) { case 'timerinfo': response = require('ChainViewer').getTimerInfo(); break; + case 'rdpport': + if (process.platform != 'win32') { + response = 'Unknown command "rdpport", type "help" for list of available commands.'; + return; + } + if (args['_'].length == 0) { + response = 'Proper usage: rdpport [get|default|PORTNUMBER]'; + } else { + switch (args['_'][0].toLocaleLowerCase()) { + case 'get': + var rdpport = require('win-registry').QueryKey(require('win-registry').HKEY.LocalMachine, 'System\\CurrentControlSet\\Control\\Terminal Server\\WinStations\\RDP-Tcp', 'PortNumber'); + response = "Current RDP Port Set To: " + rdpport + '\r\n'; + break; + case 'default': + try { + require('win-registry').WriteKey(require('win-registry').HKEY.LocalMachine, 'System\\CurrentControlSet\\Control\\Terminal Server\\WinStations\\RDP-Tcp', 'PortNumber', 3389); + response = 'RDP Port Set To 3389, Please Dont Forget To Restart Your Computer To Fully Apply'; + } catch (ex) { + response = 'Unable to Set RDP Port To: 3389'; + } + break; + default: + if (isNaN(parseFloat(args['_'][0]))){ + response = 'Proper usage: rdpport [get|default|PORTNUMBER]'; + } else if(parseFloat(args['_'][0]) < 0 || args['_'][0] > 65535) { + response = 'RDP Port Must Be More Than 0 And Less Than 65535'; + } else { + try { + require('win-registry').WriteKey(require('win-registry').HKEY.LocalMachine, 'System\\CurrentControlSet\\Control\\Terminal Server\\WinStations\\RDP-Tcp', 'PortNumber', parseFloat(args['_'][0])); + response = 'RDP Port Set To ' + args['_'][0] + ', Please Dont Forget To Restart Your Computer To Fully Apply'; + } catch (ex) { + response = 'Unable to Set RDP Port To: '+args['_'][0]; + } + } + break; + } + } + break; case 'find': if (args['_'].length <= 1) { response = "Proper usage:\r\n find root criteria [criteria2] [criteria n...]"; diff --git a/views/default.handlebars b/views/default.handlebars index 7c333d52..c0db5b7c 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -8984,6 +8984,7 @@ var online = ((currentNode.conn & 1) != 0); // If Agent (1) connected, enable remote desktop QE('connectbutton1', online); QE('connectbutton1r', online || (currentNode.mtype == 3)); + Q('connectbutton1r').value = 'RDP Connect' + ((currentNode.rdpport && currentNode.rdpport != 3389) ? ' ('+currentNode.rdpport + ')' : ''); var hwonline = ((currentNode.conn & 6) != 0); // If CIRA (2) or AMT (4) connected, enable hardware terminal QE('connectbutton1h', hwonline); QV('deskFocusBtn', (desktop != null) && (desktop.contype == 2) && (deskState != 0) && (desktopsettings.showfocus));