Skip to content

Commit c54c3f3

Browse files
committed
Added fallback resolvers dialog
1 parent dd25f30 commit c54c3f3

File tree

8 files changed

+275
-42
lines changed

8 files changed

+275
-42
lines changed

SimpleDnsCrypt/Config/Global.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ public static class Global
9292
public const string DefaultResolverIpv4 = "127.0.0.1:53";
9393
public const string DefaultResolverIpv6 = "[::1]:53";
9494

95+
/// <summary>
96+
/// List of the default fall back resolvers.
97+
/// </summary>
98+
public static readonly string[] DefaultFallbackResolvers =
99+
{
100+
"9.9.9.9:53",
101+
"8.8.8.8:53"
102+
};
103+
95104
/// <summary>
96105
/// List of files must exist.
97106
/// </summary>

SimpleDnsCrypt/SimpleDnsCrypt.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@
171171
<Compile Include="ViewModels\AddressBlacklistViewModel.cs" />
172172
<Compile Include="ViewModels\AddressBlockLogViewModel.cs" />
173173
<Compile Include="ViewModels\CloakAndForwardViewModel.cs" />
174+
<Compile Include="ViewModels\FallbackResolversViewModel.cs" />
174175
<Compile Include="ViewModels\ListenAddressesViewModel.cs" />
175176
<Compile Include="ViewModels\MetroMessageBoxViewModel.cs" />
176177
<Compile Include="ViewModels\ProxiesViewModel.cs" />
@@ -221,6 +222,10 @@
221222
<SubType>Designer</SubType>
222223
<Generator>MSBuild:Compile</Generator>
223224
</Page>
225+
<Page Include="Views\FallbackResolversView.xaml">
226+
<Generator>MSBuild:Compile</Generator>
227+
<SubType>Designer</SubType>
228+
</Page>
224229
<Page Include="Views\ListenAddressesView.xaml">
225230
<SubType>Designer</SubType>
226231
<Generator>MSBuild:Compile</Generator>

