+ client: handle upstream DNS servers for clients

This commit is contained in:
Ildar Kamalov 2019-12-04 19:08:14 +03:00
parent 72ec4d7d7e
commit 6684a120ac
3 changed files with 48 additions and 9 deletions

View File

@ -108,6 +108,7 @@
"upstream_dns": "Upstream DNS servers", "upstream_dns": "Upstream DNS servers",
"upstream_dns_hint": "If you keep this field empty, AdGuard Home will use <a href='https://www.quad9.net/' target='_blank'>Quad9</a> as an upstream.", "upstream_dns_hint": "If you keep this field empty, AdGuard Home will use <a href='https://www.quad9.net/' target='_blank'>Quad9</a> as an upstream.",
"test_upstream_btn": "Test upstreams", "test_upstream_btn": "Test upstreams",
"upstreams": "Upstreams",
"apply_btn": "Apply", "apply_btn": "Apply",
"disabled_filtering_toast": "Disabled filtering", "disabled_filtering_toast": "Disabled filtering",
"enabled_filtering_toast": "Enabled filtering", "enabled_filtering_toast": "Enabled filtering",

View File

@ -4,6 +4,7 @@ import { Trans, withNamespaces } from 'react-i18next';
import ReactTable from 'react-table'; import ReactTable from 'react-table';
import { MODAL_TYPE } from '../../../helpers/constants'; import { MODAL_TYPE } from '../../../helpers/constants';
import { normalizeTextarea } from '../../../helpers/helpers';
import Card from '../../ui/Card'; import Card from '../../ui/Card';
import Modal from './Modal'; import Modal from './Modal';
import WrapCell from './WrapCell'; import WrapCell from './WrapCell';
@ -20,13 +21,20 @@ class ClientsTable extends Component {
}; };
handleSubmit = (values) => { handleSubmit = (values) => {
let config = values; const config = values;
if (values && values.blocked_services) { if (values) {
const blocked_services = Object if (values.blocked_services) {
config.blocked_services = Object
.keys(values.blocked_services) .keys(values.blocked_services)
.filter(service => values.blocked_services[service]); .filter(service => values.blocked_services[service]);
config = { ...values, blocked_services }; }
if (values.upstreams && typeof values.upstreams === 'string') {
config.upstreams = normalizeTextarea(values.upstreams);
} else {
config.upstreams = [];
}
} }
if (this.props.modalType === MODAL_TYPE.EDIT) { if (this.props.modalType === MODAL_TYPE.EDIT) {
@ -40,10 +48,10 @@ class ClientsTable extends Component {
const client = clients.find(item => name === item.name); const client = clients.find(item => name === item.name);
if (client) { if (client) {
const { upstreams, whois_info, ...values } = client;
return { return {
use_global_settings: true, upstreams: (upstreams && upstreams.join('\n')) || '',
use_global_blocked_services: true, ...values,
...client,
}; };
} }
@ -143,6 +151,24 @@ class ClientsTable extends Component {
); );
}, },
}, },
{
Header: this.props.t('upstreams'),
accessor: 'upstreams',
minWidth: 120,
Cell: ({ value }) => {
const title = value && value.length > 0 ? (
<Trans>settings_custom</Trans>
) : (
<Trans>settings_global</Trans>
);
return (
<div className="logs__row logs__row--overflow">
<div className="logs__text">{title}</div>
</div>
);
},
},
{ {
Header: this.props.t('whois'), Header: this.props.t('whois'),
accessor: 'whois_info', accessor: 'whois_info',

View File

@ -7,6 +7,7 @@ import flow from 'lodash/flow';
import i18n from '../../../i18n'; import i18n from '../../../i18n';
import Tabs from '../../ui/Tabs'; import Tabs from '../../ui/Tabs';
import Examples from '../Dns/Upstream/Examples';
import { toggleAllServices } from '../../../helpers/helpers'; import { toggleAllServices } from '../../../helpers/helpers';
import { import {
renderField, renderField,
@ -223,6 +224,17 @@ let Form = (props) => {
</div> </div>
</div> </div>
</div> </div>
<div label="upstream" title={props.t('upstream_dns')}>
<Field
id="upstreams"
name="upstreams"
component="textarea"
type="text"
className="form-control form-control--textarea mb-5"
placeholder={t('upstream_dns')}
/>
<Examples />
</div>
</Tabs> </Tabs>
</div> </div>