diff --git a/DeviceUserControl.resx b/DeviceUserControl.resx index dc6b097..5fb69c2 100644 --- a/DeviceUserControl.resx +++ b/DeviceUserControl.resx @@ -269,7 +269,7 @@ 62, 12 - 243, 15 + 235, 15 1 @@ -296,7 +296,7 @@ 62, 32 - 243, 15 + 235, 15 2 @@ -322,12 +322,6 @@ 313, 17 - - 149, 22 - - - Set RDP port... - 150, 26 @@ -338,7 +332,7 @@ System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - 375, 6 + 367, 6 58, 47 @@ -361,6 +355,12 @@ 6 + + 149, 22 + + + Set RDP port... + 17, 17 @@ -369,7 +369,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAAy - mgAAAk1TRnQBSQFMAgEBCAEAAWABAAFgAQABMgEAATIBAAT/AREBAAj/AUIBTQE2BwABNgMAASgDAAHI + mgAAAk1TRnQBSQFMAgEBCAEAAWgBAAFoAQABMgEAATIBAAT/AREBAAj/AUIBTQE2BwABNgMAASgDAAHI AwABlgMAAQEBAAEQBQABYAHq/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A /wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A /wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A @@ -1037,7 +1037,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAC4 - mgAAAk1TRnQBSQFMAgEBCAEAAWgBAAFoAQABMgEAATIBAAT/AREBAAj/AUIBTQE2BwABNgMAASgDAAHI + mgAAAk1TRnQBSQFMAgEBCAEAAXABAAFwAQABMgEAATIBAAT/AREBAAj/AUIBTQE2BwABNgMAASgDAAHI AwABlgMAAQEBAAEQBQABYAHq/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A /wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A /wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A @@ -1706,12 +1706,6 @@ 468, 17 - - 178, 22 - - - Use Alternate Port... - 179, 26 @@ -1722,7 +1716,7 @@ System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - 311, 6 + 303, 6 58, 23 @@ -1745,11 +1739,17 @@ 5 + + 178, 22 + + + Use Alternate Port... + Top, Right - 311, 30 + 303, 30 58, 23 @@ -1776,7 +1776,7 @@ Top, Right - 375, 30 + 367, 30 58, 23 @@ -1803,7 +1803,7 @@ Top, Right - 375, 6 + 367, 6 58, 23 @@ -1833,7 +1833,7 @@ 6, 13 - 437, 56 + 433, 60 setRDPPortToolStripMenuItem diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index 1a6ba5e..2fca923 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -105,6 +105,11 @@ this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator(); this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.installTimer = new System.Windows.Forms.Timer(this.components); + this.mappingsContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components); + this.openMappingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.saveMappingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.openMapFileDialog = new System.Windows.Forms.OpenFileDialog(); + this.saveMapFileDialog = new System.Windows.Forms.SaveFileDialog(); this.panel5.SuspendLayout(); this.mainPanel.SuspendLayout(); this.mainTabControl.SuspendLayout(); @@ -132,6 +137,7 @@ ((System.ComponentModel.ISupportInitialize)(this.pictureBox7)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.trayIconContextMenuStrip.SuspendLayout(); + this.mappingsContextMenuStrip.SuspendLayout(); this.SuspendLayout(); // // panel5 @@ -680,6 +686,36 @@ // this.installTimer.Tick += new System.EventHandler(this.installTimer_Tick); // + // mappingsContextMenuStrip + // + this.mappingsContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.openMappingsToolStripMenuItem, + this.saveMappingsToolStripMenuItem}); + this.mappingsContextMenuStrip.Name = "mappingsContextMenuStrip"; + resources.ApplyResources(this.mappingsContextMenuStrip, "mappingsContextMenuStrip"); + // + // openMappingsToolStripMenuItem + // + this.openMappingsToolStripMenuItem.Name = "openMappingsToolStripMenuItem"; + resources.ApplyResources(this.openMappingsToolStripMenuItem, "openMappingsToolStripMenuItem"); + this.openMappingsToolStripMenuItem.Click += new System.EventHandler(this.openMappingsToolStripMenuItem_Click); + // + // saveMappingsToolStripMenuItem + // + this.saveMappingsToolStripMenuItem.Name = "saveMappingsToolStripMenuItem"; + resources.ApplyResources(this.saveMappingsToolStripMenuItem, "saveMappingsToolStripMenuItem"); + this.saveMappingsToolStripMenuItem.Click += new System.EventHandler(this.saveMappingsToolStripMenuItem_Click); + // + // openMapFileDialog + // + this.openMapFileDialog.DefaultExt = "mcrouter"; + resources.ApplyResources(this.openMapFileDialog, "openMapFileDialog"); + // + // saveMapFileDialog + // + this.saveMapFileDialog.DefaultExt = "mcrouter"; + resources.ApplyResources(this.saveMapFileDialog, "saveMapFileDialog"); + // // MainForm // resources.ApplyResources(this, "$this"); @@ -722,6 +758,7 @@ ((System.ComponentModel.ISupportInitialize)(this.pictureBox7)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.trayIconContextMenuStrip.ResumeLayout(false); + this.mappingsContextMenuStrip.ResumeLayout(false); this.ResumeLayout(false); } @@ -802,6 +839,11 @@ private System.Windows.Forms.Button smsTokenButton; private System.Windows.Forms.Button installButton; private System.Windows.Forms.Timer installTimer; + private System.Windows.Forms.ContextMenuStrip mappingsContextMenuStrip; + private System.Windows.Forms.ToolStripMenuItem openMappingsToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem saveMappingsToolStripMenuItem; + private System.Windows.Forms.OpenFileDialog openMapFileDialog; + private System.Windows.Forms.SaveFileDialog saveMapFileDialog; } } diff --git a/MainForm.cs b/MainForm.cs index c32a392..f9b58b4 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -15,13 +15,16 @@ limitations under the License. */ using System; +using System.IO; using System.Net; using System.Reflection; using System.Collections; using System.Diagnostics; using System.Windows.Forms; using System.Security.Principal; +using System.Collections.Generic; using System.Runtime.InteropServices; +using System.Web.Script.Serialization; using System.Security.Cryptography.X509Certificates; using Microsoft.Win32; @@ -44,6 +47,8 @@ namespace MeshCentralRouter public bool sendSMSToken = false; public Uri authLoginUrl = null; public Process installProcess = null; + public string acceptableCertHash = null; + public ArrayList mappingsToSetup = null; public void setRegValue(string name, string value) { try { Registry.SetValue(@"HKEY_CURRENT_USER\SOFTWARE\Open Source\MeshCentral Router", name, value); } catch (Exception) { } @@ -177,6 +182,7 @@ namespace MeshCentralRouter if (arg.Length > 6 && arg.Substring(0, 6).ToLower() == "-pass:") { passwordTextBox.Text = arg.Substring(6); argflags |= 4; } if (arg.Length > 8 && arg.Substring(0, 8).ToLower() == "-search:") { searchTextBox.Text = arg.Substring(8); } if (arg.Length > 11 && arg.Substring(0, 11).ToLower() == "mcrouter://") { authLoginUrl = new Uri(arg); } + if ((arg.Length > 1) && (arg[0] != '-') && (arg.ToLower().EndsWith(".mcrouter"))) { try { argflags |= loadMappingFile(File.ReadAllText(arg)); } catch (Exception) { } } } autoLogin = (argflags == 7); @@ -287,6 +293,7 @@ namespace MeshCentralRouter meshcentral = new MeshCentralServer(); meshcentral.debug = debug; meshcentral.ignoreCert = ignoreCert; + if (acceptableCertHash != null) { meshcentral.okCertHash2 = acceptableCertHash; } meshcentral.onStateChanged += Meshcentral_onStateChanged; meshcentral.onNodesChanged += Meshcentral_onNodesChanged; meshcentral.onLoginTokenChanged += Meshcentral_onLoginTokenChanged; @@ -336,9 +343,9 @@ namespace MeshCentralRouter openWebSiteButton.Visible = true; } - private void Meshcentral_onNodesChanged() + private void Meshcentral_onNodesChanged(bool fullRefresh) { - if (this.InvokeRequired) { this.Invoke(new MeshCentralServer.onNodeListChangedHandler(Meshcentral_onNodesChanged)); return; } + if (this.InvokeRequired) { this.Invoke(new MeshCentralServer.onNodeListChangedHandler(Meshcentral_onNodesChanged), fullRefresh); return; } addRelayButton.Enabled = addButton.Enabled = ((meshcentral.nodes != null) && (meshcentral.nodes.Count > 0)); // Update any active mappings @@ -354,6 +361,9 @@ namespace MeshCentralRouter updateDeviceList(); // Update list of devices addArgMappings(); reconnectUdpMaps(); + + // Setup any automatic mappings + if ((fullRefresh == true) && (mappingsToSetup != null)) { setupMappings(); } } private void updateDeviceList() @@ -980,7 +990,12 @@ namespace MeshCentralRouter private void devicesTabControl_SelectedIndexChanged(object sender, EventArgs e) { - menuLabel.Visible = searchTextBox.Visible = (devicesTabControl.SelectedIndex == 0); + searchTextBox.Visible = (devicesTabControl.SelectedIndex == 0); + if (devicesTabControl.SelectedIndex == 0) { + menuLabel.ContextMenuStrip = mainContextMenuStrip; + } else { + menuLabel.ContextMenuStrip = mappingsContextMenuStrip; + } } private void searchTextBox_KeyPress(object sender, KeyPressEventArgs e) @@ -1057,7 +1072,14 @@ namespace MeshCentralRouter private void menuLabel_Click(object sender, EventArgs e) { - mainContextMenuStrip.Show(menuLabel, menuLabel.PointToClient(Cursor.Position)); + if (devicesTabControl.SelectedIndex == 0) + { + mainContextMenuStrip.Show(menuLabel, menuLabel.PointToClient(Cursor.Position)); + } + else + { + mappingsContextMenuStrip.Show(menuLabel, menuLabel.PointToClient(Cursor.Position)); + } } private void showGroupNamesToolStripMenuItem_Click(object sender, EventArgs e) @@ -1106,6 +1128,98 @@ namespace MeshCentralRouter } } + private void openMappingsToolStripMenuItem_Click(object sender, EventArgs e) + { + if (openMapFileDialog.ShowDialog(this) == DialogResult.OK) + { + string text = null; + try { text = File.ReadAllText(openMapFileDialog.FileName); } catch (Exception) { } + if (text != null) { loadMappingFile(text); } + } + } + + private int loadMappingFile(string data) + { + int argFlags = 3; + Dictionary jsonAction = new Dictionary(); + jsonAction = new JavaScriptSerializer().Deserialize>(data); + if ((jsonAction == null) || (jsonAction["hostname"].GetType() != typeof(string)) || (jsonAction["username"].GetType() != typeof(string)) || (jsonAction["certhash"].GetType() != typeof(string))) return 0; + serverNameComboBox.Text = jsonAction["hostname"].ToString(); + userNameTextBox.Text = jsonAction["username"].ToString(); + if (jsonAction.ContainsKey("password")) { passwordTextBox.Text = jsonAction["password"].ToString(); argFlags |= 4; } + acceptableCertHash = jsonAction["certhash"].ToString(); + + if (jsonAction["mappings"] != null) + { + ArrayList mappings = (ArrayList)jsonAction["mappings"]; + if (mappings.Count > 0) { mappingsToSetup = mappings; } + } + return argFlags; + } + + private void setupMappings() + { + foreach (Dictionary x in mappingsToSetup) + { + // Find the node + string nodeId = (string)x["nodeId"]; + NodeClass node = meshcentral.nodes[nodeId]; + if (node == null) continue; + + // Add a new port map + MapUserControl map = new MapUserControl(); + map.xdebug = debug; + map.inaddrany = inaddrany; + map.protocol = (int)x["protocol"]; + map.localPort = (int)x["localPort"]; + if (x.ContainsKey("remoteIP")) { map.remoteIP = (string)x["remoteIP"]; } + map.remotePort = (int)x["remotePort"]; + map.appId = (int)x["appId"]; + 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; + map.certhash = meshcentral.wshash; + map.parent = this; + map.Dock = DockStyle.Top; + map.Start(); + + mapPanel.Controls.Add(map); + noMapLabel.Visible = false; + + // Launch any executable + if (x.ContainsKey("launch")) { try { System.Diagnostics.Process.Start((string)x["launch"]); } catch (Exception) { } } + } + mappingsToSetup = null; + } + + private void saveMappingsToolStripMenuItem_Click(object sender, EventArgs e) + { + if (saveMapFileDialog.ShowDialog(this) == DialogResult.OK) + { + string text = "{\r\n \"hostname\": \"" + serverNameComboBox.Text + "\",\r\n \"username\": \"" + userNameTextBox.Text + "\",\r\n \"certhash\": \"" + meshcentral.certHash + "\",\r\n \"mappings\":[\r\n"; + var mapCounter = 0; + foreach (Control c in mapPanel.Controls) + { + if (c.GetType() != typeof(MapUserControl)) continue; + MapUserControl mapCtrl = (MapUserControl)c; + MeshMapper map = ((MapUserControl)c).mapper; + if (mapCounter == 0) { text += " {\r\n"; } else { text += ",\r\n {\r\n"; } + text += " \"nodeName\": \"" + mapCtrl.node.name + "\",\r\n"; + text += " \"meshId\": \"" + mapCtrl.node.meshid + "\",\r\n"; + text += " \"nodeId\": \"" + mapCtrl.node.nodeid + "\",\r\n"; + text += " \"appId\": " + mapCtrl.appId + ",\r\n"; + text += " \"protocol\": " + map.protocol + ",\r\n"; + text += " \"localPort\": " + map.localport + ",\r\n"; + if (map.remoteip != null) { text += " \"remoteIP\": \"" + map.remoteip + "\",\r\n"; } + text += " \"remotePort\": " + map.remoteport + "\r\n"; + text += " }"; + mapCounter++; + } + if (mapCounter > 0) { text += "\r\n ]\r\n}"; } else { text += " ]\r\n}"; } + File.WriteAllText(saveMapFileDialog.FileName, text); + } + } + /* private delegate void displayMessageHandler(string msg, int buttons, string extra, int progress); private void displayMessage(string msg, int buttons = 0, string extra = "", int progress = 0) diff --git a/MainForm.resx b/MainForm.resx index 175a43f..6ab69ca 100644 --- a/MainForm.resx +++ b/MainForm.resx @@ -1333,10 +1333,10 @@ NoControl - 91, 96 + 2, 88 - 243, 17 + 462, 52 5 @@ -1372,10 +1372,10 @@ NoControl - 91, 97 + 2, 88 - 243, 17 + 462, 52 4 @@ -1402,7 +1402,7 @@ 0, 0 - 470, 244 + 470, 250 50 @@ -1426,7 +1426,7 @@ 3, 3, 3, 3 - 470, 244 + 470, 250 0 @@ -1462,10 +1462,10 @@ NoControl - 91, 79 + 2, 79 - 243, 52 + 462, 52 4 @@ -1494,7 +1494,7 @@ Click "Add" to get started. 0, 0 - 470, 214 + 470, 220 49 @@ -1518,7 +1518,7 @@ Click "Add" to get started. NoControl - 1, 220 + 1, 226 20, 20 @@ -1545,7 +1545,7 @@ Click "Add" to get started. NoControl - 238, 220 + 238, 226 20, 20 @@ -1575,7 +1575,7 @@ Click "Add" to get started. NoControl - 370, 218 + 370, 224 100, 23 @@ -1608,7 +1608,7 @@ Click "Add" to get started. NoControl - 264, 218 + 264, 224 100, 23 @@ -1638,7 +1638,7 @@ Click "Add" to get started. 3, 3, 3, 3 - 470, 244 + 470, 250 1 @@ -1662,7 +1662,7 @@ Click "Add" to get started. 3, 3 - 478, 273 + 478, 279 55 @@ -1953,7 +1953,7 @@ Click "Add" to get started. $this - 2 + 3 17, 17 @@ -3691,6 +3691,48 @@ Click "Add" to get started. 791, 17 + + 905, 17 + + + 168, 22 + + + &Open Mappings... + + + 168, 22 + + + &Save Mappings... + + + 169, 48 + + + mappingsContextMenuStrip + + + System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 1110, 17 + + + Router Mapping|*.mcrouter + + + Open Port Mappings + + + 1268, 17 + + + Router Mapping|*.mcrouter + + + Save Port Mappings + True @@ -5469,6 +5511,30 @@ Click "Add" to get started. System.Windows.Forms.Timer, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + openMappingsToolStripMenuItem + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + saveMappingsToolStripMenuItem + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + openMapFileDialog + + + System.Windows.Forms.OpenFileDialog, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + saveMapFileDialog + + + System.Windows.Forms.SaveFileDialog, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + MainForm diff --git a/MapUserControl.resx b/MapUserControl.resx index 577ac26..194e414 100644 --- a/MapUserControl.resx +++ b/MapUserControl.resx @@ -147,11 +147,14 @@ Microsoft Sans Serif, 8.25pt, style=Bold + + NoControl + 62, 12 - 290, 15 + 294, 15 1 @@ -174,11 +177,14 @@ Top, Left, Right + + NoControl + 62, 32 - 290, 15 + 294, 15 2 @@ -202,7 +208,7 @@ Top, Right - 358, 6 + 348, 6 75, 23 @@ -229,7 +235,7 @@ Top, Right - 358, 30 + 348, 30 75, 23 @@ -260,7 +266,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAAy - mgAAAk1TRnQBSQFMAgEBCAEAATgBAAE4AQABMgEAATIBAAT/AREBAAj/AUIBTQE2BwABNgMAASgDAAHI + mgAAAk1TRnQBSQFMAgEBCAEAAUABAAFAAQABMgEAATIBAAT/AREBAAj/AUIBTQE2BwABNgMAASgDAAHI AwABlgMAAQEBAAEQBQABYAHq/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A /wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A /wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A @@ -927,7 +933,7 @@ 6, 13 - 433, 52 + 433, 60 deviceImageList diff --git a/MeshCentralServer.cs b/MeshCentralServer.cs index 6292b52..2101e93 100644 --- a/MeshCentralServer.cs +++ b/MeshCentralServer.cs @@ -54,6 +54,7 @@ namespace MeshCentralRouter public string authCookie = null; public string loginCookie = null; public string wshash = null; + public string certHash = null; public string okCertHash = null; public string okCertHash2 = null; public bool debug = false; @@ -141,7 +142,7 @@ namespace MeshCentralRouter wc = new xwebclient(); //Debug("#" + counter + ": Connecting web socket to: " + wsurl.ToString()); wc.Start(this, wsurl, user, pass, token, wshash); - if (debug) { File.AppendAllText("debug.log", "Connect-" + wsurl + "\r\n"); } + if (debug) { try { File.AppendAllText("debug.log", "Connect-" + wsurl + "\r\n"); } catch (Exception) { } } wc.xdebug = debug; wc.xignoreCert = ignoreCert; } @@ -152,14 +153,14 @@ namespace MeshCentralRouter { wc.Dispose(); wc = null; - if (debug) { File.AppendAllText("debug.log", "Disconnect\r\n"); } + if (debug) { try { File.AppendAllText("debug.log", "Disconnect\r\n"); } catch (Exception) { } } } } public void refreshCookies() { if (wc != null) { - if (debug) { File.AppendAllText("debug.log", "RefreshCookies\r\n"); } + if (debug) { try { File.AppendAllText("debug.log", "RefreshCookies\r\n"); } catch (Exception) { } } wc.WriteStringWebSocket("{\"action\":\"authcookie\"}"); wc.WriteStringWebSocket("{\"action\":\"logincookie\"}"); } @@ -169,14 +170,14 @@ namespace MeshCentralRouter { if (wc != null) { - if (debug) { File.AppendAllText("debug.log", "SetRdpPort\r\n"); } + if (debug) { try { File.AppendAllText("debug.log", "SetRdpPort\r\n"); } catch (Exception) { } } wc.WriteStringWebSocket("{\"action\":\"changedevice\",\"nodeid\":\"" + node.nodeid + "\",\"rdpport\":" + port + "}"); } } public void processServerData(string data) { - if (debug) { File.AppendAllText("debug.log", "ServerData-" + data + "\r\n"); } + if (debug) { try { File.AppendAllText("debug.log", "ServerData-" + data + "\r\n"); } catch (Exception) { } } // Parse the received JSON Dictionary jsonAction = new Dictionary(); @@ -253,7 +254,7 @@ namespace MeshCentralRouter userGroups.Add(i, usergroupsEx["name"].ToString()); } } - if ((onNodesChanged != null) && (nodes != null)) onNodesChanged(); + if ((onNodesChanged != null) && (nodes != null)) onNodesChanged(false); } } break; @@ -314,7 +315,7 @@ namespace MeshCentralRouter meshes[meshid] = mesh; } wc.WriteStringWebSocket("{\"action\":\"nodes\"}"); - if ((onNodesChanged != null) && (nodes != null)) onNodesChanged(); + if ((onNodesChanged != null) && (nodes != null)) onNodesChanged(false); break; } case "changenode": @@ -366,7 +367,7 @@ namespace MeshCentralRouter nodes[n.nodeid] = n; } } - if ((onNodesChanged != null) && (nodes != null)) onNodesChanged(); + if ((onNodesChanged != null) && (nodes != null)) onNodesChanged(false); } else { @@ -385,7 +386,7 @@ namespace MeshCentralRouter if (ev.ContainsKey("conn")) { n.conn = (int)ev["conn"]; } nodes[n.nodeid] = n; } - if ((onNodesChanged != null) && (nodes != null)) onNodesChanged(); + if ((onNodesChanged != null) && (nodes != null)) onNodesChanged(false); } break; } @@ -521,7 +522,7 @@ namespace MeshCentralRouter } } nodes = nodes2; - if ((onNodesChanged != null) && (nodes != null)) onNodesChanged(); + if ((onNodesChanged != null) && (nodes != null)) onNodesChanged(true); break; } default: @@ -535,7 +536,7 @@ namespace MeshCentralRouter public event onStateChangedHandler onStateChanged; public void changeState(int newState) { if (constate != newState) { constate = newState; if (onStateChanged != null) { onStateChanged(constate); } } } - public delegate void onNodeListChangedHandler(); + public delegate void onNodeListChangedHandler(bool fullRefresh); public event onNodeListChangedHandler onNodesChanged; public delegate void onLoginTokenChangedHandler(); public event onLoginTokenChangedHandler onLoginTokenChanged; @@ -900,6 +901,7 @@ namespace MeshCentralRouter private bool VerifyServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { + parent.certHash = GetMeshKeyHash(certificate); if (xignoreCert) return true; if (chain.Build(new X509Certificate2(certificate)) == true) return true; @@ -909,6 +911,7 @@ namespace MeshCentralRouter // Check that the remote certificate is the expected one if ((parent.okCertHash2 != null) && ((parent.okCertHash2 == GetMeshKeyHash(certificate)) || (parent.okCertHash2 == GetMeshCertHash(certificate)))) { return true; } + parent.certHash = null; parent.disconnectMsg = "cert"; parent.disconnectCert = new X509Certificate2(certificate); return false;