Skip to content

Commit

Permalink
Fix #727 - use default parental sensitivity when it's not set
Browse files Browse the repository at this point in the history
  • Loading branch information
ameshkov committed Jun 6, 2019
1 parent f9807e4 commit 07db927
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
8 changes: 4 additions & 4 deletions clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ func clientExists(ip string) bool {
}

// Search for a client by IP
func clientFind(ip string) (Client, bool) {
func clientFind(ip string) (*Client, bool) {
clients.lock.Lock()
defer clients.lock.Unlock()

c, ok := clients.ipIndex[ip]
if ok {
return *c, true
return c, true
}

for _, c = range clients.list {
Expand All @@ -109,12 +109,12 @@ func clientFind(ip string) (Client, bool) {
continue
}
if ip == ipAddr.String() {
return *c, true
return c, true
}
}
}

return Client{}, false
return nil, false
}

// Check if Client object's fields are correct
Expand Down
4 changes: 2 additions & 2 deletions dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,15 @@ func generateServerConfig() dnsforward.ServerConfig {
// If a client has his own settings, apply them
func applyClientSettings(clientAddr string, setts *dnsfilter.RequestFilteringSettings) {
c, ok := clientFind(clientAddr)
if !ok || !c.UseOwnSettings {
if !ok || c == nil || !c.UseOwnSettings {
return
}

log.Debug("Using settings for client with IP %s", clientAddr)
setts.FilteringEnabled = c.FilteringEnabled
setts.SafeSearchEnabled = c.SafeSearchEnabled
setts.SafeBrowsingEnabled = c.SafeBrowsingEnabled
setts.ParentalEnabled = c.UseOwnSettings
setts.ParentalEnabled = c.ParentalEnabled
}

func startDNSServer() error {
Expand Down
9 changes: 7 additions & 2 deletions dnsfilter/dnsfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const defaultSafebrowsingServer = "sb.adtidy.org"
const defaultSafebrowsingURL = "%s://%s/safebrowsing-lookup-hash.html?prefixes=%s"
const defaultParentalServer = "pctrl.adguard.com"
const defaultParentalURL = "%s://%s/check-parental-control-hash?prefixes=%s&sensitivity=%d"
const maxDialCacheSize = 2 // the number of host names for safebrowsing and parental control
const defaultParentalSensitivity = 13 // use "TEEN" by default
const maxDialCacheSize = 2 // the number of host names for safebrowsing and parental control

// Custom filtering settings
type RequestFilteringSettings struct {
Expand Down Expand Up @@ -410,7 +411,11 @@ func (d *Dnsfilter) checkParental(host string) (Result, error) {
if d.UsePlainHTTP {
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
}
handleBody := func(body []byte, hashes map[string]bool) (Result, error) {
Expand Down
2 changes: 1 addition & 1 deletion dnsforward/querylog.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (l *queryLog) logRequest(question *dns.Msg, answer *dns.Msg, result *dnsfil
if needFlush {
// write to file
// do it in separate goroutine -- we are stalling DNS response this whole time
go l.flushLogBuffer(false)
go l.flushLogBuffer(false) // nolint
}

return &entry
Expand Down

0 comments on commit 07db927

Please sign in to comment.