mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-25 22:45:46 +03:00
Pull request: 4387-fix-openapi-schema
Updates #4387. * commit 'f54a2dc1da5dfd578f156cf1e0f53f32516eb844': home: imp filtering handling correct openapi schema
This commit is contained in:
commit
620ad13490
2 changed files with 54 additions and 32 deletions
|
@ -13,6 +13,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghhttp"
|
"github.com/AdguardTeam/AdGuardHome/internal/aghhttp"
|
||||||
|
"github.com/AdguardTeam/golibs/errors"
|
||||||
"github.com/AdguardTeam/golibs/log"
|
"github.com/AdguardTeam/golibs/log"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
@ -57,8 +58,8 @@ func (f *Filtering) handleFilteringAddURL(w http.ResponseWriter, r *http.Request
|
||||||
|
|
||||||
err = validateFilterURL(fj.URL)
|
err = validateFilterURL(fj.URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := fmt.Sprintf("invalid url: %s", err)
|
err = fmt.Errorf("invalid url: %s", err)
|
||||||
http.Error(w, msg, http.StatusBadRequest)
|
aghhttp.Error(r, w, http.StatusBadRequest, "%s", err)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -178,16 +179,16 @@ func (f *Filtering) handleFilteringRemoveURL(w http.ResponseWriter, r *http.Requ
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type filterURLJSON struct {
|
type filterURLReqData struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
Enabled bool `json:"enabled"`
|
Enabled bool `json:"enabled"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type filterURLReq struct {
|
type filterURLReq struct {
|
||||||
URL string `json:"url"`
|
Data *filterURLReqData `json:"data"`
|
||||||
Whitelist bool `json:"whitelist"`
|
URL string `json:"url"`
|
||||||
Data filterURLJSON `json:"data"`
|
Whitelist bool `json:"whitelist"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Filtering) handleFilteringSetURL(w http.ResponseWriter, r *http.Request) {
|
func (f *Filtering) handleFilteringSetURL(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -199,10 +200,17 @@ func (f *Filtering) handleFilteringSetURL(w http.ResponseWriter, r *http.Request
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if fj.Data == nil {
|
||||||
|
err = errors.Error("data cannot be null")
|
||||||
|
aghhttp.Error(r, w, http.StatusBadRequest, "%s", err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
err = validateFilterURL(fj.Data.URL)
|
err = validateFilterURL(fj.Data.URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := fmt.Sprintf("invalid url: %s", err)
|
err = fmt.Errorf("invalid url: %s", err)
|
||||||
http.Error(w, msg, http.StatusBadRequest)
|
aghhttp.Error(r, w, http.StatusBadRequest, "%s", err)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -223,11 +231,8 @@ func (f *Filtering) handleFilteringSetURL(w http.ResponseWriter, r *http.Request
|
||||||
}
|
}
|
||||||
|
|
||||||
onConfigModified()
|
onConfigModified()
|
||||||
restart := false
|
|
||||||
if (status & statusEnabledChanged) != 0 {
|
restart := (status & statusEnabledChanged) != 0
|
||||||
// we must add or remove filter rules
|
|
||||||
restart = true
|
|
||||||
}
|
|
||||||
if (status&statusUpdateRequired) != 0 && fj.Data.Enabled {
|
if (status&statusUpdateRequired) != 0 && fj.Data.Enabled {
|
||||||
// download new filter and apply its rules
|
// download new filter and apply its rules
|
||||||
flags := filterRefreshBlocklists
|
flags := filterRefreshBlocklists
|
||||||
|
@ -242,6 +247,7 @@ func (f *Filtering) handleFilteringSetURL(w http.ResponseWriter, r *http.Request
|
||||||
restart = true
|
restart = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if restart {
|
if restart {
|
||||||
enableFilters(true)
|
enableFilters(true)
|
||||||
}
|
}
|
||||||
|
@ -311,20 +317,20 @@ func (f *Filtering) handleFilteringRefresh(w http.ResponseWriter, r *http.Reques
|
||||||
}
|
}
|
||||||
|
|
||||||
type filterJSON struct {
|
type filterJSON struct {
|
||||||
ID int64 `json:"id"`
|
|
||||||
Enabled bool `json:"enabled"`
|
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
LastUpdated string `json:"last_updated,omitempty"`
|
||||||
|
ID int64 `json:"id"`
|
||||||
RulesCount uint32 `json:"rules_count"`
|
RulesCount uint32 `json:"rules_count"`
|
||||||
LastUpdated string `json:"last_updated"`
|
Enabled bool `json:"enabled"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type filteringConfig struct {
|
type filteringConfig struct {
|
||||||
Enabled bool `json:"enabled"`
|
|
||||||
Interval uint32 `json:"interval"` // in hours
|
|
||||||
Filters []filterJSON `json:"filters"`
|
Filters []filterJSON `json:"filters"`
|
||||||
WhitelistFilters []filterJSON `json:"whitelist_filters"`
|
WhitelistFilters []filterJSON `json:"whitelist_filters"`
|
||||||
UserRules []string `json:"user_rules"`
|
UserRules []string `json:"user_rules"`
|
||||||
|
Interval uint32 `json:"interval"` // in hours
|
||||||
|
Enabled bool `json:"enabled"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func filterToJSON(f filter) filterJSON {
|
func filterToJSON(f filter) filterJSON {
|
||||||
|
@ -402,16 +408,12 @@ func (f *Filtering) handleFilteringConfig(w http.ResponseWriter, r *http.Request
|
||||||
}
|
}
|
||||||
|
|
||||||
type checkHostRespRule struct {
|
type checkHostRespRule struct {
|
||||||
FilterListID int64 `json:"filter_list_id"`
|
|
||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
|
FilterListID int64 `json:"filter_list_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type checkHostResp struct {
|
type checkHostResp struct {
|
||||||
Reason string `json:"reason"`
|
Reason string `json:"reason"`
|
||||||
// FilterID is the ID of the rule's filter list.
|
|
||||||
//
|
|
||||||
// Deprecated: Use Rules[*].FilterListID.
|
|
||||||
FilterID int64 `json:"filter_id"`
|
|
||||||
|
|
||||||
// Rule is the text of the matched rule.
|
// Rule is the text of the matched rule.
|
||||||
//
|
//
|
||||||
|
@ -426,6 +428,11 @@ type checkHostResp struct {
|
||||||
// for Rewrite:
|
// for Rewrite:
|
||||||
CanonName string `json:"cname"` // CNAME value
|
CanonName string `json:"cname"` // CNAME value
|
||||||
IPList []net.IP `json:"ip_addrs"` // list of IP addresses
|
IPList []net.IP `json:"ip_addrs"` // list of IP addresses
|
||||||
|
|
||||||
|
// FilterID is the ID of the rule's filter list.
|
||||||
|
//
|
||||||
|
// Deprecated: Use Rules[*].FilterListID.
|
||||||
|
FilterID int64 `json:"filter_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Filtering) handleCheckHost(w http.ResponseWriter, r *http.Request) {
|
func (f *Filtering) handleCheckHost(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
@ -1396,7 +1396,6 @@
|
||||||
'required':
|
'required':
|
||||||
- 'enabled'
|
- 'enabled'
|
||||||
- 'id'
|
- 'id'
|
||||||
- 'last_updated'
|
|
||||||
- 'name'
|
- 'name'
|
||||||
- 'rules_count'
|
- 'rules_count'
|
||||||
- 'url'
|
- 'url'
|
||||||
|
@ -1434,6 +1433,10 @@
|
||||||
'type': 'array'
|
'type': 'array'
|
||||||
'items':
|
'items':
|
||||||
'$ref': '#/components/schemas/Filter'
|
'$ref': '#/components/schemas/Filter'
|
||||||
|
'whitelist_filters':
|
||||||
|
'type': 'array'
|
||||||
|
'items':
|
||||||
|
'$ref': '#/components/schemas/Filter'
|
||||||
'user_rules':
|
'user_rules':
|
||||||
'type': 'array'
|
'type': 'array'
|
||||||
'items':
|
'items':
|
||||||
|
@ -1451,18 +1454,28 @@
|
||||||
'description': 'Filtering URL settings'
|
'description': 'Filtering URL settings'
|
||||||
'properties':
|
'properties':
|
||||||
'data':
|
'data':
|
||||||
'properties':
|
'$ref': '#/components/schemas/FilterSetUrlData'
|
||||||
'enabled':
|
|
||||||
'type': 'boolean'
|
|
||||||
'name':
|
|
||||||
'type': 'string'
|
|
||||||
'url':
|
|
||||||
'type': 'string'
|
|
||||||
'type': 'object'
|
|
||||||
'url':
|
'url':
|
||||||
'type': 'string'
|
'type': 'string'
|
||||||
'whitelist':
|
'whitelist':
|
||||||
'type': 'boolean'
|
'type': 'boolean'
|
||||||
|
'FilterSetUrlData':
|
||||||
|
'type': 'object'
|
||||||
|
'description': 'Filter update data'
|
||||||
|
'required':
|
||||||
|
- 'enabled'
|
||||||
|
- 'name'
|
||||||
|
- 'url'
|
||||||
|
'properties':
|
||||||
|
'enabled':
|
||||||
|
'type': 'boolean'
|
||||||
|
'name':
|
||||||
|
'example': 'AdGuard Simplified Domain Names filter'
|
||||||
|
'type': 'string'
|
||||||
|
'url':
|
||||||
|
'type': 'string'
|
||||||
|
'example': >
|
||||||
|
https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt
|
||||||
'FilterRefreshRequest':
|
'FilterRefreshRequest':
|
||||||
'type': 'object'
|
'type': 'object'
|
||||||
'description': 'Refresh Filters request data'
|
'description': 'Refresh Filters request data'
|
||||||
|
@ -1860,6 +1873,8 @@
|
||||||
'description': 'Previously added URL containing filtering rules'
|
'description': 'Previously added URL containing filtering rules'
|
||||||
'type': 'string'
|
'type': 'string'
|
||||||
'example': 'https://filters.adtidy.org/windows/filters/15.txt'
|
'example': 'https://filters.adtidy.org/windows/filters/15.txt'
|
||||||
|
'whitelist':
|
||||||
|
'type': 'boolean'
|
||||||
'QueryLogItem':
|
'QueryLogItem':
|
||||||
'type': 'object'
|
'type': 'object'
|
||||||
'description': 'Query log item'
|
'description': 'Query log item'
|
||||||
|
|
Loading…
Reference in a new issue