Allow disabling of filtering but keeping querylog, safebrowsing, safesearch and parental working.
This commit is contained in:
parent
50b188a086
commit
09a39cce03
|
@ -160,12 +160,12 @@ func writeAllConfigs() error {
|
|||
}
|
||||
|
||||
const coreDNSConfigTemplate = `. {
|
||||
{{if .FilteringEnabled}}dnsfilter {{.FilterFile}} {
|
||||
dnsfilter {{if .FilteringEnabled}}{{.FilterFile}}{{end}} {
|
||||
{{if .SafeBrowsingEnabled}}safebrowsing{{end}}
|
||||
{{if .ParentalEnabled}}parental {{.ParentalSensitivity}}{{end}}
|
||||
{{if .SafeSearchEnabled}}safesearch{{end}}
|
||||
{{if .QueryLogEnabled}}querylog{{end}}
|
||||
}{{end}}
|
||||
}
|
||||
{{.Pprof}}
|
||||
hosts {
|
||||
fallthrough
|
||||
|
|
|
@ -92,14 +92,12 @@ func setupPlugin(c *caddy.Controller) (*plug, error) {
|
|||
p.d = dnsfilter.New()
|
||||
p.hosts = make(map[string]net.IP)
|
||||
|
||||
var filterFileName string
|
||||
filterFileNames := []string{}
|
||||
for c.Next() {
|
||||
args := c.RemainingArgs()
|
||||
if len(args) == 0 {
|
||||
// must have at least one argument
|
||||
return nil, c.ArgErr()
|
||||
if len(args) > 0 {
|
||||
filterFileNames = append(filterFileNames, args...)
|
||||
}
|
||||
filterFileName = args[0]
|
||||
for c.NextBlock() {
|
||||
switch c.Val() {
|
||||
case "safebrowsing":
|
||||
|
@ -139,6 +137,9 @@ func setupPlugin(c *caddy.Controller) (*plug, error) {
|
|||
}
|
||||
}
|
||||
|
||||
log.Printf("filterFileNames = %+v", filterFileNames)
|
||||
|
||||
for i, filterFileName := range filterFileNames {
|
||||
file, err := os.Open(filterFileName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -152,7 +153,7 @@ func setupPlugin(c *caddy.Controller) (*plug, error) {
|
|||
if p.parseEtcHosts(text) {
|
||||
continue
|
||||
}
|
||||
err = p.d.AddRule(text, 0)
|
||||
err = p.d.AddRule(text, uint32(i))
|
||||
if err == dnsfilter.ErrInvalidSyntax {
|
||||
continue
|
||||
}
|
||||
|
@ -166,7 +167,9 @@ func setupPlugin(c *caddy.Controller) (*plug, error) {
|
|||
if err = scanner.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
var err error
|
||||
p.upstream, err = upstream.New(nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -20,7 +20,8 @@ func TestSetup(t *testing.T) {
|
|||
config string
|
||||
failing bool
|
||||
}{
|
||||
{`dnsfilter`, true},
|
||||
{`dnsfilter`, false},
|
||||
{`dnsfilter /dev/nonexistent/abcdef`, true},
|
||||
{`dnsfilter ../tests/dns.txt`, false},
|
||||
{`dnsfilter ../tests/dns.txt { safebrowsing }`, false},
|
||||
{`dnsfilter ../tests/dns.txt { parental }`, true},
|
||||
|
|
Loading…
Reference in New Issue