From 7b412e404c4f3845d81ac8ed32eec2600f2904e3 Mon Sep 17 00:00:00 2001 From: Niklas Date: Wed, 30 Dec 2020 14:14:52 +0100 Subject: [PATCH] added blacklist line parser --- blacklist.go | 17 ++++++++++++++++- config.yml | 2 ++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/blacklist.go b/blacklist.go index 00ace93..9a68ac0 100644 --- a/blacklist.go +++ b/blacklist.go @@ -7,6 +7,7 @@ import ( "net" "net/http" "regexp" + "strings" "github.com/miekg/dns" ) @@ -72,9 +73,11 @@ func parseRawBlacklist(blacklist configBlacklist, raw string) []string { switch blacklist.Format { case "host": return parseHostFormat(raw) + case "line": + return parseLineFormat(raw) default: log.Printf("Failed to parse blacklist. Format not supported: %s", blacklist.Format) - log.Println("Supported types are: host") + log.Println("Supported types are: host, line") return make([]string, 0) } } @@ -92,6 +95,18 @@ func parseHostFormat(raw string) []string { return finalList } +func parseLineFormat(raw string) []string { + list := make([]string, 0) + + for _, line := range strings.Split(raw, "\n") { + if !strings.HasPrefix(line, "#") { + list = append(list, line) + } + } + + return list +} + func handleBlockedDomain(w dns.ResponseWriter, r *dns.Msg) { q := r.Question[0] diff --git a/config.yml b/config.yml index 144b94b..4603328 100644 --- a/config.yml +++ b/config.yml @@ -25,3 +25,5 @@ address: 0.0.0.0:8053 blacklist: - url: https://raw.githubusercontent.com/anudeepND/blacklist/master/adservers.txt format: host + - url: https://blocklistproject.github.io/Lists/alt-version/ads-nl.txt + format: line