Merge: * dnsfilter: parental/safebrowsing: add setting to switch between HTTP and HTTPS #646

* commit 'f23507a5546229d8ce8f69d56667cd5212f026d3':
  * dnsfilter: parental/safebrowsing: add setting to switch between HTTP and HTTPS
This commit is contained in:
Simon Zolin 2019-05-28 11:31:51 +03:00
commit 4df8868787
1 changed files with 13 additions and 4 deletions

View File

@ -30,9 +30,9 @@ const defaultHTTPTimeout = 5 * time.Minute
const defaultHTTPMaxIdleConnections = 100 const defaultHTTPMaxIdleConnections = 100
const defaultSafebrowsingServer = "sb.adtidy.org" const defaultSafebrowsingServer = "sb.adtidy.org"
const defaultSafebrowsingURL = "https://%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 = "https://%s/check-parental-control-hash?prefixes=%s&sensitivity=%d" 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 maxDialCacheSize = 2 // the number of host names for safebrowsing and parental control
// ErrInvalidSyntax is returned by AddRule when the rule is invalid // ErrInvalidSyntax is returned by AddRule when the rule is invalid
@ -51,6 +51,7 @@ type Config struct {
FilteringTempFilename string `yaml:"filtering_temp_filename"` // temporary file for storing unused filtering rules FilteringTempFilename string `yaml:"filtering_temp_filename"` // temporary file for storing unused filtering rules
ParentalSensitivity int `yaml:"parental_sensitivity"` // must be either 3, 10, 13 or 17 ParentalSensitivity int `yaml:"parental_sensitivity"` // must be either 3, 10, 13 or 17
ParentalEnabled bool `yaml:"parental_enabled"` ParentalEnabled bool `yaml:"parental_enabled"`
UsePlainHTTP bool `yaml:"-"` // use plain HTTP for requests to parental and safe browsing servers
SafeSearchEnabled bool `yaml:"safesearch_enabled"` SafeSearchEnabled bool `yaml:"safesearch_enabled"`
SafeBrowsingEnabled bool `yaml:"safebrowsing_enabled"` SafeBrowsingEnabled bool `yaml:"safebrowsing_enabled"`
ResolverAddress string // DNS server address ResolverAddress string // DNS server address
@ -346,7 +347,11 @@ func (d *Dnsfilter) checkSafeBrowsing(host string) (Result, error) {
} }
format := func(hashparam string) string { format := func(hashparam string) string {
url := fmt.Sprintf(defaultSafebrowsingURL, d.safeBrowsingServer, hashparam) schema := "https"
if d.UsePlainHTTP {
schema = "http"
}
url := fmt.Sprintf(defaultSafebrowsingURL, schema, d.safeBrowsingServer, hashparam)
return url return url
} }
handleBody := func(body []byte, hashes map[string]bool) (Result, error) { handleBody := func(body []byte, hashes map[string]bool) (Result, error) {
@ -388,7 +393,11 @@ func (d *Dnsfilter) checkParental(host string) (Result, error) {
} }
format := func(hashparam string) string { format := func(hashparam string) string {
url := fmt.Sprintf(defaultParentalURL, d.parentalServer, hashparam, d.ParentalSensitivity) schema := "https"
if d.UsePlainHTTP {
schema = "http"
}
url := fmt.Sprintf(defaultParentalURL, schema, d.parentalServer, hashparam, d.ParentalSensitivity)
return url return url
} }
handleBody := func(body []byte, hashes map[string]bool) (Result, error) { handleBody := func(body []byte, hashes map[string]bool) (Result, error) {