From 5be66e7dc7d3e1729dc4604ea5b6fcd075ae613d Mon Sep 17 00:00:00 2001 From: Ildar Kamalov Date: Thu, 11 Oct 2018 12:53:15 +0300 Subject: [PATCH 1/6] Add name field to the filter subscription dialog --- client/src/actions/index.js | 4 +-- client/src/api/Api.js | 7 +++-- client/src/components/ui/Modal.js | 46 +++++++++++++++++++++---------- 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/client/src/actions/index.js b/client/src/actions/index.js index 7a28a600..396f9136 100644 --- a/client/src/actions/index.js +++ b/client/src/actions/index.js @@ -398,10 +398,10 @@ export const addFilterRequest = createAction('ADD_FILTER_REQUEST'); export const addFilterFailure = createAction('ADD_FILTER_FAILURE'); export const addFilterSuccess = createAction('ADD_FILTER_SUCCESS'); -export const addFilter = url => async (dispatch) => { +export const addFilter = (url, name) => async (dispatch) => { dispatch(addFilterRequest()); try { - await apiClient.addFilter(url); + await apiClient.addFilter(url, name); dispatch(addFilterSuccess(url)); dispatch(getFilteringStatus()); } catch (error) { diff --git a/client/src/api/Api.js b/client/src/api/Api.js index 636b0ddd..f24d8add 100644 --- a/client/src/api/Api.js +++ b/client/src/api/Api.js @@ -167,10 +167,11 @@ export default class Api { return this.makeRequest(path, method); } - addFilter(url) { + addFilter(url, name) { const { path, method } = this.FILTERING_ADD_FILTER; - const parameter = 'url'; - const requestBody = `${parameter}=${url}`; + const urlParameter = 'url'; + const nameParameter = 'name'; + const requestBody = `${urlParameter}=${url}&${nameParameter}=${name}`; const config = { data: requestBody, header: { 'Content-Type': 'text/plain' }, diff --git a/client/src/components/ui/Modal.js b/client/src/components/ui/Modal.js index 3b39e52a..cc7cca25 100644 --- a/client/src/components/ui/Modal.js +++ b/client/src/components/ui/Modal.js @@ -7,11 +7,14 @@ import './Modal.css'; ReactModal.setAppElement('#root'); +const initialState = { + url: '', + name: '', + isUrlValid: false, +}; + export default class Modal extends Component { - state = { - url: '', - isUrlValid: false, - }; + state = initialState; // eslint-disable-next-line isUrlValid = url => { @@ -27,33 +30,48 @@ export default class Modal extends Component { } }; + handleNameChange = (e) => { + const { value: name } = e.currentTarget; + this.setState({ ...this.state, name }); + }; + handleNext = () => { - this.props.addFilter(this.state.url); + this.props.addFilter(this.state.url, this.state.name); setTimeout(() => { if (this.props.isFilterAdded) { - this.props.toggleModal(); + this.closeModal(); } }, 2000); }; + + closeModal = () => { + this.props.toggleModal(); + this.setState({ ...this.state, ...initialState }); + } + render() { const { isOpen, - toggleModal, title, inputDescription, } = this.props; - const { isUrlValid, url } = this.state; - const inputClass = classnames({ + const { isUrlValid, url, name } = this.state; + const inputUrlClass = classnames({ 'form-control mb-2': true, 'is-invalid': url.length > 0 && !isUrlValid, 'is-valid': url.length > 0 && isUrlValid, }); + const inputNameClass = classnames({ + 'form-control mb-2': true, + 'is-valid': name.length > 0, + }); const renderBody = () => { if (!this.props.isFilterAdded) { return ( - + + {inputDescription &&
{inputDescription} @@ -68,21 +86,21 @@ export default class Modal extends Component { ); }; - const isValidForSubmit = !(url.length > 0 && isUrlValid); + const isValidForSubmit = !(url.length > 0 && isUrlValid && name.length > 0); return (

{title}

-
@@ -92,7 +110,7 @@ export default class Modal extends Component { { !this.props.isFilterAdded &&
- +
} From 4b8ee9ce83941b0ac2c42469d9bfa0505f5b90c7 Mon Sep 17 00:00:00 2001 From: Ildar Kamalov Date: Thu, 11 Oct 2018 13:02:14 +0300 Subject: [PATCH 2/6] Fix params --- client/src/api/Api.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/client/src/api/Api.js b/client/src/api/Api.js index f24d8add..c194ddfa 100644 --- a/client/src/api/Api.js +++ b/client/src/api/Api.js @@ -169,9 +169,7 @@ export default class Api { addFilter(url, name) { const { path, method } = this.FILTERING_ADD_FILTER; - const urlParameter = 'url'; - const nameParameter = 'name'; - const requestBody = `${urlParameter}=${url}&${nameParameter}=${name}`; + const requestBody = `url=${url}&name=${name}`; const config = { data: requestBody, header: { 'Content-Type': 'text/plain' }, From 1e18235c1d007c19913d8151205d1145eed35769 Mon Sep 17 00:00:00 2001 From: Ildar Kamalov Date: Thu, 11 Oct 2018 15:27:01 +0300 Subject: [PATCH 3/6] Send json for addFilter request --- client/src/api/Api.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/client/src/api/Api.js b/client/src/api/Api.js index c194ddfa..0e9a1c74 100644 --- a/client/src/api/Api.js +++ b/client/src/api/Api.js @@ -169,10 +169,11 @@ export default class Api { addFilter(url, name) { const { path, method } = this.FILTERING_ADD_FILTER; - const requestBody = `url=${url}&name=${name}`; const config = { - data: requestBody, - header: { 'Content-Type': 'text/plain' }, + data: { + name, + url, + }, }; return this.makeRequest(path, method, config); } From 33958c5a2585218fbcef941b97b6a0cb0f58e8c9 Mon Sep 17 00:00:00 2001 From: Ildar Kamalov Date: Thu, 11 Oct 2018 15:56:46 +0300 Subject: [PATCH 4/6] Remove unused module --- client/package-lock.json | 62 ++++------------------------------------ client/package.json | 1 - 2 files changed, 5 insertions(+), 58 deletions(-) diff --git a/client/package-lock.json b/client/package-lock.json index 7c27b39b..f1ffff54 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -1559,6 +1559,7 @@ "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", "integrity": "sha1-llxwWGaOgrVde/4E/yM3vItWR/4=", + "dev": true, "requires": { "core-js": "^2.4.0", "regenerator-runtime": "^0.11.0" @@ -1567,7 +1568,8 @@ "core-js": { "version": "2.5.7", "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.7.tgz", - "integrity": "sha512-RszJCAxg/PP6uzXVXL6BsxSXx/B05oJAQ2vkJRjyjrEcNVycaqOmNb5OTxZPE3xa5gwZduqza6L9JOCenh/Ecw==" + "integrity": "sha512-RszJCAxg/PP6uzXVXL6BsxSXx/B05oJAQ2vkJRjyjrEcNVycaqOmNb5OTxZPE3xa5gwZduqza6L9JOCenh/Ecw==", + "dev": true } } }, @@ -3074,15 +3076,6 @@ "sha.js": "^2.4.8" } }, - "create-react-context": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/create-react-context/-/create-react-context-0.2.3.tgz", - "integrity": "sha512-CQBmD0+QGgTaxDL3OX1IDXYqjkp2It4RIbcb99jS6AEg27Ga+a9G3JtK6SIu0HBwPLZlmwt9F7UwWA4Bn92Rag==", - "requires": { - "fbjs": "^0.8.0", - "gud": "^1.0.0" - } - }, "cross-spawn": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", @@ -6203,11 +6196,6 @@ "integrity": "sha1-8QdIy+dq+WS3yWyTxrzCivEgwIE=", "dev": true }, - "gud": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/gud/-/gud-1.0.0.tgz", - "integrity": "sha512-zGEOVKFM5sVPPrYs7J5/hYEw2Pof8KCyOwyhG8sAF26mCAeUFAcYPu1mwB7hhpIP29zOIBaDqwuHdLp0jvZXjw==" - }, "handle-thing": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/handle-thing/-/handle-thing-1.2.5.tgz", @@ -9752,11 +9740,6 @@ "integrity": "sha512-ARhBOdzS3e41FbkW/XWrTEtukqqLoK5+Z/4UeDaLuSW+39JPeFgs4gCGqsrJHVZX0fUrx//4OF0K1CUGwlIFow==", "dev": true }, - "popper.js": { - "version": "1.14.4", - "resolved": "https://registry.npmjs.org/popper.js/-/popper.js-1.14.4.tgz", - "integrity": "sha1-juwdj/AqWjoVLdQ0FKFce3n9abY=" - }, "portfinder": { "version": "1.0.17", "resolved": "https://registry.npmjs.org/portfinder/-/portfinder-1.0.17.tgz", @@ -12869,19 +12852,6 @@ "raf": "^3.1.0" } }, - "react-popper": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/react-popper/-/react-popper-1.0.2.tgz", - "integrity": "sha512-vjZ94ki8sfCAg45MMi4uqnUUWdzbnYkb95sR2+HgiMaAPzQcy4DfDKYtYUOhhE+sdtkufWcUHLv09DmH2Js57w==", - "requires": { - "babel-runtime": "6.x.x", - "create-react-context": "^0.2.1", - "popper.js": "^1.14.1", - "prop-types": "^15.6.1", - "typed-styles": "^0.0.5", - "warning": "^3.0.0" - } - }, "react-redux": { "version": "5.0.7", "resolved": "https://registry.npmjs.org/react-redux/-/react-redux-5.0.7.tgz", @@ -12959,14 +12929,6 @@ "classnames": "^2.2.5" } }, - "react-text-mask": { - "version": "5.4.3", - "resolved": "https://registry.npmjs.org/react-text-mask/-/react-text-mask-5.4.3.tgz", - "integrity": "sha1-mR77QpnjDC5sLEbRP2FxaUY+DS0=", - "requires": { - "prop-types": "^15.5.6" - } - }, "react-transition-group": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/react-transition-group/-/react-transition-group-2.4.0.tgz", @@ -13147,7 +13109,8 @@ "regenerator-runtime": { "version": "0.11.1", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz", - "integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==" + "integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==", + "dev": true }, "regenerator-transform": { "version": "0.10.1", @@ -14901,16 +14864,6 @@ } } }, - "tabler-react": { - "version": "1.19.1", - "resolved": "https://registry.npmjs.org/tabler-react/-/tabler-react-1.19.1.tgz", - "integrity": "sha512-dwfG64aCG5QEJ6zINpzDi75iNVTwgFFnOhUDTcvpe2Eqn2ZCpBkVcmG9KlcJqq0xI7/t8GJcvc9osjDqXbbLPg==", - "requires": { - "classnames": "^2.2.5", - "react-popper": "^1.0.0-beta.6", - "react-text-mask": "^5.4.1" - } - }, "tapable": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/tapable/-/tapable-1.0.0.tgz", @@ -15153,11 +15106,6 @@ "mime-types": "~2.1.18" } }, - "typed-styles": { - "version": "0.0.5", - "resolved": "https://registry.npmjs.org/typed-styles/-/typed-styles-0.0.5.tgz", - "integrity": "sha512-ht+rEe5UsdEBAa3gr64+QjUOqjOLJfWLvl5HZR5Ev9uo/OnD3p43wPeFSB1hNFc13GXQF/JU1Bn0YHLUqBRIlw==" - }, "typedarray": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", diff --git a/client/package.json b/client/package.json index 1e160b99..2321cbd0 100644 --- a/client/package.json +++ b/client/package.json @@ -30,7 +30,6 @@ "redux-actions": "^2.4.0", "redux-thunk": "^2.3.0", "svg-url-loader": "^2.3.2", - "tabler-react": "^1.10.0", "tiny-version-compare": "^0.9.1", "whatwg-fetch": "2.0.3" }, From 751be05a31e8479fb0e8ca318260264466871b16 Mon Sep 17 00:00:00 2001 From: Eugene Bujak Date: Thu, 11 Oct 2018 18:32:23 +0300 Subject: [PATCH 5/6] API filtering/add_url -- accept JSON instead of name=value lines --- control.go | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/control.go b/control.go index e2e631b9..c468379d 100644 --- a/control.go +++ b/control.go @@ -437,6 +437,7 @@ func handleStatsTop(w http.ResponseWriter, r *http.Request) { func httpError(w http.ResponseWriter, code int, format string, args ...interface{}) { text := fmt.Sprintf(format, args...) + log.Println(text) http.Error(w, text, code) } @@ -705,55 +706,49 @@ func handleFilteringStatus(w http.ResponseWriter, r *http.Request) { } func handleFilteringAddURL(w http.ResponseWriter, r *http.Request) { - parameters, err := parseParametersFromBody(r.Body) + filter := filter{} + err := json.NewDecoder(r.Body).Decode(&filter) if err != nil { - errortext := fmt.Sprintf("failed to parse parameters from body: %s", err) - log.Println(errortext) - http.Error(w, errortext, 400) + httpError(w, http.StatusBadRequest, "Failed to parse request body json: %s", err) return } - url, ok := parameters["url"] - if !ok { + filter.Enabled = true + if len(filter.URL) == 0 { http.Error(w, "URL parameter was not specified", 400) return } - if valid := govalidator.IsRequestURL(url); !valid { + if valid := govalidator.IsRequestURL(filter.URL); !valid { http.Error(w, "URL parameter is not valid request URL", 400) return } // check for duplicates for i := range config.Filters { - filter := &config.Filters[i] - if filter.URL == url { - errortext := fmt.Sprintf("Filter URL already added -- %s", url) + if config.Filters[i].URL == filter.URL { + errortext := fmt.Sprintf("Filter URL already added -- %s", filter.URL) log.Println(errortext) http.Error(w, errortext, http.StatusBadRequest) return } } - var filter = filter{ - Enabled: true, - URL: url, - } - ok, err = filter.update(time.Now()) + ok, err := filter.update(time.Now()) if err != nil { - errortext := fmt.Sprintf("Couldn't fetch filter from url %s: %s", url, err) + errortext := fmt.Sprintf("Couldn't fetch filter from url %s: %s", filter.URL, err) log.Println(errortext) http.Error(w, errortext, http.StatusBadRequest) return } if filter.RulesCount == 0 { - errortext := fmt.Sprintf("Filter at url %s has no rules (maybe it points to blank page?)", url) + errortext := fmt.Sprintf("Filter at url %s has no rules (maybe it points to blank page?)", filter.URL) log.Println(errortext) http.Error(w, errortext, http.StatusBadRequest) return } if !ok { - errortext := fmt.Sprintf("Filter at url %s is invalid (maybe it points to blank page?)", url) + errortext := fmt.Sprintf("Filter at url %s is invalid (maybe it points to blank page?)", filter.URL) log.Println(errortext) http.Error(w, errortext, http.StatusBadRequest) return From 8d13770b0d4b6d8fde0a61bbfdaa7bf9817142f6 Mon Sep 17 00:00:00 2001 From: Eugene Bujak Date: Thu, 11 Oct 2018 18:33:07 +0300 Subject: [PATCH 6/6] Remove unneeded debug prints --- coredns_plugin/coredns_plugin.go | 9 +++++---- coredns_plugin/querylog_file.go | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/coredns_plugin/coredns_plugin.go b/coredns_plugin/coredns_plugin.go index 4b00eca6..cb372a22 100644 --- a/coredns_plugin/coredns_plugin.go +++ b/coredns_plugin/coredns_plugin.go @@ -242,9 +242,10 @@ func (p *plug) parseEtcHosts(text string) bool { return false } for _, host := range fields[1:] { - if val, ok := p.hosts[host]; ok { - log.Printf("warning: host %s already has value %s, will overwrite it with %s", host, val, addr) - } + // debug logging for duplicate values, pretty common if you subscribe to many hosts files + // if val, ok := p.hosts[host]; ok { + // log.Printf("warning: host %s already has value %s, will overwrite it with %s", host, val, addr) + // } p.hosts[host] = addr } return true @@ -323,7 +324,7 @@ func (p *plug) replaceHostWithValAndReply(ctx context.Context, w dns.ResponseWri // check if it's a domain name or IP address addr := net.ParseIP(val) var records []dns.RR - log.Println("Will give", val, "instead of", host) + // log.Println("Will give", val, "instead of", host) // debug logging if addr != nil { // this is an IP address, return it result, err := dns.NewRR(fmt.Sprintf("%s %d A %s", host, p.settings.BlockedTTL, val)) diff --git a/coredns_plugin/querylog_file.go b/coredns_plugin/querylog_file.go index f5f6d09b..b9078ef2 100644 --- a/coredns_plugin/querylog_file.go +++ b/coredns_plugin/querylog_file.go @@ -221,7 +221,7 @@ func genericLoader(onEntry func(entry *logEntry) error, needMore func() bool, ti } if now.Sub(entry.Time) > timeWindow { - trace("skipping entry") + // trace("skipping entry") // debug logging continue }