Skip to content

Commit 48552ea

Browse files
committed
Added View to configure proxies
- See #359
1 parent 100adc3 commit 48552ea

File tree

5 files changed

+200
-0
lines changed

5 files changed

+200
-0
lines changed

SimpleDnsCrypt/SimpleDnsCrypt.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@
219219
<Compile Include="ViewModels\AddressBlockLogViewModel.cs" />
220220
<Compile Include="ViewModels\ListenAddressesViewModel.cs" />
221221
<Compile Include="ViewModels\MetroMessageBoxViewModel.cs" />
222+
<Compile Include="ViewModels\ProxiesViewModel.cs" />
222223
<Compile Include="ViewModels\SettingsViewModel.cs" />
223224
<Compile Include="ViewModels\AboutViewModel.cs" />
224225
<Compile Include="ViewModels\DomainBlacklistViewModel.cs" />
@@ -270,6 +271,10 @@
270271
<SubType>Designer</SubType>
271272
<Generator>MSBuild:Compile</Generator>
272273
</Page>
274+
<Page Include="Views\ProxiesView.xaml">
275+
<SubType>Designer</SubType>
276+
<Generator>MSBuild:Compile</Generator>
277+
</Page>
273278
<Page Include="Views\SettingsView.xaml">
274279
<Generator>MSBuild:Compile</Generator>
275280
<SubType>Designer</SubType>

SimpleDnsCrypt/ViewModels/MainViewModel.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public class MainViewModel : Screen, INotifyDataErrorInfo
6363

6464
private SettingsViewModel _settingsViewModel;
6565
private ListenAddressesViewModel _listenAddressesViewModel;
66+
private ProxiesViewModel _proxiesViewModel;
6667
private bool _showHiddenCards;
6768
private string _windowTitle;
6869

@@ -90,6 +91,7 @@ public MainViewModel(IWindowManager windowManager, IEventAggregator events)
9091
};
9192
_settingsViewModel.PropertyChanged += SettingsViewModelOnPropertyChanged;
9293
_listenAddressesViewModel = new ListenAddressesViewModel(_windowManager, _events);
94+
_proxiesViewModel = new ProxiesViewModel(_windowManager, _events);
9395
_queryLogViewModel = new QueryLogViewModel(_windowManager, _events);
9496
_domainBlockLogViewModel = new DomainBlockLogViewModel(_windowManager, _events);
9597
_domainBlacklistViewModel = new DomainBlacklistViewModel(_windowManager, _events);
@@ -198,6 +200,17 @@ public SettingsViewModel SettingsViewModel
198200
}
199201
}
200202

203+
public ProxiesViewModel ProxiesViewModel
204+
{
205+
get => _proxiesViewModel;
206+
set
207+
{
208+
if (value.Equals(_proxiesViewModel)) return;
209+
_proxiesViewModel = value;
210+
NotifyOfPropertyChange(() => ProxiesViewModel);
211+
}
212+
}
213+
201214
public ListenAddressesViewModel ListenAddressesViewModel
202215
{
203216
get => _listenAddressesViewModel;
@@ -525,6 +538,51 @@ public void Settings()
525538
if (!result) Properties.Settings.Default.Save();
526539
}
527540