SimpleDnsCrypt/ViewModels/DomainBlockLogViewModel.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,15 @@ namespace SimpleDnsCrypt.ViewModels
2020
public class DomainBlockLogViewModel : Screen
2121
{
2222
private static readonly ILog Log = LogManagerHelper.Factory();
23-
private readonly IWindowManager _windowManager;
24-
private readonly IEventAggregator _events;
2523

2624
private ObservableCollection<DomainBlockLogLine> _domainBlockLogLines;
2725
private string _domainBlockLogFile;
2826
private bool _isDomainBlockLogLogging;
2927
private DomainBlockLogLine _selectedDomainBlockLogLine;
3028

3129
[ImportingConstructor]
32-
public DomainBlockLogViewModel(IWindowManager windowManager, IEventAggregator events)
30+
public DomainBlockLogViewModel()
3331
{
34-
_windowManager = windowManager;
35-
_events = events;
36-
_events.Subscribe(this);
3732
_isDomainBlockLogLogging = false;
3833
_domainBlockLogLines = new ObservableCollection<DomainBlockLogLine>();
3934
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
using Caliburn.Micro;
2+
using SimpleDnsCrypt.Config;
3+
using SimpleDnsCrypt.Helper;
4+
using System.Collections.ObjectModel;
5+
using System.ComponentModel.Composition;
6+
7+
namespace SimpleDnsCrypt.ViewModels
8+
{
9+
[Export(typeof(FallbackResolversViewModel))]
10+
public class FallbackResolversViewModel : Screen
11+
{
12+
private string _windowTitle;
13+
private ObservableCollection<string> _fallbackResolvers;
14+
private string _selectedFallbackResolver;
15+
private string _addressInput;
16+
17+
18+
[ImportingConstructor]
19+
public FallbackResolversViewModel()
20+
{
21+
_fallbackResolvers = new ObservableCollection<string>();
22+
}
23+
24+
/// <summary>
25+
/// The title of the window.
26+
/// </summary>
27+
public string WindowTitle
28+
{
29+
get => _windowTitle;
30+
set
31+
{
32+
_windowTitle = value;
33+
NotifyOfPropertyChange(() => WindowTitle);
34+
}
35+
}
36+
37+
public ObservableCollection<string> FallbackResolvers
38+
{
39+
get => _fallbackResolvers;
40+
set
41+
{
42+
_fallbackResolvers = value;
43+
NotifyOfPropertyChange(() => FallbackResolvers);
44+
}
45+
}
46+
47+
public string SelectedFallbackResolver
48+
{
49+
get => _selectedFallbackResolver;
50+
set
51+
{
52+
_selectedFallbackResolver = value;
53+
NotifyOfPropertyChange(() => SelectedFallbackResolver);
54+
}
55+
}
56+
57+
public string AddressInput
58+
{
59+
get => _addressInput;
60+
set
61+
{
62+
_addressInput = value;
63+
NotifyOfPropertyChange(() => AddressInput);
64+
}
65+
}
66+
67+
public void AddAddress()
68+
{
69+
if (string.IsNullOrEmpty(_addressInput)) return;
70+
var validatedAddress = ValidationHelper.ValidateIpEndpoint(_addressInput);
71+
if (string.IsNullOrEmpty(validatedAddress)) return;
72+
if (FallbackResolvers.Contains(validatedAddress)) return;
73+
FallbackResolvers.Add(validatedAddress);
74+
AddressInput = string.Empty;
75+
}
76+
77+
public void RemoveAddress()
78+
{
79+
if (string.IsNullOrEmpty(_selectedFallbackResolver)) return;
80+
if (_fallbackResolvers.Count == 1) return;
81+
_fallbackResolvers.Remove(_selectedFallbackResolver);
82+
}
83+
84+
public void RestoreDefault()
85+
{
86+
FallbackResolvers.Clear();
87+
FallbackResolvers = new ObservableCollection<string>(Global.DefaultFallbackResolvers);
88+
}
89+
}
90+
}

SimpleDnsCrypt/ViewModels/ListenAddressesViewModel.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,15 @@ namespace SimpleDnsCrypt.ViewModels
99
[Export(typeof(ListenAddressesViewModel))]
1010
public class ListenAddressesViewModel : Screen
1111
{
12-
private readonly IWindowManager _windowManager;
13-
private readonly IEventAggregator _events;
1412
private string _windowTitle;
1513
private ObservableCollection<string> _listenAddresses;
1614
private string _selectedListenAddress;
1715
private string _addressInput;
1816

19-
public ListenAddressesViewModel()
20-
{
21-
}
2217

2318
[ImportingConstructor]
24-
public ListenAddressesViewModel(IWindowManager windowManager, IEventAggregator events)
19+
public ListenAddressesViewModel()
2520
{
26-
_windowManager = windowManager;
27-
_events = events;
28-
_events.Subscribe(this);
2921
_listenAddresses = new ObservableCollection<string>();
3022
}
3123

SimpleDnsCrypt/ViewModels/MainViewModel.cs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public class MainViewModel : Screen, INotifyDataErrorInfo
5050
private SettingsViewModel _settingsViewModel;
5151
private QueryLogViewModel _queryLogViewModel;
5252
private ListenAddressesViewModel _listenAddressesViewModel;
53+
private FallbackResolversViewModel _fallbackResolversViewModel;
5354
private RouteViewModel _routeViewModel;
5455
private ProxiesViewModel _proxiesViewModel;
5556
private bool _isDnsCryptAutomaticModeEnabled;
@@ -95,11 +96,12 @@ public MainViewModel(IWindowManager windowManager, IEventAggregator events)
9596
WindowTitle = LocalizationEx.GetUiString("settings", Thread.CurrentThread.CurrentCulture)
9697
};
9798
_settingsViewModel.PropertyChanged += SettingsViewModelOnPropertyChanged;
98-
_listenAddressesViewModel = new ListenAddressesViewModel(_windowManager, _events);
99+
_listenAddressesViewModel = new ListenAddressesViewModel();
100+
_fallbackResolversViewModel = new FallbackResolversViewModel();
99101
_routeViewModel = new RouteViewModel();
100102
_proxiesViewModel = new ProxiesViewModel(_windowManager, _events);
101103
_queryLogViewModel = new QueryLogViewModel(_windowManager, _events);
102-
_domainBlockLogViewModel = new DomainBlockLogViewModel(_windowManager, _events);
104+
_domainBlockLogViewModel = new DomainBlockLogViewModel();
103105
_domainBlacklistViewModel = new DomainBlacklistViewModel(_windowManager, _events);
104106
_addressBlockLogViewModel = new AddressBlockLogViewModel(_windowManager, _events);
105107
_addressBlacklistViewModel = new AddressBlacklistViewModel(_windowManager, _events);
@@ -230,6 +232,17 @@ public ProxiesViewModel ProxiesViewModel
230232
}
231233
}
232234

