From b768b946b2cf1f12f220e1be76d99f0aea46486b Mon Sep 17 00:00:00 2001 From: milnet92 Date: Wed, 21 Aug 2024 13:08:12 +0200 Subject: [PATCH] Optionally populate external IP address when creating firewall exceptions --- 2LCS/2LCS.csproj | 9 +++ 2LCS/App.config | 3 + 2LCS/Forms/AddNSG.cs | 24 ++++++++ 2LCS/Forms/Parameters.Designer.cs | 87 ++++++++++++++++++---------- 2LCS/Forms/Parameters.cs | 4 ++ 2LCS/Forms/Parameters.resx | 50 ++++++++-------- 2LCS/Properties/Settings.Designer.cs | 14 ++++- 2LCS/Properties/Settings.settings | 3 + 8 files changed, 137 insertions(+), 57 deletions(-) diff --git a/2LCS/2LCS.csproj b/2LCS/2LCS.csproj index 4c3478c..4995d94 100644 --- a/2LCS/2LCS.csproj +++ b/2LCS/2LCS.csproj @@ -47,9 +47,18 @@ Component + + True + True + Settings.settings + PreserveNewest + + SettingsSingleFileGenerator + Settings.Designer.cs + diff --git a/2LCS/App.config b/2LCS/App.config index 20b8eaf..f0507fe 100644 --- a/2LCS/App.config +++ b/2LCS/App.config @@ -67,6 +67,9 @@ https://fix.lcs.dynamics.com + + False + diff --git a/2LCS/Forms/AddNSG.cs b/2LCS/Forms/AddNSG.cs index 72d788c..459fa16 100644 --- a/2LCS/Forms/AddNSG.cs +++ b/2LCS/Forms/AddNSG.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Net.Http; using System.Windows.Forms; namespace LCS.Forms @@ -11,6 +12,8 @@ public partial class AddNsg : Form public AddNsg() { InitializeComponent(); + + PopulateWithOwnIP(); } public bool Cancelled { get; private set; } @@ -41,6 +44,27 @@ private void CancelButton_Click(object sender, EventArgs e) Close(); } + private void PopulateWithOwnIP() + { + if (Properties.Settings.Default.populateOwnIPForNSG) + { + try + { + var ownIpAddress = new HttpClient().GetStringAsync("http://icanhazip.com").Result; + ownIpAddress = ownIpAddress.Replace("\\r\\n", "").Replace("\\n", "").Trim(); + + if (!string.IsNullOrEmpty(ownIpAddress)) + { + textBox2.Text = ownIpAddress; + } + } + catch + { + MessageBox.Show("Failed to get your IP address. Please enter it manually."); + } + } + } + private bool ValidateRule() { if (string.IsNullOrEmpty(textBox1.Text)) diff --git a/2LCS/Forms/Parameters.Designer.cs b/2LCS/Forms/Parameters.Designer.cs index 4ea2fce..6dc981f 100644 --- a/2LCS/Forms/Parameters.Designer.cs +++ b/2LCS/Forms/Parameters.Designer.cs @@ -46,20 +46,23 @@ private void InitializeComponent() LocalCredentialsCheckbox = new System.Windows.Forms.CheckBox(); RDPCredentialsCheckbox = new System.Windows.Forms.CheckBox(); groupBoxLCSUrls = new System.Windows.Forms.GroupBox(); + labelLcsDiagUrl = new System.Windows.Forms.Label(); + labelLcsFixUrl = new System.Windows.Forms.Label(); + labelLcsUpdateUrl = new System.Windows.Forms.Label(); labelLcsUrl = new System.Windows.Forms.Label(); textBoxLcsDiagUrl = new System.Windows.Forms.TextBox(); textBoxLcsFixUrl = new System.Windows.Forms.TextBox(); textBoxLcsUpdateUrl = new System.Windows.Forms.TextBox(); textBoxLcsUrl = new System.Windows.Forms.TextBox(); - labelLcsUpdateUrl = new System.Windows.Forms.Label(); - labelLcsFixUrl = new System.Windows.Forms.Label(); - labelLcsDiagUrl = new System.Windows.Forms.Label(); + groupBox1 = new System.Windows.Forms.GroupBox(); + addExternalIpAddress = new System.Windows.Forms.CheckBox(); groupBoxExportConfig.SuspendLayout(); groupBoxUIConfig.SuspendLayout(); groupBoxCaching.SuspendLayout(); groupCHE.SuspendLayout(); groupBoxCredentials.SuspendLayout(); groupBoxLCSUrls.SuspendLayout(); + groupBox1.SuspendLayout(); SuspendLayout(); // // AutoRefreshCheckBox @@ -75,7 +78,7 @@ private void InitializeComponent() // closeButton // closeButton.Anchor = System.Windows.Forms.AnchorStyles.Bottom; - closeButton.Location = new System.Drawing.Point(312, 722); + closeButton.Location = new System.Drawing.Point(304, 801); closeButton.Name = "closeButton"; closeButton.Size = new System.Drawing.Size(163, 32); closeButton.TabIndex = 4; @@ -179,7 +182,7 @@ private void InitializeComponent() // groupCHE.Controls.Add(uriSchemeEnabled); groupCHE.Controls.Add(alwaysLogAsAdmin); - groupCHE.Location = new System.Drawing.Point(11, 432); + groupCHE.Location = new System.Drawing.Point(12, 433); groupCHE.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); groupCHE.Name = "groupCHE"; groupCHE.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5); @@ -242,13 +245,40 @@ private void InitializeComponent() groupBoxLCSUrls.Controls.Add(textBoxLcsFixUrl); groupBoxLCSUrls.Controls.Add(textBoxLcsUpdateUrl); groupBoxLCSUrls.Controls.Add(textBoxLcsUrl); - groupBoxLCSUrls.Location = new System.Drawing.Point(11, 548); + groupBoxLCSUrls.Location = new System.Drawing.Point(12, 624); groupBoxLCSUrls.Name = "groupBoxLCSUrls"; - groupBoxLCSUrls.Size = new System.Drawing.Size(461, 165); + groupBoxLCSUrls.Size = new System.Drawing.Size(460, 165); groupBoxLCSUrls.TabIndex = 10; groupBoxLCSUrls.TabStop = false; groupBoxLCSUrls.Text = "LCS Urls"; // + // labelLcsDiagUrl + // + labelLcsDiagUrl.AutoSize = true; + labelLcsDiagUrl.Location = new System.Drawing.Point(9, 132); + labelLcsDiagUrl.Name = "labelLcsDiagUrl"; + labelLcsDiagUrl.Size = new System.Drawing.Size(130, 20); + labelLcsDiagUrl.TabIndex = 7; + labelLcsDiagUrl.Text = "LCS Diagnostic Url"; + // + // labelLcsFixUrl + // + labelLcsFixUrl.AutoSize = true; + labelLcsFixUrl.Location = new System.Drawing.Point(9, 99); + labelLcsFixUrl.Name = "labelLcsFixUrl"; + labelLcsFixUrl.Size = new System.Drawing.Size(139, 20); + labelLcsFixUrl.TabIndex = 6; + labelLcsFixUrl.Text = "LCS Issue Search Url"; + // + // labelLcsUpdateUrl + // + labelLcsUpdateUrl.AutoSize = true; + labelLcsUpdateUrl.Location = new System.Drawing.Point(9, 66); + labelLcsUpdateUrl.Name = "labelLcsUpdateUrl"; + labelLcsUpdateUrl.Size = new System.Drawing.Size(108, 20); + labelLcsUpdateUrl.TabIndex = 5; + labelLcsUpdateUrl.Text = "LCS Update Url"; + // // labelLcsUrl // labelLcsUrl.AutoSize = true; @@ -286,38 +316,30 @@ private void InitializeComponent() textBoxLcsUrl.Size = new System.Drawing.Size(203, 27); textBoxLcsUrl.TabIndex = 0; // - // labelLcsUpdateUrl - // - labelLcsUpdateUrl.AutoSize = true; - labelLcsUpdateUrl.Location = new System.Drawing.Point(9, 66); - labelLcsUpdateUrl.Name = "labelLcsUpdateUrl"; - labelLcsUpdateUrl.Size = new System.Drawing.Size(108, 20); - labelLcsUpdateUrl.TabIndex = 5; - labelLcsUpdateUrl.Text = "LCS Update Url"; - // - // labelLcsFixUrl + // groupBox1 // - labelLcsFixUrl.AutoSize = true; - labelLcsFixUrl.Location = new System.Drawing.Point(9, 99); - labelLcsFixUrl.Name = "labelLcsFixUrl"; - labelLcsFixUrl.Size = new System.Drawing.Size(139, 20); - labelLcsFixUrl.TabIndex = 6; - labelLcsFixUrl.Text = "LCS Issue Search Url"; + groupBox1.Controls.Add(addExternalIpAddress); + groupBox1.Location = new System.Drawing.Point(11, 549); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new System.Drawing.Size(461, 69); + groupBox1.TabIndex = 11; + groupBox1.TabStop = false; + groupBox1.Text = "Microsoft-hosted environments"; // - // labelLcsDiagUrl + // addExternalIpAddress // - labelLcsDiagUrl.AutoSize = true; - labelLcsDiagUrl.Location = new System.Drawing.Point(9, 132); - labelLcsDiagUrl.Name = "labelLcsDiagUrl"; - labelLcsDiagUrl.Size = new System.Drawing.Size(130, 20); - labelLcsDiagUrl.TabIndex = 7; - labelLcsDiagUrl.Text = "LCS Diagnostic Url"; + addExternalIpAddress.Location = new System.Drawing.Point(9, 26); + addExternalIpAddress.Name = "addExternalIpAddress"; + addExternalIpAddress.Size = new System.Drawing.Size(363, 31); + addExternalIpAddress.TabIndex = 2; + addExternalIpAddress.Text = "Add external IP when creating firewall exception"; // // Parameters // AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - ClientSize = new System.Drawing.Size(519, 770); + ClientSize = new System.Drawing.Size(487, 845); + Controls.Add(groupBox1); Controls.Add(groupBoxLCSUrls); Controls.Add(groupBoxCredentials); Controls.Add(groupBoxUIConfig); @@ -344,6 +366,7 @@ private void InitializeComponent() groupBoxCredentials.ResumeLayout(false); groupBoxLCSUrls.ResumeLayout(false); groupBoxLCSUrls.PerformLayout(); + groupBox1.ResumeLayout(false); ResumeLayout(false); } @@ -380,5 +403,7 @@ private void CachingEnabledCheckbox_Click(object sender, System.EventArgs e) private System.Windows.Forms.Label labelLcsDiagUrl; private System.Windows.Forms.Label labelLcsFixUrl; private System.Windows.Forms.Label labelLcsUpdateUrl; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.CheckBox addExternalIpAddress; } } \ No newline at end of file diff --git a/2LCS/Forms/Parameters.cs b/2LCS/Forms/Parameters.cs index bd92f13..74f8567 100644 --- a/2LCS/Forms/Parameters.cs +++ b/2LCS/Forms/Parameters.cs @@ -47,6 +47,8 @@ private void LoadParameters() textBoxLcsUpdateUrl.Text = Properties.Settings.Default.lcsUpdateURL; textBoxLcsDiagUrl.Text = Properties.Settings.Default.lcsDiagURL; textBoxLcsFixUrl.Text = Properties.Settings.Default.lcsFixURL; + addExternalIpAddress.Checked = Properties.Settings.Default.populateOwnIPForNSG; + SetStoreCacheEnabledDisabled(); } @@ -65,6 +67,8 @@ private void SetParameters() Properties.Settings.Default.lcsUpdateURL = textBoxLcsUpdateUrl.Text; Properties.Settings.Default.lcsDiagURL = textBoxLcsDiagUrl.Text; Properties.Settings.Default.lcsFixURL = textBoxLcsFixUrl.Text; + Properties.Settings.Default.populateOwnIPForNSG = addExternalIpAddress.Checked; + Properties.Settings.Default.Save(); } diff --git a/2LCS/Forms/Parameters.resx b/2LCS/Forms/Parameters.resx index 29dcb1b..b92c163 100644 --- a/2LCS/Forms/Parameters.resx +++ b/2LCS/Forms/Parameters.resx @@ -1,17 +1,17 @@  - diff --git a/2LCS/Properties/Settings.Designer.cs b/2LCS/Properties/Settings.Designer.cs index 7022128..e1e43b4 100644 --- a/2LCS/Properties/Settings.Designer.cs +++ b/2LCS/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace LCS.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.6.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.10.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -250,5 +250,17 @@ public string lcsFixURL { this["lcsFixURL"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool populateOwnIPForNSG { + get { + return ((bool)(this["populateOwnIPForNSG"])); + } + set { + this["populateOwnIPForNSG"] = value; + } + } } } diff --git a/2LCS/Properties/Settings.settings b/2LCS/Properties/Settings.settings index 520e2fa..2d75368 100644 --- a/2LCS/Properties/Settings.settings +++ b/2LCS/Properties/Settings.settings @@ -59,5 +59,8 @@ https://fix.lcs.dynamics.com + + False + \ No newline at end of file