From fcf609ac1e316140ea92410cb24498a7f2885112 Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Mon, 3 Jun 2019 11:52:39 +0300 Subject: [PATCH 1/4] - openapi: fix /add_url --- openapi/openapi.yaml | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/openapi/openapi.yaml b/openapi/openapi.yaml index 318849b0..1f3897ab 100644 --- a/openapi/openapi.yaml +++ b/openapi/openapi.yaml @@ -466,15 +466,13 @@ paths: operationId: filteringAddURL summary: 'Add filter URL' consumes: - - text/plain + - application/json parameters: - - in: body - name: url - description: 'URL containing filtering rules' - required: true - schema: - type: string - example: 'url=https://filters.adtidy.org/windows/filters/15.txt' + - in: "body" + name: "body" + required: true + schema: + $ref: "#/definitions/AddUrlRequest" responses: 200: description: OK @@ -1290,6 +1288,16 @@ definitions: type: type: "string" example: "A" + AddUrlRequest: + type: "object" + description: "/add_url request data" + properties: + name: + type: "string" + url: + description: "URL containing filtering rules" + type: "string" + example: "https://filters.adtidy.org/windows/filters/15.txt" QueryLogItem: type: "object" description: "Query log item" From 276d87a218c03413639f624270ec832906623669 Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Mon, 3 Jun 2019 11:21:57 +0300 Subject: [PATCH 2/4] - openapi: correct format --- openapi/openapi.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openapi/openapi.yaml b/openapi/openapi.yaml index 1f3897ab..d31f937f 100644 --- a/openapi/openapi.yaml +++ b/openapi/openapi.yaml @@ -144,7 +144,7 @@ paths: - 'application/json' responses: 200: - description: 'Version info. If response message is empty, UI doesn't show a version update message.' + description: 'Version info. If response message is empty, UI does not show a version update message.' schema: $ref: "#/definitions/VersionInfo" 500: From c93cb43db856e43df2013d758c8c2b90391fdcc4 Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Mon, 3 Jun 2019 12:03:45 +0300 Subject: [PATCH 3/4] * /remove_url: use JSON input data format --- control.go | 19 +++++++++---------- openapi/openapi.yaml | 22 ++++++++++++++-------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/control.go b/control.go index 77970de2..5e8f0e7a 100644 --- a/control.go +++ b/control.go @@ -676,19 +676,18 @@ func handleFilteringAddURL(w http.ResponseWriter, r *http.Request) { func handleFilteringRemoveURL(w http.ResponseWriter, r *http.Request) { log.Tracef("%s %v", r.Method, r.URL) - parameters, err := parseParametersFromBody(r.Body) + + type request struct { + URL string `json:"url"` + } + req := request{} + err := json.NewDecoder(r.Body).Decode(&req) if err != nil { - httpError(w, http.StatusBadRequest, "failed to parse parameters from body: %s", err) + httpError(w, http.StatusBadRequest, "Failed to parse request body json: %s", err) return } - url, ok := parameters["url"] - if !ok { - http.Error(w, "URL parameter was not specified", http.StatusBadRequest) - return - } - - if valid := govalidator.IsRequestURL(url); !valid { + if valid := govalidator.IsRequestURL(req.URL); !valid { http.Error(w, "URL parameter is not valid request URL", http.StatusBadRequest) return } @@ -697,7 +696,7 @@ func handleFilteringRemoveURL(w http.ResponseWriter, r *http.Request) { config.Lock() newFilters := config.Filters[:0] for _, filter := range config.Filters { - if filter.URL != url { + if filter.URL != req.URL { newFilters = append(newFilters, filter) } else { // Remove the filter file diff --git a/openapi/openapi.yaml b/openapi/openapi.yaml index d31f937f..385ac057 100644 --- a/openapi/openapi.yaml +++ b/openapi/openapi.yaml @@ -484,15 +484,13 @@ paths: operationId: filteringRemoveURL summary: 'Remove filter URL' consumes: - - text/plain + - application/json parameters: - - in: body - name: url - description: 'Previously added URL containing filtering rules' - required: true - schema: - type: string - example: 'url=https://filters.adtidy.org/windows/filters/15.txt' + - in: "body" + name: "body" + required: true + schema: + $ref: "#/definitions/RemoveUrlRequest" responses: 200: description: OK @@ -1298,6 +1296,14 @@ definitions: description: "URL containing filtering rules" type: "string" example: "https://filters.adtidy.org/windows/filters/15.txt" + RemoveUrlRequest: + type: "object" + description: "/remove_url request data" + properties: + url: + description: "Previously added URL containing filtering rules" + type: "string" + example: "https://filters.adtidy.org/windows/filters/15.txt" QueryLogItem: type: "object" description: "Query log item" From 7f5ac19b592c2a63e52a5e5319e9e8eb687c7410 Mon Sep 17 00:00:00 2001 From: Ildar Kamalov Date: Mon, 3 Jun 2019 16:33:15 +0300 Subject: [PATCH 4/4] * client: use JSON for filtering/remove_url --- client/src/__locales/en.json | 1 + client/src/api/Api.js | 21 ++++++++++----------- client/src/components/Filters/index.js | 9 ++++++++- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/client/src/__locales/en.json b/client/src/__locales/en.json index 697dbbcd..d5526750 100644 --- a/client/src/__locales/en.json +++ b/client/src/__locales/en.json @@ -297,6 +297,7 @@ "table_statistics": "Requests count (last 24 hours)", "clients_not_found": "No clients found", "client_confirm_delete": "Are you sure you want to delete client \"{{key}}\"?", + "filter_confirm_delete": "Are you sure you want to delete filter?", "auto_clients_title": "Clients (runtime)", "auto_clients_desc": "Data on the clients that use AdGuard Home, but not stored in the configuration" } \ No newline at end of file diff --git a/client/src/api/Api.js b/client/src/api/Api.js index 81bce7cf..d07772a7 100644 --- a/client/src/api/Api.js +++ b/client/src/api/Api.js @@ -188,15 +188,14 @@ export default class Api { return this.makeRequest(path, method, config); } - removeFilter(url) { + removeFilter(config) { const { path, method } = this.FILTERING_REMOVE_FILTER; - const parameter = 'url'; - const requestBody = `${parameter}=${url}`; - const config = { - data: requestBody, - header: { 'Content-Type': 'text/plain' }, + const parameters = { + data: config, + headers: { 'Content-Type': 'application/json' }, }; - return this.makeRequest(path, method, config); + + return this.makeRequest(path, method, parameters); } setRules(rules) { @@ -424,10 +423,10 @@ export default class Api { } // Per-client settings - GET_CLIENTS = { path: 'clients', method: 'GET' } - ADD_CLIENT = { path: 'clients/add', method: 'POST' } - DELETE_CLIENT = { path: 'clients/delete', method: 'POST' } - UPDATE_CLIENT = { path: 'clients/update', method: 'POST' } + GET_CLIENTS = { path: 'clients', method: 'GET' }; + ADD_CLIENT = { path: 'clients/add', method: 'POST' }; + DELETE_CLIENT = { path: 'clients/delete', method: 'POST' }; + UPDATE_CLIENT = { path: 'clients/update', method: 'POST' }; getClients() { const { path, method } = this.GET_CLIENTS; diff --git a/client/src/components/Filters/index.js b/client/src/components/Filters/index.js index 624c9f2f..efa67e59 100644 --- a/client/src/components/Filters/index.js +++ b/client/src/components/Filters/index.js @@ -32,6 +32,13 @@ class Filters extends Component { ); }; + handleDelete = (url) => { + // eslint-disable-next-line no-alert + if (window.confirm(this.props.t('filter_confirm_delete'))) { + this.props.removeFilter({ url }); + } + } + columns = [{ Header: enabled_table_header, accessor: 'enabled', @@ -62,7 +69,7 @@ class Filters extends Component {