From d64fd051e8b3a36e2f1cfe4708fd13f37affe6cf Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Wed, 28 Apr 2021 00:45:17 -0700 Subject: [PATCH] Added local device group support. --- AddPortMapForm.cs | 6 +++--- MainForm.cs | 28 +++++++++++++++------------- MapUserControl.cs | 4 ++-- MeshCentralServer.cs | 12 ++++++++++++ NodeClass.cs | 2 ++ Properties/Resources.Designer.cs | 9 +++++++++ Properties/Resources.resx | 3 +++ 7 files changed, 46 insertions(+), 18 deletions(-) diff --git a/AddPortMapForm.cs b/AddPortMapForm.cs index 4a1a9ef..acf90d5 100644 --- a/AddPortMapForm.cs +++ b/AddPortMapForm.cs @@ -40,13 +40,13 @@ namespace MeshCentralRouter foreach (string meshid in meshcentral.meshes.Keys) { MeshClass mesh = meshcentral.meshes[meshid]; - if (mesh.type == 2) + if ((mesh.type == 2) || (mesh.type == 3)) { int nodeCount = 0; foreach (string nodeid in meshcentral.nodes.Keys) { NodeClass node = meshcentral.nodes[nodeid]; - if ((node.meshid == mesh.meshid) && ((node.conn & 1) != 0)) { nodeCount++; } + if ((node.meshid == mesh.meshid) && (((node.conn & 1) != 0) || (node.mtype == 3))) { nodeCount++; } } if (nodeCount > 0) { groupComboBox.Items.Add(mesh); } } @@ -103,7 +103,7 @@ namespace MeshCentralRouter foreach (string nodeid in meshcentral.nodes.Keys) { NodeClass node = meshcentral.nodes[nodeid]; - if (((node.meshid == mesh.meshid) || ((mesh.meshid == null) && (meshcentral.userRights.ContainsKey(node.nodeid)))) && ((node.conn & 1) != 0)) { nodeComboBox.Items.Add(node); } + if (((node.meshid == mesh.meshid) || ((mesh.meshid == null) && (meshcentral.userRights.ContainsKey(node.nodeid)))) && (((node.conn & 1) != 0) || (node.mtype == 3))) { nodeComboBox.Items.Add(node); } } } diff --git a/MainForm.cs b/MainForm.cs index 0091add..80bae73 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -620,9 +620,9 @@ namespace MeshCentralRouter device.SubItems[0].Text = node.name; } - bool connVisible = ((showOfflineDevicesToolStripMenuItem.Checked) || ((node.conn & 1) != 0)); + bool connVisible = ((showOfflineDevicesToolStripMenuItem.Checked) || ((node.conn & 1) != 0)) || (node.mtype == 3); int imageIndex = (node.icon - 1) * 2; - if ((node.conn & 1) == 0) { imageIndex++; } + if (((node.conn & 1) == 0) && (node.mtype != 3)) { imageIndex++; } device.ImageIndex = imageIndex; string userSearch = null; @@ -1094,7 +1094,7 @@ namespace MeshCentralRouter 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 + if (((node.conn & 1) == 0) && (node.mtype != 3)) { return; } // Agent not connected on this device & not local device form.setNode(node); } @@ -1654,7 +1654,7 @@ namespace MeshCentralRouter if (devicesListView.SelectedItems.Count != 1) { e.Cancel = true; return; } // Device not selected ListViewItem selecteditem = devicesListView.SelectedItems[0]; NodeClass node = (NodeClass)selecteditem.Tag; - if ((node.conn & 1) == 0) { e.Cancel = true; return; } // Agent not connected on this device + if (((node.conn & 1) == 0) && (node.mtype != 3)) { e.Cancel = true; return; } // Agent not connected on this device if (node.agentid < 6) { // Windows OS @@ -1669,7 +1669,9 @@ namespace MeshCentralRouter scpToolStripMenuItem.Visible = true; rdpToolStripMenuItem.Visible = false; } - remoteDesktopToolStripMenuItem.Visible = ((node.agentcaps & 1) != 0); // Only display remote desktop if it's supported by the agent + addRelayMapToolStripMenuItem.Visible = (node.mtype != 3); // Relay mappings are not allowed for local devices + remoteDesktopToolStripMenuItem.Visible = ((node.agentcaps & 1) != 0); // Only display remote desktop if it's supported by the agent (1 = Desktop) + remoteFilesToolStripMenuItem.Visible = ((node.agentcaps & 4) != 0); // Only display remote desktop if it's supported by the agent (4 = Files) } private void httpToolStripMenuItem_Click(object sender, EventArgs e) @@ -1677,7 +1679,7 @@ namespace MeshCentralRouter 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 + if (((node.conn & 1) == 0) && (node.mtype != 3)) { return; } // Agent not connected on this device & not local device QuickMap(1, 80, 1, node); // HTTP } @@ -1686,7 +1688,7 @@ namespace MeshCentralRouter 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 + if (((node.conn & 1) == 0) && (node.mtype != 3)) { return; } // Agent not connected on this device & not local device QuickMap(1, 443, 2, node); // HTTPS } private void rdpToolStripMenuItem_Click(object sender, EventArgs e) @@ -1694,7 +1696,7 @@ namespace MeshCentralRouter 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 + if (((node.conn & 1) == 0) && (node.mtype != 3)) { return; } // Agent not connected on this device & not local device int rdpport = 3389; if (node.rdpport != 0) { rdpport = node.rdpport; } QuickMap(1, rdpport, 3, node); // RDP @@ -1705,7 +1707,7 @@ namespace MeshCentralRouter 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 + if (((node.conn & 1) == 0) && (node.mtype != 3)) { return; } // Agent not connected on this device & not local device QuickMap(1, 22, 4, node); // Putty } @@ -1714,7 +1716,7 @@ namespace MeshCentralRouter 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 + if (((node.conn & 1) == 0) && (node.mtype != 3)) { return; } // Agent not connected on this device & not local device QuickMap(1, 22, 5, node); // WinSCP } @@ -1723,7 +1725,7 @@ namespace MeshCentralRouter 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 + if (((node.conn & 1) == 0) && (node.mtype != 3)) { return; } // Agent not connected on this device & not local device addButton_Click(null, null); } @@ -1732,7 +1734,7 @@ namespace MeshCentralRouter 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 + if (((node.conn & 1) == 0) && (node.mtype != 3)) { return; } // Agent not connected on this device & not local device addRelayMapButton_Click(null, null); } @@ -1742,7 +1744,7 @@ namespace MeshCentralRouter 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 + if (((node.conn & 1) == 0) && (node.mtype != 3)) { return; } // Agent not connected on this device & not local device if (deviceDoubleClickAction == 0) { addMapToolStripMenuItem_Click(null, null); } if (deviceDoubleClickAction == 1) { addRelayMapToolStripMenuItem_Click(null, null); } diff --git a/MapUserControl.cs b/MapUserControl.cs index 94477e6..29973e3 100644 --- a/MapUserControl.cs +++ b/MapUserControl.cs @@ -70,9 +70,9 @@ namespace MeshCentralRouter string serverurl; int keyIndex = host.IndexOf("?key="); if (keyIndex >= 0) { - serverurl = "wss://" + host.Substring(0, keyIndex) + "/meshrelay.ashx?nodeid=" + node.nodeid + "&key=" + host.Substring(keyIndex + 5); + serverurl = "wss://" + host.Substring(0, keyIndex) + "/" + ((node.mtype == 3)?"local":"mesh") + "relay.ashx?nodeid=" + node.nodeid + "&key=" + host.Substring(keyIndex + 5); } else { - serverurl = "wss://" + host + "/meshrelay.ashx?nodeid=" + node.nodeid; + serverurl = "wss://" + host + "/" + ((node.mtype == 3) ? "local" : "mesh") + "relay.ashx?nodeid=" + node.nodeid; } if (protocol == 1) { serverurl += ("&tcpport=" + remotePort); diff --git a/MeshCentralServer.cs b/MeshCentralServer.cs index e03c198..169a69d 100644 --- a/MeshCentralServer.cs +++ b/MeshCentralServer.cs @@ -492,10 +492,16 @@ namespace MeshCentralRouter } n.name = (string)node["name"]; n.meshid = meshid; + if (node.ContainsKey("mtype")) + { + if (node["mtype"].GetType() == typeof(string)) { n.mtype = int.Parse((string)node["mtype"]); } + if (node["mtype"].GetType() == typeof(int)) { n.mtype = (int)node["mtype"]; } + } if (node.ContainsKey("users")) { n.users = (string[])((ArrayList)node["users"]).ToArray(typeof(string)); } else { n.users = null; } if (node.ContainsKey("rdpport")) { n.rdpport = (int)node["rdpport"]; } else { n.rdpport = 3389; } if (node.ContainsKey("conn")) { n.conn = (int)node["conn"]; } else { n.conn = 0; } if (node.ContainsKey("icon")) { n.icon = (int)node["icon"]; } + if (n.icon == 0) { n.icon = 1; } n.rights = 0; n.links = new Dictionary(); if (node.ContainsKey("links")) @@ -531,10 +537,16 @@ namespace MeshCentralRouter n.name = (string)node["name"]; n.meshid = meshid; + if (node.ContainsKey("mtype")) + { + if (node["mtype"].GetType() == typeof(string)) { n.mtype = int.Parse((string)node["mtype"]); } + if (node["mtype"].GetType() == typeof(int)) { n.mtype = (int)node["mtype"]; } + } if (node.ContainsKey("users")) { n.users = (string[])((ArrayList)node["users"]).ToArray(typeof(string)); } else { n.users = null; } if (node.ContainsKey("rdpport")) { n.rdpport = (int)node["rdpport"]; } else { n.rdpport = 3389; } if (node.ContainsKey("conn")) { n.conn = (int)node["conn"]; } else { n.conn = 0; } if (node.ContainsKey("icon")) { n.icon = (int)node["icon"]; } + if (n.icon == 0) { n.icon = 1; } n.rights = 0; n.links = new Dictionary(); if (node.ContainsKey("links")) diff --git a/NodeClass.cs b/NodeClass.cs index 2708eb4..c40280e 100644 --- a/NodeClass.cs +++ b/NodeClass.cs @@ -18,6 +18,7 @@ namespace MeshCentralRouter public int conn; public int rdpport; public ulong rights; + public int mtype; public MeshClass mesh; public ListViewItem listitem; public DeviceUserControl control; @@ -31,6 +32,7 @@ namespace MeshCentralRouter public string getStateString() { string status = ""; + if (mtype == 3) return Properties.Resources.Local; if ((conn & 1) != 0) { if (status.Length > 0) { status += ", "; } status += Properties.Resources.Agent; } if ((conn & 2) != 0) { if (status.Length > 0) { status += ", "; } status += Properties.Resources.CIRA; } if ((conn & 4) != 0) { if (status.Length > 0) { status += ", "; } status += Properties.Resources.AMT; } diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index be75755..a7d8699 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -300,6 +300,15 @@ namespace MeshCentralRouter.Properties { } } + /// + /// Looks up a localized string similar to Local. + /// + internal static string Local { + get { + return ResourceManager.GetString("Local", resourceCulture); + } + } + /// /// Looks up a localized string similar to , {0} connections.. /// diff --git a/Properties/Resources.resx b/Properties/Resources.resx index 960e5d9..dd59d0f 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -268,4 +268,7 @@ OpenSSH + + Local + \ No newline at end of file