diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index c42ab5a..e72f293 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -35,6 +35,7 @@ this.mainTabControl = new System.Windows.Forms.TabControl(); this.tabPage1 = new System.Windows.Forms.TabPage(); this.panel1 = new System.Windows.Forms.Panel(); + this.proxySettings = new System.Windows.Forms.Button(); this.installButton = new System.Windows.Forms.Button(); this.stateLabel = new System.Windows.Forms.Label(); this.label28 = new System.Windows.Forms.Label(); @@ -48,6 +49,7 @@ this.nextButton1 = new System.Windows.Forms.Button(); this.pictureBox3 = new System.Windows.Forms.PictureBox(); this.label1 = new System.Windows.Forms.Label(); + this.pictureBox2 = new System.Windows.Forms.PictureBox(); this.tabPage2 = new System.Windows.Forms.TabPage(); this.panel2 = new System.Windows.Forms.Panel(); this.tokenRememberCheckBox = new System.Windows.Forms.CheckBox(); @@ -135,13 +137,13 @@ this.settingsToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.openMapFileDialog = new System.Windows.Forms.OpenFileDialog(); this.saveMapFileDialog = new System.Windows.Forms.SaveFileDialog(); - this.pictureBox2 = new System.Windows.Forms.PictureBox(); this.panel5.SuspendLayout(); this.mainPanel.SuspendLayout(); this.mainTabControl.SuspendLayout(); this.tabPage1.SuspendLayout(); this.panel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit(); this.tabPage2.SuspendLayout(); this.panel2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox6)).BeginInit(); @@ -164,7 +166,6 @@ ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.trayIconContextMenuStrip.SuspendLayout(); this.mappingsContextMenuStrip.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit(); this.SuspendLayout(); // // panel5 @@ -200,6 +201,7 @@ // // panel1 // + this.panel1.Controls.Add(this.proxySettings); this.panel1.Controls.Add(this.installButton); this.panel1.Controls.Add(this.stateLabel); this.panel1.Controls.Add(this.label28); @@ -217,6 +219,13 @@ resources.ApplyResources(this.panel1, "panel1"); this.panel1.Name = "panel1"; // + // proxySettings + // + resources.ApplyResources(this.proxySettings, "proxySettings"); + this.proxySettings.Name = "proxySettings"; + this.proxySettings.UseVisualStyleBackColor = true; + this.proxySettings.Click += new System.EventHandler(this.button1_Click); + // // installButton // resources.ApplyResources(this.installButton, "installButton"); @@ -304,6 +313,13 @@ this.label1.Name = "label1"; this.label1.UseMnemonic = false; // + // pictureBox2 + // + resources.ApplyResources(this.pictureBox2, "pictureBox2"); + this.pictureBox2.Image = global::MeshCentralRouter.Properties.Resources.MeshCentral; + this.pictureBox2.Name = "pictureBox2"; + this.pictureBox2.TabStop = false; + // // tabPage2 // this.tabPage2.Controls.Add(this.panel2); @@ -958,13 +974,6 @@ this.saveMapFileDialog.DefaultExt = "mcrouter"; resources.ApplyResources(this.saveMapFileDialog, "saveMapFileDialog"); // - // pictureBox2 - // - resources.ApplyResources(this.pictureBox2, "pictureBox2"); - this.pictureBox2.Image = global::MeshCentralRouter.Properties.Resources.MeshCentral; - this.pictureBox2.Name = "pictureBox2"; - this.pictureBox2.TabStop = false; - // // MainForm // resources.ApplyResources(this, "$this"); @@ -984,6 +993,7 @@ this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit(); this.tabPage2.ResumeLayout(false); this.panel2.ResumeLayout(false); this.panel2.PerformLayout(); @@ -1009,7 +1019,6 @@ ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.trayIconContextMenuStrip.ResumeLayout(false); this.mappingsContextMenuStrip.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit(); this.ResumeLayout(false); } @@ -1121,6 +1130,7 @@ private System.Windows.Forms.ToolStripMenuItem askConsentToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem privacyBarToolStripMenuItem; private System.Windows.Forms.PictureBox pictureBox2; + private System.Windows.Forms.Button proxySettings; } } diff --git a/MainForm.cs b/MainForm.cs index 4f710f2..6e99f07 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -296,6 +296,7 @@ namespace MeshCentralRouter if (File.Exists(Path.Combine(selfExe.Directory.FullName, @"customization\logo.png"))) { try { pictureBox2.Image = pictureBox6.Image = (Bitmap)Image.FromFile(Path.Combine(selfExe.Directory.FullName, @"customization\logo.png")); showLicense = false; } catch (Exception) { } } if (File.Exists(Path.Combine(selfExe.Directory.FullName, @"customization\bottombanner.png"))) { try { pictureBox3.Image = pictureBox4.Image = pictureBox5.Image = pictureBox7.Image = (Bitmap)Image.FromFile(Path.Combine(selfExe.Directory.FullName, @"customization\bottombanner.png")); showLicense = false; } catch (Exception) { } } licenseLinkLabel.Visible = showLicense; + proxySettings.Visible = true; try { if (File.Exists(Path.Combine(selfExe.Directory.FullName, @"customization\customize.txt"))) @@ -1974,6 +1975,12 @@ namespace MeshCentralRouter cancelAutoClose(); } + private void button1_Click(object sender, EventArgs e) + { + ProxySettings form = new ProxySettings(); + if (form.ShowDialog(this) == DialogResult.OK) { } + } + /* 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 1f7b561..55081c0 100644 --- a/MainForm.resx +++ b/MainForm.resx @@ -121,20 +121,59 @@ FlatButtons + + Bottom, Left + + + NoControl + + + + 185, 354 + + + 4, 4, 4, 4 + + + 127, 28 + + + + 106 + + + Manual Proxy settings + + + False + + + proxySettings + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel1 + + + 0 + Bottom, Left NoControl - - 11, 285 + 15, 354 + + + 4, 4, 4, 4 - 95, 23 + 127, 28 - 104 @@ -154,7 +193,7 @@ panel1 - 0 + 1 Top, Left, Right @@ -169,10 +208,13 @@ NoControl - 241, 225 + 321, 277 + + + 4, 0, 4, 0 - 88, 13 + 114, 17 19 @@ -193,7 +235,7 @@ panel1 - 1 + 2 True @@ -202,10 +244,13 @@ NoControl - 238, 176 + 317, 217 + + + 4, 0, 4, 0 - 53, 13 + 69, 17 18 @@ -223,7 +268,7 @@ panel1 - 2 + 3 True @@ -232,10 +277,13 @@ NoControl - 238, 135 + 317, 166 + + + 4, 0, 4, 0 - 55, 13 + 73, 17 17 @@ -253,7 +301,7 @@ panel1 - 3 + 4 True @@ -262,10 +310,13 @@ NoControl - 238, 92 + 317, 113 + + + 4, 0, 4, 0 - 38, 13 + 50, 17 16 @@ -283,19 +334,22 @@ panel1 - 4 + 5 Top, Left, Right - 241, 192 + 321, 236 + + + 4, 4, 4, 4 - 214, 20 + 287, 22 102 @@ -310,7 +364,7 @@ panel1 - 5 + 6 Top, Left, Right @@ -319,10 +373,13 @@ meshcentral.com - 241, 110 + 321, 135 + + + 4, 4, 4, 4 - 214, 21 + 287, 24 100 @@ -337,16 +394,19 @@ panel1 - 6 + 7 Top, Left, Right - 241, 151 + 321, 186 + + + 4, 4, 4, 4 - 214, 20 + 287, 22 101 @@ -361,7 +421,7 @@ panel1 - 7 + 8 Bottom, Right @@ -370,10 +430,13 @@ NoControl - 174, 260 + 235, 323 + + + 4, 0, 4, 0 - 303, 13 + 404, 16 103 @@ -394,7 +457,7 @@ panel1 - 8 + 9 Bottom, Left @@ -406,10 +469,13 @@ NoControl - 3, 260 + 4, 323 + + + 4, 0, 4, 0 - 37, 13 + 47, 17 11 @@ -427,7 +493,7 @@ panel1 - 9 + 10 Bottom, Right @@ -436,10 +502,13 @@ NoControl - 371, 285 + 498, 354 + + + 4, 4, 4, 4 - 95, 23 + 127, 28 105 @@ -457,7 +526,7 @@ panel1 - 10 + 11 Bottom, Left, Right @@ -466,10 +535,13 @@ NoControl - 0, 276 + 0, 343 + + + 4, 4, 4, 4 - 478, 40 + 640, 49 StretchImage @@ -487,7 +559,7 @@ panel1 - 11 + 12 Top, Left, Right @@ -496,10 +568,13 @@ NoControl - 12, 9 + 16, 11 + + + 4, 0, 4, 0 - 454, 56 + 608, 69 6 @@ -517,7 +592,7 @@ panel1 - 12 + 13 Top, Bottom, Left, Right @@ -526,10 +601,13 @@ NoControl - 15, 68 + 20, 84 + + + 4, 4, 4, 4 - 217, 170 + 292, 212 Zoom @@ -547,16 +625,19 @@ panel1 - 13 + 14 Fill - 3, 3 + 4, 4 + + + 4, 4, 4, 4 - 478, 316 + 640, 392 6 @@ -574,13 +655,16 @@ 0 - 4, 25 + 4, 28 + + + 4, 4, 4, 4 - 3, 3, 3, 3 + 4, 4, 4, 4 - 484, 322 + 648, 400 0 @@ -607,10 +691,13 @@ NoControl - 241, 221 + 321, 272 + + + 4, 4, 4, 4 - 131, 17 + 170, 21 204 @@ -637,10 +724,13 @@ NoControl - 241, 177 + 321, 218 + + + 4, 4, 4, 4 - 95, 23 + 127, 28 202 @@ -667,10 +757,13 @@ NoControl - 342, 177 + 456, 218 + + + 4, 4, 4, 4 - 95, 23 + 127, 28 203 @@ -700,10 +793,13 @@ NoControl - 238, 182 + 317, 224 + + + 4, 0, 4, 0 - 55, 13 + 73, 17 21 @@ -733,10 +829,13 @@ NoControl - 238, 135 + 317, 166 + + + 4, 0, 4, 0 - 38, 13 + 48, 17 19 @@ -760,10 +859,13 @@ Top, Left, Right - 241, 151 + 321, 186 + + + 4, 4, 4, 4 - 214, 20 + 287, 22 201 @@ -787,10 +889,13 @@ NoControl - 15, 68 + 20, 84 + + + 4, 4, 4, 4 - 202, 170 + 272, 212 Zoom @@ -817,10 +922,13 @@ NoControl - 270, 285 + 363, 354 + + + 4, 4, 4, 4 - 95, 23 + 127, 28 205 @@ -847,10 +955,13 @@ NoControl - 371, 285 + 498, 354 + + + 4, 4, 4, 4 - 95, 23 + 127, 28 206 @@ -877,10 +988,13 @@ NoControl - 0, 276 + 0, 343 + + + 4, 4, 4, 4 - 478, 40 + 640, 49 StretchImage @@ -907,10 +1021,13 @@ NoControl - 12, 9 + 16, 11 + + + 4, 0, 4, 0 - 454, 56 + 608, 69 6 @@ -934,10 +1051,13 @@ Fill - 3, 3 + 4, 4 + + + 4, 4, 4, 4 - 478, 316 + 640, 392 7 @@ -955,13 +1075,16 @@ 0 - 4, 25 + 4, 28 + + + 4, 4, 4, 4 - 3, 3, 3, 3 + 4, 4, 4, 4 - 484, 322 + 648, 400 1 @@ -988,10 +1111,13 @@ True - 208, 255 + 277, 318 + + + 4, 4, 4, 4 - 145, 17 + 190, 21 302 @@ -1015,7 +1141,10 @@ Top, Bottom, Left, Right - 15, 82 + 20, 101 + + + 4, 4, 4, 4 True @@ -1024,7 +1153,7 @@ Vertical - 450, 162 + 602, 202 25 @@ -1048,10 +1177,13 @@ NoControl - 14, 251 + 19, 313 + + + 4, 4, 4, 4 - 188, 23 + 251, 28 301 @@ -1081,10 +1213,13 @@ NoControl - 8, 6 + 11, 7 + + + 4, 0, 4, 0 - 468, 22 + 627, 27 23 @@ -1114,10 +1249,13 @@ NoControl - 12, 34 + 16, 42 + + + 4, 0, 4, 0 - 454, 45 + 608, 55 22 @@ -1144,10 +1282,13 @@ NoControl - 276, 291 + 371, 362 + + + 4, 4, 4, 4 - 95, 23 + 127, 28 303 @@ -1174,10 +1315,13 @@ NoControl - 377, 291 + 506, 362 + + + 4, 4, 4, 4 - 95, 23 + 127, 28 304 @@ -1204,10 +1348,13 @@ NoControl - 0, 282 + 0, 351 + + + 4, 4, 4, 4 - 484, 40 + 648, 49 StretchImage @@ -1233,8 +1380,11 @@ 0, 0 + + 4, 4, 4, 4 + - 484, 322 + 648, 400 8 @@ -1252,10 +1402,13 @@ 0 - 4, 25 + 4, 28 + + + 4, 4, 4, 4 - 484, 322 + 648, 400 2 @@ -1285,43 +1438,43 @@ 613, 17 - 185, 22 + 218, 26 Show &Group Names - 185, 22 + 218, 26 Show &Offline Devices - 182, 6 + 215, 6 - 185, 22 + 218, 26 Sort by &Name - 185, 22 + 218, 26 Sort by G&roup - 182, 6 + 215, 6 - 185, 22 + 218, 26 S&ettings... - 186, 126 + 219, 146 mainContextMenuStrip @@ -1336,10 +1489,13 @@ NoControl - 454, 2 + 608, 2 + + + 4, 0, 4, 0 - 25, 25 + 31, 31 403 @@ -1363,10 +1519,13 @@ Top, Right - 306, 5 + 411, 6 + + + 4, 4, 4, 4 - 146, 20 + 193, 22 402 @@ -1399,10 +1558,13 @@ Bottom, Left - 4, 174 + 5, 206 + + + 4, 4, 4, 4 - 168, 35 + 224, 43 405 @@ -1444,82 +1606,82 @@ Segoe UI, 9pt, style=Bold - 170, 22 + 198, 24 Add &Map... - 170, 22 + 198, 24 Add &Relay Map... - 167, 6 + 195, 6 - 171, 22 + 212, 26 Ask Consent + Bar - 171, 22 + 212, 26 Ask Consent - 171, 22 + 212, 26 Privacy Bar - 170, 22 + 198, 24 Remote Desktop... - 170, 22 + 198, 24 Remote Files... - 170, 22 + 198, 24 HTTP - 170, 22 + 198, 24 HTTPS - 170, 22 + 198, 24 RDP - 170, 22 + 198, 24 SSH - 170, 22 + 198, 24 SCP - 171, 208 + 199, 226 devicesContextMenuStrip @@ -1535,7 +1697,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADg - HQAAAk1TRnQBSQFMAgEBEAEAAXgBAAF4AQABEAEAARABAAT/ARkBAAj/AUIBTQE2BwABNgMAASgDAAFA + HQAAAk1TRnQBSQFMAgEBEAEAAYgBAAGIAQABEAEAARABAAT/ARkBAAj/AUIBTQE2BwABNgMAASgDAAFA AwABUAMAAQEBAAEYBgABPP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AJYAA/0D+AP3A/sD/yEAA/0D+gP5 A/wD/xgAAfoB+wH6A/4qAAP9A/8tAAP7A88D1QPbA88D1AO+A9QYAAP8A90D4APjA90D4APUA+MSAAP8 AZEBjwF9AU4BaAEhAfQB9QH0JAAD/gPRA8YD+ioAAcYCxwHPAtAB2ALZA90DywPBA68DmgP3FQAD2APd @@ -1666,10 +1828,13 @@ - 10, 4 + 13, 5 + + + 4, 4, 4, 4 - 446, 210 + 593, 258 404 @@ -1699,10 +1864,13 @@ NoControl - 2, 88 + 3, 108 + + + 4, 0, 4, 0 - 399, 52 + 526, 64 5 @@ -1738,10 +1906,13 @@ NoControl - 2, 88 + 3, 108 + + + 4, 0, 4, 0 - 399, 52 + 526, 64 4 @@ -1767,8 +1938,11 @@ 0, 0 + + 4, 4, 4, 4 + - 470, 248 + 628, 305 50 @@ -1786,13 +1960,16 @@ 0 - 4, 25 + 4, 28 + + + 4, 4, 4, 4 - 3, 3, 3, 3 + 4, 4, 4, 4 - 470, 250 + 632, 315 0 @@ -1819,10 +1996,13 @@ NoControl - 4, 185 + 5, 221 + + + 4, 4, 4, 4 - 168, 35 + 224, 43 55 @@ -1861,10 +2041,13 @@ NoControl - 6, 79 + 8, 97 + + + 4, 0, 4, 0 - 453, 52 + 594, 64 4 @@ -1892,8 +2075,11 @@ Click "Add" to get started. 0, 0 + + 4, 4, 4, 4 + - 473, 224 + 628, 268 49 @@ -1917,10 +2103,13 @@ Click "Add" to get started. NoControl - 1, 229 + 1, 275 + + + 4, 4, 4, 4 - 20, 20 + 27, 25 54 @@ -1944,10 +2133,13 @@ Click "Add" to get started. NoControl - 241, 229 + 320, 275 + + + 4, 4, 4, 4 - 20, 20 + 27, 25 5 @@ -1974,10 +2166,13 @@ Click "Add" to get started. NoControl - 373, 227 + 496, 272 + + + 4, 4, 4, 4 - 100, 23 + 133, 28 50 @@ -2007,10 +2202,13 @@ Click "Add" to get started. NoControl - 267, 227 + 355, 272 + + + 4, 4, 4, 4 - 100, 23 + 133, 28 52 @@ -2031,13 +2229,16 @@ Click "Add" to get started. 5 - 4, 25 + 4, 28 + + + 4, 4, 4, 4 - 3, 3, 3, 3 + 4, 4, 4, 4 - 473, 256 + 632, 315 1 @@ -2058,10 +2259,13 @@ Click "Add" to get started. 1 - 3, 3 + 4, 4 + + + 4, 4, 4, 4 - 478, 279 + 640, 347 401 @@ -2085,10 +2289,13 @@ Click "Add" to get started. NoControl - 15, 291 + 20, 362 + + + 4, 4, 4, 4 - 109, 23 + 145, 28 406 @@ -2118,10 +2325,13 @@ Click "Add" to get started. NoControl - 276, 291 + 371, 362 + + + 4, 4, 4, 4 - 95, 23 + 127, 28 407 @@ -2148,10 +2358,13 @@ Click "Add" to get started. NoControl - 377, 291 + 506, 362 + + + 4, 4, 4, 4 - 95, 23 + 127, 28 408 @@ -2178,10 +2391,13 @@ Click "Add" to get started. NoControl - 0, 282 + 0, 351 + + + 4, 4, 4, 4 - 484, 40 + 648, 49 StretchImage @@ -2207,8 +2423,11 @@ Click "Add" to get started. 0, 0 + + 4, 4, 4, 4 + - 484, 322 + 648, 400 8 @@ -2226,10 +2445,13 @@ Click "Add" to get started. 0 - 4, 25 + 4, 28 + + + 4, 4, 4, 4 - 484, 322 + 648, 400 4 @@ -2259,7 +2481,7 @@ Click "Add" to get started. 0, 0, 0, 0 - 492, 351 + 656, 432 8 @@ -2283,10 +2505,13 @@ Click "Add" to get started. Fill - 0, 65 + 0, 80 + + + 4, 4, 4, 4 - 492, 351 + 656, 432 9 @@ -2312,8 +2537,11 @@ Click "Add" to get started. 0, 0 + + 4, 4, 4, 4 + - 492, 65 + 656, 80 Zoom @@ -2339,8 +2567,11 @@ Click "Add" to get started. 0, 0 + + 4, 4, 4, 4 + - 492, 416 + 656, 512 8 @@ -2370,22 +2601,22 @@ Click "Add" to get started. 418, 17 - 112, 22 + 123, 24 &Open... - 109, 6 + 120, 6 - 112, 22 + 123, 24 E&xit - 113, 54 + 124, 58 trayIconContextMenuStrip @@ -4097,28 +4328,28 @@ Click "Add" to get started. 905, 17 - 168, 22 + 193, 24 &Open Mappings... - 168, 22 + 193, 24 &Save Mappings... - 165, 6 + 190, 6 - 168, 22 + 193, 24 S&ettings... - 169, 76 + 194, 82 mappingsContextMenuStrip @@ -4148,10 +4379,10 @@ Click "Add" to get started. True - 6, 13 + 8, 16 - 492, 416 + 656, 512 @@ -5847,6 +6078,9 @@ Click "Add" to get started. AADAPwAAwD8AAMA/AADAPwAA + + 4, 4, 4, 4 + MeshCentral Router diff --git a/MeshCentralRouter.csproj b/MeshCentralRouter.csproj index 7ba5a07..aab95b0 100644 --- a/MeshCentralRouter.csproj +++ b/MeshCentralRouter.csproj @@ -18,6 +18,10 @@ 3.5 + false + + + publish\ true Disk @@ -30,12 +34,8 @@ true 0 1.0.0.%2a - false false true - - - true @@ -106,6 +106,12 @@ FileDialogMsgForm.cs + + Form + + + ProxySettings.cs + Form @@ -274,6 +280,9 @@ FileDialogMsgForm.cs + + ProxySettings.cs + SshUsernameForm.cs diff --git a/MeshCentralServer.cs b/MeshCentralServer.cs index 3e40085..c1da0f1 100644 --- a/MeshCentralServer.cs +++ b/MeshCentralServer.cs @@ -99,31 +99,6 @@ namespace MeshCentralRouter try { return Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\OpenSource\MeshRouter", name, "").ToString(); } catch (Exception) { return ""; } } - public static string GetProxyForUrlUsingPac(string DestinationUrl, string PacUri) - { - IntPtr WinHttpSession = Win32Api.WinHttpOpen("User", Win32Api.WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, IntPtr.Zero, IntPtr.Zero, 0); - - Win32Api.WINHTTP_AUTOPROXY_OPTIONS ProxyOptions = new Win32Api.WINHTTP_AUTOPROXY_OPTIONS(); - Win32Api.WINHTTP_PROXY_INFO ProxyInfo = new Win32Api.WINHTTP_PROXY_INFO(); - - ProxyOptions.dwFlags = Win32Api.WINHTTP_AUTOPROXY_CONFIG_URL; - ProxyOptions.dwAutoDetectFlags = (Win32Api.WINHTTP_AUTO_DETECT_TYPE_DHCP | Win32Api.WINHTTP_AUTO_DETECT_TYPE_DNS_A); - ProxyOptions.lpszAutoConfigUrl = PacUri; - - // Get Proxy - bool IsSuccess = Win32Api.WinHttpGetProxyForUrl(WinHttpSession, DestinationUrl, ref ProxyOptions, ref ProxyInfo); - Win32Api.WinHttpCloseHandle(WinHttpSession); - - if (IsSuccess) - { - return ProxyInfo.lpszProxy; - } - else - { - Console.WriteLine("Error: {0}", Win32Api.GetLastError()); - return null; - } - } // Parse the URL query parameters and returns a collection public static NameValueCollection GetQueryStringParameters() @@ -722,6 +697,7 @@ namespace MeshCentralRouter private bool accmask = false; private int acclen = 0; private bool proxyInUse = false; + private Uri proxyUri = null; private string user = null; private string pass = null; private string token = null; @@ -752,31 +728,17 @@ namespace MeshCentralRouter this.user = user; this.pass = pass; this.token = token; - Uri proxyUri = null; + this.proxyUri = null; - // Check if we need to use a HTTP proxy (Auto-proxy way) - try { - RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true); - Object x = registryKey.GetValue("AutoConfigURL", null); - if ((x != null) && (x.GetType() == typeof(string))) { - string proxyStr = GetProxyForUrlUsingPac("http" + ((url.Port == 80) ? "" : "s") + "://" + url.Host + ":" + url.Port, x.ToString()); - if (proxyStr != null) { proxyUri = new Uri("http://" + proxyStr); } - } - } catch (Exception) { proxyUri = null; } - - // Check if we need to use a HTTP proxy (Normal way) - if (proxyUri == null) { - var proxy = System.Net.HttpWebRequest.GetSystemWebProxy(); - proxyUri = proxy.GetProxy(url); - if ((url.Host.ToLower() == proxyUri.Host.ToLower()) && (url.Port == proxyUri.Port)) { proxyUri = null; } - } + this.proxyUri = Win32Api.GetProxy(url); if (proxyUri != null) { // Proxy in use proxyInUse = true; wsclient = new TcpClient(); - Debug("Connecting with proxy in use: " + proxyUri.ToString()); + // This may log proxy password to debug log + Debug("Connecting with proxy in use: " + proxyUri.ToString()); wsclient.BeginConnect(proxyUri.Host, proxyUri.Port, new AsyncCallback(OnConnectSink), this); } else @@ -808,7 +770,16 @@ namespace MeshCentralRouter { // Send proxy connection request wsrawstream = wsclient.GetStream(); - byte[] proxyRequestBuf = UTF8Encoding.UTF8.GetBytes("CONNECT " + url.Host + ":" + url.Port + " HTTP/1.1\r\nHost: " + url.Host + ":" + url.Port + "\r\n\r\n"); + string userCreds = proxyUri.UserInfo; + string basicAuth = ""; + if (userCreds.Length > 0) + { + // Base64 encode for basic authentication + userCreds = System.Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(userCreds)); + basicAuth = "\r\nProxy-Authorization: Basic " + userCreds; + } + + byte[] proxyRequestBuf = UTF8Encoding.UTF8.GetBytes("CONNECT " + url.Host + ":" + url.Port + " HTTP/1.1\r\nHost: " + url.Host + ":" + url.Port + basicAuth + "\r\n\r\n"); TlsDump("OutRaw", proxyRequestBuf, 0, proxyRequestBuf.Length); try { wsrawstream.Write(proxyRequestBuf, 0, proxyRequestBuf.Length); } catch (Exception ex) { Debug(ex.ToString()); } wsrawstream.BeginRead(readBuffer, readBufferLen, readBuffer.Length - readBufferLen, new AsyncCallback(OnProxyResponseSink), this); diff --git a/MeshMapper.cs b/MeshMapper.cs index 2a9476f..3584ca1 100644 --- a/MeshMapper.cs +++ b/MeshMapper.cs @@ -50,31 +50,7 @@ namespace MeshCentralRouter public delegate void onStateMsgChangedHandler(string statemsg); public event onStateMsgChangedHandler onStateMsgChanged; - public static string GetProxyForUrlUsingPac(string DestinationUrl, string PacUri) - { - IntPtr WinHttpSession = Win32Api.WinHttpOpen("User", Win32Api.WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, IntPtr.Zero, IntPtr.Zero, 0); - - Win32Api.WINHTTP_AUTOPROXY_OPTIONS ProxyOptions = new Win32Api.WINHTTP_AUTOPROXY_OPTIONS(); - Win32Api.WINHTTP_PROXY_INFO ProxyInfo = new Win32Api.WINHTTP_PROXY_INFO(); - - ProxyOptions.dwFlags = Win32Api.WINHTTP_AUTOPROXY_CONFIG_URL; - ProxyOptions.dwAutoDetectFlags = (Win32Api.WINHTTP_AUTO_DETECT_TYPE_DHCP | Win32Api.WINHTTP_AUTO_DETECT_TYPE_DNS_A); - ProxyOptions.lpszAutoConfigUrl = PacUri; - - // Get Proxy - bool IsSuccess = Win32Api.WinHttpGetProxyForUrl(WinHttpSession, DestinationUrl, ref ProxyOptions, ref ProxyInfo); - Win32Api.WinHttpCloseHandle(WinHttpSession); - - if (IsSuccess) - { - return ProxyInfo.lpszProxy; - } - else - { - Console.WriteLine("Error: {0}", Win32Api.GetLastError()); - return null; - } - } + // Starts the routing server, called when the start button is pressed public void start(MeshCentralServer parent, int protocol, int localPort, string url, int remotePort, string remoteIP) diff --git a/ProxySettings.Designer.cs b/ProxySettings.Designer.cs new file mode 100644 index 0000000..49a0bf5 --- /dev/null +++ b/ProxySettings.Designer.cs @@ -0,0 +1,194 @@ +namespace MeshCentralRouter +{ + partial class ProxySettings + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.SaveProxyConfig = new System.Windows.Forms.Button(); + this.manualHttpProxyHost = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.manualHttpProxyPort = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.manualHttpProxyUsername = new System.Windows.Forms.TextBox(); + this.label4 = new System.Windows.Forms.Label(); + this.manualHttpProxyPassword = new System.Windows.Forms.TextBox(); + this.label5 = new System.Windows.Forms.Label(); + this.useManualProxySettings = new System.Windows.Forms.CheckBox(); + this.cancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // SaveProxyConfig + // + this.SaveProxyConfig.Location = new System.Drawing.Point(124, 404); + this.SaveProxyConfig.Name = "SaveProxyConfig"; + this.SaveProxyConfig.Size = new System.Drawing.Size(75, 23); + this.SaveProxyConfig.TabIndex = 1; + this.SaveProxyConfig.Text = "Ok"; + this.SaveProxyConfig.UseVisualStyleBackColor = true; + this.SaveProxyConfig.Click += new System.EventHandler(this.SaveProxyConfig_Click); + // + // manualHttpProxyHost + // + this.manualHttpProxyHost.Location = new System.Drawing.Point(104, 141); + this.manualHttpProxyHost.Name = "manualHttpProxyHost"; + this.manualHttpProxyHost.Size = new System.Drawing.Size(203, 22); + this.manualHttpProxyHost.TabIndex = 2; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(75, 114); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(103, 17); + this.label1.TabIndex = 3; + this.label1.Text = "Http proxy host"; + this.label1.Click += new System.EventHandler(this.label1_Click); + // + // manualHttpProxyPort + // + this.manualHttpProxyPort.Location = new System.Drawing.Point(104, 208); + this.manualHttpProxyPort.Name = "manualHttpProxyPort"; + this.manualHttpProxyPort.Size = new System.Drawing.Size(203, 22); + this.manualHttpProxyPort.TabIndex = 4; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(75, 181); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(101, 17); + this.label2.TabIndex = 5; + this.label2.Text = "Http proxy port"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(75, 257); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(139, 17); + this.label3.TabIndex = 7; + this.label3.Text = "Http proxy username"; + // + // manualHttpProxyUsername + // + this.manualHttpProxyUsername.Location = new System.Drawing.Point(104, 286); + this.manualHttpProxyUsername.Name = "manualHttpProxyUsername"; + this.manualHttpProxyUsername.Size = new System.Drawing.Size(203, 22); + this.manualHttpProxyUsername.TabIndex = 6; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(78, 332); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(136, 17); + this.label4.TabIndex = 9; + this.label4.Text = "Http proxy password"; + // + // manualHttpProxyPassword + // + this.manualHttpProxyPassword.Location = new System.Drawing.Point(104, 362); + this.manualHttpProxyPassword.Name = "manualHttpProxyPassword"; + this.manualHttpProxyPassword.PasswordChar = '*'; + this.manualHttpProxyPassword.Size = new System.Drawing.Size(203, 22); + this.manualHttpProxyPassword.TabIndex = 8; + // + // label5 + // + this.label5.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.label5.ImeMode = System.Windows.Forms.ImeMode.NoControl; + this.label5.Location = new System.Drawing.Point(13, 9); + this.label5.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(396, 69); + this.label5.TabIndex = 10; + this.label5.Text = "Manually configure an HTTP proxy server to use. Username and password are optiona" + + "l. Only basic auth is supported."; + this.label5.UseMnemonic = false; + // + // useManualProxySettings + // + this.useManualProxySettings.AutoSize = true; + this.useManualProxySettings.Location = new System.Drawing.Point(43, 81); + this.useManualProxySettings.Name = "useManualProxySettings"; + this.useManualProxySettings.Size = new System.Drawing.Size(194, 21); + this.useManualProxySettings.TabIndex = 11; + this.useManualProxySettings.Text = "use manual proxy settings"; + this.useManualProxySettings.UseVisualStyleBackColor = true; + this.useManualProxySettings.CheckedChanged += new System.EventHandler(this.useManualProxySettings_CheckedChanged); + // + // cancel + // + this.cancel.Location = new System.Drawing.Point(232, 404); + this.cancel.Name = "cancel"; + this.cancel.Size = new System.Drawing.Size(75, 23); + this.cancel.TabIndex = 12; + this.cancel.Text = "Cancel"; + this.cancel.UseVisualStyleBackColor = true; + this.cancel.Click += new System.EventHandler(this.cancel_Click); + // + // ProxySettings + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(482, 450); + this.Controls.Add(this.cancel); + this.Controls.Add(this.useManualProxySettings); + this.Controls.Add(this.label5); + this.Controls.Add(this.label4); + this.Controls.Add(this.manualHttpProxyPassword); + this.Controls.Add(this.label3); + this.Controls.Add(this.manualHttpProxyUsername); + this.Controls.Add(this.label2); + this.Controls.Add(this.manualHttpProxyPort); + this.Controls.Add(this.label1); + this.Controls.Add(this.manualHttpProxyHost); + this.Controls.Add(this.SaveProxyConfig); + this.Name = "ProxySettings"; + this.Text = "Proxy Settings"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private System.Windows.Forms.Button SaveProxyConfig; + private System.Windows.Forms.TextBox manualHttpProxyHost; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox manualHttpProxyPort; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox manualHttpProxyUsername; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.TextBox manualHttpProxyPassword; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.CheckBox useManualProxySettings; + private System.Windows.Forms.Button cancel; + } +} \ No newline at end of file diff --git a/ProxySettings.cs b/ProxySettings.cs new file mode 100644 index 0000000..28d010b --- /dev/null +++ b/ProxySettings.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace MeshCentralRouter +{ + public partial class ProxySettings : Form + { + public ProxySettings() + { + InitializeComponent(); + useManualProxySettings.Checked = Settings.GetRegValue("Use_Manual_Http_proxy", false); + manualHttpProxyHost.Text = Settings.GetRegValue("Manual_Http_proxy_host", ""); + manualHttpProxyPort.Text = Settings.GetRegValue("Manual_Http_proxy_port", ""); + manualHttpProxyUsername.Text = Settings.GetRegValue("Manual_Http_proxy_username", ""); + manualHttpProxyPassword.Text = Settings.GetRegValue("Manual_Http_proxy_password", ""); + checkbox_refresh_form(); + } + + private void label1_Click(object sender, EventArgs e) + { + + } + + private void SaveProxyConfig_Click(object sender, EventArgs e) + { + Settings.SetRegValue("Use_Manual_Http_proxy", useManualProxySettings.Checked); + Settings.SetRegValue("Manual_Http_proxy_host", manualHttpProxyHost.Text); + Settings.SetRegValue("Manual_Http_proxy_port", manualHttpProxyPort.Text); + Settings.SetRegValue("Manual_Http_proxy_username", manualHttpProxyUsername.Text); + Settings.SetRegValue("Manual_Http_proxy_password", manualHttpProxyPassword.Text); + DialogResult = DialogResult.OK; + } + + private void checkbox_refresh_form() + { + if (useManualProxySettings.Checked) + { + manualHttpProxyHost.ReadOnly = false; + manualHttpProxyPort.ReadOnly = false; + manualHttpProxyUsername.ReadOnly = false; + manualHttpProxyPassword.ReadOnly = false; + } + else + { + manualHttpProxyHost.ReadOnly = true; + manualHttpProxyPort.ReadOnly = true; + manualHttpProxyUsername.ReadOnly = true; + manualHttpProxyPassword.ReadOnly = true; + } + } + + private void useManualProxySettings_CheckedChanged(object sender, EventArgs e) + { + checkbox_refresh_form(); + } + + private void cancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + } + } +} diff --git a/ProxySettings.resx b/ProxySettings.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ProxySettings.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/WebSocketClient.cs b/WebSocketClient.cs index b504478..2ec7348 100644 --- a/WebSocketClient.cs +++ b/WebSocketClient.cs @@ -43,6 +43,7 @@ namespace MeshCentralRouter private bool accmask = false; private int acclen = 0; private bool proxyInUse = false; + private Uri proxyUri = null; private string tlsCertFingerprint = null; //private ConnectionErrors lastError = ConnectionErrors.NoError; public bool debug = false; @@ -134,30 +135,11 @@ namespace MeshCentralRouter SetState(ConnectionStates.Connecting); this.url = url; if (tlsCertFingerprint != null) { this.tlsCertFingerprint = tlsCertFingerprint.ToUpper(); } - Uri proxyUri = null; + Log("Websocket Start, URL=" + ((url == null) ? "(NULL)" : url.ToString())); - // Check if we need to use a HTTP proxy (Auto-proxy way) - try - { - RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true); - Object x = registryKey.GetValue("AutoConfigURL", null); - if ((x != null) && (x.GetType() == typeof(string))) - { - string proxyStr = GetProxyForUrlUsingPac("http" + ((url.Port == 80) ? "" : "s") + "://" + url.Host + ":" + url.Port, x.ToString()); - if (proxyStr != null) { proxyUri = new Uri("http://" + proxyStr); } - } - } - catch (Exception) { proxyUri = null; } - - // Check if we need to use a HTTP proxy (Normal way) - if (proxyUri == null) - { - var proxy = System.Net.HttpWebRequest.GetSystemWebProxy(); - proxyUri = proxy.GetProxy(url); - if ((url.Host.ToLower() == proxyUri.Host.ToLower()) && (url.Port == proxyUri.Port)) { proxyUri = null; } - } + proxyUri = Win32Api.GetProxy(url); if (proxyUri != null) { @@ -201,7 +183,17 @@ namespace MeshCentralRouter { // Send proxy connection request wsrawstream = wsclient.GetStream(); - byte[] proxyRequestBuf = UTF8Encoding.UTF8.GetBytes("CONNECT " + url.Host + ":" + url.Port + " HTTP/1.1\r\nHost: " + url.Host + ":" + url.Port + "\r\n\r\n"); + + string userCreds = proxyUri.UserInfo; + string basicAuth = ""; + if (userCreds.Length > 0) + { + // Base64 encode for basic authentication + userCreds = System.Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(userCreds)); + basicAuth = "\r\nProxy-Authorization: Basic " + userCreds; + } + + byte[] proxyRequestBuf = UTF8Encoding.UTF8.GetBytes("CONNECT " + url.Host + ":" + url.Port + " HTTP/1.1\r\nHost: " + url.Host + ":" + url.Port + basicAuth + "\r\n\r\n"); wsrawstream.Write(proxyRequestBuf, 0, proxyRequestBuf.Length); wsrawstream.BeginRead(readBuffer, readBufferLen, readBuffer.Length - readBufferLen, new AsyncCallback(OnProxyResponseSink), this); } diff --git a/Win32Api.cs b/Win32Api.cs index 493d854..9a2a7f6 100644 --- a/Win32Api.cs +++ b/Win32Api.cs @@ -78,6 +78,24 @@ namespace MeshCentralRouter public static Uri GetProxy(Uri url) { + // Manual http proxy with optional basic auth. Other auth type would be difficult to support as proxy authentication is done manually within the websocketclient + if(Settings.GetRegValue("Use_Manual_Http_proxy", false)) + { + string proxyStr = ""; + string proxyUserName = Settings.GetRegValue("Manual_Http_proxy_username", ""); + string proxyPassword = Settings.GetRegValue("Manual_Http_proxy_password", ""); + + if (proxyUserName.Length > 0 && proxyPassword.Length > 0) + { + proxyStr = "http://" + proxyUserName + ":" + proxyPassword + "@" + Settings.GetRegValue("Manual_Http_proxy_host", "") + ":" + Settings.GetRegValue("Manual_Http_proxy_port", ""); + } + else + { + proxyStr = "http://" + Settings.GetRegValue("Manual_Http_proxy_host", "") + ":" + Settings.GetRegValue("Manual_Http_proxy_port", ""); + + } + return new Uri(proxyStr); + } // Check if we need to use a HTTP proxy (Auto-proxy way) try { @@ -86,7 +104,10 @@ namespace MeshCentralRouter if ((x != null) && (x.GetType() == typeof(string))) { string proxyStr = GetProxyForUrlUsingPac("http" + ((url.Port == 80) ? "" : "s") + "://" + url.Host + ":" + url.Port, x.ToString()); - return new Uri("http://" + proxyStr); + if (proxyStr != null) + { + return new Uri("http://" + proxyStr); + } } } catch (Exception) { }