Skip to content

Commit

Permalink
Merge branch 'master' into fix/1687
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemBaskal committed May 29, 2020
2 parents c6b50c7 + 83b9b70 commit 5287da0
Show file tree
Hide file tree
Showing 32 changed files with 1,246 additions and 876 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
3 changes: 1 addition & 2 deletions client/src/components/Settings/Dns/Upstream/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Field, reduxForm, formValueSelector } from 'redux-form';
import { Trans, withTranslation } from 'react-i18next';
import flow from 'lodash/flow';
import classnames from 'classnames';
import { nanoid } from 'nanoid';

import Examples from './Examples';
import { renderRadioField } from '../../../../helpers/form';
Expand Down Expand Up @@ -63,7 +62,7 @@ let Form = (props) => {
<div className="row">
{INPUT_FIELDS.map(({
name, component, type, className, placeholder, getTitle, subtitle, disabled, value,
}) => <div className="col-12 mb-4" key={nanoid()}>
}) => <div className="col-12 mb-4" key={placeholder}>
{typeof getTitle === 'function' && getTitle()}
<Field
id={name}
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
2 changes: 1 addition & 1 deletion home/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

const (
clientsUpdatePeriod = 1 * time.Hour
clientsUpdatePeriod = 10 * time.Minute
)

var webHandlersRegistered = false
Expand Down
Loading

0 comments on commit 5287da0

Please sign in to comment.