Skip to content

Commit

Permalink
Optionally populate external IP address when creating firewall except…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
milnet92 authored and FH-Inway committed Aug 21, 2024
1 parent 5696d74 commit b768b94
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 57 deletions.
9 changes: 9 additions & 0 deletions 2LCS/2LCS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,18 @@
<Compile Update="ExtendedWebBrowser.cs">
<SubType>Component</SubType>
</Compile>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
<None Update="LICENSE">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.6.1">
Expand Down
3 changes: 3 additions & 0 deletions 2LCS/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
<setting name="lcsFixURL" serializeAs="String">
<value>https://fix.lcs.dynamics.com</value>
</setting>
<setting name="populateOwnIPForNSG" serializeAs="String">
<value>False</value>
</setting>
</LCS.Properties.Settings>
</userSettings>
<runtime>
Expand Down
24 changes: 24 additions & 0 deletions 2LCS/Forms/AddNSG.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Windows.Forms;

namespace LCS.Forms
Expand All @@ -11,6 +12,8 @@ public partial class AddNsg : Form
public AddNsg()
{
InitializeComponent();

PopulateWithOwnIP();
}

public bool Cancelled { get; private set; }
Expand Down Expand Up @@ -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))
Expand Down
87 changes: 56 additions & 31 deletions 2LCS/Forms/Parameters.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions 2LCS/Forms/Parameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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();
}

Expand Down
50 changes: 25 additions & 25 deletions 2LCS/Forms/Parameters.resx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
Expand All @@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
Expand Down
14 changes: 13 additions & 1 deletion 2LCS/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions 2LCS/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,8 @@
<Setting Name="lcsFixURL" Type="System.String" Scope="User">
<Value Profile="(Default)">https://fix.lcs.dynamics.com</Value>
</Setting>
<Setting Name="populateOwnIPForNSG" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>

0 comments on commit b768b94

Please sign in to comment.