Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 1535-whois-resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
szolin committed May 27, 2020
2 parents db76471 + 355e634 commit e24e945
Show file tree
Hide file tree
Showing 23 changed files with 1,149 additions and 844 deletions.
4 changes: 3 additions & 1 deletion changelog.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ module.exports = {
],
"scopes": [
"",
"ui",
"global",
"dnsfilter",
"home",
"dnsforward",
"dhcpd",
"documentation"
"querylog",
"documentation",
],
"types": {
"+": {
Expand Down
1 change: 1 addition & 0 deletions client/src/components/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class App extends Component {
dnsPort={dashboard.dnsPort}
processingVersion={dashboard.processingVersion}
getVersion={getVersion}
checkUpdateFlag={dashboard.checkUpdateFlag}
/>
<Toasts />
<Icons />
Expand Down
112 changes: 56 additions & 56 deletions client/src/components/ui/Footer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component, Fragment } from 'react';
import PropTypes from 'prop-types';
import { Trans, withTranslation } from 'react-i18next';
import classNames from 'classnames';

import { REPOSITORY, PRIVACY_POLICY_LINK } from '../../helpers/constants';
import { LANGUAGES } from '../../helpers/twosky';
Expand All @@ -10,6 +11,22 @@ import Version from './Version';
import './Footer.css';
import './Select.css';

const linksData = [
{
href: REPOSITORY.URL,
name: 'homepage',
},
{
href: PRIVACY_POLICY_LINK,
name: 'privacy_policy',
},
{
href: REPOSITORY.ISSUES,
className: 'btn btn-outline-primary btn-sm footer__link--report',
name: 'report_an_issue',
},
];

class Footer extends Component {
getYear = () => {
const today = new Date();
Expand All @@ -20,87 +37,69 @@ class Footer extends Component {
i18n.changeLanguage(event.target.value);
};

renderCopyright = () => <div className="footer__column">
<div className="footer__copyright">
<Trans>copyright</Trans> &copy; {this.getYear()}{' '}
<a target="_blank" rel="noopener noreferrer" href="https://adguard.com/">AdGuard</a>
</div>
</div>;

renderLinks = (linksData) => linksData.map(({ name, href, className = '' }) => <a
key={name}
href={href}
className={classNames('footer__link', className)}
target="_blank"
rel="noopener noreferrer"
>
<Trans>{name}</Trans>
</a>);


render() {
const {
dnsVersion, processingVersion, getVersion,
dnsVersion, processingVersion, getVersion, checkUpdateFlag,
} = this.props;

return (
<Fragment>
<footer className="footer">
<div className="container">
<div className="footer__row">
{!dnsVersion && (
<div className="footer__column">
<div className="footer__copyright">
<Trans>copyright</Trans> &copy; {this.getYear()}{' '}
<a target="_blank" rel="noopener noreferrer" href="https://adguard.com/">AdGuard</a>
</div>
</div>
)}
<div className="footer__column footer__column--links">
<a
href={REPOSITORY.URL}
className="footer__link"
target="_blank"
rel="noopener noreferrer"
>
<Trans>homepage</Trans>
</a>
<a
href={PRIVACY_POLICY_LINK}
className="footer__link"
target="_blank"
rel="noopener noreferrer"
>
<Trans>privacy_policy</Trans>
</a>
<a
href={REPOSITORY.ISSUES}
className="btn btn-outline-primary btn-sm footer__link footer__link--report"
target="_blank"
rel="noopener noreferrer"
>
<Trans>report_an_issue</Trans>
</a>
{this.renderLinks(linksData)}
</div>
<div className="footer__column footer__column--language">
<select
className="form-control select select--language"
value={i18n.language}
onChange={this.changeLanguage}
>
{Object.keys(LANGUAGES).map((lang) => (
<option key={lang} value={lang}>
{LANGUAGES[lang]}
</option>
))}
{Object.keys(LANGUAGES)
.map((lang) => (
<option key={lang} value={lang}>
{LANGUAGES[lang]}
</option>
))}
</select>
</div>
</div>
</div>
</footer>
{dnsVersion && (
<div className="footer">
<div className="container">
<div className="footer__row">
<div className="footer__column">
<div className="footer__copyright">
<Trans>copyright</Trans> &copy; {this.getYear()}{' '}
<a target="_blank" rel="noopener noreferrer" href="https://adguard.com/">AdGuard</a>
</div>
</div>
<div className="footer__column footer__column--language">
<Version
dnsVersion={dnsVersion}
processingVersion={processingVersion}
getVersion={getVersion}
/>
</div>
<div className="footer">
<div className="container">
<div className="footer__row">
{this.renderCopyright()}
<div className="footer__column footer__column--language">
<Version
dnsVersion={dnsVersion}
processingVersion={processingVersion}
getVersion={getVersion}
checkUpdateFlag={checkUpdateFlag}
/>
</div>
</div>
</div>
)}
</div>
</Fragment>
);
}
Expand All @@ -110,6 +109,7 @@ Footer.propTypes = {
dnsVersion: PropTypes.string,
processingVersion: PropTypes.bool,
getVersion: PropTypes.func,
checkUpdateFlag: PropTypes.bool,
};

export default withTranslation()(Footer);
10 changes: 6 additions & 4 deletions client/src/components/ui/Version.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import './Version.css';

const Version = (props) => {
const {
dnsVersion, processingVersion, t,
dnsVersion = 'undefined', processingVersion, t, checkUpdateFlag,
} = props;

return (
<div className="version">
<div className="version__text">
<Trans>version</Trans>:&nbsp;<span className="version__value" title={dnsVersion}>{dnsVersion}</span>
<button
<Trans>version</Trans>:&nbsp;
<span className="version__value" title={dnsVersion}>{dnsVersion}</span>
{checkUpdateFlag && <button
type="button"
className="btn btn-icon btn-icon-sm btn-outline-primary btn-sm ml-2"
onClick={() => props.getVersion(true)}
Expand All @@ -23,7 +24,7 @@ const Version = (props) => {
<svg className="icons">
<use xlinkHref="#refresh" />
</svg>
</button>
</button>}
</div>
</div>
);
Expand All @@ -33,6 +34,7 @@ Version.propTypes = {
dnsVersion: PropTypes.string.isRequired,
getVersion: PropTypes.func.isRequired,
processingVersion: PropTypes.bool.isRequired,
checkUpdateFlag: PropTypes.bool.isRequired,
t: PropTypes.func.isRequired,
};

Expand Down
2 changes: 2 additions & 0 deletions client/src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const dashboard = handleActions(
canAutoUpdate,
isUpdateAvailable: true,
processingVersion: false,
checkUpdateFlag: !!payload,
};
return newState;
}
Expand Down Expand Up @@ -165,6 +166,7 @@ const dashboard = handleActions(
autoClients: [],
supportedTags: [],
name: '',
checkUpdateFlag: false,
},
);

Expand Down
7 changes: 7 additions & 0 deletions dnsfilter/dnsfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ func (d *Dnsfilter) CheckHost(host string, qtype uint16, setts *RequestFiltering

// Process rewrites table
// . Find CNAME for a domain name (exact match or by wildcard)
// . if found and CNAME equals to domain name - this is an exception; exit
// . if found, set domain name to canonical name
// . repeat for the new domain name (Note: we return only the last CNAME)
// . Find A or AAAA record for a domain name (exact match or by wildcard)
Expand All @@ -409,6 +410,12 @@ func (d *Dnsfilter) processRewrites(host string) Result {
origHost := host
for len(rr) != 0 && rr[0].Type == dns.TypeCNAME {
log.Debug("Rewrite: CNAME for %s is %s", host, rr[0].Answer)

if host == rr[0].Answer { // "host == CNAME" is an exception
res.Reason = 0
return res
}

host = rr[0].Answer
_, ok := cnames[host]
if ok {
Expand Down
10 changes: 5 additions & 5 deletions dnsfilter/rewrites.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ func (a rewritesArray) Len() int { return len(a) }
func (a rewritesArray) Swap(i, j int) { a[i], a[j] = a[j], a[i] }

// Priority:
// . CNAME > A/AAAA;
// . exact > wildcard;
// . higher level wildcard > lower level wildcard
// . CNAME < A/AAAA;
// . exact < wildcard;
// . higher level wildcard < lower level wildcard
func (a rewritesArray) Less(i, j int) bool {
if a[i].Type == dns.TypeCNAME && a[j].Type != dns.TypeCNAME {
return false
} else if a[i].Type != dns.TypeCNAME && a[j].Type == dns.TypeCNAME {
return true
} else if a[i].Type != dns.TypeCNAME && a[j].Type == dns.TypeCNAME {
return false
}

if isWildcard(a[i].Domain) {
Expand Down
40 changes: 40 additions & 0 deletions dnsfilter/rewrites_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,43 @@ func TestRewritesLevels(t *testing.T) {
assert.Equal(t, 1, len(r.IPList))
assert.Equal(t, "3.3.3.3", r.IPList[0].String())
}

func TestRewritesException(t *testing.T) {
d := Dnsfilter{}
// wildcard; exception for a sub-domain
d.Rewrites = []RewriteEntry{
RewriteEntry{"*.host.com", "2.2.2.2", 0, nil},
RewriteEntry{"sub.host.com", "sub.host.com", 0, nil},
}
d.prepareRewrites()

// match sub-domain
r := d.processRewrites("my.host.com")
assert.Equal(t, ReasonRewrite, r.Reason)
assert.Equal(t, 1, len(r.IPList))
assert.Equal(t, "2.2.2.2", r.IPList[0].String())

// match sub-domain, but handle exception
r = d.processRewrites("sub.host.com")
assert.Equal(t, NotFilteredNotFound, r.Reason)
}

func TestRewritesExceptionWC(t *testing.T) {
d := Dnsfilter{}
// wildcard; exception for a sub-wildcard
d.Rewrites = []RewriteEntry{
RewriteEntry{"*.host.com", "2.2.2.2", 0, nil},
RewriteEntry{"*.sub.host.com", "*.sub.host.com", 0, nil},
}
d.prepareRewrites()

// match sub-domain
r := d.processRewrites("my.host.com")
assert.Equal(t, ReasonRewrite, r.Reason)
assert.Equal(t, 1, len(r.IPList))
assert.Equal(t, "2.2.2.2", r.IPList[0].String())

// match sub-domain, but handle exception
r = d.processRewrites("my.sub.host.com")
assert.Equal(t, NotFilteredNotFound, r.Reason)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.14
require (
github.com/AdguardTeam/dnsproxy v0.28.1
github.com/AdguardTeam/golibs v0.4.2
github.com/AdguardTeam/urlfilter v0.10.0
github.com/AdguardTeam/urlfilter v0.10.1
github.com/NYTimes/gziphandler v1.1.1
github.com/fsnotify/fsnotify v1.4.7
github.com/gobuffalo/packr v1.30.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ github.com/AdguardTeam/golibs v0.4.0/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKU
github.com/AdguardTeam/golibs v0.4.2 h1:7M28oTZFoFwNmp8eGPb3ImmYbxGaJLyQXeIFVHjME0o=
github.com/AdguardTeam/golibs v0.4.2/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4=
github.com/AdguardTeam/gomitmproxy v0.2.0/go.mod h1:Qdv0Mktnzer5zpdpi5rAwixNJzW2FN91LjKJCkVbYGU=
github.com/AdguardTeam/urlfilter v0.10.0 h1:/YZ4w/UF3KDkL4/QLrQtqalvwBfHHGgrMhk+u3Xm8Mo=
github.com/AdguardTeam/urlfilter v0.10.0/go.mod h1:aMuejlNxpWppOVjiEV87X6z0eMf7wsXHTAIWQuylfZY=
github.com/AdguardTeam/urlfilter v0.10.1 h1:ECago6OvZjOTKlOqxU39C+V/ecAslaCDYcf5s+/hwaY=
github.com/AdguardTeam/urlfilter v0.10.1/go.mod h1:aMuejlNxpWppOVjiEV87X6z0eMf7wsXHTAIWQuylfZY=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cqUQ3I=
github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c=
Expand Down
7 changes: 7 additions & 0 deletions openapi/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# AdGuard Home API Change Log

## v0.103: API changes

### API: Get querylog: GET /control/querylog

* Added optional "offset" and "limit" parameters

We are still using "older_than" approach in AdGuard Home UI, but we realize that it's easier to use offset/limit so here is this option now.

## v0.102: API changes

Expand Down
15 changes: 14 additions & 1 deletion openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,26 @@ paths:
tags:
- log
operationId: queryLog
summary: Get DNS server query log
summary: Get DNS server query log.
parameters:
- name: older_than
in: query
description: Filter by older than
schema:
type: string
- name: offset
in: query
description:
Specify the ranking number of the first item on the page.
Even though it is possible to use "offset" and "older_than",
we recommend choosing one of them and sticking to it.
schema:
type: integer
- name: limit
in: query
description: Limit the number of records to be returned
schema:
type: integer
- name: filter_domain
in: query
description: Filter by domain name
Expand Down
Loading

0 comments on commit e24e945

Please sign in to comment.