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"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
@ -72,9 +73,11 @@ func parseRawBlacklist(blacklist configBlacklist, raw string) []string {
|
|||||||
switch blacklist.Format {
|
switch blacklist.Format {
|
||||||
case "host":
|
case "host":
|
||||||
return parseHostFormat(raw)
|
return parseHostFormat(raw)
|
||||||
|
case "line":
|
||||||
|
return parseLineFormat(raw)
|
||||||
default:
|
default:
|
||||||
log.Printf("Failed to parse blacklist. Format not supported: %s", blacklist.Format)
|
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)
|
return make([]string, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,6 +95,18 @@ func parseHostFormat(raw string) []string {
|
|||||||
return finalList
|
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) {
|
func handleBlockedDomain(w dns.ResponseWriter, r *dns.Msg) {
|
||||||
q := r.Question[0]
|
q := r.Question[0]
|
||||||
|
|
||||||
|
@ -25,3 +25,5 @@ address: 0.0.0.0:8053
|
|||||||
blacklist:
|
blacklist:
|
||||||
- url: https://raw.githubusercontent.com/anudeepND/blacklist/master/adservers.txt
|
- url: https://raw.githubusercontent.com/anudeepND/blacklist/master/adservers.txt
|
||||||
format: host
|
format: host
|
||||||
|
- url: https://blocklistproject.github.io/Lists/alt-version/ads-nl.txt
|
||||||
|
format: line
|
||||||
|
Loading…
Reference in New Issue
Block a user