Fix #727 - use default parental sensitivity when it's not set

This commit is contained in:
Andrey Meshkov 2019-06-06 22:42:17 +03:00
parent f9807e4011
commit 07db927246
4 changed files with 14 additions and 9 deletions

View File

@ -89,13 +89,13 @@ func clientExists(ip string) bool {
} }
// Search for a client by IP // Search for a client by IP
func clientFind(ip string) (Client, bool) { func clientFind(ip string) (*Client, bool) {
clients.lock.Lock() clients.lock.Lock()
defer clients.lock.Unlock() defer clients.lock.Unlock()
c, ok := clients.ipIndex[ip] c, ok := clients.ipIndex[ip]
if ok { if ok {
return *c, true return c, true
} }
for _, c = range clients.list { for _, c = range clients.list {
@ -109,12 +109,12 @@ func clientFind(ip string) (Client, bool) {
continue continue
} }
if ip == ipAddr.String() { if ip == ipAddr.String() {
return *c, true return c, true
} }
} }
} }
return Client{}, false return nil, false
} }
// Check if Client object's fields are correct // Check if Client object's fields are correct

4
dns.go
View File

@ -216,7 +216,7 @@ func generateServerConfig() dnsforward.ServerConfig {
// If a client has his own settings, apply them // If a client has his own settings, apply them
func applyClientSettings(clientAddr string, setts *dnsfilter.RequestFilteringSettings) { func applyClientSettings(clientAddr string, setts *dnsfilter.RequestFilteringSettings) {
c, ok := clientFind(clientAddr) c, ok := clientFind(clientAddr)
if !ok || !c.UseOwnSettings { if !ok || c == nil || !c.UseOwnSettings {
return return
} }
@ -224,7 +224,7 @@ func applyClientSettings(clientAddr string, setts *dnsfilter.RequestFilteringSet
setts.FilteringEnabled = c.FilteringEnabled setts.FilteringEnabled = c.FilteringEnabled
setts.SafeSearchEnabled = c.SafeSearchEnabled setts.SafeSearchEnabled = c.SafeSearchEnabled
setts.SafeBrowsingEnabled = c.SafeBrowsingEnabled setts.SafeBrowsingEnabled = c.SafeBrowsingEnabled
setts.ParentalEnabled = c.UseOwnSettings setts.ParentalEnabled = c.ParentalEnabled
} }
func startDNSServer() error { func startDNSServer() error {

View File

@ -33,6 +33,7 @@ const defaultSafebrowsingServer = "sb.adtidy.org"
const defaultSafebrowsingURL = "%s://%s/safebrowsing-lookup-hash.html?prefixes=%s" const defaultSafebrowsingURL = "%s://%s/safebrowsing-lookup-hash.html?prefixes=%s"
const defaultParentalServer = "pctrl.adguard.com" const defaultParentalServer = "pctrl.adguard.com"
const defaultParentalURL = "%s://%s/check-parental-control-hash?prefixes=%s&sensitivity=%d" const defaultParentalURL = "%s://%s/check-parental-control-hash?prefixes=%s&sensitivity=%d"
const defaultParentalSensitivity = 13 // use "TEEN" by default
const maxDialCacheSize = 2 // the number of host names for safebrowsing and parental control const maxDialCacheSize = 2 // the number of host names for safebrowsing and parental control
// Custom filtering settings // Custom filtering settings
@ -410,7 +411,11 @@ func (d *Dnsfilter) checkParental(host string) (Result, error) {
if d.UsePlainHTTP { if d.UsePlainHTTP {
schema = "http" schema = "http"
} }
url := fmt.Sprintf(defaultParentalURL, schema, d.parentalServer, hashparam, d.ParentalSensitivity) sensitivity := d.ParentalSensitivity
if sensitivity == 0 {
sensitivity = defaultParentalSensitivity
}
url := fmt.Sprintf(defaultParentalURL, schema, d.parentalServer, hashparam, sensitivity)
return url return url
} }
handleBody := func(body []byte, hashes map[string]bool) (Result, error) { handleBody := func(body []byte, hashes map[string]bool) (Result, error) {

View File

@ -123,7 +123,7 @@ func (l *queryLog) logRequest(question *dns.Msg, answer *dns.Msg, result *dnsfil
if needFlush { if needFlush {
// write to file // write to file
// do it in separate goroutine -- we are stalling DNS response this whole time // do it in separate goroutine -- we are stalling DNS response this whole time
go l.flushLogBuffer(false) go l.flushLogBuffer(false) // nolint
} }
return &entry return &entry