Skip to content

Commit

Permalink
Merge pull request #95 from micahmo/release/v2.0.7
Browse files Browse the repository at this point in the history
Release/v2.0.7
  • Loading branch information
micahmo authored Feb 13, 2023
2 parents 4453e60 + d987488 commit 14efd9a
Show file tree
Hide file tree
Showing 15 changed files with 208 additions and 48 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.6.0</AssemblyVersion>
<FileVersion>2.0.6.0</FileVersion>
<InformationalVersion>2.0.6.0</InformationalVersion>
<AssemblyVersion>2.0.7.0</AssemblyVersion>
<FileVersion>2.0.7.0</FileVersion>
<InformationalVersion>2.0.7.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.6"
#define MyAppVersion "2.0.7"
#define MyAppPublisher "Micah Morrison"
#define MyAppURL "https://github.com/micahmo/WgServerforWindows"
#define MyAppExeName "WgServerforWindows.exe"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ In addition to creating/udpating the configuration file for the server endpoint,
You should set the Endpoint property to your public IPv4, IPv6, or domain address, followed by whatever port you have forwarded. The `Detect Public IP Address` button will attempt to detect your public address automatically using the [ipify.org](https://ipify.org) API. However, if possible, it is recommended that you use a domain name with DDNS. That way, if your public IP address changes, your clients will be able to find your server endpoint without reconfiguration.

### Client Configuration
![ClientConfiguration](https://user-images.githubusercontent.com/7417301/173172783-5a16da01-f725-4a47-b738-1e52f79f49cd.png)
![ClientConfiguration](https://user-images.githubusercontent.com/7417301/218290866-f36b8bda-208f-4dfd-a66f-40e5b960b0af.png)

Here you can configure the client(s). The Address can be entered manually or calculated based on the server's network range. For example, if the server's network is `10.253.0.0/24`, the client config can determine that `10.253.0.2` is a valid address. Note that the first address in the range (in this example, `10.253.0.1`) is reserved for the server. DNS is optional, but recommended. You may add DNS Search Domains (also known as DNS Suffixes, [read more](https://en.wikipedia.org/wiki/Search_domain)). Lastly, the Private Key, Public Key, and Preshared Key are generated using `wg genkey`, `wg pubkey [private key]`, and `wg genpsk`. (You may specify your own Private Key. Preshared Keys are optional, generated uniquely per-client, and shared with the server's configuration. See [#34](https://github.com/micahmo/WgServerforWindows/issues/34) for more info.)

Expand Down
46 changes: 36 additions & 10 deletions WgServerforWindows/Controls/ClientConfigurationEditorWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
xmlns:properties="clr-namespace:WgServerforWindows.Properties"
xmlns:controls="clr-namespace:WgServerforWindows.Controls"
xmlns:converters="clr-namespace:WgServerforWindows.Converters"
xmlns:c="clr-namespace:CalcBinding;assembly=CalcBinding"
xmlns:esb="clr-namespace:ExplorerSearchBox;assembly=ExplorerSearchBox"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=models:ClientConfigurationList}"
Width="600" Height="600"
Title="{x:Static properties:Resources.ClientConfiguration}">

<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
Expand All @@ -25,30 +28,53 @@
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<Grid Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3">
<Grid Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="4">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="40" />
<ColumnDefinition Width="40" />
<ColumnDefinition Width="5" />
</Grid.ColumnDefinitions>

<Button Grid.Column="1" Grid.Row="0" Margin="0,10,0,10" Content="{x:Static properties:Resources.AddClient}" Command="{Binding AddClientConfigurationCommand}"/>
<Button Grid.Column="0" Grid.Row="0" Margin="10,10,5,10" Height="30" Content="{x:Static properties:Resources.AddClient}" Command="{Binding AddClientConfigurationCommand}"/>
<esb:ExplorerSearchBox Grid.Column="1" Margin="5,0,5,0" FocusManager.IsFocusScope="True" HintText="Filter" VerticalAlignment="Center" HorizontalAlignment="Stretch" SearchRequested="ExplorerSearchBox_SearchRequested" />
<Button Grid.Column="2" Grid.Row="0" Margin="5,10,5,10" Content="+" FontSize="15" ToolTip="{x:Static properties:Resources.ExpandAll}" Command="{Binding ExpandAllConfigurationsCommand}"/>
<Button Grid.Column="3" Grid.Row="0" Margin="5,10,5,10" Content="-" FontSize="15" ToolTip="{x:Static properties:Resources.CollapseAll}" Command="{Binding CollapseAllConfigurationsCommand}"/>
</Grid>

<ScrollViewer Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="3" VerticalScrollBarVisibility="Auto">
<ScrollViewer Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="4" VerticalScrollBarVisibility="Visible">
<ItemsControl ItemsSource="{Binding List}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<Canvas Height="10" Margin="20" Background="LightGray"/>
<controls:ConfigurationEditorControl DataContext="{Binding}"/>
<Expander IsExpanded="{Binding IsExpanded}" Margin="0,0,0,0" Visibility="{c:Binding IsVisible, FalseToVisibility=Collapsed}">
<Expander.Header>
<Grid HorizontalAlignment="{Binding HorizontalAlignment, RelativeSource={RelativeSource AncestorType=ContentPresenter}, Mode=OneWayToSource}"
Margin="-23,-3,0,0" Background="LightGray">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
<ColumnDefinition Width="20"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{c:Binding 'IsExpanded ? ExpandedSymbol : CollapsedSymbol'}" VerticalAlignment="Center" TextAlignment="Center" FontWeight="Bold" TextTrimming="CharacterEllipsis"/>
<TextBlock Grid.Column="2" Text="{Binding NameProperty.Value}" TextAlignment="Center" FontWeight="Bold" FontSize="13" Padding="5" />
</Grid>
</Expander.Header>
<Grid Margin="0,5,0,0">
<controls:ConfigurationEditorControl DataContext="{Binding}"/>
</Grid>
</Expander>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>

<Button Grid.Column="1" Grid.Row="2" Margin="10,10,5,10" Padding="10,5,10,5" HorizontalAlignment="Right" Content="{x:Static properties:Resources.Cancel}" Click="CancelButton_Click"/>
<Button Grid.Column="2" Grid.Row="2" Margin="5,10,10,10" Padding="10,5,10,5" HorizontalAlignment="Right" Content="{x:Static properties:Resources.Save}" Click="SaveButton_Click"/>
<Label Grid.Column="0" Grid.Row="2" Content="{Binding CountString}" Padding="10,5,10,10" VerticalContentAlignment="Bottom"/>
<Button Grid.Column="2" Grid.Row="2" Margin="10,10,5,10" Padding="10,5,10,5" HorizontalAlignment="Right" Content="{x:Static properties:Resources.Cancel}" Click="CancelButton_Click"/>
<Button Grid.Column="3" Grid.Row="2" Margin="5,10,10,10" Padding="10,5,10,5" HorizontalAlignment="Right" Content="{x:Static properties:Resources.Save}" Click="SaveButton_Click"/>
</Grid>
</Window>
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using WgServerforWindows.Models;

namespace WgServerforWindows.Controls
{
Expand Down Expand Up @@ -34,5 +36,20 @@ private void CancelButton_Click(object sender, RoutedEventArgs e)
}

#endregion

private void ExplorerSearchBox_SearchRequested(object sender, string e)
{
if (DataContext is ClientConfigurationList clientConfigurationList)
{
clientConfigurationList.List.ToList().ForEach(c => c.IsVisible = true);

if (!string.IsNullOrWhiteSpace(e))
{
clientConfigurationList.List.Where(c => !c.Name.Contains(e, StringComparison.OrdinalIgnoreCase)).ToList().ForEach(c => c.IsVisible = false);
}

clientConfigurationList.RaisePropertyChanged(nameof(clientConfigurationList.CountString));
}
}
}
}
7 changes: 7 additions & 0 deletions WgServerforWindows/Models/AppSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows;
using GalaSoft.MvvmLight;
Expand Down Expand Up @@ -47,6 +48,7 @@ public void Load()
Tracker.Configure<AppSettings>()
.Property(a => a.CustomServerConfigDirectory)
.Property(a => a.CustomClientConfigDirectory)
.Property(a => a.ClientConfigurationExpansionStates)
.Track(this);
}

Expand Down Expand Up @@ -79,6 +81,11 @@ public string CustomClientConfigDirectory
}
private string _customClientConfigDirectory;

