Skip to content

Commit

Permalink
New plugin: ldns_blocking
Browse files Browse the repository at this point in the history
- Added ldns_blocking support
- Updated application screenshots
  • Loading branch information
bitbeans committed Feb 5, 2016
1 parent e05b69d commit 084a62b
Show file tree
Hide file tree
Showing 12 changed files with 387 additions and 49 deletions.
4 changes: 2 additions & 2 deletions SimpleDnsCrypt/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
ResourceDictionaryLocation.None,
ResourceDictionaryLocation.SourceAssembly
)]
[assembly: AssemblyVersion("0.3.0")]
[assembly: AssemblyFileVersion("0.3.0")]
[assembly: AssemblyVersion("0.3.1")]
[assembly: AssemblyFileVersion("0.3.1")]
36 changes: 36 additions & 0 deletions SimpleDnsCrypt/Resources/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions SimpleDnsCrypt/Resources/Strings.de.resx
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,16 @@
<data name="default_settings_info_port" xml:space="preserve">
<value>DNSCrypt wird auf diesem Port lauschen (Standard: 53)</value>
</data>
<data name="block_plugin_title" xml:space="preserve">
<value>Blockieren von Adressen und Domains</value>
</data>
<data name="block_plugin_sub_domains_header" xml:space="preserve">
<value>Domains blockieren</value>
</data>
<data name="block_plugin_sub_addresses_header" xml:space="preserve">
<value>IP Adressen blockieren</value>
</data>
<data name="block_plugin_text" xml:space="preserve">
<value>Dieses Plugin gibt als Response REFUSED zurück, falls die Anfrage in der Domain-Blacklist oder in der IP-Blacklist aufgeführt ist.</value>
</data>
</root>
12 changes: 12 additions & 0 deletions SimpleDnsCrypt/Resources/Strings.en.resx
Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,16 @@ The logs are stored in a local file.</value>
<data name="default_settings_info_port" xml:space="preserve">
<value>DNSCrypt will listen on this port (default: 53)</value>
</data>
<data name="block_plugin_title" xml:space="preserve">
<value>Block addresses and domains</value>
</data>
<data name="block_plugin_text" xml:space="preserve">
<value>This plugin returns a REFUSED response if the query name is in a list of blacklisted names, or if at least one of the returned IP addresses happens to be in a list of blacklisted IPs.</value>
</data>
<data name="block_plugin_sub_domains_header" xml:space="preserve">
<value>Block domains</value>
</data>
<data name="block_plugin_sub_addresses_header" xml:space="preserve">
<value>Block addresses</value>
</data>
</root>
12 changes: 12 additions & 0 deletions SimpleDnsCrypt/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,16 @@ The logs are stored in a local file.</value>
<data name="default_settings_info_port" xml:space="preserve">
<value>DNSCrypt will listen on this port (default: 53)</value>
</data>
<data name="block_plugin_title" xml:space="preserve">
<value>Block addresses and domains</value>
</data>
<data name="block_plugin_text" xml:space="preserve">
<value>This plugin returns a REFUSED response if the query name is in a list of blacklisted names, or if at least one of the returned IP addresses happens to be in a list of blacklisted IPs.</value>
</data>
<data name="block_plugin_sub_domains_header" xml:space="preserve">
<value>Block domains</value>
</data>
<data name="block_plugin_sub_addresses_header" xml:space="preserve">
<value>Block addresses</value>
</data>
</root>
5 changes: 3 additions & 2 deletions SimpleDnsCrypt/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.Dynamic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net.NetworkInformation;
Expand Down Expand Up @@ -69,8 +70,8 @@ private MainViewModel(IWindowManager windowManager, IEventAggregator eventAggreg
LocalizeDictionary.Instance.SetCurrentThreadCulture = true;
LocalizeDictionary.Instance.Culture = Thread.CurrentThread.CurrentCulture;

// this is already defined in the app.manifest, but to be sure check it again
if (!IsAdministrator())
// this is already defined in the app.manifest, but to be sure check it again
if (!IsAdministrator())
{
_windowManager.ShowMetroMessageBox(
LocalizationEx.GetUiString("dialog_message_bad_privileges", Thread.CurrentThread.CurrentCulture),
Expand Down
215 changes: 194 additions & 21 deletions SimpleDnsCrypt/ViewModels/PluginManagerViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.Composition;
using System.IO;
using System.Windows.Forms;
Expand All @@ -14,14 +15,19 @@ namespace SimpleDnsCrypt.ViewModels
[Export]
public sealed class PluginManagerViewModel : Screen
{
private const string LibdcpluginLdns = "libdcplugin_ldns_aaaa_blocking.dll";
private const string LibdcpluginLogging = "libdcplugin_logging.dll";
private const string LibdcpluginLdnsIpv6 = "libdcplugin_ldns_aaaa_blocking.dll";
private const string LibdcpluginLdns = "libdcplugin_ldns_blocking.dll";
private const string LibdcpluginLogging = "libdcplugin_logging.dll";
private bool _blockIpv6Plugin;
private bool _logPlugin;
private string _logPluginPath;
private bool _blacklistPlugin;
private string _addressBlacklistPath;
private string _domainBlacklistPath;
private string _logPluginPath;
private List<string> _plugins;


/// <summary>
/// <summary>
/// PluginManagerViewModel constructor.
/// </summary>
[ImportingConstructor]
Expand All @@ -43,22 +49,96 @@ public List<string> Plugins
}
}

/// <summary>
/// To manage the block IPv6 plugin.
/// </summary>
public bool BlockIpv6Plugin
/// <summary>
/// To manage the blacklist plugin.
/// </summary>
public bool BlacklistPlugin
{
get { return _blacklistPlugin; }
set
{
_blacklistPlugin = value;
if (value)
{
if (AddressBlacklistPath != null && File.Exists(AddressBlacklistPath) || DomainBlacklistPath != null && File.Exists(DomainBlacklistPath))
{
var p = LibdcpluginLdns + "";
var kindCounter = 0;

if (!string.IsNullOrEmpty(AddressBlacklistPath))
{
// dnscrypt-proxy will not start if the file is empty
if (File.ReadAllLines(AddressBlacklistPath).Length != 0)
{
p += ",--ips=" + AddressBlacklistPath;
kindCounter++;
}
else
{
// better show a notification to the user
AddressBlacklistPath = string.Empty;
}
}

if (!string.IsNullOrEmpty(DomainBlacklistPath))
{
// dnscrypt-proxy will not start if the file is empty
if (File.ReadAllLines(DomainBlacklistPath).Length != 0)
{
p += ",--domains=" + DomainBlacklistPath;
kindCounter++;
}
else
{
// better show a notification to the user
DomainBlacklistPath = string.Empty;
}
}

if (kindCounter > 0)
{
Plugins.Add(p);
_blacklistPlugin = true;
}
else
{
_blacklistPlugin = false;
}
}
else
{
_blacklistPlugin = false;
}
}
else
{
for (var i = 0; i < Plugins.Count; i++)
{
if (!Plugins[i].StartsWith(LibdcpluginLdns)) continue;
Plugins.RemoveAt(i);
NotifyOfPropertyChange(() => BlacklistPlugin);
}
}
NotifyOfPropertyChange(() => BlacklistPlugin);
}
}

/// <summary>
/// To manage the block IPv6 plugin.
/// </summary>
public bool BlockIpv6Plugin
{
get { return _blockIpv6Plugin; }
set
{
_blockIpv6Plugin = value;
if (value)
{
Plugins.Add(LibdcpluginLdns);
Plugins.Add(LibdcpluginLdnsIpv6);
}
else
{
Plugins.Remove(LibdcpluginLdns);
Plugins.Remove(LibdcpluginLdnsIpv6);
}
NotifyOfPropertyChange(() => BlockIpv6Plugin);
}
Expand Down Expand Up @@ -113,10 +193,36 @@ public string LogPluginPath
}
}

/// <summary>
/// FolderBrowserDialog to select the log folder.
/// </summary>
public void SelectFolder()
/// <summary>
/// The full path to the domain blacklist file.
/// </summary>
public string DomainBlacklistPath
{
get { return _domainBlacklistPath; }
set
{
_domainBlacklistPath = value;
NotifyOfPropertyChange(() => DomainBlacklistPath);
}
}

/// <summary>
/// The full path to the address blacklist file.
/// </summary>
public string AddressBlacklistPath
{
get { return _addressBlacklistPath; }
set
{
_addressBlacklistPath = value;
NotifyOfPropertyChange(() => AddressBlacklistPath);
}
}

/// <summary>
/// FolderBrowserDialog to select the log folder.
/// </summary>
public void SelectFolder()
{
try
{
Expand All @@ -131,20 +237,87 @@ public void SelectFolder()
}
}

/// <summary>
/// Set the used plugins.
/// </summary>
/// <param name="plugins">List of plugins.</param>
public void SetPlugins(List<string> plugins)
/// <summary>
/// FileBrowserDialog to select the domain blacklist file.
/// </summary>
public void SelectDomainBlacklist()
{
try
{
var dialog = new OpenFileDialog
{
Multiselect = false,
CheckFileExists = true
};
var result = dialog.ShowDialog();
if (result != DialogResult.OK) return;
DomainBlacklistPath = dialog.FileName;
}
catch (Exception)
{
DomainBlacklistPath = string.Empty;
}
}

/// <summary>
/// FileBrowserDialog to select the address blacklist file.
/// </summary>
public void SelectAddressBlacklist()
{
try
{
var dialog = new OpenFileDialog
{
Multiselect = false,
CheckFileExists = true
};
var result = dialog.ShowDialog();
if (result != DialogResult.OK) return;
AddressBlacklistPath = dialog.FileName;
}
catch (Exception)
{
AddressBlacklistPath = string.Empty;
}
}

/// <summary>
/// Set the used plugins.
/// </summary>
/// <param name="plugins">List of plugins.</param>
public void SetPlugins(List<string> plugins)
{
_plugins = plugins;
foreach (var plugin in _plugins)
{
if (plugin.Equals(LibdcpluginLdns))
if (plugin.Equals(LibdcpluginLdnsIpv6))
{
_blockIpv6Plugin = true;
}
if (plugin.StartsWith(LibdcpluginLogging))
if (plugin.StartsWith(LibdcpluginLdns))
{
var a = plugin.Split(',');

for (var r = 1; r < a.Length; r++)
{
if (a[r].StartsWith("--ips"))
{
var b = a[r].Split('=');
_addressBlacklistPath = b[1];
}
if (a[r].StartsWith("--domains"))
{
var b = a[r].Split('=');
_domainBlacklistPath = b[1];
}
}

if (!string.IsNullOrEmpty(_addressBlacklistPath) || !string.IsNullOrEmpty(_domainBlacklistPath))
{
_blacklistPlugin = true;
}
}
if (plugin.StartsWith(LibdcpluginLogging))
{
var a = plugin.Split(',');
_logPluginPath = a[1];
Expand Down
Loading

0 comments on commit 084a62b

Please sign in to comment.