mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-12-14 18:51:34 +03:00
6363f8a2e7
Squashed commit of the following: commit1909dfed99
Merge:3856fda5f
2c64ab5a5
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Oct 9 16:21:38 2024 +0300 Merge branch 'master' into AGDNS-2374-slog-safesearch commit3856fda5f3
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Oct 8 20:04:34 2024 +0300 home: imp code commitde774009aa
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Oct 7 16:41:58 2024 +0300 all: imp code commit038bae59d5
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Oct 3 20:24:48 2024 +0300 all: imp code commit792975e248
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Oct 3 15:46:40 2024 +0300 all: slog safesearch
55 lines
1.8 KiB
Go
55 lines
1.8 KiB
Go
package filtering
|
|
|
|
import "context"
|
|
|
|
// 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(ctx context.Context, 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(ctx context.Context, 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
|
|
}
|
|
|
|
// TODO(s.chzhen): Pass context.
|
|
ctx := context.TODO()
|
|
|
|
clientSafeSearch := setts.ClientSafeSearch
|
|
if clientSafeSearch != nil {
|
|
return clientSafeSearch.CheckHost(ctx, host, qtype)
|
|
}
|
|
|
|
return d.safeSearch.CheckHost(ctx, host, qtype)
|
|
}
|