541+
public void Proxies()
542+
{
543+
dynamic settings = new ExpandoObject();
544+
settings.WindowStartupLocation = WindowStartupLocation.CenterOwner;
545+
ProxiesViewModel.WindowTitle = "Manage Proxies";
546+
ProxiesViewModel.HttpProxyInput = string.IsNullOrEmpty(DnscryptProxyConfiguration.http_proxy) ? "" : DnscryptProxyConfiguration.http_proxy;
547+
ProxiesViewModel.SocksProxyInput = string.IsNullOrEmpty(DnscryptProxyConfiguration.proxy) ? "" : DnscryptProxyConfiguration.proxy;
548+
var result = _windowManager.ShowDialog(ProxiesViewModel, null, settings);
549+
if (result) return;
550+
var saveAdvancedSettings = false;
551+
552+
if (string.IsNullOrEmpty(ProxiesViewModel.HttpProxyInput))
553+
{
554+
if (!string.IsNullOrEmpty(DnscryptProxyConfiguration.http_proxy))
555+
{
556+
DnscryptProxyConfiguration.http_proxy = null;
557+
saveAdvancedSettings = true;
558+
}
559+
}
560+
else
561+
{
562+
DnscryptProxyConfiguration.http_proxy = ProxiesViewModel.HttpProxyInput;
563+
saveAdvancedSettings = true;
564+
}
565+
566+
if (string.IsNullOrEmpty(ProxiesViewModel.SocksProxyInput))
567+
{
568+
if (!string.IsNullOrEmpty(DnscryptProxyConfiguration.proxy))
569+
{
570+
DnscryptProxyConfiguration.proxy = null;
571+
saveAdvancedSettings = true;
572+
}
573+
}
574+
else
575+
{
576+
DnscryptProxyConfiguration.proxy = ProxiesViewModel.SocksProxyInput;
577+
saveAdvancedSettings = true;
578+
}
579+
580+
if (saveAdvancedSettings)
581+
{
582+
SaveAdvancedSettings();
583+
}
584+
}
585+
528586
public async void ListenAddresses()
529587
{
530588
dynamic settings = new ExpandoObject();
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel.Composition;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using Caliburn.Micro;
8+
9+
namespace SimpleDnsCrypt.ViewModels
10+
{
11+
[Export(typeof(ListenAddressesViewModel))]
12+
public class ProxiesViewModel : Screen
13+
{
14+
private readonly IWindowManager _windowManager;
15+
private readonly IEventAggregator _events;
16+
private string _windowTitle;
17+
private string _httpProxyInput;
18+
private string _socksProxyInput;
19+
20+
public ProxiesViewModel()
21+
{
22+
}
23+
24+
[ImportingConstructor]
25+
public ProxiesViewModel(IWindowManager windowManager, IEventAggregator events)
26+
{
27+
_windowManager = windowManager;
28+
_events = events;
29+
_events.Subscribe(this);
30+
}
31+
32+
/// <summary>
33+
/// The title of the window.
34+
/// </summary>
35+
public string WindowTitle
36+
{
37+
get => _windowTitle;
38+
set
39+
{
40+
_windowTitle = value;
41+
NotifyOfPropertyChange(() => WindowTitle);
42+
}
43+
}
44+
45+
public string HttpProxyInput
46+
{
47+
get => _httpProxyInput;
48+
set
49+
{
50+
_httpProxyInput = value;
51+
NotifyOfPropertyChange(() => HttpProxyInput);
52+
}
53+
}
54+
55+
public string SocksProxyInput
56+
{
57+
get => _socksProxyInput;
58+
set
59+
{
60+
_socksProxyInput = value;
61+
NotifyOfPropertyChange(() => SocksProxyInput);
62+
}
63+
}
64+
}
65+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<UserControl x:Class="SimpleDnsCrypt.Views.ProxiesView"
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:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
8+
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
9+
mc:Ignorable="d"
10+
Height="Auto" Width="400"
11+
lex:LocalizeDictionary.DesignCulture="en"
12+
lex:ResxLocalizationProvider.DefaultAssembly="SimpleDnsCrypt"
13+
lex:ResxLocalizationProvider.DefaultDictionary="Translation">
14+
<Grid Background="#198AB328">
15+
<Border BorderThickness="1" Grid.Row="0" Grid.Column="0" Background="#198AB328" Margin="10"
16+
Padding="10">
17+
<Border.BorderBrush>
18+
<DrawingBrush Viewport="0,0,8,8" ViewportUnits="Absolute" TileMode="Tile" Opacity="0.4">
19+
<DrawingBrush.Drawing>
20+
<DrawingGroup>
21+
<GeometryDrawing Brush="#FF8ab329">
22+
<GeometryDrawing.Geometry>
23+
<GeometryGroup>
24+
<RectangleGeometry Rect="0,0,50,50" />
25+
<RectangleGeometry Rect="50,50,50,50" />
26+
</GeometryGroup>
27+
</GeometryDrawing.Geometry>
28+
</GeometryDrawing>
29+
</DrawingGroup>
30+
</DrawingBrush.Drawing>
31+
</DrawingBrush>
32+
</Border.BorderBrush>
33+
<StackPanel Orientation="Vertical">
34+
<StackPanel Orientation="Horizontal">
35+
<iconPacks:PackIconMaterial Height="20"
36+
Width="20" Kind="AccountNetwork" Opacity="0.7"
37+
Foreground="#FF8ab329"
38+
HorizontalAlignment="Left"
39+
VerticalAlignment="Center" />
40+
<TextBlock Text="Proxies"
41+
TextWrapping="Wrap" VerticalAlignment="Center"
42+
Foreground="#FF8ab329" FontSize="20"
43+
Opacity="0.7" Margin="5,0,0,3" FontWeight="Bold">
44+
</TextBlock>
45+
</StackPanel>
46+
<TextBlock Text="HTTP/HTTPS proxy"
47+
TextWrapping="Wrap" VerticalAlignment="Center"
48+
Foreground="#FF8ab329" FontSize="14"
49+
Opacity="0.7" Margin="5,8,0,3" FontWeight="Bold">
50+
</TextBlock>
51+
<TextBlock Text="Only for DoH servers"
52+
TextWrapping="Wrap" VerticalAlignment="Center"
53+
Foreground="#FF575757" Margin="5,0,0,3">
54+
</TextBlock>
55+
<TextBox Margin="0,5,0,0" mah:TextBoxHelper.Watermark="http://127.0.0.1:8888" Text="{Binding HttpProxyInput}" mah:TextBoxHelper.ClearTextButton="True"></TextBox>
56+
<TextBlock Text="SOCKS proxy"
57+
TextWrapping="Wrap" VerticalAlignment="Center"
58+
Foreground="#FF8ab329" FontSize="14"
59+
Opacity="0.7" Margin="5,8,0,3" FontWeight="Bold">
60+
</TextBlock>
61+
<TextBlock Text="You can route all TCP connections to a local Tor node. Tor doesn't support UDP, so you should enable Force TCP (Advanced Settings) as well."
62+
TextWrapping="Wrap" VerticalAlignment="Center"
63+
Foreground="#FF575757" Margin="5,0,0,3">
64+
</TextBlock>
65+
<TextBox Margin="0,5,0,0" mah:TextBoxHelper.Watermark="socks5://127.0.0.1:9050" Text="{Binding SocksProxyInput}" mah:TextBoxHelper.ClearTextButton="True"></TextBox>
66+
</StackPanel>
67+
</Border>
68+
</Grid>
69+
</UserControl>

SimpleDnsCrypt/Windows/BaseWindow.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
<Button Cursor="Hand" x:Name="Settings" cal:Message.Attach="Settings" ToolTip="{lex:Loc Key=settings}">
3333
<iconPacks:PackIconMaterial Kind="Settings"/>
3434
</Button>
35+
<Button Cursor="Hand" x:Name="Proxies" cal:Message.Attach="Proxies" ToolTip="Manage Proxies">
36+
<iconPacks:PackIconMaterial Kind="AccountNetwork"/>
37+
</Button>
3538
<ComboBox Style="{StaticResource MetroComboBox}"
3639
ItemsSource="{Binding Languages}"
3740
SelectedItem="{Binding SelectedLanguage}"

0 commit comments

Comments
 (0)