diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d81e05e..6bab4254 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ NOTE: Add new changes BELOW THIS COMMENT. ### Added +- New fields `"groups"` and `"group_id"` added to the HTTP API (`GET /control/blocked_services/all`). See `openapi/openapi.yaml` for the full description. +- The *HaGeZi's DNS Rebind Protection* filter for protecting against DNS rebinding attacks ([#102]). - Support for configuring the suggested default HTTP port for the installation wizard via the `ADGUARD_HOME_DEFAULT_WEB_PORT` environment variable (useful for vendors). ### Changed @@ -31,6 +33,7 @@ NOTE: Add new changes BELOW THIS COMMENT. - Excessive configuration file overwrites when visiting the Web UI and a non-empty `language` is set. - Lowered the severity of log messages for failed deletion of old filter files ([#7964]). +[#102]: https://github.com/AdguardTeam/AdGuardHome/issues/102 [#7964]: https://github.com/AdguardTeam/AdGuardHome/issues/7964 -## v0.108.0: API changes +## v0.107.67: API changes + +- The new field `"groups"` in `GET /control/blocked_services/all` is a list of service group. Groups make it possible to block multiple services with equal `"group_id"` at once. + +- The new field `"group_id"` for each `BlockedService` object in `GET /control/blocked_services/all` indicates which group the service belongs to. ## v0.107.64: API changes diff --git a/openapi/openapi.yaml b/openapi/openapi.yaml index ba7b1b3b..aa252a5c 100644 --- a/openapi/openapi.yaml +++ b/openapi/openapi.yaml @@ -3012,8 +3012,12 @@ 'items': '$ref': '#/components/schemas/BlockedService' 'type': 'array' + 'groups': + 'items': + '$ref': '#/components/schemas/ServiceGroup' 'required': - 'blocked_services' + - 'groups' 'type': 'object' 'BlockedService': 'properties': @@ -3036,12 +3040,25 @@ 'items': 'type': 'string' 'type': 'array' + 'group_id': + 'description': > + The ID of the group, that the service belongs to. + 'type': 'string' 'required': - 'icon_svg' - 'id' - 'name' - 'rules' 'type': 'object' + 'ServiceGroup': + 'properties': + 'id': + 'description': > + The ID of this group. + 'type': 'string' + 'required': + - 'id' + 'type': 'object' 'BlockedServicesSchedule': 'type': 'object' 'properties': diff --git a/scripts/blocked-services/main.go b/scripts/blocked-services/main.go index 27c52d9f..3e0f5d8c 100644 --- a/scripts/blocked-services/main.go +++ b/scripts/blocked-services/main.go @@ -86,6 +86,12 @@ type blockedService struct { Name string ` + "`" + `json:"name"` + "`" + ` IconSVG []byte ` + "`" + `json:"icon_svg"` + "`" + ` Rules []string ` + "`" + `json:"rules"` + "`" + ` + GroupID string ` + "`" + `json:"group_id"` + "`" + ` +} + +// serviceGroup represents single group of services. +type serviceGroup struct { + ID string ` + "`" + `json:"id"` + "`" + ` } // blockedServices contains raw blocked service data. @@ -97,6 +103,13 @@ var blockedServices = []blockedService{<% $l := len .BlockedServices %> Rules: []string{<% range $s.Rules %> <% printf "%q" . %>,<% end %> }, + GroupID: <% printf "%q" $s.Group %>, +}<% if isnotlast $i $l %>, <% end %><% end %>} + +// serviceGroups contains raw service group data. +var serviceGroups = []serviceGroup{<% $l := len .ServiceGroups %> + <%- range $i, $s := .ServiceGroups %>{ + ID: <% printf "%q" $s.ID %>, }<% if isnotlast $i $l %>, <% end %><% end %>} ` @@ -104,6 +117,7 @@ var blockedServices = []blockedService{<% $l := len .BlockedServices %> // index. type hlServices struct { BlockedServices []*hlServicesService `json:"blocked_services"` + ServiceGroups []*hlServicesGroup `json:"groups"` } // hlServicesService is the JSON structure for a service in the Hostlists @@ -113,4 +127,11 @@ type hlServicesService struct { Name string `json:"name"` IconSVG string `json:"icon_svg"` Rules []string `json:"rules"` + Group string `json:"group"` +} + +// hlServicesGroup is the JSON structure for a service group in the Hostlists +// Registry. +type hlServicesGroup struct { + ID string `json:"id"` } diff --git a/scripts/install.sh b/scripts/install.sh index be7575d5..fa5a323b 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -301,7 +301,7 @@ fix_darwin() { # Function fix_freebsd performs some fixes to make it work on FreeBSD. fix_freebsd() { - if ! [ "$os" = 'freebsd' ]; then + if [ "$os" != 'freebsd' ]; then return 0 fi diff --git a/scripts/make/go-lint.sh b/scripts/make/go-lint.sh index 2e2448ac..400c7449 100644 --- a/scripts/make/go-lint.sh +++ b/scripts/make/go-lint.sh @@ -180,13 +180,10 @@ run_linter gocognit --over='14' \ ./internal/dhcpd \ ; -run_linter gocognit --over='13' \ - ./internal/aghnet/ \ - ; - run_linter gocognit --over='10' \ ./internal/aghalg/ \ ./internal/aghhttp/ \ + ./internal/aghnet/ \ ./internal/aghos/ \ ./internal/aghrenameio/ \ ./internal/aghtest/ \ diff --git a/scripts/translations/download.go b/scripts/translations/download.go index 3e27c642..df05d5e4 100644 --- a/scripts/translations/download.go +++ b/scripts/translations/download.go @@ -17,6 +17,7 @@ import ( "github.com/AdguardTeam/golibs/errors" "github.com/AdguardTeam/golibs/ioutil" "github.com/AdguardTeam/golibs/logutil/slogutil" + "github.com/AdguardTeam/golibs/syncutil" ) // download and save all translations. @@ -47,7 +48,7 @@ func (c *twoskyClient) download(ctx context.Context, l *slog.Logger) (err error) dw := &downloadWorker{ ctx: ctx, l: l, - failed: &sync.Map{}, + failed: syncutil.NewMap[string, struct{}](), client: &http.Client{ Timeout: 10 * time.Second, }, @@ -72,25 +73,24 @@ func (c *twoskyClient) download(ctx context.Context, l *slog.Logger) (err error) return nil } -// printFailedLocales prints sorted list of failed downloads, if any. -func printFailedLocales(ctx context.Context, l *slog.Logger, failed *sync.Map) { - keys := []string{} - failed.Range(func(k, _ any) bool { - s, ok := k.(string) - if !ok { - panic("unexpected type") - } - - keys = append(keys, s) - - return true - }) +// printFailedLocales prints sorted list of failed downloads, if any. l and +// failed must not be nil. +func printFailedLocales( + ctx context.Context, + l *slog.Logger, + failed *syncutil.Map[string, struct{}], +) { + var keys []string + for k := range failed.Range { + keys = append(keys, k) + } if len(keys) == 0 { return } slices.Sort(keys) + l.InfoContext(ctx, "failed", "locales", keys) } @@ -100,7 +100,7 @@ func printFailedLocales(ctx context.Context, l *slog.Logger, failed *sync.Map) { type downloadWorker struct { ctx context.Context l *slog.Logger - failed *sync.Map + failed *syncutil.Map[string, struct{}] client *http.Client uriCh <-chan *url.URL }