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

133 lines
4.8 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';
2018-10-25 10:33:44 +00:00
import { withNamespaces, Trans } from 'react-i18next';
2018-08-30 14:25:33 +00:00
import Upstream from './Upstream';
import Dhcp from './Dhcp';
import Encryption from './Encryption';
2018-08-30 14:25:33 +00:00
import Checkbox from '../ui/Checkbox';
import Loading from '../ui/Loading';
import PageTitle from '../ui/PageTitle';
import Card from '../ui/Card';
import './Settings.css';
2018-10-25 10:33:44 +00:00
class Settings extends Component {
2018-08-30 14:25:33 +00:00
settings = {
filtering: {
enabled: false,
2018-11-09 06:51:28 +00:00
title: 'block_domain_use_filters_and_hosts',
subtitle: 'filters_block_toggle_hint',
2018-08-30 14:25:33 +00:00
},
safebrowsing: {
enabled: false,
2018-11-09 06:51:28 +00:00
title: 'use_adguard_browsing_sec',
subtitle: 'use_adguard_browsing_sec_hint',
2018-08-30 14:25:33 +00:00
},
parental: {
enabled: false,
2018-11-09 06:51:28 +00:00
title: 'use_adguard_parental',
subtitle: 'use_adguard_parental_hint',
2018-08-30 14:25:33 +00:00
},
safesearch: {
enabled: false,
2018-11-09 06:51:28 +00:00
title: 'enforce_safe_search',
subtitle: 'enforce_save_search_hint',
2018-08-30 14:25:33 +00:00
},
};
componentDidMount() {
this.props.initSettings(this.settings);
this.props.getDhcpStatus();
2018-12-24 08:48:23 +00:00
this.props.getDhcpInterfaces();
this.props.getTlsStatus();
2018-08-30 14:25:33 +00:00
}
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 {
2018-11-09 06:51:28 +00:00
this.props.addErrorToast({ error: this.props.t('no_servers_specified') });
2018-09-21 15:50:06 +00:00
}
};
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 (
2018-11-09 06:51:28 +00:00
<div><Trans>no_settings</Trans></div>
2018-08-30 14:25:33 +00:00
);
}
render() {
2018-10-25 10:33:44 +00:00
const { settings, t } = this.props;
const { upstreamDns } = this.props.dashboard;
2018-08-30 14:25:33 +00:00
return (
<Fragment>
2018-11-09 06:51:28 +00:00
<PageTitle title={ t('settings') } />
2018-08-30 14:25:33 +00:00
{settings.processing && <Loading />}
{!settings.processing &&
<div className="content">
<div className="row">
<div className="col-md-12">
2018-11-09 06:51:28 +00:00
<Card title={ t('general_settings') } bodyType="card-body box-body--settings">
2018-08-30 14:25:33 +00:00
<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
/>
<Encryption
encryption={this.props.encryption}
setTlsConfig={this.props.setTlsConfig}
validateTlsConfig={this.props.validateTlsConfig}
/>
<Dhcp
dhcp={this.props.dhcp}
toggleDhcp={this.props.toggleDhcp}
getDhcpStatus={this.props.getDhcpStatus}
findActiveDhcp={this.props.findActiveDhcp}
setDhcpConfig={this.props.setDhcpConfig}
/>
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,
2018-10-25 10:33:44 +00:00
t: PropTypes.func,
2018-08-30 14:25:33 +00:00
};
2018-10-25 10:33:44 +00:00
export default withNamespaces()(Settings);