Skip to content

Commit e29deb3

Browse files
committed
Allow whitelist from block log
1 parent 6fe044f commit e29deb3

4 files changed

Lines changed: 52 additions & 3 deletions

File tree

SimpleDnsCrypt/ViewModels/DomainBlacklistViewModel.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,16 @@ public async Task BuildBlacklist()
454454
{
455455
File.WriteAllLines(_domainBlacklistFile, rules);
456456
}
457+
458+
if (DnsCryptProxyManager.IsDnsCryptProxyInstalled())
459+
{
460+
if (DnsCryptProxyManager.IsDnsCryptProxyRunning())
461+
{
462+
DnsCryptProxyManager.Restart();
463+
await Task.Delay(Global.ServiceRestartTime);
464+
}
465+
}
466+
457467
await metroWindow.HideMetroDialogAsync(dialog);
458468
}
459469
catch (Exception exception)

SimpleDnsCrypt/ViewModels/DomainBlockLogViewModel.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66
using System.Collections.ObjectModel;
77
using System.ComponentModel.Composition;
88
using System.IO;
9+
using System.Linq;
910
using System.Threading;
1011
using System.Threading.Tasks;
12+
using System.Windows;
13+
using DnsCrypt.Blacklist;
14+
using MahApps.Metro.Controls;
15+
using MahApps.Metro.Controls.Dialogs;
1116

1217
namespace SimpleDnsCrypt.ViewModels
1318
{
@@ -89,6 +94,39 @@ public bool IsDomainBlockLogLogging
8994
}
9095
}
9196

97+
public async void UnblockBlockLogEntry()
98+
{
99+
try
100+
{
101+
if (_selectedDomainBlockLogLine == null) return;
102+
if (MainViewModel.Instance.DomainBlacklistViewModel == null) return;
103+
var dialogSettings = new MetroDialogSettings
104+
{
105+
DefaultText = _selectedDomainBlockLogLine.Message.ToLower(),
106+
AffirmativeButtonText = LocalizationEx.GetUiString("add", Thread.CurrentThread.CurrentCulture),
107+
NegativeButtonText = LocalizationEx.GetUiString("cancel", Thread.CurrentThread.CurrentCulture),
108+
ColorScheme = MetroDialogColorScheme.Theme
109+
};
110+
111+
var metroWindow = Application.Current.Windows.OfType<MetroWindow>().FirstOrDefault();
112+
//TODO: translate
113+
var dialogResult = await metroWindow.ShowInputAsync(LocalizationEx.GetUiString("message_title_new_whitelist_rule", Thread.CurrentThread.CurrentCulture),
114+
"Rule:", dialogSettings);
115+
116+
if (string.IsNullOrEmpty(dialogResult)) return;
117+
var newCustomRule = dialogResult.ToLower().Trim();
118+
var parsed = DomainBlacklist.ParseBlacklist(newCustomRule, true);
119+
var enumerable = parsed as string[] ?? parsed.ToArray();
120+
if (enumerable.Length != 1) return;
121+
MainViewModel.Instance.DomainBlacklistViewModel.DomainWhitelistRules.Add(enumerable[0]);
122+
MainViewModel.Instance.DomainBlacklistViewModel.SaveWhitelistRulesToFile();
123+
}
124+
catch (Exception exception)
125+
{
126+
Log.Error(exception);
127+
}
128+
}
129+
92130
private async void DomainBlockLog(DnscryptProxyConfiguration dnscryptProxyConfiguration)
93131
{
94132
const string defaultLogFormat = "ltsv";

SimpleDnsCrypt/ViewModels/QueryLogViewModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ public async void BlockQueryLogEntry()
7575
};
7676

7777
var metroWindow = Application.Current.Windows.OfType<MetroWindow>().FirstOrDefault();
78-
var dialogResult = await metroWindow.ShowInputAsync("new",
79-
"rule", dialogSettings);
78+
//TODO: translate
79+
var dialogResult = await metroWindow.ShowInputAsync(LocalizationEx.GetUiString("message_title_new_blacklist_rule", Thread.CurrentThread.CurrentCulture),
80+
"Rule:", dialogSettings);
8081

8182
if (string.IsNullOrEmpty(dialogResult)) return;
8283
var newCustomRule = dialogResult.ToLower().Trim();

SimpleDnsCrypt/Views/MainView.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@
10591059
</Button>
10601060
<Button x:Name="UnblockBlockLogEntry"
10611061
cal:Message.Attach="UnblockBlockLogEntry"
1062-
Background="White" IsEnabled="False"
1062+
Background="White"
10631063
Width="30"
10641064
Height="30"
10651065
Cursor="Hand"

0 commit comments

Comments
 (0)