NxDomain: removed newtonsoft.

This commit is contained in:
Shreyas Zare
2022-12-24 11:53:47 +05:30
parent 724a13484e
commit 7759893bbc

View File

@@ -1,6 +1,6 @@
/*
Technitium DNS Server
Copyright (C) 2021 Shreyas Zare (shreyas@technitium.com)
Copyright (C) 2022 Shreyas Zare (shreyas@technitium.com)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -18,10 +18,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using DnsServerCore.ApplicationCommon;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Net;
using System.Text.Json;
using System.Threading.Tasks;
using TechnitiumLibrary;
using TechnitiumLibrary.Net.Dns;
using TechnitiumLibrary.Net.Dns.ResourceRecords;
@@ -51,16 +53,6 @@ namespace NxDomain
#region private
private static IReadOnlyDictionary<string, object> ReadJsonDomainArray(dynamic jsonDomainArray)
{
Dictionary<string, object> domains = new Dictionary<string, object>(jsonDomainArray.Count);
foreach (dynamic jsonDomain in jsonDomainArray)
domains.TryAdd(jsonDomain.Value, null);
return domains;
}
private static string GetParentZone(string domain)
{
int i = domain.IndexOf('.');
@@ -100,18 +92,21 @@ namespace NxDomain
{
_soaRecord = new DnsSOARecordData(dnsServer.ServerDomain, "hostadmin@" + dnsServer.ServerDomain, 1, 14400, 3600, 604800, 60);
dynamic jsonConfig = JsonConvert.DeserializeObject(config);
using JsonDocument jsonDocument = JsonDocument.Parse(config);
JsonElement jsonConfig = jsonDocument.RootElement;
_enableBlocking = jsonConfig.enableBlocking.Value;
_allowTxtBlockingReport = jsonConfig.allowTxtBlockingReport.Value;
_blockListZone = ReadJsonDomainArray(jsonConfig.blocked);
_enableBlocking = jsonConfig.GetProperty("enableBlocking").GetBoolean();
_allowTxtBlockingReport = jsonConfig.GetProperty("allowTxtBlockingReport").GetBoolean();
_blockListZone = jsonConfig.ReadArrayAsMap("blocked", delegate (JsonElement jsonDomainName) { return new Tuple<string, object>(jsonDomainName.GetString(), null); });
return Task.CompletedTask;
}
public Task<DnsDatagram> ProcessRequestAsync(DnsDatagram request, IPEndPoint remoteEP, DnsTransportProtocol protocol, bool isRecursionAllowed)
{
if (!_enableBlocking)
return Task.FromResult<DnsDatagram>(null);
DnsQuestionRecord question = request.Question[0];
if (!IsZoneBlocked(question.Name, out string blockedDomain))