Skip to content

Commit

Permalink
+ client: add requests count for client_id
Browse files Browse the repository at this point in the history
  • Loading branch information
IldarKamalov committed Jan 26, 2021
1 parent 2d68df4 commit 32991a0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
14 changes: 8 additions & 6 deletions client/src/components/Dashboard/Clients.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ const Clients = ({
const { t } = useTranslation();
const topClients = useSelector((state) => state.stats.topClients, shallowEqual);

return <Card
return (
<Card
title={t('top_clients')}
subtitle={subtitle}
bodyType="card-table"
refresh={refreshButton}
>
<ReactTable
>
<ReactTable
data={topClients.map(({
name: ip, count, info, blocked,
}) => ({
Expand All @@ -107,7 +108,7 @@ const Clients = ({
}))}
columns={[
{
Header: 'IP',
Header: <Trans>client_table_header</Trans>,
accessor: 'ip',
sortMethod: sortIp,
Cell: ClientCell,
Expand All @@ -134,8 +135,9 @@ const Clients = ({

return disallowed ? { className: 'logs__row--red' } : {};
}}
/>
</Card>;
/>
</Card>
);
};

Clients.propTypes = {
Expand Down
1 change: 1 addition & 0 deletions client/src/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ export const TOAST_TIMEOUTS = {
export const ADDRESS_TYPES = {
IP: 'IP',
CIDR: 'CIDR',
CLIENT_ID: 'CLIENT_ID',
UNKNOWN: 'UNKNOWN',
};

Expand Down
20 changes: 16 additions & 4 deletions client/src/helpers/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
DHCP_VALUES_PLACEHOLDERS,
FILTERED,
FILTERED_STATUS,
R_CLIENT_ID,
SERVICES_ID_NAME_MAP,
STANDARD_DNS_PORT,
STANDARD_HTTPS_PORT,
Expand Down Expand Up @@ -536,7 +537,7 @@ export const isIpInCidr = (ip, cidr) => {
/**
*
* @param ipOrCidr
* @returns {'IP' | 'CIDR' | 'UNKNOWN'}
* @returns {'IP' | 'CIDR' | 'CLIENT_ID' | 'UNKNOWN'}
*
*/
export const findAddressType = (address) => {
Expand All @@ -549,6 +550,9 @@ export const findAddressType = (address) => {
if (cidrMaybe && ipaddr.parseCIDR(address)) {
return ADDRESS_TYPES.CIDR;
}
if (R_CLIENT_ID.test(address)) {
return ADDRESS_TYPES.CLIENT_ID;
}

return ADDRESS_TYPES.UNKNOWN;
} catch (e) {
Expand All @@ -569,17 +573,25 @@ export const separateIpsAndCidrs = (ids) => ids.reduce((acc, curr) => {
if (addressType === ADDRESS_TYPES.CIDR) {
acc.cidrs.push(curr);
}
if (addressType === ADDRESS_TYPES.CLIENT_ID) {
acc.clientIds.push(curr);
}
return acc;
}, { ips: [], cidrs: [] });
}, { ips: [], cidrs: [], clientIds: [] });

export const countClientsStatistics = (ids, autoClients) => {
const { ips, cidrs } = separateIpsAndCidrs(ids);
const { ips, cidrs, clientIds } = separateIpsAndCidrs(ids);

const ipsCount = ips.reduce((acc, curr) => {
const count = autoClients[curr] || 0;
return acc + count;
}, 0);

const clientIdsCount = clientIds.reduce((acc, curr) => {
const count = autoClients[curr] || 0;
return acc + count;
}, 0);

const cidrsCount = Object.entries(autoClients)
.reduce((acc, curr) => {
const [id, count] = curr;
Expand All @@ -590,7 +602,7 @@ export const countClientsStatistics = (ids, autoClients) => {
return acc;
}, 0);

return ipsCount + cidrsCount;
return ipsCount + cidrsCount + clientIdsCount;
};

/**
Expand Down

0 comments on commit 32991a0

Please sign in to comment.