*: merge with master
This commit is contained in:
@@ -3,7 +3,6 @@ import { t } from 'i18next';
|
||||
|
||||
import apiClient from '../api/Api';
|
||||
import { addErrorToast, addSuccessToast } from './index';
|
||||
import { getStats, getStatsConfig } from './stats';
|
||||
import { normalizeTextarea } from '../helpers/helpers';
|
||||
import { ACTION } from '../helpers/constants';
|
||||
|
||||
@@ -50,11 +49,13 @@ export const toggleClientBlockRequest = createAction('TOGGLE_CLIENT_BLOCK_REQUES
|
||||
export const toggleClientBlockFailure = createAction('TOGGLE_CLIENT_BLOCK_FAILURE');
|
||||
export const toggleClientBlockSuccess = createAction('TOGGLE_CLIENT_BLOCK_SUCCESS');
|
||||
|
||||
export const toggleClientBlock = (type, ip) => async (dispatch, getState) => {
|
||||
export const toggleClientBlock = (type, ip) => async (dispatch) => {
|
||||
dispatch(toggleClientBlockRequest());
|
||||
try {
|
||||
const { allowed_clients, disallowed_clients, blocked_hosts } = getState().access;
|
||||
let updatedDisallowedClients = normalizeTextarea(disallowed_clients);
|
||||
const {
|
||||
allowed_clients, disallowed_clients, blocked_hosts,
|
||||
} = await apiClient.getAccessList();
|
||||
let updatedDisallowedClients = disallowed_clients;
|
||||
|
||||
if (type === ACTION.unblock && updatedDisallowedClients.includes(ip)) {
|
||||
updatedDisallowedClients = updatedDisallowedClients.filter(client => client !== ip);
|
||||
@@ -63,23 +64,19 @@ export const toggleClientBlock = (type, ip) => async (dispatch, getState) => {
|
||||
}
|
||||
|
||||
const values = {
|
||||
allowed_clients: normalizeTextarea(allowed_clients),
|
||||
blocked_hosts: normalizeTextarea(blocked_hosts),
|
||||
allowed_clients,
|
||||
blocked_hosts,
|
||||
disallowed_clients: updatedDisallowedClients,
|
||||
};
|
||||
|
||||
await apiClient.setAccessList(values);
|
||||
dispatch(toggleClientBlockSuccess());
|
||||
dispatch(toggleClientBlockSuccess(values));
|
||||
|
||||
if (type === ACTION.unblock) {
|
||||
dispatch(addSuccessToast(t('client_unblocked', { ip })));
|
||||
} else if (type === ACTION.block) {
|
||||
dispatch(addSuccessToast(t('client_blocked', { ip })));
|
||||
}
|
||||
|
||||
dispatch(getStats());
|
||||
dispatch(getStatsConfig());
|
||||
dispatch(getAccessList());
|
||||
} catch (error) {
|
||||
dispatch(addErrorToast({ error }));
|
||||
dispatch(toggleClientBlockFailure());
|
||||
|
||||
@@ -2,7 +2,7 @@ import { createAction } from 'redux-actions';
|
||||
|
||||
import apiClient from '../api/Api';
|
||||
import { addErrorToast, addSuccessToast } from './index';
|
||||
import { normalizeTopStats, secondsToMilliseconds, getParamsForClientsSearch, addClientInfo, addClientStatus } from '../helpers/helpers';
|
||||
import { normalizeTopStats, secondsToMilliseconds, getParamsForClientsSearch, addClientInfo } from '../helpers/helpers';
|
||||
|
||||
export const getStatsConfigRequest = createAction('GET_STATS_CONFIG_REQUEST');
|
||||
export const getStatsConfigFailure = createAction('GET_STATS_CONFIG_FAILURE');
|
||||
@@ -46,15 +46,12 @@ export const getStats = () => async (dispatch) => {
|
||||
const normalizedTopClients = normalizeTopStats(stats.top_clients);
|
||||
const clientsParams = getParamsForClientsSearch(normalizedTopClients, 'name');
|
||||
const clients = await apiClient.findClients(clientsParams);
|
||||
const accessData = await apiClient.getAccessList();
|
||||
const { disallowed_clients } = accessData;
|
||||
const topClientsWithInfo = addClientInfo(normalizedTopClients, clients, 'name');
|
||||
const topClientsWithStatus = addClientStatus(topClientsWithInfo, disallowed_clients, 'name');
|
||||
|
||||
const normalizedStats = {
|
||||
...stats,
|
||||
top_blocked_domains: normalizeTopStats(stats.top_blocked_domains),
|
||||
top_clients: topClientsWithStatus,
|
||||
top_clients: topClientsWithInfo,
|
||||
top_queried_domains: normalizeTopStats(stats.top_queried_domains),
|
||||
avg_processing_time: secondsToMilliseconds(stats.avg_processing_time),
|
||||
};
|
||||
|
||||
@@ -57,10 +57,12 @@ const renderBlockingButton = (blocked, ip, handleClick, processing) => {
|
||||
);
|
||||
};
|
||||
|
||||
const clientCell = (t, toggleClientStatus, processing) =>
|
||||
const isBlockedClient = (clients, ip) => !!(clients && clients.includes(ip));
|
||||
|
||||
const clientCell = (t, toggleClientStatus, processing, disallowedClients) =>
|
||||
function cell(row) {
|
||||
const { original, value } = row;
|
||||
const { blocked } = original;
|
||||
const { value } = row;
|
||||
const blocked = isBlockedClient(disallowedClients, value);
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
@@ -80,6 +82,7 @@ const Clients = ({
|
||||
dnsQueries,
|
||||
toggleClientStatus,
|
||||
processingAccessSet,
|
||||
disallowedClients,
|
||||
}) => (
|
||||
<Card
|
||||
title={t('top_clients')}
|
||||
@@ -102,7 +105,7 @@ const Clients = ({
|
||||
accessor: 'ip',
|
||||
sortMethod: (a, b) =>
|
||||
parseInt(a.replace(/\./g, ''), 10) - parseInt(b.replace(/\./g, ''), 10),
|
||||
Cell: clientCell(t, toggleClientStatus, processingAccessSet),
|
||||
Cell: clientCell(t, toggleClientStatus, processingAccessSet, disallowedClients),
|
||||
},
|
||||
{
|
||||
Header: <Trans>requests_count</Trans>,
|
||||
@@ -122,9 +125,9 @@ const Clients = ({
|
||||
return {};
|
||||
}
|
||||
|
||||
const { blocked } = rowInfo.original;
|
||||
const { ip } = rowInfo.original;
|
||||
|
||||
if (blocked) {
|
||||
if (isBlockedClient(disallowedClients, ip)) {
|
||||
return {
|
||||
className: 'red',
|
||||
};
|
||||
@@ -148,6 +151,7 @@ Clients.propTypes = {
|
||||
t: PropTypes.func.isRequired,
|
||||
toggleClientStatus: PropTypes.func.isRequired,
|
||||
processingAccessSet: PropTypes.bool.isRequired,
|
||||
disallowedClients: PropTypes.string.isRequired,
|
||||
};
|
||||
|
||||
export default withNamespaces()(Clients);
|
||||
|
||||
@@ -19,6 +19,7 @@ class Dashboard extends Component {
|
||||
}
|
||||
|
||||
getAllStats = () => {
|
||||
this.props.getAccessList();
|
||||
this.props.getStats();
|
||||
this.props.getStatsConfig();
|
||||
};
|
||||
@@ -53,7 +54,8 @@ class Dashboard extends Component {
|
||||
dashboard, stats, access, t,
|
||||
} = this.props;
|
||||
const statsProcessing = stats.processingStats
|
||||
|| stats.processingGetConfig;
|
||||
|| stats.processingGetConfig
|
||||
|| access.processing;
|
||||
|
||||
const subtitle =
|
||||
stats.interval === 1
|
||||
@@ -130,6 +132,7 @@ class Dashboard extends Component {
|
||||
refreshButton={refreshButton}
|
||||
toggleClientStatus={this.toggleClientStatus}
|
||||
processingAccessSet={access.processingSet}
|
||||
disallowedClients={access.disallowed_clients}
|
||||
/>
|
||||
</div>
|
||||
<div className="col-lg-6">
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import React, { Component, Fragment } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Trans, withNamespaces } from 'react-i18next';
|
||||
import { REPOSITORY, LANGUAGES, PRIVACY_POLICY_LINK } from '../../helpers/constants';
|
||||
|
||||
import { REPOSITORY, PRIVACY_POLICY_LINK } from '../../helpers/constants';
|
||||
import { LANGUAGES } from '../../helpers/twosky';
|
||||
import i18n from '../../i18n';
|
||||
|
||||
import Version from './Version';
|
||||
@@ -68,9 +70,9 @@ class Footer extends Component {
|
||||
value={i18n.language}
|
||||
onChange={this.changeLanguage}
|
||||
>
|
||||
{LANGUAGES.map(language => (
|
||||
<option key={language.key} value={language.key}>
|
||||
{language.name}
|
||||
{Object.keys(LANGUAGES).map(lang => (
|
||||
<option key={lang} value={lang}>
|
||||
{LANGUAGES[lang]}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
|
||||
@@ -31,117 +31,6 @@ export const REPOSITORY = {
|
||||
|
||||
export const PRIVACY_POLICY_LINK = 'https://adguard.com/privacy/home.html';
|
||||
|
||||
export const LANGUAGES = [
|
||||
{
|
||||
key: 'da',
|
||||
name: 'Dansk',
|
||||
},
|
||||
{
|
||||
key: 'de',
|
||||
name: 'Deutsch',
|
||||
},
|
||||
{
|
||||
key: 'nl',
|
||||
name: 'Dutch',
|
||||
},
|
||||
{
|
||||
key: 'en',
|
||||
name: 'English',
|
||||
},
|
||||
{
|
||||
key: 'es',
|
||||
name: 'Español',
|
||||
},
|
||||
{
|
||||
key: 'fr',
|
||||
name: 'Français',
|
||||
},
|
||||
{
|
||||
key: 'id',
|
||||
name: 'Indonesian',
|
||||
},
|
||||
{
|
||||
key: 'it',
|
||||
name: 'Italiano',
|
||||
},
|
||||
{
|
||||
key: 'pl',
|
||||
name: 'Polski',
|
||||
},
|
||||
{
|
||||
key: 'pt-br',
|
||||
name: 'Portuguese (BR)',
|
||||
},
|
||||
{
|
||||
key: 'pt-pt',
|
||||
name: 'Portuguese (PT)',
|
||||
},
|
||||
{
|
||||
key: 'sk',
|
||||
name: 'Slovenčina',
|
||||
},
|
||||
{
|
||||
key: 'sl',
|
||||
name: 'Slovenščina',
|
||||
},
|
||||
{
|
||||
key: 'sv',
|
||||
name: 'Svenska',
|
||||
},
|
||||
{
|
||||
key: 'vi',
|
||||
name: 'Tiếng Việt',
|
||||
},
|
||||
{
|
||||
key: 'tr',
|
||||
name: 'Türkçe',
|
||||
},
|
||||
{
|
||||
key: 'cs',
|
||||
name: 'Český',
|
||||
},
|
||||
{
|
||||
key: 'bg',
|
||||
name: 'Български',
|
||||
},
|
||||
{
|
||||
key: 'ru',
|
||||
name: 'Русский',
|
||||
},
|
||||
{
|
||||
key: 'ja',
|
||||
name: '日本語',
|
||||
},
|
||||
{
|
||||
key: 'zh-tw',
|
||||
name: '正體中文',
|
||||
},
|
||||
{
|
||||
key: 'zh-cn',
|
||||
name: '简体中文',
|
||||
},
|
||||
{
|
||||
key: 'no',
|
||||
name: 'Norsk',
|
||||
},
|
||||
{
|
||||
key: 'sr-cs',
|
||||
name: 'Srpski',
|
||||
},
|
||||
{
|
||||
key: 'hr',
|
||||
name: 'Hrvatski',
|
||||
},
|
||||
{
|
||||
key: 'fa',
|
||||
name: 'فارسی',
|
||||
},
|
||||
{
|
||||
key: 'ko',
|
||||
name: '한국어',
|
||||
},
|
||||
];
|
||||
|
||||
export const INSTALL_FIRST_STEP = 1;
|
||||
export const INSTALL_TOTAL_STEPS = 5;
|
||||
|
||||
|
||||
@@ -122,17 +122,6 @@ export const addClientInfo = (data, clients, param) => (
|
||||
})
|
||||
);
|
||||
|
||||
export const addClientStatus = (data, disallowedClients, param) => (
|
||||
data.map((row) => {
|
||||
const clientIp = row[param];
|
||||
const blocked = !!(disallowedClients && disallowedClients.includes(clientIp));
|
||||
return {
|
||||
...row,
|
||||
blocked,
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
export const normalizeFilteringStatus = (filteringStatus) => {
|
||||
const {
|
||||
enabled, filters, user_rules: userRules, interval,
|
||||
|
||||
@@ -96,6 +96,11 @@
|
||||
"name": "Microsoft Azure",
|
||||
"categoryId": 10,
|
||||
"url": "https://azure.microsoft.com/"
|
||||
},
|
||||
"button": {
|
||||
"name": "Button",
|
||||
"categoryId": 4,
|
||||
"url": "https://www.usebutton.com/"
|
||||
}
|
||||
},
|
||||
"trackerDomains": {
|
||||
@@ -119,6 +124,7 @@
|
||||
"edgecastcdn.net": "markmonitor",
|
||||
"appcenter.ms": "appcenter",
|
||||
"unityads.unity3d.com": "unity_ads",
|
||||
"azure.com": "azure"
|
||||
"azure.com": "azure",
|
||||
"bttn.io": "button"
|
||||
}
|
||||
}
|
||||
@@ -696,11 +696,6 @@
|
||||
"categoryId": 4,
|
||||
"url": "http://adgoto.com/"
|
||||
},
|
||||
"adguard": {
|
||||
"name": "Adguard",
|
||||
"categoryId": 12,
|
||||
"url": "https://adguard.com/"
|
||||
},
|
||||
"adhands": {
|
||||
"name": "AdHands",
|
||||
"categoryId": 4,
|
||||
@@ -16201,7 +16196,6 @@
|
||||
"smartredirect.de": "adgoal",
|
||||
"adgorithms.com": "adgorithms",
|
||||
"adgoto.com": "adgoto",
|
||||
"adguard.com": "adguard",
|
||||
"adhands.ru": "adhands",
|
||||
"adhese.be": "adhese",
|
||||
"adhese.com": "adhese",
|
||||
|
||||
6
client/src/helpers/twosky.js
Normal file
6
client/src/helpers/twosky.js
Normal file
@@ -0,0 +1,6 @@
|
||||
import twosky from 'MainRoot/.twosky.json';
|
||||
|
||||
export const {
|
||||
languages: LANGUAGES,
|
||||
base_locale: BASE_LOCALE,
|
||||
} = twosky[0];
|
||||
@@ -3,7 +3,7 @@ import { reactI18nextModule } from 'react-i18next';
|
||||
import { initReactI18n } from 'react-i18next/hooks';
|
||||
import langDetect from 'i18next-browser-languagedetector';
|
||||
|
||||
import { DEFAULT_LANGUAGE } from './helpers/constants';
|
||||
import { LANGUAGES, BASE_LOCALE } from './helpers/twosky';
|
||||
|
||||
import vi from './__locales/vi.json';
|
||||
import en from './__locales/en.json';
|
||||
@@ -117,7 +117,7 @@ const resources = {
|
||||
},
|
||||
};
|
||||
|
||||
const availableLanguages = Object.keys(resources);
|
||||
const availableLanguages = Object.keys(LANGUAGES);
|
||||
|
||||
i18n
|
||||
.use(langDetect)
|
||||
@@ -126,7 +126,7 @@ i18n
|
||||
.init({
|
||||
resources,
|
||||
lowerCaseLng: true,
|
||||
fallbackLng: DEFAULT_LANGUAGE,
|
||||
fallbackLng: BASE_LOCALE,
|
||||
keySeparator: false,
|
||||
nsSeparator: false,
|
||||
returnEmptyString: false,
|
||||
@@ -136,9 +136,10 @@ i18n
|
||||
react: {
|
||||
wait: true,
|
||||
},
|
||||
whitelist: availableLanguages,
|
||||
}, () => {
|
||||
if (!availableLanguages.includes(i18n.language)) {
|
||||
i18n.changeLanguage(DEFAULT_LANGUAGE);
|
||||
i18n.changeLanguage(BASE_LOCALE);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -34,7 +34,21 @@ const access = handleActions(
|
||||
|
||||
[actions.toggleClientBlockRequest]: state => ({ ...state, processingSet: true }),
|
||||
[actions.toggleClientBlockFailure]: state => ({ ...state, processingSet: false }),
|
||||
[actions.toggleClientBlockSuccess]: state => ({ ...state, processingSet: false }),
|
||||
[actions.toggleClientBlockSuccess]: (state, { payload }) => {
|
||||
const {
|
||||
allowed_clients,
|
||||
disallowed_clients,
|
||||
blocked_hosts,
|
||||
} = payload;
|
||||
const newState = {
|
||||
...state,
|
||||
allowed_clients: (allowed_clients && allowed_clients.join('\n')) || '',
|
||||
disallowed_clients: (disallowed_clients && disallowed_clients.join('\n')) || '',
|
||||
blocked_hosts: (blocked_hosts && blocked_hosts.join('\n')) || '',
|
||||
processingSet: false,
|
||||
};
|
||||
return newState;
|
||||
},
|
||||
},
|
||||
{
|
||||
processing: true,
|
||||
|
||||
Reference in New Issue
Block a user