235+
public FallbackResolversViewModel FallbackResolversViewModel
236+
{
237+
get => _fallbackResolversViewModel;
238+
set
239+
{
240+
if (value.Equals(_fallbackResolversViewModel)) return;
241+
_fallbackResolversViewModel = value;
242+
NotifyOfPropertyChange(() => FallbackResolversViewModel);
243+
}
244+
}
245+
233246
public ListenAddressesViewModel ListenAddressesViewModel
234247
{
235248
get => _listenAddressesViewModel;
@@ -658,9 +671,24 @@ public void Proxies()
658671
}
659672
}
660673

661-
public async void ManageFallbackResolvers()
674+
public void ManageFallbackResolvers()
662675
{
676+
dynamic settings = new ExpandoObject();
677+
settings.WindowStartupLocation = WindowStartupLocation.CenterOwner;
678+
var oldAddressed = new List<string>(DnscryptProxyConfiguration.listen_addresses);
679+
FallbackResolversViewModel.FallbackResolvers = DnscryptProxyConfiguration.fallback_resolvers;
680+
FallbackResolversViewModel.WindowTitle = LocalizationEx.GetUiString("address_settings_listen_addresses", Thread.CurrentThread.CurrentCulture);
681+
var result = _windowManager.ShowDialog(FallbackResolversViewModel, null, settings);
682+
if (!result)
683+
{
684+
if (FallbackResolversViewModel.FallbackResolvers.Count == 0) return;
663685

686+
var a = FallbackResolversViewModel.FallbackResolvers.Except(oldAddressed).ToList();
687+
var b = oldAddressed.Except(FallbackResolversViewModel.FallbackResolvers).ToList();
688+
if (!a.Any() && !b.Any()) return;
689+
DnscryptProxyConfiguration.fallback_resolvers = FallbackResolversViewModel.FallbackResolvers;
690+
SaveAdvancedSettings();
691+
}
664692
}
665693

