From 63f651081ff429dd4e3889dad5941e80a60e14a2 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Wed, 3 Feb 2021 11:29:44 -0800 Subject: [PATCH] Different attempt at the RDP/Putty fix. --- AddPortMapForm.cs | 21 ++++++++++---- AddRelayMapForm.cs | 15 ++++++++-- MainForm.cs | 23 ++++++++------- MapUserControl.cs | 58 +++++++++++++++++++------------------- Properties/AssemblyInfo.cs | 2 +- 5 files changed, 68 insertions(+), 51 deletions(-) diff --git a/AddPortMapForm.cs b/AddPortMapForm.cs index 455a10c..4a1a9ef 100644 --- a/AddPortMapForm.cs +++ b/AddPortMapForm.cs @@ -18,7 +18,16 @@ namespace MeshCentralRouter public int getProtocol() { return (int)(tcpRadioButton.Checked?1:2); } public int getLocalPort() { return (int)localNumericUpDown.Value; } public int getRemotePort() { return (int)remoteNumericUpDown.Value; } - public int getAppId() { return (int)appComboBox.SelectedIndex; } + public int getAppId() { + int x = (int)appComboBox.SelectedIndex; + if (x == 0) { return 0; } // Custom + if (x == 1) { return 1; } // HTTP + if (x == 2) { return 2; } // HTTPS + if (x == 3) { return 4; } // PuTTY + if (x == 4) { return 3; } // RDP + if (x == 5) { return 5; } // WinSCP + return x; + } public NodeClass getNode() { return (NodeClass)nodeComboBox.SelectedItem; } public void setNode(NodeClass node) { selectedNode = node; } @@ -103,11 +112,11 @@ namespace MeshCentralRouter private void appComboBox_SelectedIndexChanged(object sender, EventArgs e) { - if (appComboBox.SelectedIndex == 1) { remoteNumericUpDown.Value = 80; } - if (appComboBox.SelectedIndex == 2) { remoteNumericUpDown.Value = 443; } - if (appComboBox.SelectedIndex == 3) { remoteNumericUpDown.Value = 22; } - if (appComboBox.SelectedIndex == 4) { remoteNumericUpDown.Value = 3389; } - if (appComboBox.SelectedIndex == 5) { remoteNumericUpDown.Value = 22; } + if (appComboBox.SelectedIndex == 1) { remoteNumericUpDown.Value = 80; } // HTTP + if (appComboBox.SelectedIndex == 2) { remoteNumericUpDown.Value = 443; } // HTTPS + if (appComboBox.SelectedIndex == 3) { remoteNumericUpDown.Value = 22; } // SSH + if (appComboBox.SelectedIndex == 4) { remoteNumericUpDown.Value = 3389; } // RDP + if (appComboBox.SelectedIndex == 5) { remoteNumericUpDown.Value = 22; } // SCP } private void cancelButton_Click(object sender, EventArgs e) diff --git a/AddRelayMapForm.cs b/AddRelayMapForm.cs index f1646d2..fc3dd94 100644 --- a/AddRelayMapForm.cs +++ b/AddRelayMapForm.cs @@ -21,7 +21,16 @@ namespace MeshCentralRouter public int getLocalPort() { return (int)localNumericUpDown.Value; } public int getRemotePort() { return (int)remoteNumericUpDown.Value; } public string getRemoteIP() { return remoteIpTextBox.Text; } - public int getAppId() { return (int)appComboBox.SelectedIndex; } + public int getAppId() { + int x = (int)appComboBox.SelectedIndex; + if (x == 0) { return 0; } // Custom + if (x == 1) { return 1; } // HTTP + if (x == 2) { return 2; } // HTTPS + if (x == 3) { return 4; } // PuTTY + if (x == 4) { return 3; } // RDP + if (x == 5) { return 5; } // WinSCP + return x; + } public NodeClass getNode() { return (NodeClass)nodeComboBox.SelectedItem; } public void setNode(NodeClass node) { selectedNode = node; } @@ -107,8 +116,8 @@ namespace MeshCentralRouter { if (appComboBox.SelectedIndex == 1) { remoteNumericUpDown.Value = 80; } if (appComboBox.SelectedIndex == 2) { remoteNumericUpDown.Value = 443; } - if (appComboBox.SelectedIndex == 3) { remoteNumericUpDown.Value = 22; } - if (appComboBox.SelectedIndex == 4) { remoteNumericUpDown.Value = 3389; } + if (appComboBox.SelectedIndex == 3) { remoteNumericUpDown.Value = 3389; } + if (appComboBox.SelectedIndex == 4) { remoteNumericUpDown.Value = 22; } if (appComboBox.SelectedIndex == 5) { remoteNumericUpDown.Value = 22; } } diff --git a/MainForm.cs b/MainForm.cs index 1bb3276..334be7f 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -1337,7 +1337,7 @@ namespace MeshCentralRouter map.protocol = protocol; // 1 = TCP, 2 = UDP map.localPort = 0; // Any map.remotePort = port; // HTTP - map.appId = appId; // 0 = Custom, 1 = HTTP, 2 = HTTPS, 3 = PuTTY, 4 = RDP, 5 = WinSCP + map.appId = appId; // 0 = Custom, 1 = HTTP, 2 = HTTPS, 3 = RDP, 4 = PuTTY, 5 = WinSCP map.node = node; if (authLoginUrl != null) { map.host = authLoginUrl.Host + ":" + ((authLoginUrl.Port > 0) ? authLoginUrl.Port : 443); } else { map.host = serverNameComboBox.Text; } map.authCookie = meshcentral.authCookie; @@ -1608,16 +1608,6 @@ namespace MeshCentralRouter if ((node.conn & 1) == 0) { return; } // Agent not connected on this device QuickMap(1, 443, 2, node); // HTTPS } - - private void sshToolStripMenuItem_Click(object sender, EventArgs e) - { - if (devicesListView.SelectedItems.Count != 1) { return; } - ListViewItem selecteditem = devicesListView.SelectedItems[0]; - NodeClass node = (NodeClass)selecteditem.Tag; - if ((node.conn & 1) == 0) { return; } // Agent not connected on this device - QuickMap(1, 22, 3, node); // Putty - } - private void rdpToolStripMenuItem_Click(object sender, EventArgs e) { if (devicesListView.SelectedItems.Count != 1) { return; } @@ -1626,7 +1616,16 @@ namespace MeshCentralRouter if ((node.conn & 1) == 0) { return; } // Agent not connected on this device int rdpport = 3389; if (node.rdpport != 0) { rdpport = node.rdpport; } - QuickMap(1, rdpport, 4, node); // RDP + QuickMap(1, rdpport, 3, node); // RDP + } + + private void sshToolStripMenuItem_Click(object sender, EventArgs e) + { + if (devicesListView.SelectedItems.Count != 1) { return; } + ListViewItem selecteditem = devicesListView.SelectedItems[0]; + NodeClass node = (NodeClass)selecteditem.Tag; + if ((node.conn & 1) == 0) { return; } // Agent not connected on this device + QuickMap(1, 22, 4, node); // Putty } private void scpToolStripMenuItem_Click(object sender, EventArgs e) diff --git a/MapUserControl.cs b/MapUserControl.cs index 03fa17f..fd725c9 100644 --- a/MapUserControl.cs +++ b/MapUserControl.cs @@ -95,8 +95,8 @@ namespace MeshCentralRouter } else { if (appId == 1) { statemsg = "HTTP: " + statemsg; } else if (appId == 2) { statemsg = "HTTPS: " + statemsg; } - else if (appId == 3) { statemsg = "PuTTY: " + statemsg; } - else if (appId == 4) { statemsg = "RDP: " + statemsg; } + else if (appId == 3) { statemsg = "RDP: " + statemsg; } + else if (appId == 4) { statemsg = "PuTTY: " + statemsg; } else if (appId == 5) { statemsg = "WinSCP: " + statemsg; } else { statemsg = "TCP: " + statemsg; } } @@ -111,6 +111,33 @@ namespace MeshCentralRouter if (appId == 1) { System.Diagnostics.Process.Start("http://localhost:" + mapper.localport); } if (appId == 2) { System.Diagnostics.Process.Start("https://localhost:" + mapper.localport); } if (appId == 3) + { + System.Diagnostics.Process proc = null; + string cmd = System.Environment.GetFolderPath(System.Environment.SpecialFolder.System) + "\\mstsc.exe"; + string tfile = Path.Combine(Path.GetTempPath(), "MeshRdpFile.rdp"); + string[] f = null; + try { if (File.Exists(tfile)) f = File.ReadAllLines(tfile); } catch (Exception) { } + if (f != null) + { + List f2 = new List(); + foreach (string fx in f) { if (!fx.StartsWith("full address")) f2.Add(fx); } + f2.Add(string.Format("full address:s:127.0.0.1:{0}", mapper.localport)); + File.WriteAllLines(tfile, f2.ToArray()); + } + else + { + File.WriteAllText(tfile, string.Format("full address:s:127.0.0.1:{0}", mapper.localport)); + } + string args = "/edit:\"" + tfile + "\""; + + // Launch the process + try { proc = System.Diagnostics.Process.Start(cmd, args); } + catch (System.ComponentModel.Win32Exception) { } + + // Setup auto-exit + if ((autoexit == true) && (parent.autoExitProc == null)) { parent.autoExitProc = proc; parent.SetAutoClose(); autoExitTimer.Enabled = true; } + } + if (appId == 4) { string puttyPath = loadFromRegistry("PuttyPath"); if ((shift == false) && (File.Exists(puttyPath))) @@ -147,33 +174,6 @@ namespace MeshCentralRouter } } } - if (appId == 4) - { - System.Diagnostics.Process proc = null; - string cmd = System.Environment.GetFolderPath(System.Environment.SpecialFolder.System) + "\\mstsc.exe"; - string tfile = Path.Combine(Path.GetTempPath(), "MeshRdpFile.rdp"); - string[] f = null; - try { if (File.Exists(tfile)) f = File.ReadAllLines(tfile); } catch (Exception) { } - if (f != null) - { - List f2 = new List(); - foreach (string fx in f) { if (!fx.StartsWith("full address")) f2.Add(fx); } - f2.Add(string.Format("full address:s:127.0.0.1:{0}", mapper.localport)); - File.WriteAllLines(tfile, f2.ToArray()); - } - else - { - File.WriteAllText(tfile, string.Format("full address:s:127.0.0.1:{0}", mapper.localport)); - } - string args = "/edit:\"" + tfile + "\""; - - // Launch the process - try { proc = System.Diagnostics.Process.Start(cmd, args); } - catch (System.ComponentModel.Win32Exception) { } - - // Setup auto-exit - if ((autoexit == true) && (parent.autoExitProc == null)) { parent.autoExitProc = proc; parent.SetAutoClose(); autoExitTimer.Enabled = true; } - } if (appId == 5) { string winScpPath = loadFromRegistry("WinSCPPath"); diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index e106fb8..0d4d268 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -31,6 +31,6 @@ using System.Runtime.InteropServices; // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("1.2.*")] +[assembly: AssemblyVersion("1.3.*")] //[assembly: AssemblyVersion("1.0.0.0")] //[assembly: AssemblyFileVersion("1.0.0.0")]