Skip to content

Commit

Permalink
all: document changes, improve api
Browse files Browse the repository at this point in the history
  • Loading branch information
ainar-g committed Dec 16, 2020
1 parent bc59b76 commit 4f04845
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to

### Added

- The host checking API and the query logs API can now return multiple mached
rules ([#2102]).
- Detecting of network interface configurated to have static IP address via
`/etc/network/interfaces` ([#2302]).
- DNSCrypt protocol support ([#1361]).
Expand All @@ -24,6 +26,7 @@ and this project adheres to
- HTTP API request body size limit ([#2305]).

[#1361]: https://github.com/AdguardTeam/AdGuardHome/issues/1361
[#2102]: https://github.com/AdguardTeam/AdGuardHome/issues/2102
[#2302]: https://github.com/AdguardTeam/AdGuardHome/issues/2302
[#2304]: https://github.com/AdguardTeam/AdGuardHome/issues/2304
[#2305]: https://github.com/AdguardTeam/AdGuardHome/issues/2305
Expand Down
18 changes: 15 additions & 3 deletions internal/home/controlfiltering.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"strings"
"time"

"github.com/AdguardTeam/AdGuardHome/internal/dnsfilter"
"github.com/AdguardTeam/AdGuardHome/internal/util"
"github.com/AdguardTeam/golibs/log"
"github.com/miekg/dns"
Expand Down Expand Up @@ -347,6 +346,11 @@ func (f *Filtering) handleFilteringConfig(w http.ResponseWriter, r *http.Request
enableFilters(true)
}

type checkHostRespRule struct {
FilterListID int64 `json:"filter_list_id"`
Text string `json:"text"`
}

type checkHostResp struct {
Reason string `json:"reason"`

Expand All @@ -357,7 +361,7 @@ type checkHostResp struct {

Rule string `json:"rule"`

Rules []*dnsfilter.ResultRule `json:"rules"`
Rules []*checkHostRespRule `json:"rules"`

// for FilteredBlockedService:
SvcName string `json:"service_name"`
Expand All @@ -384,10 +388,18 @@ func (f *Filtering) handleCheckHost(w http.ResponseWriter, r *http.Request) {
resp.Reason = result.Reason.String()
resp.FilterID = result.Rules[0].FilterListID
resp.Rule = result.Rules[0].Text
resp.Rules = result.Rules
resp.SvcName = result.ServiceName
resp.CanonName = result.CanonName
resp.IPList = result.IPList

resp.Rules = make([]*checkHostRespRule, len(result.Rules))
for i, r := range result.Rules {
resp.Rules[i] = &checkHostRespRule{
FilterListID: r.FilterListID,
Text: r.Text,
}
}

js, err := json.Marshal(resp)
if err != nil {
httpError(w, http.StatusInternalServerError, "json encode: %s", err)
Expand Down
18 changes: 17 additions & 1 deletion openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1259,11 +1259,26 @@
- 'FilteredBlockedService'
- 'ReasonRewrite'
'filter_id':
'deprecated': true
'description': >
In case if there's a rule applied to this DNS request, this is ID of
the filter list that the rule belongs to.
Deprecated: use `rules[*].filter_list_id` instead.
'type': 'integer'
'rule':
'deprecated': true
'type': 'string'
'example': '||example.org^'
'description': 'Filtering rule applied to the request (if any)'
'description': >
Filtering rule applied to the request (if any).
Deprecated: use `rules[*].text` instead.
'rules':
'description': 'Applied rules.'
'type': 'array'
'items':
'$ref': '#/components/schemas/ResultRule'
'service_name':
'type': 'string'
'description': 'Set if reason=FilteredBlockedService'
Expand Down Expand Up @@ -1688,6 +1703,7 @@
In case if there's a rule applied to this DNS request, this is ID of
the filter list that the rule belongs to.
'example': 123123
'format': 'int64'
'type': 'integer'
'text':
'description': >
Expand Down

0 comments on commit 4f04845

Please sign in to comment.