666694
public async void ListenAddresses()
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<UserControl x:Class="SimpleDnsCrypt.Views.FallbackResolversView"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:lex="http://wpflocalizeextension.codeplex.com"
7+
xmlns:converters="clr-namespace:SimpleDnsCrypt.Converters"
8+
xmlns:cal="http://www.caliburnproject.org"
9+
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
10+
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
11+
mc:Ignorable="d"
12+
Height="Auto" Width="250"
13+
lex:LocalizeDictionary.DesignCulture="en"
14+
lex:ResxLocalizationProvider.DefaultAssembly="SimpleDnsCrypt"
15+
lex:ResxLocalizationProvider.DefaultDictionary="Translation">
16+
<Grid Background="#198AB328">
17+
<Border BorderThickness="1" Grid.Row="0" Grid.Column="0" Background="#198AB328" Margin="10"
18+
Padding="10">
19+
<Border.BorderBrush>
20+
<DrawingBrush Viewport="0,0,8,8" ViewportUnits="Absolute" TileMode="Tile" Opacity="0.4">
21+
<DrawingBrush.Drawing>
22+
<DrawingGroup>
23+
<GeometryDrawing Brush="#FF8ab329">
24+
<GeometryDrawing.Geometry>
25+
<GeometryGroup>
26+
<RectangleGeometry Rect="0,0,50,50" />
27+
<RectangleGeometry Rect="50,50,50,50" />
28+
</GeometryGroup>
29+
</GeometryDrawing.Geometry>
30+
</GeometryDrawing>
31+
</DrawingGroup>
32+
</DrawingBrush.Drawing>
33+
</DrawingBrush>
34+
</Border.BorderBrush>
35+
<StackPanel Orientation="Vertical">
36+
<StackPanel Orientation="Horizontal">
37+
<iconPacks:PackIconMaterial Height="20"
38+
Width="20" Kind="Ethernet" Opacity="0.7"
39+
Foreground="#FF8ab329"
40+
HorizontalAlignment="Left"
41+
VerticalAlignment="Center" />
42+
<TextBlock Text="{lex:Loc Key=fallback_resolver_settings_addresses}"
43+
TextWrapping="Wrap" VerticalAlignment="Center"
44+
Foreground="#FF8ab329" FontSize="20"
45+
Opacity="0.7" Margin="5,0,0,3" FontWeight="Bold">
46+
</TextBlock>
47+
</StackPanel>
48+
<StackPanel Orientation="Vertical">
49+
<ListBox ItemsSource="{Binding FallbackResolvers}" SelectionMode="Single" SelectedItem="{Binding SelectedFallbackResolver}"/>
50+
<TextBox Margin="0,5,0,0" mah:TextBoxHelper.Watermark="9.9.9.9:53" Text="{Binding AddressInput}"></TextBox>
51+
</StackPanel>
52+
<StackPanel Orientation="Horizontal" Margin="0,5,0,0">
53+
<Button x:Name="AddAddress"
54+
cal:Message.Attach="AddAddress"
55+
Background="White"
56+
Width="30"
57+
Height="30"
58+
Cursor="Hand"
59+
HorizontalContentAlignment="Center"
60+
VerticalContentAlignment="Center"
61+
BorderBrush="{DynamicResource AccentColorBrush}"
62+
FocusVisualStyle="{DynamicResource MahApps.Metro.Styles.MetroCircleFocusVisual}"
63+
Style="{DynamicResource MahApps.Metro.Styles.MetroCircleButtonStyle}"
64+
Margin="5,0,5,0">
65+
<iconPacks:PackIconMaterial
66+
Kind="Plus"
67+
Width="15"
68+
Height="15"
69+
HorizontalContentAlignment="Center"
70+
VerticalContentAlignment="Center"
71+
Foreground="{DynamicResource AccentColorBrush}" />
72+
<Button.ToolTip>
73+
<Label
74+
Content="{lex:Loc Key=address_settings_add}"
75+
FontWeight="DemiBold" />
76+
</Button.ToolTip>
77+
</Button>
78+
<Button x:Name="RemoveAddress"
79+
cal:Message.Attach="RemoveAddress"
80+
Background="White"
81+
Width="30"
82+
Height="30"
83+
Cursor="Hand"
84+
HorizontalContentAlignment="Center"
85+
VerticalContentAlignment="Center"
86+
BorderBrush="{DynamicResource AccentColorBrush}"
87+
FocusVisualStyle="{DynamicResource MahApps.Metro.Styles.MetroCircleFocusVisual}"
88+
Style="{DynamicResource MahApps.Metro.Styles.MetroCircleButtonStyle}"
89+
Margin="5,0,5,0">
90+
<iconPacks:PackIconMaterial
91+
Kind="Minus"
92+
Width="15"
93+
Height="15"
94+
HorizontalContentAlignment="Center"
95+
VerticalContentAlignment="Center"
96+
Foreground="{DynamicResource AccentColorBrush}" />
97+
<Button.ToolTip>
98+
<Label
99+
Content="{lex:Loc Key=address_settings_remove}"
100+
FontWeight="DemiBold" />
101+
</Button.ToolTip>
102+
</Button>
103+
<Button x:Name="RestoreDefault"
104+
cal:Message.Attach="RestoreDefault"
105+
Background="White"
106+
Width="30"
107+
Height="30"
108+
Cursor="Hand"
109+
HorizontalContentAlignment="Center"
110+
VerticalContentAlignment="Center"
111+
BorderBrush="{DynamicResource AccentColorBrush}"
112+
FocusVisualStyle="{DynamicResource MahApps.Metro.Styles.MetroCircleFocusVisual}"
113+
Style="{DynamicResource MahApps.Metro.Styles.MetroCircleButtonStyle}"
114+
Margin="5,0,5,0">
115+
<iconPacks:PackIconMaterial
116+
Kind="Restore"
117+
Width="15"
118+
Height="15"
119+
HorizontalContentAlignment="Center"
120+
VerticalContentAlignment="Center"
121+
Foreground="{DynamicResource AccentColorBrush}" />
122+
<Button.ToolTip>
123+
<Label
124+
Content="{lex:Loc Key=address_settings_restore}"
125+
FontWeight="DemiBold" />
126+
</Button.ToolTip>
127+
</Button>
128+
</StackPanel>
129+
</StackPanel>
130+
</Border>
131+
</Grid>
132+
</UserControl>

0 commit comments

Comments
 (0)