diff --git a/internal/filtering/blocked.go b/internal/filtering/blocked.go index 44ae91775fa..14954c421f7 100644 --- a/internal/filtering/blocked.go +++ b/internal/filtering/blocked.go @@ -125,7 +125,10 @@ func (d *DNSFilter) handleBlockedServicesAll(w http.ResponseWriter, r *http.Requ }) } -// Deprecated: Use handleBlockedServicesSchedule. +// 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) { d.confLock.RLock() list := d.Config.BlockedServices.IDs @@ -134,7 +137,10 @@ func (d *DNSFilter) handleBlockedServicesList(w http.ResponseWriter, r *http.Req _ = aghhttp.WriteJSONResponse(w, r, list) } -// Deprecated: Use handleBlockedServicesScheduleUpdate. +// 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) { list := []string{} err := json.NewDecoder(r.Body).Decode(&list) @@ -153,9 +159,9 @@ func (d *DNSFilter) handleBlockedServicesSet(w http.ResponseWriter, r *http.Requ d.Config.ConfigModified() } -// handleBlockedServicesSchedule is the handler for the GET -// /control/blocked_services/schedule HTTP API. -func (d *DNSFilter) handleBlockedServicesSchedule(w http.ResponseWriter, r *http.Request) { +// handleBlockedServicesGet is the handler for the GET +// /control/blocked_services/get HTTP API. +func (d *DNSFilter) handleBlockedServicesGet(w http.ResponseWriter, r *http.Request) { var bsvc *BlockedServices func() { d.confLock.RLock() @@ -167,9 +173,9 @@ func (d *DNSFilter) handleBlockedServicesSchedule(w http.ResponseWriter, r *http _ = aghhttp.WriteJSONResponse(w, r, bsvc) } -// handleBlockedServicesScheduleUpdate is the handler for the PUT -// /control/blocked_services/schedule/update HTTP API. -func (d *DNSFilter) handleBlockedServicesScheduleUpdate(w http.ResponseWriter, r *http.Request) { +// handleBlockedServicesUpdate is the handler for the PUT +// /control/blocked_services/update HTTP API. +func (d *DNSFilter) handleBlockedServicesUpdate(w http.ResponseWriter, r *http.Request) { bsvc := &BlockedServices{} err := json.NewDecoder(r.Body).Decode(bsvc) if err != nil { diff --git a/internal/filtering/http.go b/internal/filtering/http.go index b730c5d54e4..0c89d2a3db4 100644 --- a/internal/filtering/http.go +++ b/internal/filtering/http.go @@ -565,8 +565,8 @@ func (d *DNSFilter) RegisterFilteringHandlers() { registerHTTP(http.MethodGet, "/control/blocked_services/list", d.handleBlockedServicesList) registerHTTP(http.MethodPost, "/control/blocked_services/set", d.handleBlockedServicesSet) - registerHTTP(http.MethodGet, "/control/blocked_services/schedule", d.handleBlockedServicesSchedule) - registerHTTP(http.MethodPut, "/control/blocked_services/schedule/update", d.handleBlockedServicesScheduleUpdate) + registerHTTP(http.MethodGet, "/control/blocked_services/get", d.handleBlockedServicesGet) + registerHTTP(http.MethodPut, "/control/blocked_services/update", d.handleBlockedServicesUpdate) registerHTTP(http.MethodGet, "/control/filtering/status", d.handleFilteringStatus) registerHTTP(http.MethodPost, "/control/filtering/config", d.handleFilteringConfig) diff --git a/internal/home/clientshttp.go b/internal/home/clientshttp.go index c6a378424ed..181dd8ad624 100644 --- a/internal/home/clientshttp.go +++ b/internal/home/clientshttp.go @@ -57,16 +57,32 @@ type clientJSON struct { IgnoreStatistics aghalg.NullBool `json:"ignore_statistics"` } -// copySchedule returns a copy of weekly schedule from JSON, previous client, -// or creates new empty schedule. -func (j *clientJSON) copySchedule(prev *Client) (weekly *schedule.Weekly) { +// copySettings returns a copy of specific settings from JSON or a previous +// client. +func (j *clientJSON) copySettings( + prev *Client, +) (weekly *schedule.Weekly, ignoreQueryLog, ignoreStatistics bool) { if j.Schedule != nil { - return j.Schedule.Clone() + weekly = j.Schedule.Clone() } else if prev != nil && prev.BlockedServices != nil { - return prev.BlockedServices.Schedule.Clone() + weekly = prev.BlockedServices.Schedule.Clone() + } else { + weekly = schedule.EmptyWeekly() + } + + if j.IgnoreQueryLog != aghalg.NBNull { + ignoreQueryLog = j.IgnoreQueryLog == aghalg.NBTrue + } else if prev != nil { + ignoreQueryLog = prev.IgnoreQueryLog + } + + if j.IgnoreStatistics != aghalg.NBNull { + ignoreStatistics = j.IgnoreStatistics == aghalg.NBTrue + } else if prev != nil { + ignoreStatistics = prev.IgnoreStatistics } - return schedule.EmptyWeekly() + return weekly, ignoreQueryLog, ignoreStatistics } type runtimeClientJSON struct { @@ -135,7 +151,7 @@ func (clients *clientsContainer) jsonToClient(cj clientJSON, prev *Client) (c *C } } - weekly := cj.copySchedule(prev) + weekly, ignoreQueryLog, ignoreStatistics := cj.copySettings(prev) c = &Client{ safeSearchConf: safeSearchConf, @@ -156,18 +172,13 @@ func (clients *clientsContainer) jsonToClient(cj clientJSON, prev *Client) (c *C ParentalEnabled: cj.ParentalEnabled, SafeBrowsingEnabled: cj.SafeBrowsingEnabled, UseOwnBlockedServices: !cj.UseGlobalBlockedServices, + IgnoreQueryLog: ignoreQueryLog, + IgnoreStatistics: ignoreStatistics, } - if cj.IgnoreQueryLog != aghalg.NBNull { - c.IgnoreQueryLog = cj.IgnoreQueryLog == aghalg.NBTrue - } else if prev != nil { - c.IgnoreQueryLog = prev.IgnoreQueryLog - } - - if cj.IgnoreStatistics != aghalg.NBNull { - c.IgnoreStatistics = cj.IgnoreStatistics == aghalg.NBTrue - } else if prev != nil { - c.IgnoreStatistics = prev.IgnoreStatistics + err = c.BlockedServices.Validate() + if err != nil { + return nil, fmt.Errorf("validating blocked services: %w", err) } if safeSearchConf.Enabled { diff --git a/openapi/CHANGELOG.md b/openapi/CHANGELOG.md index a23fdba6a13..8cf35f14d82 100644 --- a/openapi/CHANGELOG.md +++ b/openapi/CHANGELOG.md @@ -9,17 +9,17 @@ ### Deprecated blocked services APIs * The `GET /control/blocked_services/list` HTTP API; use the new `GET - /control/blocked_services/schedule` API instead. + /control/blocked_services/get` API instead. * The `POST /control/blocked_services/set` HTTP API; use the new `PUT - /control/blocked_services/schedule/update` API instead. + /control/blocked_services/update` API instead. ### New blocked services APIs -* The new `GET /control/blocked_services/schedule` HTTP API. +* The new `GET /control/blocked_services/get` HTTP API. -* The new `PUT /control/blocked_services/schedule/update` HTTP API allows - config updates. +* The new `PUT /control/blocked_services/update` HTTP API allows config + updates. These APIs accept and return a JSON object with the following format: diff --git a/openapi/openapi.yaml b/openapi/openapi.yaml index eeefbcdecc7..bccd3f55d1d 100644 --- a/openapi/openapi.yaml +++ b/openapi/openapi.yaml @@ -1003,7 +1003,7 @@ 'get': 'deprecated': true 'description': > - Deprecated: Use `GET /blocked_services/schedule` instead. + Deprecated: Use `GET /blocked_services/get` instead. 'tags': - 'blocked_services' 'operationId': 'blockedServicesList' @@ -1019,7 +1019,7 @@ 'post': 'deprecated': true 'description': > - Deprecated: Use `PUT /blocked_services/schedule/update` instead. + Deprecated: Use `PUT /blocked_services/update` instead. 'tags': - 'blocked_services' 'operationId': 'blockedServicesSet' @@ -1032,7 +1032,7 @@ 'responses': '200': 'description': 'OK.' - '/blocked_services/schedule': + '/blocked_services/get': 'get': 'tags': - 'blocked_services' @@ -1045,7 +1045,7 @@ 'application/json': 'schema': '$ref': '#/components/schemas/BlockedServicesSchedule' - '/blocked_services/schedule/update': + '/blocked_services/update': 'put': 'tags': - 'blocked_services'