From e2c26ec554e4cf38b424fc02c1369a6768ef78ab Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Mon, 14 Oct 2019 15:55:58 +0300 Subject: [PATCH] * API changes * filtering_info -> filtering/status * filtering_config -> filtering/config --- AGHTechDoc.md | 24 ++++++++------------ home/control_filtering.go | 6 ++--- openapi/openapi.yaml | 46 ++++++++++++++++++++++++--------------- querylog/qlog_http.go | 44 ++++++++++++++++++------------------- 4 files changed, 61 insertions(+), 59 deletions(-) diff --git a/AGHTechDoc.md b/AGHTechDoc.md index c6e70391..adf483d0 100644 --- a/AGHTechDoc.md +++ b/AGHTechDoc.md @@ -1044,20 +1044,14 @@ We store data for a limited amount of time - the log file is automatically rotat 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 - { - 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 `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. 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: - GET /control/filtering_info + GET /control/filtering/status Response: @@ -1171,7 +1165,7 @@ Response: Request: - POST /control/filtering_config + POST /control/filtering/config { "enabled": true | false diff --git a/home/control_filtering.go b/home/control_filtering.go index 2eddaf13..92a0a01b 100644 --- a/home/control_filtering.go +++ b/home/control_filtering.go @@ -204,7 +204,7 @@ type filteringConfig struct { } // Get filtering configuration -func handleFilteringInfo(w http.ResponseWriter, r *http.Request) { +func handleFilteringStatus(w http.ResponseWriter, r *http.Request) { resp := filteringConfig{} config.RLock() resp.Enabled = config.DNS.FilteringEnabled @@ -261,8 +261,8 @@ func handleFilteringConfig(w http.ResponseWriter, r *http.Request) { // RegisterFilteringHandlers - register handlers func RegisterFilteringHandlers() { - httpRegister(http.MethodGet, "/control/filtering_info", handleFilteringInfo) - httpRegister(http.MethodPost, "/control/filtering_config", handleFilteringConfig) + httpRegister(http.MethodGet, "/control/filtering/status", handleFilteringStatus) + httpRegister(http.MethodPost, "/control/filtering/config", handleFilteringConfig) httpRegister(http.MethodPost, "/control/filtering/add_url", handleFilteringAddURL) httpRegister(http.MethodPost, "/control/filtering/remove_url", handleFilteringRemoveURL) httpRegister(http.MethodPost, "/control/filtering/set_url", handleFilteringSetURL) diff --git a/openapi/openapi.yaml b/openapi/openapi.yaml index ffb7fc4a..36df7793 100644 --- a/openapi/openapi.yaml +++ b/openapi/openapi.yaml @@ -176,16 +176,34 @@ paths: # -------------------------------------------------- /querylog: - post: + get: tags: - log operationId: queryLog summary: 'Get DNS server query log' parameters: - - in: "body" - name: "body" - schema: - $ref: '#/definitions/QueryLogRequest' + - name: older_than + in: query + type: string + - 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: 200: description: OK @@ -438,19 +456,19 @@ paths: # Filtering status methods # -------------------------------------------------- - /filtering_info: + /filtering/status: get: tags: - filtering - operationId: filteringInfo + operationId: filteringStatus summary: 'Get filtering parameters' responses: 200: description: OK schema: - $ref: "#/definitions/FilterInfo" + $ref: "#/definitions/FilterStatus" - /filtering_config: + /filtering/config: post: tags: - filtering @@ -1063,7 +1081,7 @@ definitions: type: "string" example: "https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt" - FilterInfo: + FilterStatus: type: "object" description: "Filtering settings" properties: @@ -1400,14 +1418,6 @@ definitions: items: $ref: "#/definitions/QueryLogItem" - QueryLogRequest: - type: "object" - description: "Query log request data" - properties: - offset: - type: "integer" - example: 1234 - QueryLogConfig: type: "object" description: "Query log configuration" diff --git a/querylog/qlog_http.go b/querylog/qlog_http.go index 1b06abc9..d48cd053 100644 --- a/querylog/qlog_http.go +++ b/querylog/qlog_http.go @@ -18,16 +18,12 @@ func httpError(r *http.Request, w http.ResponseWriter, code int, format string, 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 { - OlderThan string `json:"older_than"` - Filter filterJSON `json:"filter"` + olderThan string + filterDomain string + filterClient string + filterQuestionType string + filterResponseStatus string } // "value" -> value, return TRUE @@ -41,20 +37,22 @@ func getDoubleQuotesEnclosedValue(s *string) bool { } func (l *queryLog) handleQueryLog(w http.ResponseWriter, r *http.Request) { + var err error req := request{} - err := json.NewDecoder(r.Body).Decode(&req) - if err != nil { - httpError(r, w, http.StatusBadRequest, "json decode: %s", err) - return - } + q := r.URL.Query() + req.olderThan = q.Get("older_than") + req.filterDomain = q.Get("filter_domain") + req.filterClient = q.Get("filter_client") + req.filterQuestionType = q.Get("filter_question_type") + req.filterResponseStatus = q.Get("filter_response_status") params := getDataParams{ - Domain: req.Filter.Domain, - Client: req.Filter.Client, + Domain: req.filterDomain, + Client: req.filterClient, ResponseStatus: responseStatusAll, } - if len(req.OlderThan) != 0 { - params.OlderThan, err = time.Parse(time.RFC3339Nano, req.OlderThan) + if len(req.olderThan) != 0 { + params.OlderThan, err = time.Parse(time.RFC3339Nano, req.olderThan) if err != nil { httpError(r, w, http.StatusBadRequest, "invalid time stamp: %s", err) return @@ -68,8 +66,8 @@ func (l *queryLog) handleQueryLog(w http.ResponseWriter, r *http.Request) { params.StrictMatchClient = true } - if len(req.Filter.QuestionType) != 0 { - qtype, ok := dns.StringToType[req.Filter.QuestionType] + if len(req.filterQuestionType) != 0 { + qtype, ok := dns.StringToType[req.filterQuestionType] if !ok { httpError(r, w, http.StatusBadRequest, "invalid question_type") return @@ -77,8 +75,8 @@ func (l *queryLog) handleQueryLog(w http.ResponseWriter, r *http.Request) { params.QuestionType = qtype } - if len(req.Filter.ResponseStatus) != 0 { - switch req.Filter.ResponseStatus { + if len(req.filterResponseStatus) != 0 { + switch req.filterResponseStatus { case "filtered": params.ResponseStatus = responseStatusFiltered default: @@ -155,7 +153,7 @@ func (l *queryLog) handleQueryLogConfig(w http.ResponseWriter, r *http.Request) // Register web handlers 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("POST", "/control/querylog_clear", l.handleQueryLogClear) l.conf.HTTPRegister("POST", "/control/querylog_config", l.handleQueryLogConfig)