/// <summary>
/// Tracks whether each client configuration is expanded in the UI or not
/// </summary>
public Dictionary<string, bool> ClientConfigurationExpansionStates = new Dictionary<string, bool>();

/// <summary>
/// The public tracker instance. Can be used to track things other than the <see cref="Instance"/>.
/// </summary>
Expand Down
19 changes: 19 additions & 0 deletions WgServerforWindows/Models/ClientConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public ClientConfiguration(ClientConfigurationList parentList)
PublicKeyProperty.TargetTypes.Add(typeof(ServerConfiguration));
ServerPersistentKeepaliveProperty.TargetTypes.Add(typeof(ServerConfiguration));

ServerConfigurationPrerequisite.EnsureConfigFile();
var serverConfiguration = new ServerConfiguration().Load<ServerConfiguration>(Configuration.LoadFromFile(ServerConfigurationPrerequisite.ServerDataPath));
string serverIp = serverConfiguration.AddressProperty.Value;
string allowedIpsDefault = serverConfiguration.AllowedIpsProperty.Value;
Expand Down Expand Up @@ -448,6 +449,24 @@ public ClientConfiguration(ClientConfigurationList parentList)
});
private RelayCommand _removeClientCommand;

public bool IsVisible
{
get => _isVisible;
set => Set(nameof(IsVisible), ref _isVisible, value);
}
private bool _isVisible = true;

public bool IsExpanded
{
get => _isExpanded;
set => Set(nameof(IsExpanded), ref _isExpanded, value);
}
private bool _isExpanded = true;

