* API changes

* filtering_info -> filtering/status
* filtering_config -> filtering/config
This commit is contained in:
Simon Zolin 2019-10-14 15:55:58 +03:00
parent bfc6c98109
commit e2c26ec554
4 changed files with 61 additions and 59 deletions

View File

@ -1044,20 +1044,14 @@ We store data for a limited amount of time - the log file is automatically rotat
Request: Request:
POST /control/querylog GET /control/querylog
?older_than=2006-01-02T15:04:05.999999999Z07:00
&filter_domain=...
&filter_client=...
&filter_question_type=A | AAAA
&filter_response_status= | filtered
{ If `older_than` value is set, server returns the next chunk of entries that are older than this time stamp. This setting is used for paging. UI sets the empty value on the first request and gets the latest log entries. To get the older entries, UI sets this value to the timestamp of the last (the oldest) entry from the previous response from Server.
older_than: "2006-01-02T15:04:05.999999999Z07:00" // must be "" for the first request
filter:{
domain: "..."
client: "..."
question_type: "A" | "AAAA"
response_status: "" | "filtered"
}
}
If `older_than` value is set, server returns the next chunk of entries that are older than this time stamp. This setting is used for paging. UI sets this value to `""` on the first request and gets the latest log entries. To get the older entries, UI sets this value to the timestamp of the last (the oldest) entry from the previous response from Server.
If "filter" settings are set, server returns only entries that match the specified request. If "filter" settings are set, server returns only entries that match the specified request.
@ -1143,7 +1137,7 @@ As a result of the update procedure, all enabled filter files are written to dis
Request: Request:
GET /control/filtering_info GET /control/filtering/status
Response: Response:
@ -1171,7 +1165,7 @@ Response:
Request: Request:
POST /control/filtering_config POST /control/filtering/config
{ {
"enabled": true | false "enabled": true | false

View File

@ -204,7 +204,7 @@ type filteringConfig struct {
} }
// Get filtering configuration // Get filtering configuration
func handleFilteringInfo(w http.ResponseWriter, r *http.Request) { func handleFilteringStatus(w http.ResponseWriter, r *http.Request) {
resp := filteringConfig{} resp := filteringConfig{}
config.RLock() config.RLock()
resp.Enabled = config.DNS.FilteringEnabled resp.Enabled = config.DNS.FilteringEnabled
@ -261,8 +261,8 @@ func handleFilteringConfig(w http.ResponseWriter, r *http.Request) {
// RegisterFilteringHandlers - register handlers // RegisterFilteringHandlers - register handlers
func RegisterFilteringHandlers() { func RegisterFilteringHandlers() {
httpRegister(http.MethodGet, "/control/filtering_info", handleFilteringInfo) httpRegister(http.MethodGet, "/control/filtering/status", handleFilteringStatus)
httpRegister(http.MethodPost, "/control/filtering_config", handleFilteringConfig) httpRegister(http.MethodPost, "/control/filtering/config", handleFilteringConfig)
httpRegister(http.MethodPost, "/control/filtering/add_url", handleFilteringAddURL) httpRegister(http.MethodPost, "/control/filtering/add_url", handleFilteringAddURL)
httpRegister(http.MethodPost, "/control/filtering/remove_url", handleFilteringRemoveURL) httpRegister(http.MethodPost, "/control/filtering/remove_url", handleFilteringRemoveURL)
httpRegister(http.MethodPost, "/control/filtering/set_url", handleFilteringSetURL) httpRegister(http.MethodPost, "/control/filtering/set_url", handleFilteringSetURL)

View File

@ -176,16 +176,34 @@ paths:
# -------------------------------------------------- # --------------------------------------------------
/querylog: /querylog:
post: get:
tags: tags:
- log - log
operationId: queryLog operationId: queryLog
summary: 'Get DNS server query log' summary: 'Get DNS server query log'
parameters: parameters:
- in: "body" - name: older_than
name: "body" in: query
schema: type: string
$ref: '#/definitions/QueryLogRequest' - name: filter_domain
in: query
type: string
description: "Filter by domain name"
- name: filter_client
in: query
type: string
description: "Filter by client"
- name: filter_question_type
in: query
type: string
description: "Filter by question type"
- name: filter_response_status
in: query
type: string
description: "Filter by response status"
enum:
-
- filtered
responses: responses:
200: 200:
description: OK description: OK
@ -438,19 +456,19 @@ paths:
# Filtering status methods # Filtering status methods
# -------------------------------------------------- # --------------------------------------------------
/filtering_info: /filtering/status:
get: get:
tags: tags:
- filtering - filtering
operationId: filteringInfo operationId: filteringStatus
summary: 'Get filtering parameters' summary: 'Get filtering parameters'
responses: responses:
200: 200:
description: OK description: OK
schema: schema:
$ref: "#/definitions/FilterInfo" $ref: "#/definitions/FilterStatus"
/filtering_config: /filtering/config:
post: post:
tags: tags:
- filtering - filtering
@ -1063,7 +1081,7 @@ definitions:
type: "string" type: "string"
example: "https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt" example: "https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt"
FilterInfo: FilterStatus:
type: "object" type: "object"
description: "Filtering settings" description: "Filtering settings"
properties: properties:
@ -1400,14 +1418,6 @@ definitions:
items: items:
$ref: "#/definitions/QueryLogItem" $ref: "#/definitions/QueryLogItem"
QueryLogRequest:
type: "object"
description: "Query log request data"
properties:
offset:
type: "integer"
example: 1234
QueryLogConfig: QueryLogConfig:
type: "object" type: "object"
description: "Query log configuration" description: "Query log configuration"

View File

@ -18,16 +18,12 @@ func httpError(r *http.Request, w http.ResponseWriter, code int, format string,
http.Error(w, text, code) http.Error(w, text, code)
} }
type filterJSON struct {
Domain string `json:"domain"`
Client string `json:"client"`
QuestionType string `json:"question_type"`
ResponseStatus string `json:"response_status"`
}
type request struct { type request struct {
OlderThan string `json:"older_than"` olderThan string
Filter filterJSON `json:"filter"` filterDomain string
filterClient string
filterQuestionType string
filterResponseStatus string
} }
// "value" -> value, return TRUE // "value" -> value, return TRUE
@ -41,20 +37,22 @@ func getDoubleQuotesEnclosedValue(s *string) bool {
} }
func (l *queryLog) handleQueryLog(w http.ResponseWriter, r *http.Request) { func (l *queryLog) handleQueryLog(w http.ResponseWriter, r *http.Request) {
var err error
req := request{} req := request{}
err := json.NewDecoder(r.Body).Decode(&req) q := r.URL.Query()
if err != nil { req.olderThan = q.Get("older_than")
httpError(r, w, http.StatusBadRequest, "json decode: %s", err) req.filterDomain = q.Get("filter_domain")
return req.filterClient = q.Get("filter_client")
} req.filterQuestionType = q.Get("filter_question_type")
req.filterResponseStatus = q.Get("filter_response_status")
params := getDataParams{ params := getDataParams{
Domain: req.Filter.Domain, Domain: req.filterDomain,
Client: req.Filter.Client, Client: req.filterClient,
ResponseStatus: responseStatusAll, ResponseStatus: responseStatusAll,
} }
if len(req.OlderThan) != 0 { if len(req.olderThan) != 0 {
params.OlderThan, err = time.Parse(time.RFC3339Nano, req.OlderThan) params.OlderThan, err = time.Parse(time.RFC3339Nano, req.olderThan)
if err != nil { if err != nil {
httpError(r, w, http.StatusBadRequest, "invalid time stamp: %s", err) httpError(r, w, http.StatusBadRequest, "invalid time stamp: %s", err)
return return
@ -68,8 +66,8 @@ func (l *queryLog) handleQueryLog(w http.ResponseWriter, r *http.Request) {
params.StrictMatchClient = true params.StrictMatchClient = true
} }
if len(req.Filter.QuestionType) != 0 { if len(req.filterQuestionType) != 0 {
qtype, ok := dns.StringToType[req.Filter.QuestionType] qtype, ok := dns.StringToType[req.filterQuestionType]
if !ok { if !ok {
httpError(r, w, http.StatusBadRequest, "invalid question_type") httpError(r, w, http.StatusBadRequest, "invalid question_type")
return return
@ -77,8 +75,8 @@ func (l *queryLog) handleQueryLog(w http.ResponseWriter, r *http.Request) {
params.QuestionType = qtype params.QuestionType = qtype
} }
if len(req.Filter.ResponseStatus) != 0 { if len(req.filterResponseStatus) != 0 {
switch req.Filter.ResponseStatus { switch req.filterResponseStatus {
case "filtered": case "filtered":
params.ResponseStatus = responseStatusFiltered params.ResponseStatus = responseStatusFiltered
default: default:
@ -155,7 +153,7 @@ func (l *queryLog) handleQueryLogConfig(w http.ResponseWriter, r *http.Request)
// Register web handlers // Register web handlers
func (l *queryLog) initWeb() { func (l *queryLog) initWeb() {
l.conf.HTTPRegister("POST", "/control/querylog", l.handleQueryLog) l.conf.HTTPRegister("GET", "/control/querylog", l.handleQueryLog)
l.conf.HTTPRegister("GET", "/control/querylog_info", l.handleQueryLogInfo) l.conf.HTTPRegister("GET", "/control/querylog_info", l.handleQueryLogInfo)
l.conf.HTTPRegister("POST", "/control/querylog_clear", l.handleQueryLogClear) l.conf.HTTPRegister("POST", "/control/querylog_clear", l.handleQueryLogClear)
l.conf.HTTPRegister("POST", "/control/querylog_config", l.handleQueryLogConfig) l.conf.HTTPRegister("POST", "/control/querylog_config", l.handleQueryLogConfig)