Allow disabling of filtering but keeping querylog, safebrowsing, safesearch and parental working.
This commit is contained in:
parent
50b188a086
commit
09a39cce03
10
config.go
10
config.go
|
@ -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}}
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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},
|
||||||
|
|
Loading…
Reference in New Issue