2018-08-30 14:25:33 +00:00
|
|
|
import React, { Component, Fragment } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2020-05-22 14:06:05 +00:00
|
|
|
import { Trans, withTranslation } from 'react-i18next';
|
2018-08-30 14:25:33 +00:00
|
|
|
|
|
|
|
import Statistics from './Statistics';
|
|
|
|
import Counters from './Counters';
|
|
|
|
import Clients from './Clients';
|
|
|
|
import QueriedDomains from './QueriedDomains';
|
|
|
|
import BlockedDomains from './BlockedDomains';
|
|
|
|
|
|
|
|
import PageTitle from '../ui/PageTitle';
|
|
|
|
import Loading from '../ui/Loading';
|
2020-01-30 10:58:54 +00:00
|
|
|
import { ACTION } from '../../helpers/constants';
|
2018-10-12 16:52:19 +00:00
|
|
|
import './Dashboard.css';
|
2018-08-30 14:25:33 +00:00
|
|
|
|
|
|
|
class Dashboard extends Component {
|
|
|
|
componentDidMount() {
|
2018-09-17 14:44:32 +00:00
|
|
|
this.getAllStats();
|
|
|
|
}
|
|
|
|
|
|
|
|
getAllStats = () => {
|
2020-02-04 12:48:07 +00:00
|
|
|
this.props.getAccessList();
|
2018-08-30 14:25:33 +00:00
|
|
|
this.props.getStats();
|
2019-08-22 13:10:47 +00:00
|
|
|
this.props.getStatsConfig();
|
|
|
|
};
|
2018-09-26 14:12:31 +00:00
|
|
|
|
|
|
|
getToggleFilteringButton = () => {
|
2019-01-16 11:51:17 +00:00
|
|
|
const { protectionEnabled, processingProtection } = this.props.dashboard;
|
2018-11-09 06:51:28 +00:00
|
|
|
const buttonText = protectionEnabled ? 'disable_protection' : 'enable_protection';
|
2018-10-11 07:57:36 +00:00
|
|
|
const buttonClass = protectionEnabled ? 'btn-gray' : 'btn-success';
|
2018-09-26 14:12:31 +00:00
|
|
|
|
|
|
|
return (
|
2019-01-16 11:51:17 +00:00
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className={`btn btn-sm mr-2 ${buttonClass}`}
|
|
|
|
onClick={() => this.props.toggleProtection(protectionEnabled)}
|
|
|
|
disabled={processingProtection}
|
|
|
|
>
|
2018-11-09 06:51:28 +00:00
|
|
|
<Trans>{buttonText}</Trans>
|
2018-09-26 14:12:31 +00:00
|
|
|
</button>
|
|
|
|
);
|
2019-08-22 13:10:47 +00:00
|
|
|
};
|
2018-08-30 14:25:33 +00:00
|
|
|
|
2020-01-30 10:58:54 +00:00
|
|
|
toggleClientStatus = (type, ip) => {
|
|
|
|
const confirmMessage = type === ACTION.block ? 'client_confirm_block' : 'client_confirm_unblock';
|
|
|
|
|
|
|
|
if (window.confirm(this.props.t(confirmMessage, { ip }))) {
|
|
|
|
this.props.toggleClientBlock(type, ip);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-30 14:25:33 +00:00
|
|
|
render() {
|
2020-01-30 10:58:54 +00:00
|
|
|
const {
|
|
|
|
dashboard, stats, access, t,
|
|
|
|
} = this.props;
|
|
|
|
const statsProcessing = stats.processingStats
|
2020-02-04 12:48:07 +00:00
|
|
|
|| stats.processingGetConfig
|
|
|
|
|| access.processing;
|
2019-08-22 13:10:47 +00:00
|
|
|
|
2020-05-22 14:06:05 +00:00
|
|
|
const subtitle = stats.interval === 1
|
|
|
|
? t('for_last_24_hours')
|
|
|
|
: t('for_last_days', { count: stats.interval });
|
2018-08-30 14:25:33 +00:00
|
|
|
|
2019-06-25 14:56:50 +00:00
|
|
|
const refreshFullButton = (
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="btn btn-outline-primary btn-sm"
|
|
|
|
onClick={() => this.getAllStats()}
|
|
|
|
>
|
|
|
|
<Trans>refresh_statics</Trans>
|
|
|
|
</button>
|
|
|
|
);
|
2019-08-22 13:10:47 +00:00
|
|
|
|
2019-06-25 14:56:50 +00:00
|
|
|
const refreshButton = (
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="btn btn-icon btn-outline-primary btn-sm"
|
|
|
|
onClick={() => this.getAllStats()}
|
|
|
|
>
|
|
|
|
<svg className="icons">
|
|
|
|
<use xlinkHref="#refresh" />
|
|
|
|
</svg>
|
|
|
|
</button>
|
|
|
|
);
|
2018-08-30 14:25:33 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Fragment>
|
2019-08-22 13:10:47 +00:00
|
|
|
<PageTitle title={t('dashboard')}>
|
2018-08-30 14:25:33 +00:00
|
|
|
<div className="page-title__actions">
|
2018-09-26 14:12:31 +00:00
|
|
|
{this.getToggleFilteringButton()}
|
2018-08-30 14:25:33 +00:00
|
|
|
{refreshFullButton}
|
|
|
|
</div>
|
|
|
|
</PageTitle>
|
2019-12-06 15:00:01 +00:00
|
|
|
{statsProcessing && <Loading />}
|
|
|
|
{!statsProcessing && (
|
2018-08-30 14:25:33 +00:00
|
|
|
<div className="row row-cards">
|
2019-08-22 13:10:47 +00:00
|
|
|
<div className="col-lg-12">
|
|
|
|
<Statistics
|
|
|
|
interval={stats.interval}
|
|
|
|
dnsQueries={stats.dnsQueries}
|
|
|
|
blockedFiltering={stats.blockedFiltering}
|
|
|
|
replacedSafebrowsing={stats.replacedSafebrowsing}
|
|
|
|
replacedParental={stats.replacedParental}
|
|
|
|
numDnsQueries={stats.numDnsQueries}
|
|
|
|
numBlockedFiltering={stats.numBlockedFiltering}
|
|
|
|
numReplacedSafebrowsing={stats.numReplacedSafebrowsing}
|
|
|
|
numReplacedParental={stats.numReplacedParental}
|
|
|
|
refreshButton={refreshButton}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="col-lg-6">
|
|
|
|
<Counters
|
|
|
|
subtitle={subtitle}
|
|
|
|
interval={stats.interval}
|
|
|
|
dnsQueries={stats.numDnsQueries}
|
|
|
|
blockedFiltering={stats.numBlockedFiltering}
|
|
|
|
replacedSafebrowsing={stats.numReplacedSafebrowsing}
|
|
|
|
replacedParental={stats.numReplacedParental}
|
|
|
|
replacedSafesearch={stats.numReplacedSafesearch}
|
|
|
|
avgProcessingTime={stats.avgProcessingTime}
|
|
|
|
refreshButton={refreshButton}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="col-lg-6">
|
|
|
|
<Clients
|
|
|
|
subtitle={subtitle}
|
|
|
|
dnsQueries={stats.numDnsQueries}
|
|
|
|
topClients={stats.topClients}
|
|
|
|
clients={dashboard.clients}
|
|
|
|
autoClients={dashboard.autoClients}
|
|
|
|
refreshButton={refreshButton}
|
2020-01-30 10:58:54 +00:00
|
|
|
toggleClientStatus={this.toggleClientStatus}
|
|
|
|
processingAccessSet={access.processingSet}
|
2020-02-04 12:48:07 +00:00
|
|
|
disallowedClients={access.disallowed_clients}
|
2019-08-22 13:10:47 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="col-lg-6">
|
|
|
|
<QueriedDomains
|
|
|
|
subtitle={subtitle}
|
|
|
|
dnsQueries={stats.numDnsQueries}
|
|
|
|
topQueriedDomains={stats.topQueriedDomains}
|
|
|
|
refreshButton={refreshButton}
|
|
|
|
/>
|
|
|
|
</div>
|
2018-08-30 14:25:33 +00:00
|
|
|
<div className="col-lg-6">
|
2019-08-22 13:10:47 +00:00
|
|
|
<BlockedDomains
|
|
|
|
subtitle={subtitle}
|
|
|
|
topBlockedDomains={stats.topBlockedDomains}
|
|
|
|
blockedFiltering={stats.numBlockedFiltering}
|
|
|
|
replacedSafebrowsing={stats.numReplacedSafebrowsing}
|
|
|
|
replacedParental={stats.numReplacedParental}
|
|
|
|
refreshButton={refreshButton}
|
|
|
|
/>
|
2018-08-30 14:25:33 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-08-22 13:10:47 +00:00
|
|
|
)}
|
2018-08-30 14:25:33 +00:00
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Dashboard.propTypes = {
|
2019-08-22 13:10:47 +00:00
|
|
|
dashboard: PropTypes.object.isRequired,
|
|
|
|
stats: PropTypes.object.isRequired,
|
2020-01-30 10:58:54 +00:00
|
|
|
access: PropTypes.object.isRequired,
|
2019-08-22 13:10:47 +00:00
|
|
|
getStats: PropTypes.func.isRequired,
|
|
|
|
getStatsConfig: PropTypes.func.isRequired,
|
|
|
|
toggleProtection: PropTypes.func.isRequired,
|
|
|
|
getClients: PropTypes.func.isRequired,
|
|
|
|
t: PropTypes.func.isRequired,
|
2020-01-30 10:58:54 +00:00
|
|
|
toggleClientBlock: PropTypes.func.isRequired,
|
|
|
|
getAccessList: PropTypes.func.isRequired,
|
2018-08-30 14:25:33 +00:00
|
|
|
};
|
|
|
|
|
2020-05-22 14:06:05 +00:00
|
|
|
export default withTranslation()(Dashboard);
|