diff --git a/Directory.Build.props b/Directory.Build.props index c7320b2..234478b 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,9 +1,9 @@ - 2.1.2.0 - 2.1.2.0 - 2.1.2.0 + 2.1.3.0 + 2.1.3.0 + 2.1.3.0 Micah Morrison WS4W diff --git a/Installer/WS4WSetupScript.iss b/Installer/WS4WSetupScript.iss index 0557ce0..4082dff 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.1.2" +#define MyAppVersion "2.1.3" #define MyAppPublisher "Micah Morrison" #define MyAppURL "https://github.com/micahmo/WgServerforWindows" #define MyAppExeName "WgServerforWindows.exe" diff --git a/WgServerforWindows/Models/TunnelServicePrerequisite.cs b/WgServerforWindows/Models/TunnelServicePrerequisite.cs index 1c222c0..a8bd3ef 100644 --- a/WgServerforWindows/Models/TunnelServicePrerequisite.cs +++ b/WgServerforWindows/Models/TunnelServicePrerequisite.cs @@ -1,9 +1,12 @@ using System; using System.Linq; +using System.Net; using System.Net.NetworkInformation; using System.Windows.Input; +using SharpConfig; using WgAPI; using WgAPI.Commands; +using WgServerforWindows.Controls; using WgServerforWindows.Properties; namespace WgServerforWindows.Models @@ -35,6 +38,73 @@ public TunnelServicePrerequisite(TunnelServiceNameSubCommand tunnelServiceNameSu public override async void Resolve() { + try + { + // Load the server config and check the listen port + ServerConfiguration serverConfiguration = new ServerConfiguration().Load(Configuration.LoadFromFile(ServerConfigurationPrerequisite.ServerDataPath)); + string listenPort = serverConfiguration.ListenPortProperty.Value; + + if (int.TryParse(listenPort, out int listenPortInt)) + { + IPEndPoint[] tcpEndPoints = IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners(); + IPEndPoint[] udpEndPoints = IPGlobalProperties.GetIPGlobalProperties().GetActiveUdpListeners(); + + bool anyTcpListener = tcpEndPoints.Any(endpoint => endpoint.Port == listenPortInt); + bool anyUdpListener = udpEndPoints.Any(endpoint => endpoint.Port == listenPortInt); + + if (anyUdpListener) + { + // Give the user strong warning about UDP listener + bool canceled = false; + UnhandledErrorWindow portWarningDialog = new UnhandledErrorWindow(); + portWarningDialog.DataContext = new UnhandledErrorWindowModel + { + Title = Resources.PotentialPortConflict, + Text = string.Format(Resources.UDPPortConflictMessage, listenPort), + SecondaryButtonText = Resources.Cancel, + SecondaryButtonAction = () => + { + canceled = true; + portWarningDialog.Close(); + } + }; + portWarningDialog.ShowDialog(); + + if (canceled) + { + return; + } + } + else if (anyTcpListener) + { + // Give the user less strong warning about TCP listener + bool canceled = false; + UnhandledErrorWindow portWarningDialog = new UnhandledErrorWindow(); + portWarningDialog.DataContext = new UnhandledErrorWindowModel + { + Title = Resources.PotentialPortConflict, + Text = string.Format(Resources.TCPPortConflictMessage, listenPort), + SecondaryButtonText = Resources.Cancel, + SecondaryButtonAction = () => + { + canceled = true; + portWarningDialog.Close(); + } + }; + portWarningDialog.ShowDialog(); + + if (canceled) + { + return; + } + } + } + } + catch + { + // If we can't verify the listen port, it's ok. + } + WaitCursor.SetOverrideCursor(Cursors.Wait); using (TemporaryFile temporaryFile = new(ServerConfigurationPrerequisite.ServerWGPath, ServerConfigurationPrerequisite.ServerWGPathWithCustomTunnelName)) diff --git a/WgServerforWindows/Properties/Resources.Designer.cs b/WgServerforWindows/Properties/Resources.Designer.cs index ddbda37..1e8a568 100644 --- a/WgServerforWindows/Properties/Resources.Designer.cs +++ b/WgServerforWindows/Properties/Resources.Designer.cs @@ -1017,6 +1017,15 @@ public static string PortValidationError { } } + /// + /// Looks up a localized string similar to Potential Port Conflict. + /// + public static string PotentialPortConflict { + get { + return ResourceManager.GetString("PotentialPortConflict", resourceCulture); + } + } + /// /// Looks up a localized string similar to Preshared Key. /// @@ -1361,6 +1370,15 @@ public static string SplashScreenText { } } + /// + /// Looks up a localized string similar to Another process is listening on TCP Port {0}. Since WireGuard uses UDP, there should not (but there may) be a conflict. Do you wish to proceed?. + /// + public static string TCPPortConflictMessage { + get { + return ResourceManager.GetString("TCPPortConflictMessage", resourceCulture); + } + } + /// /// Looks up a localized string similar to Temporary Profile Detected. /// @@ -1415,6 +1433,15 @@ public static string TunnelServiceNotInstalled { } } + /// + /// Looks up a localized string similar to Another process is listening on UDP Port {0} which may conflict with WireGuard. If you continue, WS4W may fail to install the tunnel service. Do you wish to proceed?. + /// + public static string UDPPortConflictMessage { + get { + return ResourceManager.GetString("UDPPortConflictMessage", resourceCulture); + } + } + /// /// Looks up a localized string similar to UNDEFINED. /// diff --git a/WgServerforWindows/Properties/Resources.resx b/WgServerforWindows/Properties/Resources.resx index 9ac7e37..b77004a 100644 --- a/WgServerforWindows/Properties/Resources.resx +++ b/WgServerforWindows/Properties/Resources.resx @@ -620,4 +620,13 @@ Note: It is preferable to use a domain name with DDNS to avoid dynamic WAN IPs.< Don't Show Again + + Potential Port Conflict + + + Another process is listening on UDP Port {0} which may conflict with WireGuard. If you continue, WS4W may fail to install the tunnel service. Do you wish to proceed? + + + Another process is listening on TCP Port {0}. Since WireGuard uses UDP, there should not (but there may) be a conflict. Do you wish to proceed? + \ No newline at end of file diff --git a/WireGuardServerForWindows/VersionInfo2.xml b/WireGuardServerForWindows/VersionInfo2.xml index 76dcbfc..79475c9 100644 --- a/WireGuardServerForWindows/VersionInfo2.xml +++ b/WireGuardServerForWindows/VersionInfo2.xml @@ -2,14 +2,12 @@ - 2.1.2.0 - 2025-02-20 + 2.1.3.0 + 2025-03-05 - https://github.com/micahmo/WgServerforWindows/releases/download/v2.1.2/WS4WSetup-2.1.2.exe - WS4WSetup-2.1.2.exe + https://github.com/micahmo/WgServerforWindows/releases/download/v2.1.3/WS4WSetup-2.1.3.exe + WS4WSetup-2.1.3.exe - - Added the ability to customize the tunnel service name (#104) - - Delay the WS4W Set NetIPAddress task (#108) - - Show a warning if the user is running with a temporary profile (#122) + - Show warning if another process is listening on the configured WireGuard server port (#138 and #188)