some library updates and adds support for adblock lists

This commit is contained in:
2025-05-02 20:57:03 -05:00
parent 03b1cc13ee
commit ce4b4a11ff
19 changed files with 712 additions and 139 deletions

View File

@@ -3,6 +3,8 @@ package main
import (
"regexp"
"sort"
"gitlab.smoothnet.org/nhyatt/bind-response-policy-zone-creator/internal/log"
)
func cleanBadDomains(domains []string) []string {
@@ -17,7 +19,7 @@ func cleanBadDomains(domains []string) []string {
}
}
domains = list
cfg.Log.Info("hosts removed from blocklist", "reason", "duplicate", "hosts", total-len(domains))
log.Info("hosts removed from blocklist", "reason", "duplicate", "hosts", total-len(domains))
// remove hosts that are too long
total = len(domains)
@@ -29,7 +31,7 @@ func cleanBadDomains(domains []string) []string {
list = append(list, blocklistItem)
}
domains = list
cfg.Log.Info("hosts removed from blocklist", "reason", "too many characters", "hosts", total-len(domains))
log.Info("hosts removed from blocklist", "reason", "too many characters", "hosts", total-len(domains))
// remove allow-listed matches
total = len(domains)
@@ -39,7 +41,7 @@ func cleanBadDomains(domains []string) []string {
for _, allowedItem := range cfg.ConfigFile.AllowLists {
_, err := regexp.Compile(allowedItem)
if err != nil {
cfg.Log.Error("unable to parse allow list item", "error", err, "regex", allowedItem)
log.Error("unable to parse allow list item", "error", err, "regex", allowedItem)
continue
}
goodAllowedItemList = append(goodAllowedItemList, allowedItem)
@@ -50,7 +52,7 @@ func cleanBadDomains(domains []string) []string {
addEntry := true
for _, allowedItem := range goodAllowedItemList {
if regexp.MustCompile(allowedItem).MatchString(v) {
cfg.Log.Debug("hosts removed from blocklist", "reason", "allowed host", "match string", allowedItem, "host", v)
log.Debug("hosts removed from blocklist", "reason", "allowed host", "match string", allowedItem, "host", v)
addEntry = false
}
}
@@ -59,9 +61,9 @@ func cleanBadDomains(domains []string) []string {
}
}
domains = list
cfg.Log.Info("hosts removed from blocklist", "hosts", total-len(domains))
log.Info("hosts removed from blocklist", "hosts", total-len(domains))
cfg.Log.Info("total domains in list", "hosts", len(domains))
log.Info("total domains in list", "hosts", len(domains))
sort.Strings(domains)
return domains
}