Squashed commit of the following:
commit 787b5d40394889510c24f4abc3a08410ecc96e5e
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date: Wed Jul 31 15:09:18 2024 +0300
configmigrate: revert
commit a036638c05967298d13ef435dc5b377103cfe163
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date: Wed Jul 31 09:37:25 2024 +0300
docs
commit a3b2e8de4bab7214dd6b260655bba9f45eee6bd2
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date: Wed Jul 31 09:18:25 2024 +0300
locales
commit a01a22019ef02ae77e9006dd9444da462419908f
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date: Wed Jul 31 09:02:14 2024 +0300
filtering: imp code
commit bc268cdd526c82cb605b1a474d51b79f593cd3da
Merge: 5ad88d914 bc6d20ff1
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date: Wed Jul 31 08:00:05 2024 +0300
Merge remote-tracking branch 'origin/master' into 5009-ecosia-safesearch
commit 5ad88d914cf9b03f399efd481ae39ebd56243e66
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date: Tue Jul 30 13:49:51 2024 +0300
all: ecosia safesearch
50 lines
1.7 KiB
Go
50 lines
1.7 KiB
Go
package filtering
|
|
|
|
// SafeSearch interface describes a service for search engines hosts rewrites.
|
|
type SafeSearch interface {
|
|
// CheckHost checks host with safe search filter. CheckHost must be safe
|
|
// for concurrent use. qtype must be either [dns.TypeA] or [dns.TypeAAAA].
|
|
CheckHost(host string, qtype uint16) (res Result, err error)
|
|
|
|
// Update updates the configuration of the safe search filter. Update must
|
|
// be safe for concurrent use. An implementation of Update may ignore some
|
|
// fields, but it must document which.
|
|
Update(conf SafeSearchConfig) (err error)
|
|
}
|
|
|
|
// SafeSearchConfig is a struct with safe search related settings.
|
|
type SafeSearchConfig struct {
|
|
// Enabled indicates if safe search is enabled entirely.
|
|
Enabled bool `yaml:"enabled" json:"enabled"`
|
|
|
|
// Services flags. Each flag indicates if the corresponding service is
|
|
// enabled or disabled.
|
|
|
|
Bing bool `yaml:"bing" json:"bing"`
|
|
DuckDuckGo bool `yaml:"duckduckgo" json:"duckduckgo"`
|
|
Ecosia bool `yaml:"ecosia" json:"ecosia"`
|
|
Google bool `yaml:"google" json:"google"`
|
|
Pixabay bool `yaml:"pixabay" json:"pixabay"`
|
|
Yandex bool `yaml:"yandex" json:"yandex"`
|
|
YouTube bool `yaml:"youtube" json:"youtube"`
|
|
}
|
|
|
|
// checkSafeSearch checks host with safe search engine. Matches
|
|
// [hostChecker.check].
|
|
func (d *DNSFilter) checkSafeSearch(
|
|
host string,
|
|
qtype uint16,
|
|
setts *Settings,
|
|
) (res Result, err error) {
|
|
if d.safeSearch == nil || !setts.ProtectionEnabled || !setts.SafeSearchEnabled {
|
|
return Result{}, nil
|
|
}
|
|
|
|
clientSafeSearch := setts.ClientSafeSearch
|
|
if clientSafeSearch != nil {
|
|
return clientSafeSearch.CheckHost(host, qtype)
|
|
}
|
|
|
|
return d.safeSearch.CheckHost(host, qtype)
|
|
}
|