mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2026-12-06 15:11:29 +09:00
AGH-232 Rm-deprecated-vol-2 (76)
* all: rm part of deprecated apis and behaviors * all: rm deprecated ups mode, querylog, filter apis * client_v2: rm more * client_v2: rm unused files * dnsforward: imp api * doc: rm img
This commit is contained in:
1 parent
8636119e45
commit
d4eedec229
18 files changed
+179
-442
No files matched your search
@@ -77,6 +77,7 @@ type Config struct {
|
||||
FallbackDNS []string `yaml:"fallback_dns"`
|
||||
|
||||
// UpstreamMode determines the logic through which upstreams will be used.
|
||||
// It must be valid.
|
||||
UpstreamMode proxy.UpstreamMode `yaml:"upstream_mode"`
|
||||
|
||||
// FastestTimeout replaces the default timeout for dialing IP addresses
|
||||
|
||||
@@ -207,7 +207,10 @@ type DNSCreateParams struct {
|
||||
PrivateNets netutil.SubnetSet
|
||||
|
||||
Anonymizer *aghnet.IPMut
|
||||
EtcHosts *aghnet.HostsContainer
|
||||
|
||||
// EtcHosts, if not nil, is used along with the bootstrap addresses to
|
||||
// initialize upstream configuration.
|
||||
EtcHosts *aghnet.HostsContainer
|
||||
|
||||
// TLSManager provides a TLS configuration for the server. It must
|
||||
// not be nil.
|
||||
|
||||
@@ -131,12 +131,6 @@ type jsonDNSConfig struct {
|
||||
type jsonUpstreamMode string
|
||||
|
||||
const (
|
||||
// jsonUpstreamModeEmpty is the default value on frontend, it is used as
|
||||
// jsonUpstreamModeLoadBalance mode.
|
||||
//
|
||||
// Deprecated: Use jsonUpstreamModeLoadBalance instead.
|
||||
jsonUpstreamModeEmpty jsonUpstreamMode = ""
|
||||
|
||||
jsonUpstreamModeLoadBalance jsonUpstreamMode = "load_balance"
|
||||
jsonUpstreamModeParallel jsonUpstreamMode = "parallel"
|
||||
jsonUpstreamModeFastestAddr jsonUpstreamMode = "fastest_addr"
|
||||
@@ -176,15 +170,18 @@ func (s *Server) getDNSConfig(ctx context.Context) (c *jsonDNSConfig) {
|
||||
localPTRUpstreams := stringutil.CloneSliceOrEmpty(s.conf.LocalPTRResolvers)
|
||||
|
||||
var upstreamMode jsonUpstreamMode
|
||||
switch s.conf.UpstreamMode {
|
||||
switch m := s.conf.UpstreamMode; m {
|
||||
case proxy.UpstreamModeLoadBalance:
|
||||
// TODO(d.kolyshev): Support jsonUpstreamModeLoadBalance on frontend
|
||||
// instead of jsonUpstreamModeEmpty.
|
||||
upstreamMode = jsonUpstreamModeEmpty
|
||||
upstreamMode = jsonUpstreamModeLoadBalance
|
||||
case proxy.UpstreamModeParallel:
|
||||
upstreamMode = jsonUpstreamModeParallel
|
||||
case proxy.UpstreamModeFastestAddr:
|
||||
upstreamMode = jsonUpstreamModeFastestAddr
|
||||
default:
|
||||
// TODO(a.garipov): Remove or replace with a panic once the
|
||||
// configuration file is properly validated.
|
||||
s.logger.WarnContext(ctx, "bad upstream mode; using load balance", "mode", m)
|
||||
upstreamMode = jsonUpstreamModeLoadBalance
|
||||
}
|
||||
|
||||
defPTRUps, err := s.defaultLocalPTRUpstreams(ctx)
|
||||
@@ -269,7 +266,6 @@ func (req *jsonDNSConfig) checkUpstreamMode() (err error) {
|
||||
|
||||
switch um := *req.UpstreamMode; um {
|
||||
case
|
||||
jsonUpstreamModeEmpty,
|
||||
jsonUpstreamModeLoadBalance,
|
||||
jsonUpstreamModeParallel,
|
||||
jsonUpstreamModeFastestAddr:
|
||||
@@ -620,7 +616,7 @@ func (s *Server) setConfig(dc *jsonDNSConfig) (shouldRestart bool) {
|
||||
// Panics in case of invalid value.
|
||||
func mustParseUpstreamMode(mode jsonUpstreamMode) (um proxy.UpstreamMode) {
|
||||
switch mode {
|
||||
case jsonUpstreamModeEmpty, jsonUpstreamModeLoadBalance:
|
||||
case jsonUpstreamModeLoadBalance:
|
||||
return proxy.UpstreamModeLoadBalance
|
||||
case jsonUpstreamModeParallel:
|
||||
return proxy.UpstreamModeParallel
|
||||
|
||||
@@ -40,10 +40,6 @@ var strToSVCBKey = map[string]dns.SVCBKey{
|
||||
"mandatory": dns.SVCB_MANDATORY,
|
||||
"no-default-alpn": dns.SVCB_NO_DEFAULT_ALPN,
|
||||
"port": dns.SVCB_PORT,
|
||||
|
||||
// TODO(a.garipov): This is the previous name for the parameter that has
|
||||
// since been changed. Remove this in v0.109.0.
|
||||
"echconfig": dns.SVCB_ECHCONFIG,
|
||||
}
|
||||
|
||||
// svcbKeyHandler is a handler for one SVCB parameter key. l must not be nil.
|
||||
@@ -130,27 +126,6 @@ var svcbKeyHandlers = map[string]svcbKeyHandler{
|
||||
}
|
||||
},
|
||||
|
||||
// TODO(a.garipov): This is the previous name for the parameter that has
|
||||
// since been changed. Remove this in v0.109.0.
|
||||
"echconfig": func(ctx context.Context, l *slog.Logger, valStr string) (val dns.SVCBKeyValue) {
|
||||
l.WarnContext(
|
||||
ctx,
|
||||
`svcb/https record parameter name "echconfig" is deprecated; `+
|
||||
`use "ech" instead`,
|
||||
)
|
||||
|
||||
ech, err := base64.StdEncoding.DecodeString(valStr)
|
||||
if err != nil {
|
||||
l.DebugContext(ctx, "can't parse svcb/https ech; ignoring", slogutil.KeyError, err)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
return &dns.SVCBECHConfig{
|
||||
ECH: ech,
|
||||
}
|
||||
},
|
||||
|
||||
"dohpath": func(_ context.Context, _ *slog.Logger, valStr string) (val dns.SVCBKeyValue) {
|
||||
return &dns.SVCBDoHPath{
|
||||
Template: valStr,
|
||||
|
||||
@@ -101,14 +101,6 @@ func TestGenAnswerHTTPS_andSVCB(t *testing.T) {
|
||||
svcb: dnssvcb("ech", "AAAA"),
|
||||
want: wantsvcb(&dns.SVCBECHConfig{ECH: []byte{0, 0, 0}}),
|
||||
name: "ech",
|
||||
}, {
|
||||
svcb: dnssvcb("echconfig", "AAAA"),
|
||||
want: wantsvcb(&dns.SVCBECHConfig{ECH: []byte{0, 0, 0}}),
|
||||
name: "ech_deprecated",
|
||||
}, {
|
||||
svcb: dnssvcb("echconfig", "%BAD%"),
|
||||
want: wantsvcb(nil),
|
||||
name: "ech_invalid",
|
||||
}, {
|
||||
svcb: dnssvcb("ipv4hint", "127.0.0.1"),
|
||||
want: wantsvcb(&dns.SVCBIPv4Hint{Hint: []net.IP{ip4}}),
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
"edns_cs_enabled": false,
|
||||
"dnssec_enabled": false,
|
||||
"disable_ipv6": false,
|
||||
"upstream_mode": "",
|
||||
"upstream_mode": "load_balance",
|
||||
"cache_size": 0,
|
||||
"cache_ttl_min": 0,
|
||||
"cache_ttl_max": 0,
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
"edns_cs_enabled": false,
|
||||
"dnssec_enabled": false,
|
||||
"disable_ipv6": false,
|
||||
"upstream_mode": "",
|
||||
"upstream_mode": "load_balance",
|
||||
"cache_size": 0,
|
||||
"cache_ttl_min": 0,
|
||||
"cache_ttl_max": 0,
|
||||
@@ -76,7 +76,7 @@
|
||||
"edns_cs_enabled": false,
|
||||
"dnssec_enabled": false,
|
||||
"disable_ipv6": false,
|
||||
"upstream_mode": "",
|
||||
"upstream_mode": "load_balance",
|
||||
"cache_size": 0,
|
||||
"cache_ttl_min": 0,
|
||||
"cache_ttl_max": 0,
|
||||
@@ -120,7 +120,7 @@
|
||||
"edns_cs_enabled": false,
|
||||
"dnssec_enabled": false,
|
||||
"disable_ipv6": false,
|
||||
"upstream_mode": "",
|
||||
"upstream_mode": "load_balance",
|
||||
"cache_size": 0,
|
||||
"cache_ttl_min": 0,
|
||||
"cache_ttl_max": 0,
|
||||
@@ -164,7 +164,7 @@
|
||||
"edns_cs_enabled": false,
|
||||
"dnssec_enabled": false,
|
||||
"disable_ipv6": false,
|
||||
"upstream_mode": "",
|
||||
"upstream_mode": "load_balance",
|
||||
"cache_size": 0,
|
||||
"cache_ttl_min": 0,
|
||||
"cache_ttl_max": 0,
|
||||
@@ -208,7 +208,7 @@
|
||||
"edns_cs_enabled": false,
|
||||
"dnssec_enabled": false,
|
||||
"disable_ipv6": false,
|
||||
"upstream_mode": "",
|
||||
"upstream_mode": "load_balance",
|
||||
"cache_size": 0,
|
||||
"cache_ttl_min": 0,
|
||||
"cache_ttl_max": 0,
|
||||
@@ -254,7 +254,7 @@
|
||||
"edns_cs_enabled": false,
|
||||
"dnssec_enabled": false,
|
||||
"disable_ipv6": false,
|
||||
"upstream_mode": "",
|
||||
"upstream_mode": "load_balance",
|
||||
"cache_size": 0,
|
||||
"cache_ttl_min": 0,
|
||||
"cache_ttl_max": 0,
|
||||
@@ -301,7 +301,7 @@
|
||||
"edns_cs_enabled": false,
|
||||
"dnssec_enabled": false,
|
||||
"disable_ipv6": false,
|
||||
"upstream_mode": "",
|
||||
"upstream_mode": "load_balance",
|
||||
"cache_size": 0,
|
||||
"cache_ttl_min": 0,
|
||||
"cache_ttl_max": 0,
|
||||
@@ -345,7 +345,7 @@
|
||||
"edns_cs_enabled": true,
|
||||
"dnssec_enabled": false,
|
||||
"disable_ipv6": false,
|
||||
"upstream_mode": "",
|
||||
"upstream_mode": "load_balance",
|
||||
"cache_size": 0,
|
||||
"cache_ttl_min": 0,
|
||||
"cache_ttl_max": 0,
|
||||
@@ -391,7 +391,7 @@
|
||||
"edns_cs_enabled": true,
|
||||
"dnssec_enabled": false,
|
||||
"disable_ipv6": false,
|
||||
"upstream_mode": "",
|
||||
"upstream_mode": "load_balance",
|
||||
"cache_size": 0,
|
||||
"cache_ttl_min": 0,
|
||||
"cache_ttl_max": 0,
|
||||
@@ -437,7 +437,7 @@
|
||||
"edns_cs_enabled": false,
|
||||
"dnssec_enabled": false,
|
||||
"disable_ipv6": false,
|
||||
"upstream_mode": "",
|
||||
"upstream_mode": "load_balance",
|
||||
"cache_size": 0,
|
||||
"cache_ttl_min": 0,
|
||||
"cache_ttl_max": 0,
|
||||
@@ -481,7 +481,7 @@
|
||||
"edns_cs_enabled": false,
|
||||
"dnssec_enabled": true,
|
||||
"disable_ipv6": false,
|
||||
"upstream_mode": "",
|
||||
"upstream_mode": "load_balance",
|
||||
"cache_size": 0,
|
||||
"cache_ttl_min": 0,
|
||||
"cache_ttl_max": 0,
|
||||
@@ -525,7 +525,7 @@
|
||||
"edns_cs_enabled": false,
|
||||
"dnssec_enabled": false,
|
||||
"disable_ipv6": false,
|
||||
"upstream_mode": "",
|
||||
"upstream_mode": "load_balance",
|
||||
"cache_size": 1024,
|
||||
"cache_ttl_min": 0,
|
||||
"cache_ttl_max": 0,
|
||||
@@ -570,7 +570,7 @@
|
||||
"edns_cs_enabled": false,
|
||||
"dnssec_enabled": false,
|
||||
"disable_ipv6": false,
|
||||
"upstream_mode": "",
|
||||
"upstream_mode": "load_balance",
|
||||
"cache_size": 1024,
|
||||
"cache_ttl_min": 0,
|
||||
"cache_ttl_max": 0,
|
||||
@@ -704,7 +704,7 @@
|
||||
"edns_cs_enabled": false,
|
||||
"dnssec_enabled": false,
|
||||
"disable_ipv6": false,
|
||||
"upstream_mode": "",
|
||||
"upstream_mode": "load_balance",
|
||||
"cache_size": 0,
|
||||
"cache_ttl_min": 0,
|
||||
"cache_ttl_max": 0,
|
||||
@@ -750,7 +750,7 @@
|
||||
"edns_cs_enabled": false,
|
||||
"dnssec_enabled": false,
|
||||
"disable_ipv6": false,
|
||||
"upstream_mode": "",
|
||||
"upstream_mode": "load_balance",
|
||||
"cache_size": 0,
|
||||
"cache_ttl_min": 0,
|
||||
"cache_ttl_max": 0,
|
||||
@@ -795,7 +795,7 @@
|
||||
"edns_cs_enabled": false,
|
||||
"dnssec_enabled": false,
|
||||
"disable_ipv6": false,
|
||||
"upstream_mode": "",
|
||||
"upstream_mode": "load_balance",
|
||||
"cache_size": 0,
|
||||
"cache_ttl_min": 0,
|
||||
"cache_ttl_max": 0,
|
||||
@@ -839,7 +839,7 @@
|
||||
"edns_cs_enabled": false,
|
||||
"dnssec_enabled": false,
|
||||
"disable_ipv6": false,
|
||||
"upstream_mode": "",
|
||||
"upstream_mode": "load_balance",
|
||||
"cache_size": 0,
|
||||
"cache_ttl_min": 0,
|
||||
"cache_ttl_max": 0,
|
||||
@@ -885,7 +885,7 @@
|
||||
"edns_cs_enabled": false,
|
||||
"dnssec_enabled": false,
|
||||
"disable_ipv6": false,
|
||||
"upstream_mode": "",
|
||||
"upstream_mode": "load_balance",
|
||||
"cache_size": 0,
|
||||
"cache_ttl_min": 0,
|
||||
"cache_ttl_max": 0,
|
||||
@@ -934,7 +934,7 @@
|
||||
"edns_cs_enabled": false,
|
||||
"dnssec_enabled": false,
|
||||
"disable_ipv6": false,
|
||||
"upstream_mode": "",
|
||||
"upstream_mode": "load_balance",
|
||||
"cache_size": 0,
|
||||
"cache_ttl_min": 0,
|
||||
"cache_ttl_max": 0,
|
||||
@@ -978,7 +978,7 @@
|
||||
"edns_cs_enabled": false,
|
||||
"dnssec_enabled": false,
|
||||
"disable_ipv6": false,
|
||||
"upstream_mode": "",
|
||||
"upstream_mode": "load_balance",
|
||||
"cache_size": 0,
|
||||
"cache_ttl_min": 0,
|
||||
"cache_ttl_max": 0,
|
||||
@@ -1026,7 +1026,7 @@
|
||||
"edns_cs_enabled": false,
|
||||
"dnssec_enabled": false,
|
||||
"disable_ipv6": false,
|
||||
"upstream_mode": "",
|
||||
"upstream_mode": "load_balance",
|
||||
"cache_size": 0,
|
||||
"cache_ttl_min": 0,
|
||||
"cache_ttl_max": 0,
|
||||
@@ -1070,7 +1070,7 @@
|
||||
"edns_cs_enabled": false,
|
||||
"dnssec_enabled": false,
|
||||
"disable_ipv6": false,
|
||||
"upstream_mode": "",
|
||||
"upstream_mode": "load_balance",
|
||||
"cache_size": 0,
|
||||
"cache_ttl_min": 0,
|
||||
"cache_ttl_max": 0,
|
||||
@@ -1117,7 +1117,7 @@
|
||||
"edns_cs_enabled": false,
|
||||
"dnssec_enabled": false,
|
||||
"disable_ipv6": false,
|
||||
"upstream_mode": "",
|
||||
"upstream_mode": "load_balance",
|
||||
"cache_size": 0,
|
||||
"cache_ttl_min": 0,
|
||||
"cache_ttl_max": 0,
|
||||
@@ -1161,7 +1161,7 @@
|
||||
"edns_cs_enabled": false,
|
||||
"dnssec_enabled": false,
|
||||
"disable_ipv6": false,
|
||||
"upstream_mode": "",
|
||||
"upstream_mode": "load_balance",
|
||||
"cache_size": 0,
|
||||
"cache_ttl_min": 0,
|
||||
"cache_ttl_max": 0,
|
||||
|
||||
@@ -21,14 +21,10 @@ import (
|
||||
// serviceRules maps a service ID to its filtering rules.
|
||||
var serviceRules map[string][]*rules.NetworkRule
|
||||
|
||||
// serviceIDs contains service IDs sorted alphabetically.
|
||||
var serviceIDs []string
|
||||
|
||||
// initBlockedServices initializes package-level blocked service data. l must
|
||||
// not be nil.
|
||||
func initBlockedServices(ctx context.Context, l *slog.Logger) {
|
||||
svcLen := len(blockedServices)
|
||||
serviceIDs = make([]string, svcLen)
|
||||
serviceRules = make(map[string][]*rules.NetworkRule, svcLen)
|
||||
|
||||
for i, s := range blockedServices {
|
||||
@@ -44,18 +40,16 @@ func initBlockedServices(ctx context.Context, l *slog.Logger) {
|
||||
l.ErrorContext(
|
||||
ctx,
|
||||
"parsing blocked service rule",
|
||||
"idx", i,
|
||||
"svc", s.ID,
|
||||
"rule", text,
|
||||
slogutil.KeyError, err,
|
||||
)
|
||||
}
|
||||
|
||||
serviceIDs[i] = s.ID
|
||||
serviceRules[s.ID] = netRules
|
||||
}
|
||||
|
||||
slices.Sort(serviceIDs)
|
||||
|
||||
l.DebugContext(ctx, "initialized services", "svc_len", svcLen)
|
||||
}
|
||||
|
||||
@@ -153,10 +147,6 @@ func (d *DNSFilter) ApplyBlockedServicesList(setts *Settings, list []string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (d *DNSFilter) handleBlockedServicesIDs(w http.ResponseWriter, r *http.Request) {
|
||||
aghhttp.WriteJSONResponseOK(r.Context(), d.logger, w, r, serviceIDs)
|
||||
}
|
||||
|
||||
func (d *DNSFilter) handleBlockedServicesAll(w http.ResponseWriter, r *http.Request) {
|
||||
aghhttp.WriteJSONResponseOK(r.Context(), d.logger, w, r, struct {
|
||||
BlockedServices []blockedService `json:"blocked_services"`
|
||||
@@ -167,48 +157,6 @@ func (d *DNSFilter) handleBlockedServicesAll(w http.ResponseWriter, r *http.Requ
|
||||
})
|
||||
}
|
||||
|
||||
// handleBlockedServicesList is the handler for the GET
|
||||
// /control/blocked_services/list HTTP API.
|
||||
//
|
||||
// Deprecated: Use handleBlockedServicesGet.
|
||||
func (d *DNSFilter) handleBlockedServicesList(w http.ResponseWriter, r *http.Request) {
|
||||
var list []string
|
||||
func() {
|
||||
d.confMu.Lock()
|
||||
defer d.confMu.Unlock()
|
||||
|
||||
list = d.conf.BlockedServices.IDs
|
||||
}()
|
||||
|
||||
aghhttp.WriteJSONResponseOK(r.Context(), d.logger, w, r, list)
|
||||
}
|
||||
|
||||
// handleBlockedServicesSet is the handler for the POST
|
||||
// /control/blocked_services/set HTTP API.
|
||||
//
|
||||
// Deprecated: Use handleBlockedServicesUpdate.
|
||||
func (d *DNSFilter) handleBlockedServicesSet(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
|
||||
list := []string{}
|
||||
err := json.NewDecoder(r.Body).Decode(&list)
|
||||
if err != nil {
|
||||
aghhttp.ErrorAndLog(ctx, d.logger, r, w, http.StatusBadRequest, "json.Decode: %s", err)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func() {
|
||||
d.confMu.Lock()
|
||||
defer d.confMu.Unlock()
|
||||
|
||||
d.conf.BlockedServices.IDs = list
|
||||
d.logger.DebugContext(ctx, "updated blocked services list", "len", len(list))
|
||||
}()
|
||||
|
||||
d.conf.ConfModifier.Apply(ctx)
|
||||
}
|
||||
|
||||
// handleBlockedServicesGet is the handler for the GET
|
||||
// /control/blocked_services/get HTTP API.
|
||||
func (d *DNSFilter) handleBlockedServicesGet(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -101,7 +101,8 @@ type Config struct {
|
||||
BlockedServices *BlockedServices `yaml:"blocked_services"`
|
||||
|
||||
// EtcHosts is a container of IP-hostname pairs taken from the operating
|
||||
// system configuration files (e.g. /etc/hosts).
|
||||
// system configuration files (e.g. /etc/hosts). If nil, no matching for
|
||||
// hostnames from hosts files is performed, e.g. in rDNS and rewrites.
|
||||
//
|
||||
// TODO(e.burkov): Move it to dnsforward entirely.
|
||||
EtcHosts hostsfile.Storage `yaml:"-"`
|
||||
|
||||
@@ -344,10 +344,6 @@ type filteringRulesReq struct {
|
||||
func (d *DNSFilter) handleFilteringSetRules(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
|
||||
if aghhttp.WriteTextPlainDeprecated(ctx, d.logger, w, r) {
|
||||
return
|
||||
}
|
||||
|
||||
req := &filteringRulesReq{}
|
||||
err := json.NewDecoder(r.Body).Decode(req)
|
||||
if err != nil {
|
||||
@@ -496,11 +492,6 @@ type checkHostRespRule struct {
|
||||
type checkHostResp struct {
|
||||
Reason string `json:"reason"`
|
||||
|
||||
// Rule is the text of the matched rule.
|
||||
//
|
||||
// Deprecated: Use Rules[*].Text.
|
||||
Rule string `json:"rule"`
|
||||
|
||||
Rules []*checkHostRespRule `json:"rules"`
|
||||
|
||||
// for FilteredBlockedService:
|
||||
@@ -509,11 +500,6 @@ type checkHostResp struct {
|
||||
// for Rewrite:
|
||||
CanonName string `json:"cname"` // CNAME value
|
||||
IPList []netip.Addr `json:"ip_addrs"` // list of IP addresses
|
||||
|
||||
// FilterID is the ID of the rule's filter list.
|
||||
//
|
||||
// Deprecated: Use Rules[*].FilterListID.
|
||||
FilterID rulelist.APIID `json:"filter_id"`
|
||||
}
|
||||
|
||||
// handleCheckHost is the handler for the GET /control/filtering/check_host HTTP
|
||||
@@ -589,7 +575,6 @@ func (d *DNSFilter) handleCheckHost(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
rulesLen := len(result.Rules)
|
||||
resp := checkHostResp{
|
||||
Reason: result.Reason.String(),
|
||||
SvcName: result.ServiceName,
|
||||
@@ -598,11 +583,6 @@ func (d *DNSFilter) handleCheckHost(w http.ResponseWriter, r *http.Request) {
|
||||
Rules: make([]*checkHostRespRule, len(result.Rules)),
|
||||
}
|
||||
|
||||
if rulesLen > 0 {
|
||||
resp.FilterID = result.Rules[0].FilterListID
|
||||
resp.Rule = result.Rules[0].Text
|
||||
}
|
||||
|
||||
for i, r := range result.Rules {
|
||||
resp.Rules[i] = &checkHostRespRule{
|
||||
FilterListID: r.FilterListID,
|
||||
@@ -726,8 +706,6 @@ func (d *DNSFilter) RegisterFilteringHandlers() {
|
||||
registerHTTP(http.MethodPost, "/control/parental/disable", d.handleParentalDisable)
|
||||
registerHTTP(http.MethodGet, "/control/parental/status", d.handleParentalStatus)
|
||||
|
||||
registerHTTP(http.MethodPost, "/control/safesearch/enable", d.handleSafeSearchEnable)
|
||||
registerHTTP(http.MethodPost, "/control/safesearch/disable", d.handleSafeSearchDisable)
|
||||
registerHTTP(http.MethodGet, "/control/safesearch/status", d.handleSafeSearchStatus)
|
||||
registerHTTP(http.MethodPut, "/control/safesearch/settings", d.handleSafeSearchSettings)
|
||||
|
||||
@@ -738,13 +716,7 @@ func (d *DNSFilter) RegisterFilteringHandlers() {
|
||||
registerHTTP(http.MethodPut, "/control/rewrite/settings/update", d.handleRewriteSettingsUpdate)
|
||||
registerHTTP(http.MethodPut, "/control/rewrite/update", d.handleRewriteUpdate)
|
||||
|
||||
registerHTTP(http.MethodGet, "/control/blocked_services/services", d.handleBlockedServicesIDs)
|
||||
registerHTTP(http.MethodGet, "/control/blocked_services/all", d.handleBlockedServicesAll)
|
||||
|
||||
// Deprecated handlers.
|
||||
registerHTTP(http.MethodGet, "/control/blocked_services/list", d.handleBlockedServicesList)
|
||||
registerHTTP(http.MethodPost, "/control/blocked_services/set", d.handleBlockedServicesSet)
|
||||
|
||||
registerHTTP(http.MethodGet, "/control/blocked_services/get", d.handleBlockedServicesGet)
|
||||
registerHTTP(http.MethodPut, "/control/blocked_services/update", d.handleBlockedServicesUpdate)
|
||||
|
||||
|
||||
@@ -411,7 +411,6 @@ func TestDNSFilter_HandleCheckHost(t *testing.T) {
|
||||
url: notFilteredURL,
|
||||
want: &checkHostResp{
|
||||
Reason: reasonNames[NotFilteredNotFound],
|
||||
Rule: "",
|
||||
Rules: []*checkHostRespRule{},
|
||||
},
|
||||
}, {
|
||||
@@ -419,7 +418,6 @@ func TestDNSFilter_HandleCheckHost(t *testing.T) {
|
||||
url: allowedURL,
|
||||
want: &checkHostResp{
|
||||
Reason: reasonNames[NotFilteredAllowList],
|
||||
Rule: allowedRule,
|
||||
Rules: []*checkHostRespRule{{
|
||||
Text: allowedRule,
|
||||
}},
|
||||
@@ -429,7 +427,6 @@ func TestDNSFilter_HandleCheckHost(t *testing.T) {
|
||||
url: blockedURL,
|
||||
want: &checkHostResp{
|
||||
Reason: reasonNames[FilteredBlockList],
|
||||
Rule: blockedRule,
|
||||
Rules: []*checkHostRespRule{{
|
||||
Text: blockedRule,
|
||||
}},
|
||||
@@ -439,7 +436,6 @@ func TestDNSFilter_HandleCheckHost(t *testing.T) {
|
||||
url: blockedClientURL,
|
||||
want: &checkHostResp{
|
||||
Reason: reasonNames[FilteredBlockList],
|
||||
Rule: blockedClientRule,
|
||||
Rules: []*checkHostRespRule{{
|
||||
Text: blockedClientRule,
|
||||
}},
|
||||
@@ -449,7 +445,6 @@ func TestDNSFilter_HandleCheckHost(t *testing.T) {
|
||||
url: allowedQTypeURL,
|
||||
want: &checkHostResp{
|
||||
Reason: reasonNames[NotFilteredNotFound],
|
||||
Rule: "",
|
||||
Rules: []*checkHostRespRule{},
|
||||
},
|
||||
}, {
|
||||
@@ -457,7 +452,6 @@ func TestDNSFilter_HandleCheckHost(t *testing.T) {
|
||||
url: blockedQTypeURL,
|
||||
want: &checkHostResp{
|
||||
Reason: reasonNames[FilteredBlockList],
|
||||
Rule: blockedQTypeRule,
|
||||
Rules: []*checkHostRespRule{{
|
||||
Text: blockedQTypeRule,
|
||||
}},
|
||||
@@ -467,7 +461,6 @@ func TestDNSFilter_HandleCheckHost(t *testing.T) {
|
||||
url: blockedClientQTypeURL,
|
||||
want: &checkHostResp{
|
||||
Reason: reasonNames[FilteredBlockList],
|
||||
Rule: blockedClientQTypeRule,
|
||||
Rules: []*checkHostRespRule{{
|
||||
Text: blockedClientQTypeRule,
|
||||
}},
|
||||
@@ -477,7 +470,6 @@ func TestDNSFilter_HandleCheckHost(t *testing.T) {
|
||||
url: allowedClientQTypeURL,
|
||||
want: &checkHostResp{
|
||||
Reason: reasonNames[NotFilteredNotFound],
|
||||
Rule: "",
|
||||
Rules: []*checkHostRespRule{},
|
||||
},
|
||||
}}
|
||||
|
||||
@@ -7,24 +7,6 @@ import (
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/aghhttp"
|
||||
)
|
||||
|
||||
// handleSafeSearchEnable is the handler for POST /control/safesearch/enable
|
||||
// HTTP API.
|
||||
//
|
||||
// Deprecated: Use handleSafeSearchSettings.
|
||||
func (d *DNSFilter) handleSafeSearchEnable(w http.ResponseWriter, r *http.Request) {
|
||||
setProtectedBool(d.confMu, &d.conf.SafeSearchConf.Enabled, true)
|
||||
d.conf.ConfModifier.Apply(r.Context())
|
||||
}
|
||||
|
||||
// handleSafeSearchDisable is the handler for POST /control/safesearch/disable
|
||||
// HTTP API.
|
||||
//
|
||||
// Deprecated: Use handleSafeSearchSettings.
|
||||
func (d *DNSFilter) handleSafeSearchDisable(w http.ResponseWriter, r *http.Request) {
|
||||
setProtectedBool(d.confMu, &d.conf.SafeSearchConf.Enabled, false)
|
||||
d.conf.ConfModifier.Apply(r.Context())
|
||||
}
|
||||
|
||||
// handleSafeSearchStatus is the handler for GET /control/safesearch/status
|
||||
// HTTP API.
|
||||
func (d *DNSFilter) handleSafeSearchStatus(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
package querylog
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||
"github.com/AdguardTeam/golibs/container"
|
||||
"github.com/AdguardTeam/golibs/errors"
|
||||
)
|
||||
|
||||
// TODO(a.garipov): Remove once the old frontend is completely gone.
|
||||
|
||||
// ctFilteringStatus is for searching by the filtering status.
|
||||
//
|
||||
// See (*searchCriterion).ctFilteringStatusCase for details.
|
||||
//
|
||||
// Deprecated: Remove when migration to reason criterion is complete.
|
||||
const ctFilteringStatus criterionType = ctReason + 1
|
||||
|
||||
const (
|
||||
filteringStatusAll = "all"
|
||||
filteringStatusFiltered = "filtered" // all kinds of filtering
|
||||
|
||||
filteringStatusBlocked = "blocked" // blocked or blocked services
|
||||
filteringStatusBlockedService = "blocked_services" // blocked
|
||||
filteringStatusBlockedSafebrowsing = "blocked_safebrowsing" // blocked by safebrowsing
|
||||
filteringStatusBlockedParental = "blocked_parental" // blocked by parental control
|
||||
filteringStatusWhitelisted = "whitelisted" // whitelisted
|
||||
filteringStatusRewritten = "rewritten" // all kinds of rewrites
|
||||
filteringStatusSafeSearch = "safe_search" // enforced safe search
|
||||
filteringStatusProcessed = "processed" // not blocked, not white-listed entries
|
||||
)
|
||||
|
||||
// filteringStatusValues is the set of all possible [filteringStatus] values.
|
||||
var filteringStatusValues = container.NewMapSet(
|
||||
filteringStatusAll,
|
||||
filteringStatusBlocked,
|
||||
filteringStatusBlockedParental,
|
||||
filteringStatusBlockedSafebrowsing,
|
||||
filteringStatusBlockedService,
|
||||
filteringStatusFiltered,
|
||||
filteringStatusProcessed,
|
||||
filteringStatusRewritten,
|
||||
filteringStatusSafeSearch,
|
||||
filteringStatusWhitelisted,
|
||||
)
|
||||
|
||||
// ctFilteringStatusCase returns true if the result matches the value.
|
||||
func (c *searchCriterion) ctFilteringStatusCase(
|
||||
reason filtering.Reason,
|
||||
isFiltered bool,
|
||||
) (matched bool) {
|
||||
switch c.value {
|
||||
case filteringStatusAll:
|
||||
return true
|
||||
case filteringStatusFiltered:
|
||||
return isFiltered || reason == filtering.NotFilteredAllowList || reasonIsRewrite(reason)
|
||||
case
|
||||
filteringStatusBlocked,
|
||||
filteringStatusBlockedParental,
|
||||
filteringStatusBlockedSafebrowsing,
|
||||
filteringStatusBlockedService,
|
||||
filteringStatusSafeSearch:
|
||||
return isFiltered && c.isFilteredWithReason(reason)
|
||||
case filteringStatusWhitelisted:
|
||||
return reason == filtering.NotFilteredAllowList
|
||||
case filteringStatusRewritten:
|
||||
return reasonIsRewrite(reason)
|
||||
case filteringStatusProcessed:
|
||||
return !reasonIsRuleList(reason)
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// reasonIsRewrite returns true if r is one of:
|
||||
// - [filtering.RewrittenAutoHosts]
|
||||
// - [filtering.RewrittenRule]
|
||||
// - [filtering.Rewritten]
|
||||
func reasonIsRewrite(r filtering.Reason) (ok bool) {
|
||||
return r == filtering.RewrittenAutoHosts ||
|
||||
r == filtering.RewrittenRule ||
|
||||
r == filtering.Rewritten
|
||||
}
|
||||
|
||||
// isFilteredWithReason returns true if reason matches the criterion value.
|
||||
// c.value must be one of:
|
||||
// - [filteringStatusBlockedParental]
|
||||
// - [filteringStatusBlockedSafebrowsing]
|
||||
// - [filteringStatusBlockedService]
|
||||
// - [filteringStatusBlocked]
|
||||
// - [filteringStatusSafeSearch]
|
||||
func (c *searchCriterion) isFilteredWithReason(reason filtering.Reason) (matched bool) {
|
||||
switch c.value {
|
||||
case filteringStatusBlocked:
|
||||
switch reason {
|
||||
case
|
||||
filtering.FilteredBlockList,
|
||||
filtering.FilteredBlockedService:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
case filteringStatusBlockedParental:
|
||||
return reason == filtering.FilteredParental
|
||||
case filteringStatusBlockedSafebrowsing:
|
||||
return reason == filtering.FilteredSafeBrowsing
|
||||
case filteringStatusBlockedService:
|
||||
return reason == filtering.FilteredBlockedService
|
||||
case filteringStatusSafeSearch:
|
||||
return reason == filtering.FilteredSafeSearch
|
||||
default:
|
||||
panic(fmt.Errorf("%w: %q", errors.ErrBadEnumValue, c.value))
|
||||
}
|
||||
}
|
||||
|
||||
// reasonIsRuleList returns true if r is one of:
|
||||
// - [filtering.FilteredBlockList]
|
||||
// - [filtering.FilteredBlockedService]
|
||||
// - [filtering.NotFilteredAllowList]
|
||||
func reasonIsRuleList(r filtering.Reason) (ok bool) {
|
||||
return r == filtering.FilteredBlockList ||
|
||||
r == filtering.FilteredBlockedService ||
|
||||
r == filtering.NotFilteredAllowList
|
||||
}
|
||||
+6
-108
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -18,26 +17,9 @@ import (
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||
"github.com/AdguardTeam/golibs/errors"
|
||||
"github.com/AdguardTeam/golibs/logutil/slogutil"
|
||||
"github.com/AdguardTeam/golibs/timeutil"
|
||||
"golang.org/x/net/idna"
|
||||
)
|
||||
|
||||
// configJSON is the JSON structure for the querylog configuration.
|
||||
type configJSON struct {
|
||||
// Interval is the querylog rotation interval. Use float64 here to support
|
||||
// fractional numbers and not mess the API users by changing the units.
|
||||
Interval float64 `json:"interval"`
|
||||
|
||||
// Enabled shows if the querylog is enabled. It is an aghalg.NullBool to
|
||||
// be able to tell when it's set without using pointers.
|
||||
Enabled aghalg.NullBool `json:"enabled"`
|
||||
|
||||
// AnonymizeClientIP shows if the clients' IP addresses must be anonymized.
|
||||
// It is an [aghalg.NullBool] to be able to tell when it's set without using
|
||||
// pointers.
|
||||
AnonymizeClientIP aghalg.NullBool `json:"anonymize_client_ip"`
|
||||
}
|
||||
|
||||
// getConfigResp is the JSON structure for the querylog configuration.
|
||||
type getConfigResp struct {
|
||||
// Ignored is the list of host names, which should not be written to log.
|
||||
@@ -70,10 +52,6 @@ func (l *queryLog) initWeb() {
|
||||
"/control/querylog/config/update",
|
||||
l.handlePutQueryLogConfig,
|
||||
)
|
||||
|
||||
// Deprecated handlers.
|
||||
l.conf.HTTPReg.Register(http.MethodGet, "/control/querylog_info", l.handleQueryLogInfo)
|
||||
l.conf.HTTPReg.Register(http.MethodPost, "/control/querylog_config", l.handleQueryLogConfig)
|
||||
}
|
||||
|
||||
// handleQueryLog is the handler for the GET /control/querylog HTTP API.
|
||||
@@ -106,29 +84,6 @@ func (l *queryLog) handleQueryLogClear(_ http.ResponseWriter, r *http.Request) {
|
||||
l.clear(r.Context())
|
||||
}
|
||||
|
||||
// handleQueryLogInfo is the handler for the GET /control/querylog_info HTTP
|
||||
// API.
|
||||
//
|
||||
// Deprecated: Remove it when migration to the new API is over.
|
||||
func (l *queryLog) handleQueryLogInfo(w http.ResponseWriter, r *http.Request) {
|
||||
l.confMu.RLock()
|
||||
defer l.confMu.RUnlock()
|
||||
|
||||
ivl := l.conf.RotationIvl
|
||||
|
||||
if !checkInterval(ivl) {
|
||||
// NOTE: If interval is custom we set it to 90 days for compatibility
|
||||
// with old API.
|
||||
ivl = timeutil.Day * 90
|
||||
}
|
||||
|
||||
aghhttp.WriteJSONResponseOK(r.Context(), l.logger, w, r, configJSON{
|
||||
Enabled: aghalg.BoolToNullBool(l.conf.Enabled),
|
||||
Interval: ivl.Hours() / 24,
|
||||
AnonymizeClientIP: aghalg.BoolToNullBool(l.conf.AnonymizeClientIP),
|
||||
})
|
||||
}
|
||||
|
||||
// handleGetQueryLogConfig is the handler for the GET /control/querylog/config
|
||||
// HTTP API.
|
||||
func (l *queryLog) handleGetQueryLogConfig(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -163,61 +118,6 @@ func AnonymizeIP(ip net.IP) {
|
||||
}
|
||||
}
|
||||
|
||||
// handleQueryLogConfig is the handler for the POST /control/querylog_config
|
||||
// HTTP API.
|
||||
//
|
||||
// Deprecated: Remove it when migration to the new API is over.
|
||||
func (l *queryLog) handleQueryLogConfig(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
|
||||
// Set NaN as initial value to be able to know if it changed later by
|
||||
// comparing it to NaN.
|
||||
newConf := &configJSON{
|
||||
Interval: math.NaN(),
|
||||
}
|
||||
|
||||
err := json.NewDecoder(r.Body).Decode(newConf)
|
||||
if err != nil {
|
||||
aghhttp.ErrorAndLog(ctx, l.logger, r, w, http.StatusBadRequest, "%s", err)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
ivl := time.Duration(float64(timeutil.Day) * newConf.Interval)
|
||||
|
||||
hasIvl := !math.IsNaN(newConf.Interval)
|
||||
if hasIvl && !checkInterval(ivl) {
|
||||
aghhttp.ErrorAndLog(ctx, l.logger, r, w, http.StatusBadRequest, "unsupported interval")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
defer l.conf.ConfigModifier.Apply(ctx)
|
||||
|
||||
l.confMu.Lock()
|
||||
defer l.confMu.Unlock()
|
||||
|
||||
conf := *l.conf
|
||||
if newConf.Enabled != aghalg.NBNull {
|
||||
conf.Enabled = newConf.Enabled == aghalg.NBTrue
|
||||
}
|
||||
|
||||
if hasIvl {
|
||||
conf.RotationIvl = ivl
|
||||
}
|
||||
|
||||
if newConf.AnonymizeClientIP != aghalg.NBNull {
|
||||
conf.AnonymizeClientIP = newConf.AnonymizeClientIP == aghalg.NBTrue
|
||||
if conf.AnonymizeClientIP {
|
||||
l.anonymizer.Store(AnonymizeIP)
|
||||
} else {
|
||||
l.anonymizer.Store(nil)
|
||||
}
|
||||
}
|
||||
|
||||
l.conf = &conf
|
||||
}
|
||||
|
||||
// handlePutQueryLogConfig is the handler for the PUT
|
||||
// /control/querylog/config/update HTTP API.
|
||||
func (l *queryLog) handlePutQueryLogConfig(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -377,6 +277,7 @@ func (l *queryLog) parseSearchCriterion(
|
||||
asciiVal = ""
|
||||
}
|
||||
case ctFilteringStatus:
|
||||
// TODO(a.garipov): Remove once the old frontend is completely gone.
|
||||
if !filteringStatusValues.Has(val) {
|
||||
return false, sc, fmt.Errorf("invalid value %s", val)
|
||||
}
|
||||
@@ -390,7 +291,7 @@ func (l *queryLog) parseSearchCriterion(
|
||||
return false, sc, fmt.Errorf(
|
||||
"invalid criterion type %v: should be one of %v",
|
||||
ct,
|
||||
[]criterionType{ctTerm, ctFilteringStatus, ctReason},
|
||||
[]criterionType{ctTerm, ctReason},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -435,10 +336,6 @@ func (l *queryLog) parseSearchParams(
|
||||
p = newSearchParams()
|
||||
|
||||
q := r.URL.Query()
|
||||
if q.Has("reason") && q.Has("response_status") {
|
||||
return nil,
|
||||
errors.Error(`"reason" and "response_status" criteria cannot be used together`)
|
||||
}
|
||||
|
||||
olderThan := q.Get("older_than")
|
||||
if len(olderThan) != 0 {
|
||||
@@ -484,12 +381,13 @@ func (l *queryLog) parseSearchCriterions(
|
||||
}{{
|
||||
urlField: "search",
|
||||
ct: ctTerm,
|
||||
}, {
|
||||
urlField: "response_status",
|
||||
ct: ctFilteringStatus,
|
||||
}, {
|
||||
urlField: "reason",
|
||||
ct: ctReason,
|
||||
}, {
|
||||
// TODO(a.garipov): Remove once the old frontend is completely gone.
|
||||
urlField: "response_status",
|
||||
ct: ctFilteringStatus,
|
||||
}} {
|
||||
var ok bool
|
||||
var c searchCriterion
|
||||
|
||||
@@ -100,16 +100,6 @@ func TestQuerylog_HandleQueryLog_reasonSearchCriterion(t *testing.T) {
|
||||
wantMsg: `parsing params: reason: bad enum value: "InvalidReason"` + "\n",
|
||||
wantStatus: http.StatusBadRequest,
|
||||
wantHosts: nil,
|
||||
}, {
|
||||
name: "reason_and_status_conflict",
|
||||
query: url.Values{
|
||||
"reason": []string{filtering.Rewritten.String()},
|
||||
"response_status": []string{filteringStatusAll},
|
||||
},
|
||||
wantMsg: `parsing params: "reason" and "response_status"` +
|
||||
` criteria cannot be used together` + "\n",
|
||||
wantStatus: http.StatusBadRequest,
|
||||
wantHosts: nil,
|
||||
}}
|
||||
|
||||
for _, tc := range testCases {
|
||||
|
||||
@@ -80,13 +80,6 @@ func (l *queryLog) entryToJSON(
|
||||
jsonEntry["ecs"] = entry.ReqECS
|
||||
}
|
||||
|
||||
if len(entry.Result.Rules) > 0 {
|
||||
if r := entry.Result.Rules[0]; len(r.Text) > 0 {
|
||||
jsonEntry["rule"] = r.Text
|
||||
jsonEntry["filterId"] = r.FilterListID
|
||||
}
|
||||
}
|
||||
|
||||
if len(entry.Result.ServiceName) != 0 {
|
||||
jsonEntry["service_name"] = entry.Result.ServiceName
|
||||
}
|
||||
|
||||
@@ -113,19 +113,6 @@ func (l *queryLog) Shutdown(ctx context.Context) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkInterval(ivl time.Duration) (ok bool) {
|
||||
// The constants for possible values of query log's rotation interval.
|
||||
const (
|
||||
quarterDay = timeutil.Day / 4
|
||||
day = timeutil.Day
|
||||
week = timeutil.Day * 7
|
||||
month = timeutil.Day * 30
|
||||
threeMonths = timeutil.Day * 90
|
||||
)
|
||||
|
||||
return ivl == quarterDay || ivl == day || ivl == week || ivl == month || ivl == threeMonths
|
||||
}
|
||||
|
||||
// validateIvl returns an error if ivl is less than an hour or more than a
|
||||
// year.
|
||||
func validateIvl(ivl time.Duration) (err error) {
|
||||
|
||||
@@ -2,64 +2,25 @@ package querylog
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||
"github.com/AdguardTeam/golibs/container"
|
||||
"github.com/AdguardTeam/golibs/errors"
|
||||
"github.com/AdguardTeam/golibs/stringutil"
|
||||
)
|
||||
|
||||
type criterionType int
|
||||
|
||||
const (
|
||||
// ctTerm is for searching by the domain name, the client's IP address,
|
||||
// the client's ID or the client's name. The domain name search
|
||||
// supports IDNAs.
|
||||
// ctTerm is for searching by the domain name, the client's IP address, the
|
||||
// client's ID or the client's name. The domain name search supports IDNAs.
|
||||
ctTerm criterionType = iota
|
||||
|
||||
// ctFilteringStatus is for searching by the filtering status.
|
||||
//
|
||||
// See (*searchCriterion).ctFilteringStatusCase for details.
|
||||
//
|
||||
// Deprecated: Remove when migration to reason criterion is complete.
|
||||
ctFilteringStatus
|
||||
|
||||
// ctReason is for searching by the filtering reason.
|
||||
ctReason
|
||||
)
|
||||
|
||||
const (
|
||||
filteringStatusAll = "all"
|
||||
filteringStatusFiltered = "filtered" // all kinds of filtering
|
||||
|
||||
filteringStatusBlocked = "blocked" // blocked or blocked services
|
||||
filteringStatusBlockedService = "blocked_services" // blocked
|
||||
filteringStatusBlockedSafebrowsing = "blocked_safebrowsing" // blocked by safebrowsing
|
||||
filteringStatusBlockedParental = "blocked_parental" // blocked by parental control
|
||||
filteringStatusWhitelisted = "whitelisted" // whitelisted
|
||||
filteringStatusRewritten = "rewritten" // all kinds of rewrites
|
||||
filteringStatusSafeSearch = "safe_search" // enforced safe search
|
||||
filteringStatusProcessed = "processed" // not blocked, not white-listed entries
|
||||
)
|
||||
|
||||
// filteringStatusValues is the set of all possible [filteringStatus] values.
|
||||
var filteringStatusValues = container.NewMapSet(
|
||||
filteringStatusAll,
|
||||
filteringStatusBlocked,
|
||||
filteringStatusBlockedParental,
|
||||
filteringStatusBlockedSafebrowsing,
|
||||
filteringStatusBlockedService,
|
||||
filteringStatusFiltered,
|
||||
filteringStatusProcessed,
|
||||
filteringStatusRewritten,
|
||||
filteringStatusSafeSearch,
|
||||
filteringStatusWhitelisted,
|
||||
)
|
||||
|
||||
// reasonCodes is a set of all valid reason codes.
|
||||
var reasonCodes = [...]string{
|
||||
filtering.NotFilteredAllowList: "1",
|
||||
@@ -160,6 +121,8 @@ func (c *searchCriterion) quickMatch(
|
||||
case ctFilteringStatus:
|
||||
// Go on, as we currently don't do quick matches against
|
||||
// filtering statuses.
|
||||
//
|
||||
// TODO(a.garipov): Remove once the old frontend is completely gone.
|
||||
return true
|
||||
case ctReason:
|
||||
reasonCode := readJSONNumericValue(line, `"Reason":`)
|
||||
@@ -185,12 +148,13 @@ func (c *searchCriterion) match(entry *logEntry) bool {
|
||||
switch c.criterionType {
|
||||
case ctTerm:
|
||||
return c.ctDomainOrClientCase(entry)
|
||||
case ctFilteringStatus:
|
||||
return c.ctFilteringStatusCase(entry.Result.Reason, entry.Result.IsFiltered)
|
||||
case ctReason:
|
||||
// TODO(f.setrakov): Consider comparing [filtering.Reason] instead of
|
||||
// strings.
|
||||
return slices.Contains(c.values, entry.Result.Reason.String())
|
||||
case ctFilteringStatus:
|
||||
// TODO(a.garipov): Remove once the old frontend is completely gone.
|
||||
return c.ctFilteringStatusCase(entry.Result.Reason, entry.Result.IsFiltered)
|
||||
}
|
||||
|
||||
return false
|
||||
@@ -212,85 +176,3 @@ func (c *searchCriterion) ctDomainOrClientCase(e *logEntry) bool {
|
||||
|
||||
return ctDomainOrClientCaseNonStrict(c.value, c.asciiVal, clientID, name, host, ip)
|
||||
}
|
||||
|
||||
// ctFilteringStatusCase returns true if the result matches the value.
|
||||
func (c *searchCriterion) ctFilteringStatusCase(
|
||||
reason filtering.Reason,
|
||||
isFiltered bool,
|
||||
) (matched bool) {
|
||||
switch c.value {
|
||||
case filteringStatusAll:
|
||||
return true
|
||||
case filteringStatusFiltered:
|
||||
return isFiltered || reason == filtering.NotFilteredAllowList || reasonIsRewrite(reason)
|
||||
case
|
||||
filteringStatusBlocked,
|
||||
filteringStatusBlockedParental,
|
||||
filteringStatusBlockedSafebrowsing,
|
||||
filteringStatusBlockedService,
|
||||
filteringStatusSafeSearch:
|
||||
return isFiltered && c.isFilteredWithReason(reason)
|
||||
case filteringStatusWhitelisted:
|
||||
return reason == filtering.NotFilteredAllowList
|
||||
case filteringStatusRewritten:
|
||||
return reasonIsRewrite(reason)
|
||||
case filteringStatusProcessed:
|
||||
return !reasonIsRuleList(reason)
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// reasonIsRewrite returns true if r is one of:
|
||||
//
|
||||
// - [filtering.RewrittenAutoHosts]
|
||||
// - [filtering.RewrittenRule]
|
||||
// - [filtering.Rewritten]
|
||||
func reasonIsRewrite(r filtering.Reason) (ok bool) {
|
||||
return r == filtering.RewrittenAutoHosts ||
|
||||
r == filtering.RewrittenRule ||
|
||||
r == filtering.Rewritten
|
||||
}
|
||||
|
||||
// isFilteredWithReason returns true if reason matches the criterion value.
|
||||
// c.value must be one of:
|
||||
//
|
||||
// - [filteringStatusBlockedParental]
|
||||
// - [filteringStatusBlockedSafebrowsing]
|
||||
// - [filteringStatusBlockedService]
|
||||
// - [filteringStatusBlocked]
|
||||
// - [filteringStatusSafeSearch]
|
||||
func (c *searchCriterion) isFilteredWithReason(reason filtering.Reason) (matched bool) {
|
||||
switch c.value {
|
||||
case filteringStatusBlocked:
|
||||
switch reason {
|
||||
case
|
||||
filtering.FilteredBlockList,
|
||||
filtering.FilteredBlockedService:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
case filteringStatusBlockedParental:
|
||||
return reason == filtering.FilteredParental
|
||||
case filteringStatusBlockedSafebrowsing:
|
||||
return reason == filtering.FilteredSafeBrowsing
|
||||
case filteringStatusBlockedService:
|
||||
return reason == filtering.FilteredBlockedService
|
||||
case filteringStatusSafeSearch:
|
||||
return reason == filtering.FilteredSafeSearch
|
||||
default:
|
||||
panic(fmt.Errorf("%w: %q", errors.ErrBadEnumValue, c.value))
|
||||
}
|
||||
}
|
||||
|
||||
// reasonIsRuleList returns true if r is one of:
|
||||
//
|
||||
// - [filtering.FilteredBlockList]
|
||||
// - [filtering.FilteredBlockedService]
|
||||
// - [filtering.NotFilteredAllowList]
|
||||
func reasonIsRuleList(r filtering.Reason) (ok bool) {
|
||||
return r == filtering.FilteredBlockList ||
|
||||
r == filtering.FilteredBlockedService ||
|
||||
r == filtering.NotFilteredAllowList
|
||||
}
|
||||
Reference in new issue
Block a user