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

158 lines
6.6 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';
2019-05-23 11:14:22 +00:00
2018-08-30 14:25:33 +00:00
import Upstream from './Upstream';
import Dhcp from './Dhcp';
import Encryption from './Encryption';
2019-05-22 14:59:57 +00:00
import Clients from './Clients';
2019-05-23 11:14:22 +00:00
import AutoClients from './Clients/AutoClients';
2019-05-30 14:26:19 +00:00
import Access from './Access';
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';
2019-05-23 11:14:22 +00:00
2018-08-30 14:25:33 +00:00
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();
2019-05-30 14:26:19 +00:00
this.props.getAccessList();
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;
2019-05-22 14:59:57 +00:00
return (
<Checkbox
key={key}
{...settings[key]}
handleChange={() => this.props.toggleSetting(key, enabled)}
/>
);
2018-08-30 14:25:33 +00:00
});
}
return (
2019-05-22 14:59:57 +00:00
<div>
<Trans>no_settings</Trans>
</div>
2018-08-30 14:25:33 +00:00
);
2019-05-22 14:59:57 +00:00
};
2018-08-30 14:25:33 +00:00
render() {
2019-05-22 14:59:57 +00:00
const {
2019-05-30 14:26:19 +00:00
settings, dashboard, clients, access, t,
2019-05-22 14:59:57 +00:00
} = this.props;
2018-08-30 14:25:33 +00:00
return (
<Fragment>
2019-05-22 14:59:57 +00:00
<PageTitle title={t('settings')} />
2018-08-30 14:25:33 +00:00
{settings.processing && <Loading />}
2019-05-22 14:59:57 +00:00
{!settings.processing && (
2018-08-30 14:25:33 +00:00
<div className="content">
<div className="row">
<div className="col-md-12">
2019-05-22 14:59:57 +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
2019-03-06 11:45:21 +00:00
upstreamDns={dashboard.upstreamDns}
bootstrapDns={dashboard.bootstrapDns}
2019-03-06 11:45:21 +00:00
allServers={dashboard.allServers}
setUpstream={this.props.setUpstream}
testUpstream={this.props.testUpstream}
processingTestUpstream={settings.processingTestUpstream}
2019-03-06 11:45:21 +00:00
processingSetUpstream={settings.processingSetUpstream}
2018-08-30 14:25:33 +00:00
/>
2019-05-22 14:59:57 +00:00
{!dashboard.processingTopStats && !dashboard.processingClients && (
2019-05-23 11:14:22 +00:00
<Fragment>
<Clients
clients={dashboard.clients}
topStats={dashboard.topStats}
isModalOpen={clients.isModalOpen}
modalClientName={clients.modalClientName}
modalType={clients.modalType}
addClient={this.props.addClient}
updateClient={this.props.updateClient}
deleteClient={this.props.deleteClient}
toggleClientModal={this.props.toggleClientModal}
processingAdding={clients.processingAdding}
processingDeleting={clients.processingDeleting}
processingUpdating={clients.processingUpdating}
/>
<AutoClients
autoClients={dashboard.autoClients}
topStats={dashboard.topStats}
/>
</Fragment>
2019-05-22 14:59:57 +00:00
)}
2019-05-30 14:26:19 +00:00
<Access access={access} setAccessList={this.props.setAccessList} />
<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}
2019-05-28 12:07:46 +00:00
addStaticLease={this.props.addStaticLease}
removeStaticLease={this.props.removeStaticLease}
toggleLeaseModal={this.props.toggleLeaseModal}
/>
2018-08-30 14:25:33 +00:00
</div>
</div>
</div>
2019-05-22 14:59:57 +00:00
)}
2018-08-30 14:25:33 +00:00
</Fragment>
);
}
}
Settings.propTypes = {
initSettings: PropTypes.func,
settings: PropTypes.object,
settingsList: PropTypes.object,
toggleSetting: PropTypes.func,
handleUpstreamChange: PropTypes.func,
setUpstream: PropTypes.func,
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);