Skip to content

Commit

Permalink
Merge pull request #151 from micahmo/release/v2.0.11
Browse files Browse the repository at this point in the history
Release/v2.0.11
  • Loading branch information
micahmo authored Feb 5, 2024
2 parents 913f6a2 + 1e9eb13 commit 55e9197
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 42 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.10.0</AssemblyVersion>
<FileVersion>2.0.10.0</FileVersion>
<InformationalVersion>2.0.10.0</InformationalVersion>
<AssemblyVersion>2.0.11.0</AssemblyVersion>
<FileVersion>2.0.11.0</FileVersion>
<InformationalVersion>2.0.11.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.10"
#define MyAppVersion "2.0.11"
#define MyAppPublisher "Micah Morrison"
#define MyAppURL "https://github.com/micahmo/WgServerforWindows"
#define MyAppExeName "WgServerforWindows.exe"
Expand Down
44 changes: 33 additions & 11 deletions WgServerforWindows/Models/ClientConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public ClientConfiguration(ClientConfigurationList parentList)
// Server properties
PresharedKeyProperty.TargetTypes.Add(typeof(ServerConfiguration));
PublicKeyProperty.TargetTypes.Add(typeof(ServerConfiguration));
ServerPersistentKeepaliveProperty.TargetTypes.Add(typeof(ServerConfiguration));

ServerConfigurationPrerequisite.EnsureConfigFile();
var serverConfiguration = new ServerConfiguration().Load<ServerConfiguration>(Configuration.LoadFromFile(ServerConfigurationPrerequisite.ServerDataPath));
Expand Down Expand Up @@ -195,6 +194,39 @@ public ClientConfiguration(ClientConfigurationList parentList)
};
Properties.Add(allowedIpsProperty);

// This is a client property which goes in the client's (peer) section of the server's config,
// so it should be defined and configured here, and should be targeted to the server's config.
ConfigurationProperty PersistentKeepaliveProperty = new ConfigurationProperty(this)
{
PersistentPropertyName = "PersistentKeepalive",
Name = nameof(PersistentKeepaliveProperty),
DefaultValue = 0.ToString(),
Validation = new ConfigurationPropertyValidation
{
Validate = prop =>
{
string result = default;

if (string.IsNullOrEmpty(prop.Value) || int.TryParse(prop.Value, out _) == false)
{
result = Resources.PersistentKeepaliveValidationError;
}

return result;
}
}
};
// On load, do a migration of the old value from the server config, if needed.
PersistentKeepaliveProperty.OnLoadAction = _ =>
{
if (string.IsNullOrEmpty(PersistentKeepaliveProperty.Value))
{
PersistentKeepaliveProperty.Value = serverConfiguration.ServerPersistentKeepaliveProperty.Value ?? 0.ToString();
}
};
Properties.Add(PersistentKeepaliveProperty);
PersistentKeepaliveProperty.TargetTypes.Add(typeof(ServerConfiguration));

// Adjust index of properties and resort
AddressProperty.Index = 1;
DnsProperty.Index = 2;
Expand Down Expand Up @@ -347,16 +379,6 @@ public ClientConfiguration(ClientConfigurationList parentList)
};
private ConfigurationProperty _fullDnsProperty;

// Note: This is really a server property, but it goes in the in the (peer) client section of the server's config.
// So we'll trick the config generator by putting it in the client, targeting it to the server, and returning the server's value,
// which the server will set on the client while saving
public ConfigurationProperty ServerPersistentKeepaliveProperty => _persistentKeepaliveProperty ??= new ConfigurationProperty(this)
{
PersistentPropertyName = "PersistentKeepalive",
IsHidden = true
};
private ConfigurationProperty _persistentKeepaliveProperty;

// Note: This is a client-specific property. It goes in the peer (client) section of the server's config, and is thus targeted to the server config type.
// However, it also goes in the peer (server) section of the client config.
// Therefore, it must also be defined on the server, targeted to the client, and return this client's value.
Expand Down
1 change: 1 addition & 0 deletions WgServerforWindows/Models/ConfigurationBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public ConfigurationBase Load(Configuration configuration)
}

TopLevelActions.ForEach(a => a.OnLoadAction?.Invoke(this));
Properties.ForEach(p => p.OnLoadAction?.Invoke(this));

return this;
}
Expand Down
5 changes: 5 additions & 0 deletions WgServerforWindows/Models/ConfigurationProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ public string DefaultValue

public HashSet<Type> TargetTypes { get; } = new HashSet<Type>();

/// <summary>
/// An action to be invoked after the configuration has been loaded
/// </summary>
public Action<ConfigurationBase> OnLoadAction { get; set; }

#region Commands

public ICommand ExecuteActionCommand => _executeActionCommand ??= new RelayCommand(() =>
Expand Down
26 changes: 5 additions & 21 deletions WgServerforWindows/Models/ServerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,28 +215,12 @@ public ServerConfiguration()
};
private EndpointConfigurationProperty _endpointProperty;

// Note: Although this property is configured on the server, it goes in the peer (client) section of the server's config,
// which means it also has to be defined on the client, targeted to the server's config.
// The client should return the server's value, and the server should not target this property to any config type.
public ConfigurationProperty PersistentKeepaliveProperty => _persistentKeepaliveProperty ??= new ConfigurationProperty(this)
// This property is now configured on the client (and targeted to the client's (peer) section in the server config).
// It exists here only for backwards compatibility, since it used to be configured here.
public ConfigurationProperty ServerPersistentKeepaliveProperty => _persistentKeepaliveProperty ??= new ConfigurationProperty(this)
{
PersistentPropertyName = "PersistentKeepalive", // Don't really need this since it isn't saved from here
Name = nameof(PersistentKeepaliveProperty),
DefaultValue = 0.ToString(),
Validation = new ConfigurationPropertyValidation
{
Validate = prop =>
{
string result = default;

if (string.IsNullOrEmpty(prop.Value) || int.TryParse(prop.Value, out _) == false)
{
result = Resources.PersistentKeepaliveValidationError;
}

return result;
}
}
PersistentPropertyName = "PersistentKeepalive",
IsHidden = true
};
private ConfigurationProperty _persistentKeepaliveProperty;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ private void SaveWG(ServerConfiguration serverConfiguration)

if (clientConfiguration.IsEnabledProperty.Value == true.ToString())
{
clientConfiguration.ServerPersistentKeepaliveProperty.Value = serverConfiguration.PersistentKeepaliveProperty.Value;
configuration = configuration.Merge(clientConfiguration.ToConfiguration<ServerConfiguration>());
}
}
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.10.0</Version>
<ReleaseDate>2023-04-19</ReleaseDate>
<Version>2.0.11.0</Version>
<ReleaseDate>2024-02-05</ReleaseDate>
<!-- Default download -->
<DownloadLink>https://github.com/micahmo/WgServerforWindows/releases/download/v2.0.10/WS4WSetup-2.0.10.exe</DownloadLink>
<DownloadFileName>WS4WSetup-2.0.10.exe</DownloadFileName>
<DownloadLink>https://github.com/micahmo/WgServerforWindows/releases/download/v2.0.11/WS4WSetup-2.0.11.exe</DownloadLink>
<DownloadFileName>WS4WSetup-2.0.11.exe</DownloadFileName>
<!-- Release notes -->
<VersionNotes> - Specify a custom subnet range for NAT network</VersionNotes>
<VersionNotes> - Allow PersistentKeepalive to be configured per client</VersionNotes>
<ReleaseNotes></ReleaseNotes>
</AppUpdate>

0 comments on commit 55e9197

Please sign in to comment.