diff --git a/Directory.Build.props b/Directory.Build.props index 075feef..710fb4e 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,9 +1,9 @@ - 2.0.10.0 - 2.0.10.0 - 2.0.10.0 + 2.0.11.0 + 2.0.11.0 + 2.0.11.0 Micah Morrison WS4W diff --git a/Installer/WS4WSetupScript.iss b/Installer/WS4WSetupScript.iss index 301c2bb..5cf9eb8 100644 --- a/Installer/WS4WSetupScript.iss +++ b/Installer/WS4WSetupScript.iss @@ -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" diff --git a/WgServerforWindows/Models/ClientConfiguration.cs b/WgServerforWindows/Models/ClientConfiguration.cs index 217e69e..8415809 100644 --- a/WgServerforWindows/Models/ClientConfiguration.cs +++ b/WgServerforWindows/Models/ClientConfiguration.cs @@ -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(Configuration.LoadFromFile(ServerConfigurationPrerequisite.ServerDataPath)); @@ -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; @@ -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. diff --git a/WgServerforWindows/Models/ConfigurationBase.cs b/WgServerforWindows/Models/ConfigurationBase.cs index b46e1ee..8d25420 100644 --- a/WgServerforWindows/Models/ConfigurationBase.cs +++ b/WgServerforWindows/Models/ConfigurationBase.cs @@ -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; } diff --git a/WgServerforWindows/Models/ConfigurationProperty.cs b/WgServerforWindows/Models/ConfigurationProperty.cs index 2cff521..e9718b7 100644 --- a/WgServerforWindows/Models/ConfigurationProperty.cs +++ b/WgServerforWindows/Models/ConfigurationProperty.cs @@ -73,6 +73,11 @@ public string DefaultValue public HashSet TargetTypes { get; } = new HashSet(); + /// + /// An action to be invoked after the configuration has been loaded + /// + public Action OnLoadAction { get; set; } + #region Commands public ICommand ExecuteActionCommand => _executeActionCommand ??= new RelayCommand(() => diff --git a/WgServerforWindows/Models/ServerConfiguration.cs b/WgServerforWindows/Models/ServerConfiguration.cs index d340788..d383be9 100644 --- a/WgServerforWindows/Models/ServerConfiguration.cs +++ b/WgServerforWindows/Models/ServerConfiguration.cs @@ -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; diff --git a/WgServerforWindows/Models/ServerConfigurationPrerequisite.cs b/WgServerforWindows/Models/ServerConfigurationPrerequisite.cs index 083d0fd..77205ec 100644 --- a/WgServerforWindows/Models/ServerConfigurationPrerequisite.cs +++ b/WgServerforWindows/Models/ServerConfigurationPrerequisite.cs @@ -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()); } } diff --git a/WireGuardServerForWindows/VersionInfo2.xml b/WireGuardServerForWindows/VersionInfo2.xml index 2102672..a2ac3f1 100644 --- a/WireGuardServerForWindows/VersionInfo2.xml +++ b/WireGuardServerForWindows/VersionInfo2.xml @@ -2,12 +2,12 @@ - 2.0.10.0 - 2023-04-19 + 2.0.11.0 + 2024-02-05 - https://github.com/micahmo/WgServerforWindows/releases/download/v2.0.10/WS4WSetup-2.0.10.exe - WS4WSetup-2.0.10.exe + https://github.com/micahmo/WgServerforWindows/releases/download/v2.0.11/WS4WSetup-2.0.11.exe + WS4WSetup-2.0.11.exe - - Specify a custom subnet range for NAT network + - Allow PersistentKeepalive to be configured per client