Skip to content

Commit

Permalink
Merge pull request #69 from micahmo/release/v2.0.4
Browse files Browse the repository at this point in the history
Release/v2.0.4
  • Loading branch information
micahmo authored Dec 31, 2022
2 parents 1dcfbd0 + 06ea6ce commit 6b97a5a
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 29 deletions.
6 changes: 3 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project>
<PropertyGroup>
<!-- Keep in sync with WS4WSetupScript.iss and VersionInfo.xml -->
<AssemblyVersion>2.0.3.0</AssemblyVersion>
<FileVersion>2.0.3.0</FileVersion>
<InformationalVersion>2.0.3.0</InformationalVersion>
<AssemblyVersion>2.0.4.0</AssemblyVersion>
<FileVersion>2.0.4.0</FileVersion>
<InformationalVersion>2.0.4.0</InformationalVersion>
<Authors>Micah Morrison</Authors>
<Product>WS4W</Product>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion Installer/WS4WSetupScript.iss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#define MyAppNameOld "WireGuard Server For Windows"
#define MyAppName "Wg Server for Windows"
#define MyAppVersion "2.0.3"
#define MyAppVersion "2.0.4"
#define MyAppPublisher "Micah Morrison"
#define MyAppURL "https://github.com/micahmo/WgServerforWindows"
#define MyAppExeName "WgServerforWindows.exe"
Expand Down
48 changes: 38 additions & 10 deletions WgServerforWindows/Models/ClientConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,49 @@ public ClientConfiguration(ClientConfigurationList parentList)
DependencySatisfiedFunc = prop => string.IsNullOrEmpty(prop.Validation?.Validate?.Invoke(prop)),
Action = (conf, prop) =>
{
IPNetwork serverNetwork = IPNetwork.Parse(serverConfiguration.AddressProperty.Value);
var possibleAddresses = serverNetwork.ListIPAddress().Skip(2).SkipLast(1); // Skip reserved .0 and .1 and .255.
WaitCursor.SetOverrideCursor(Cursors.Wait);

var serverAddresses = serverConfiguration.AddressProperty.Value
.Split(',')
.Select(a => IPNetwork.Parse(a.Trim()))
.ToList(); // Prevent multiple enumeration

var currentClientAddresses = prop.Value
.Split(',')
.Select(a =>
{
IPAddress.TryParse(a.Trim(), out var address);
return address;
})
.Where(a => a != null)
.ToList(); // Prevent multiple enumeration

var newClientAddresses = new HashSet<string>();
var serverAddressesToConsider = new List<IPNetwork>(serverAddresses); // Copy

// If the current address is already in range, we're done
if (IPAddress.TryParse(prop.Value, out var currentAddress) && serverNetwork.Contains(currentAddress))
// See if any existing client addresses are in any of the server's address ranges
foreach (var serverAddress in serverAddresses)
{
return;
foreach (var clientAddress in currentClientAddresses)
{
if (serverAddress.Contains(clientAddress))
{
newClientAddresses.Add(clientAddress.ToString());
serverAddressesToConsider.Remove(serverAddress);
}
}
}

WaitCursor.SetOverrideCursor(Cursors.Wait);

var existingAddresses = parentList.List.Select(c => c.AddressProperty.Value);

// Find the first address that isn't used by another client
prop.Value = possibleAddresses.FirstOrDefault(a => existingAddresses.Contains(a.ToString()) == false)?.ToString();
newClientAddresses.UnionWith(serverAddressesToConsider.Select(s => s
.ListIPAddress()
.Skip(2)
.SkipLast(1)
.FirstOrDefault(a => !existingAddresses.Contains(a.ToString()))
?.ToString()
));

prop.Value = string.Join(", ", newClientAddresses);

WaitCursor.SetOverrideCursor(null);
}
Expand Down
19 changes: 9 additions & 10 deletions WgServerforWindows/Models/ServerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,24 @@ public ServerConfiguration()
{
Validate = obj =>
{
string result = default;

if (IPNetwork.TryParse(obj.Value, out _) == false)
{
result = Resources.NetworkAddressValidationError;
}
else // TryParse succeeded
// Multiple server addresses are supported, so validate all of them
foreach (string address in obj.Value.Split(',').Select(a => a.Trim()))
{
if (IPNetwork.TryParse(address, out _) == false)
{
return Resources.NetworkAddressValidationError;
}
// IPNetwork.TryParse recognizes single IP addresses as CIDR (with 8 mask).
// This is not good, because we want an explicit CIDR for the server.
// Therefore, if IPNetwork.TryParse succeeds, and IPAddress.TryParse also succeeds, we have a problem.
if (IPAddress.TryParse(obj.Value, out _))
if (IPAddress.TryParse(address, out _))
{
// This is just a regular address. We want CIDR.
result = Resources.NetworkAddressValidationError;
return Resources.NetworkAddressValidationError;
}
}

return result;
return default;
}
};

Expand Down
10 changes: 5 additions & 5 deletions WireGuardServerForWindows/VersionInfo2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<!-- Things to update: Version, Date, Release Notes -->
<AppUpdate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/micahmo/WgServerforWindows/master/WireGuardServerForWindows/AppUpdate.xsd">
<Version>2.0.3.0</Version>
<ReleaseDate>2022-10-31</ReleaseDate>
<Version>2.0.4.0</Version>
<ReleaseDate>2022-12-31</ReleaseDate>
<!-- Default download -->
<DownloadLink>https://github.com/micahmo/WgServerforWindows/releases/download/v2.0.3/WS4WSetup-2.0.3.exe</DownloadLink>
<DownloadFileName>WS4WSetup-2.0.3.exe</DownloadFileName>
<DownloadLink>https://github.com/micahmo/WgServerforWindows/releases/download/v2.0.4/WS4WSetup-2.0.4.exe</DownloadLink>
<DownloadFileName>WS4WSetup-2.0.4.exe</DownloadFileName>
<!-- Release notes -->
<VersionNotes> - Fix New-NetNat feature check (#62)</VersionNotes>
<VersionNotes> - Add support for generating client addresses from mulitple server address subnets (#67 and #68). Thanks @xeptore!</VersionNotes>
<ReleaseNotes></ReleaseNotes>
</AppUpdate>

0 comments on commit 6b97a5a

Please sign in to comment.