added blacklist line parser
This commit is contained in:
parent
87d9dca1ce
commit
7b412e404c
17
blacklist.go
17
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]
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user