mirror of
https://github.com/fergalmoran/DnsServer.git
synced 2025-12-22 09:29:50 +00:00
DnsServerWindowsService: implemented support for auto firewall entry option.
This commit is contained in:
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
using DnsServerCore;
|
using DnsServerCore;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Win32;
|
||||||
using System;
|
using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@@ -66,6 +67,25 @@ namespace DnsServerWindowsService
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void CheckFirewallEntries()
|
private static void CheckFirewallEntries()
|
||||||
|
{
|
||||||
|
bool autoFirewallEntry = true;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
#pragma warning disable CA1416 // Validate platform compatibility
|
||||||
|
|
||||||
|
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Technitium\DNS Server", false))
|
||||||
|
{
|
||||||
|
if (key is not null)
|
||||||
|
autoFirewallEntry = Convert.ToInt32(key.GetValue("AutoFirewallEntry", 1)) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma warning restore CA1416 // Validate platform compatibility
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{ }
|
||||||
|
|
||||||
|
if (autoFirewallEntry)
|
||||||
{
|
{
|
||||||
string appPath = Assembly.GetEntryAssembly().Location;
|
string appPath = Assembly.GetEntryAssembly().Location;
|
||||||
|
|
||||||
@@ -75,6 +95,7 @@ namespace DnsServerWindowsService
|
|||||||
if (!WindowsFirewallEntryExists(appPath))
|
if (!WindowsFirewallEntryExists(appPath))
|
||||||
AddWindowsFirewallEntry(appPath);
|
AddWindowsFirewallEntry(appPath);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static bool WindowsFirewallEntryExists(string appPath)
|
private static bool WindowsFirewallEntryExists(string appPath)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user