badguardhome/client/src/components/Settings/index.js

112 lines
4.2 KiB
JavaScript
Raw Normal View History

2018-08-30 14:25:33 +00:00
import React, { Component, Fragment } from 'react';
import PropTypes from 'prop-types';
import Upstream from './Upstream';
import Checkbox from '../ui/Checkbox';
import Loading from '../ui/Loading';
import PageTitle from '../ui/PageTitle';
import Card from '../ui/Card';
import './Settings.css';
export default class Settings extends Component {
settings = {
filtering: {
enabled: false,
title: 'Block domains using filters and hosts files',
subtitle: 'You can setup blocking rules in the <a href="#filters">Filters</a> settings.',
},
safebrowsing: {
enabled: false,
title: 'Use AdGuard browsing security web service',
2018-10-10 14:24:12 +00:00
subtitle: 'AdGuard DNS will check if domain is blacklisted by the browsing security web service. It will use privacy-friendly lookup API to perform the check: only a short prefix of the domain name SHA256 hash is sent to the server.',
2018-08-30 14:25:33 +00:00
},
parental: {
enabled: false,
title: 'Use AdGuard parental control web service',
subtitle: 'AdGuard DNS will check if domain contains adult materials. It uses the same privacy-friendly API as the browsing security web service.',
},
safesearch: {
enabled: false,
title: 'Enforce safe search',
2018-10-10 14:24:12 +00:00
subtitle: 'AdGuard DNS can enforce safe search in the following search engines: Google, Bing, Yandex.',
2018-08-30 14:25:33 +00:00
},
};
componentDidMount() {
this.props.initSettings(this.settings);
}
handleUpstreamChange = (value) => {
this.props.handleUpstreamChange({ upstreamDns: value });
2018-08-30 14:25:33 +00:00
};
handleUpstreamSubmit = () => {
this.props.setUpstream(this.props.dashboard.upstreamDns);
2018-08-30 14:25:33 +00:00
};
handleUpstreamTest = () => {
if (this.props.dashboard.upstreamDns.length > 0) {
this.props.testUpstream(this.props.dashboard.upstreamDns);
2018-09-21 15:50:06 +00:00
} else {
this.props.addErrorToast({ error: 'No servers specified' });
}
};
2018-08-30 14:25:33 +00:00
renderSettings = (settings) => {
if (Object.keys(settings).length > 0) {
return Object.keys(settings).map((key) => {
const setting = settings[key];
const { enabled } = setting;
return (<Checkbox
key={key}
{...settings[key]}
handleChange={() => this.props.toggleSetting(key, enabled)}
/>);
});
}
return (
<div>No settings</div>
);
}
render() {
const { settings } = this.props;
const { upstreamDns } = this.props.dashboard;
2018-08-30 14:25:33 +00:00
return (
<Fragment>
<PageTitle title="Settings" />
{settings.processing && <Loading />}
{!settings.processing &&
<div className="content">
<div className="row">
<div className="col-md-12">
<Card title="General settings" bodyType="card-body box-body--settings">
<div className="form">
{this.renderSettings(settings.settingsList)}
</div>
</Card>
<Upstream
upstreamDns={upstreamDns}
processingTestUpstream={settings.processingTestUpstream}
2018-08-30 14:25:33 +00:00
handleUpstreamChange={this.handleUpstreamChange}
handleUpstreamSubmit={this.handleUpstreamSubmit}
handleUpstreamTest={this.handleUpstreamTest}
2018-08-30 14:25:33 +00:00
/>
</div>
</div>
</div>
}
</Fragment>
);
}
}
Settings.propTypes = {
initSettings: PropTypes.func,
settings: PropTypes.object,
settingsList: PropTypes.object,
toggleSetting: PropTypes.func,
handleUpstreamChange: PropTypes.func,
setUpstream: PropTypes.func,
upstream: PropTypes.string,
};