public string ExpandedSymbol => "▼";

public string CollapsedSymbol => "▶";

#endregion

#region Private fields
Expand Down
29 changes: 28 additions & 1 deletion WgServerforWindows/Models/ClientConfigurationList.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Input;
using System.Windows.Threading;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using WgServerforWindows.Properties;

namespace WgServerforWindows.Models
{
public class ClientConfigurationList
public class ClientConfigurationList : ObservableObject
{
public ClientConfigurationList()
{
List.CollectionChanged += (_, __) =>
{
RaisePropertyChanged(nameof(CountString));
};
}

public ObservableCollection<ClientConfiguration> List { get; } = new ObservableCollection<ClientConfiguration>();

public string CountString => List.Any(c => !c.IsVisible)
? string.Format(Resources.FilteredClientCount, List.Count(c => c.IsVisible), List.Count)
: string.Format(Resources.ClientCount, List.Count);

public ICommand AddClientConfigurationCommand => _addClientConfigurationCommand ??= new RelayCommand(() =>
{
using (new WaitCursor(dispatcherPriority: DispatcherPriority.Render, restoreCursorToNull: true))
Expand All @@ -17,5 +32,17 @@ public class ClientConfigurationList
}
});
private RelayCommand _addClientConfigurationCommand;

public ICommand ExpandAllConfigurationsCommand => _expandAllConfigurationsCommand ??= new RelayCommand(() =>
{
List.ToList().ForEach(c => c.IsExpanded = true);
});
private RelayCommand _expandAllConfigurationsCommand;

public ICommand CollapseAllConfigurationsCommand => _collapseAllConfigurationsCommand ??= new RelayCommand(() =>
{
List.ToList().ForEach(c => c.IsExpanded = false);
});
private RelayCommand _collapseAllConfigurationsCommand;
}
}
12 changes: 12 additions & 0 deletions WgServerforWindows/Models/ClientConfigurationsPrerequisite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ public override void Configure()
clientConfigurations.List.Add(clientConfiguration);
}

clientConfigurations.List.ToList().ForEach(c =>
{
if (AppSettings.Instance.ClientConfigurationExpansionStates.TryGetValue(c.Name, out bool expansionState))
{
c.IsExpanded = expansionState;
}
});

ClientConfigurationEditorWindow clientConfigurationEditorWindow = new ClientConfigurationEditorWindow {DataContext = clientConfigurations};

WaitCursor.SetOverrideCursor(Cursors.Wait);
Expand Down Expand Up @@ -184,6 +192,10 @@ public override void Configure()
WaitCursor.SetOverrideCursor(null);
}

AppSettings.Instance.ClientConfigurationExpansionStates.Clear();
clientConfigurations.List.ToList().ForEach(c => AppSettings.Instance.ClientConfigurationExpansionStates[c.Name] = c.IsExpanded);
AppSettings.Instance.Save();

Refresh();
}

Expand Down
51 changes: 24 additions & 27 deletions WgServerforWindows/Models/ServerConfigurationPrerequisite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,33 +77,7 @@ public ServerConfigurationPrerequisite(

public override void Resolve()
{
if (Directory.Exists(Path.GetDirectoryName(ServerDataPath)) == false)
{
Directory.CreateDirectory(Path.GetDirectoryName(ServerDataPath));
}

if (File.Exists(ServerDataPath) == false)
{
#pragma warning disable CS0642
// There is intentionally no code block after the using statement,
// because we want to create and then release the file without holding it open.
using (File.Create(ServerDataPath));
#pragma warning restore CS0642
}

if (Directory.Exists(Path.GetDirectoryName(ServerWGPath)) == false)
{
Directory.CreateDirectory(Path.GetDirectoryName(ServerWGPath));
}

if (File.Exists(ServerWGPath) == false)
{
#pragma warning disable CS0642
// There is intentionally no code block after the using statement,
// because we want to create and then release the file without holding it open.
using (File.Create(ServerWGPath));
#pragma warning restore CS0642
}
EnsureConfigFile();

Configure();
}
Expand Down Expand Up @@ -236,6 +210,29 @@ private void SaveWG(ServerConfiguration serverConfiguration)

#region Public static methods

public static void EnsureConfigFile()
{
if (Directory.Exists(Path.GetDirectoryName(ServerDataPath)) == false)
{
Directory.CreateDirectory(Path.GetDirectoryName(ServerDataPath));
}

if (File.Exists(ServerDataPath) == false)
{
File.Create(ServerDataPath).Dispose();
}

if (Directory.Exists(Path.GetDirectoryName(ServerWGPath)) == false)
{
Directory.CreateDirectory(Path.GetDirectoryName(ServerWGPath));
}

if (File.Exists(ServerWGPath) == false)
{
File.Create(ServerWGPath).Dispose();
}
}

public static Network GetNetwork(TimeSpan? timeout = null)
{
Network result = default;
Expand Down
Loading

0 comments on commit 14efd9a

Please sign in to comment.