* 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:
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

View File

@ -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)

View File

@ -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"

View File

@ -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)