Merge pull request #37 in DNS/adguard-dns from bugfix/333 to master

* commit '09a39cce03f69b1f9801e66d763d7b5208411336':
  Allow disabling of filtering but keeping querylog, safebrowsing, safesearch and parental working.
  Makefile -- make it a bit less noisy during build and much less noisy during clean
This commit is contained in:
Eugene Bujak 2018-09-25 19:44:07 +03:00
commit 6a53dd0f00
4 changed files with 39 additions and 37 deletions

View file

@ -19,7 +19,6 @@ $(STATIC): client/node_modules
npm --prefix client run build-prod npm --prefix client run build-prod
AdguardDNS: $(STATIC) *.go AdguardDNS: $(STATIC) *.go
echo mkfile_dir = $(mkfile_dir)
mkdir -p $(GOPATH) mkdir -p $(GOPATH)
GOPATH=$(GOPATH) go get -v -d . GOPATH=$(GOPATH) go get -v -d .
GOPATH=$(GOPATH) go get -v -d -u github.com/AdguardTeam/AdguardDNS GOPATH=$(GOPATH) go get -v -d -u github.com/AdguardTeam/AdguardDNS
@ -28,7 +27,6 @@ AdguardDNS: $(STATIC) *.go
GOPATH=$(GOPATH) PATH=$(GOPATH)/bin:$(PATH) packr build -ldflags="-X main.VersionString=$(GIT_VERSION)" -o AdguardDNS GOPATH=$(GOPATH) PATH=$(GOPATH)/bin:$(PATH) packr build -ldflags="-X main.VersionString=$(GIT_VERSION)" -o AdguardDNS
coredns: coredns_plugin/*.go dnsfilter/*.go coredns: coredns_plugin/*.go dnsfilter/*.go
echo mkfile_dir = $(mkfile_dir)
GOPATH=$(GOPATH) go get -v -d github.com/coredns/coredns GOPATH=$(GOPATH) go get -v -d github.com/coredns/coredns
cd $(GOPATH)/src/github.com/prometheus/client_golang && git checkout -q v0.8.0 cd $(GOPATH)/src/github.com/prometheus/client_golang && git checkout -q v0.8.0
cd $(GOPATH)/src/github.com/coredns/coredns && perl -p -i.bak -e 's/^(trace|route53|federation|kubernetes|etcd):.*//' plugin.cfg cd $(GOPATH)/src/github.com/coredns/coredns && perl -p -i.bak -e 's/^(trace|route53|federation|kubernetes|etcd):.*//' plugin.cfg
@ -40,8 +38,8 @@ coredns: coredns_plugin/*.go dnsfilter/*.go
clean: clean:
$(MAKE) cleanfast $(MAKE) cleanfast
rm -rvf build rm -rf build
rm -rvf client/node_modules rm -rf client/node_modules
cleanfast: cleanfast:
rm -vf coredns AdguardDNS rm -f coredns AdguardDNS

View file

@ -160,16 +160,16 @@ func writeAllConfigs() error {
} }
const coreDNSConfigTemplate = `. { const coreDNSConfigTemplate = `. {
{{if .FilteringEnabled}}dnsfilter {{.FilterFile}} { dnsfilter {{if .FilteringEnabled}}{{.FilterFile}}{{end}} {
{{if .SafeBrowsingEnabled}}safebrowsing{{end}} {{if .SafeBrowsingEnabled}}safebrowsing{{end}}
{{if .ParentalEnabled}}parental {{.ParentalSensitivity}}{{end}} {{if .ParentalEnabled}}parental {{.ParentalSensitivity}}{{end}}
{{if .SafeSearchEnabled}}safesearch{{end}} {{if .SafeSearchEnabled}}safesearch{{end}}
{{if .QueryLogEnabled}}querylog{{end}} {{if .QueryLogEnabled}}querylog{{end}}
}{{end}} }
{{.Pprof}} {{.Pprof}}
hosts { hosts {
fallthrough fallthrough
} }
{{if .UpstreamDNS}}forward . {{range .UpstreamDNS}}{{.}} {{end}}{{end}} {{if .UpstreamDNS}}forward . {{range .UpstreamDNS}}{{.}} {{end}}{{end}}
{{.Cache}} {{.Cache}}
{{.Prometheus}} {{.Prometheus}}

View file

@ -92,14 +92,12 @@ func setupPlugin(c *caddy.Controller) (*plug, error) {
p.d = dnsfilter.New() p.d = dnsfilter.New()
p.hosts = make(map[string]net.IP) p.hosts = make(map[string]net.IP)
var filterFileName string filterFileNames := []string{}
for c.Next() { for c.Next() {
args := c.RemainingArgs() args := c.RemainingArgs()
if len(args) == 0 { if len(args) > 0 {
// must have at least one argument filterFileNames = append(filterFileNames, args...)
return nil, c.ArgErr()
} }
filterFileName = args[0]
for c.NextBlock() { for c.NextBlock() {
switch c.Val() { switch c.Val() {
case "safebrowsing": case "safebrowsing":
@ -139,34 +137,39 @@ func setupPlugin(c *caddy.Controller) (*plug, error) {
} }
} }
file, err := os.Open(filterFileName) log.Printf("filterFileNames = %+v", filterFileNames)
if err != nil {
return nil, err
}
defer file.Close()
count := 0 for i, filterFileName := range filterFileNames {
scanner := bufio.NewScanner(file) file, err := os.Open(filterFileName)
for scanner.Scan() {
text := scanner.Text()
if p.parseEtcHosts(text) {
continue
}
err = p.d.AddRule(text, 0)
if err == dnsfilter.ErrInvalidSyntax {
continue
}
if err != nil { if err != nil {
return nil, err return nil, err
} }
count++ defer file.Close()
}
log.Printf("Added %d rules from %s", count, filterFileName)
if err = scanner.Err(); err != nil { count := 0
return nil, err scanner := bufio.NewScanner(file)
for scanner.Scan() {
text := scanner.Text()
if p.parseEtcHosts(text) {
continue
}
err = p.d.AddRule(text, uint32(i))
if err == dnsfilter.ErrInvalidSyntax {
continue
}
if err != nil {
return nil, err
}
count++
}
log.Printf("Added %d rules from %s", count, filterFileName)
if err = scanner.Err(); err != nil {
return nil, err
}
} }
var err error
p.upstream, err = upstream.New(nil) p.upstream, err = upstream.New(nil)
if err != nil { if err != nil {
return nil, err return nil, err

View file

@ -20,7 +20,8 @@ func TestSetup(t *testing.T) {
config string config string
failing bool failing bool
}{ }{
{`dnsfilter`, true}, {`dnsfilter`, false},
{`dnsfilter /dev/nonexistent/abcdef`, true},
{`dnsfilter ../tests/dns.txt`, false}, {`dnsfilter ../tests/dns.txt`, false},
{`dnsfilter ../tests/dns.txt { safebrowsing }`, false}, {`dnsfilter ../tests/dns.txt { safebrowsing }`, false},
{`dnsfilter ../tests/dns.txt { parental }`, true}, {`dnsfilter ../tests/dns.txt { parental }`, true},