badguardhome/client/src/reducers/index.js

321 lines
11 KiB
JavaScript
Raw Normal View History

2018-08-30 14:25:33 +00:00
import { combineReducers } from 'redux';
import { handleActions } from 'redux-actions';
import { loadingBarReducer } from 'react-redux-loading-bar';
import { reducer as formReducer } from 'redux-form';
2019-09-17 14:37:26 +00:00
import { isVersionGreater } from '../helpers/helpers';
2018-08-30 14:25:33 +00:00
import * as actions from '../actions';
2019-02-07 12:40:26 +00:00
import toasts from './toasts';
import encryption from './encryption';
2019-05-22 14:59:57 +00:00
import clients from './clients';
2019-05-30 14:26:19 +00:00
import access from './access';
2019-07-22 12:32:12 +00:00
import rewrites from './rewrites';
2019-07-18 11:52:47 +00:00
import services from './services';
import stats from './stats';
2019-09-04 14:39:35 +00:00
import queryLogs from './queryLogs';
2019-12-04 18:52:38 +00:00
import dnsConfig from './dnsConfig';
2019-09-12 13:19:35 +00:00
import filtering from './filtering';
2018-08-30 14:25:33 +00:00
const settings = handleActions(
{
[actions.initSettingsRequest]: state => ({ ...state, processing: true }),
[actions.initSettingsFailure]: state => ({ ...state, processing: false }),
[actions.initSettingsSuccess]: (state, { payload }) => {
const { settingsList } = payload;
const newState = { ...state, settingsList, processing: false };
return newState;
},
[actions.toggleSettingStatus]: (state, { payload }) => {
const { settingsList } = state;
const { settingKey } = payload;
const setting = settingsList[settingKey];
2018-08-30 14:25:33 +00:00
const newSetting = { ...setting, enabled: !setting.enabled };
const newSettingsList = { ...settingsList, [settingKey]: newSetting };
return { ...state, settingsList: newSettingsList };
},
[actions.testUpstreamRequest]: state => ({ ...state, processingTestUpstream: true }),
[actions.testUpstreamFailure]: state => ({ ...state, processingTestUpstream: false }),
[actions.testUpstreamSuccess]: state => ({ ...state, processingTestUpstream: false }),
2018-08-30 14:25:33 +00:00
},
{
processing: true,
processingTestUpstream: false,
processingDhcpStatus: false,
settingsList: {},
2018-08-30 14:25:33 +00:00
},
);
2018-08-30 14:25:33 +00:00
const dashboard = handleActions(
{
[actions.setDnsRunningStatus]: (state, { payload }) =>
({ ...state, isCoreRunning: payload }),
[actions.dnsStatusRequest]: state => ({ ...state, processing: true }),
[actions.dnsStatusFailure]: state => ({ ...state, processing: false }),
[actions.dnsStatusSuccess]: (state, { payload }) => {
2018-09-21 12:20:41 +00:00
const {
version,
dns_port: dnsPort,
dns_addresses: dnsAddresses,
protection_enabled: protectionEnabled,
http_port: httpPort,
+ client: add fastest_addr setting Squashed commit of the following: commit e47fae25f7bac950bfb452fc8f18b9c0865b08ba Merge: a23285ec e2ddc82d Author: Simon Zolin <s.zolin@adguard.com> Date: Wed Apr 22 19:16:01 2020 +0300 Merge remote-tracking branch 'origin/master' into 715 commit a23285ec3ace78fe4ce19122a51ecf3e6cdd942c Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Apr 22 18:30:30 2020 +0300 Review changes commit f80d62a0d2038ff9d070ae9e9c77c33b92232d9c Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Apr 21 16:37:42 2020 +0300 + client: Add fastest addr option commit 9e713df80c5bf113c98794c0a20915c756a76938 Merge: e3bf4037 9b7c1181 Author: Simon Zolin <s.zolin@adguard.com> Date: Tue Apr 21 16:02:03 2020 +0300 Merge remote-tracking branch 'origin/master' into 715-fastest-addr commit e3bf4037f49198e42bde55305d6f9077341b556a Author: Simon Zolin <s.zolin@adguard.com> Date: Tue Apr 21 15:40:49 2020 +0300 minor commit d6e6a823c5e51acc061b2850d362772efcb827e1 Author: Simon Zolin <s.zolin@adguard.com> Date: Fri Apr 17 17:56:24 2020 +0300 * API changes . removed POST /set_upstreams_config . removed fields from GET /status: bootstrap_dns, upstream_dns, all_servers . added new fields to /dns_config and /dns_info commit 237a452d09cc48ff8f00e81c7fd35e7828bea835 Author: Simon Zolin <s.zolin@adguard.com> Date: Fri Apr 17 16:43:13 2020 +0300 * API: /dns_info, /dns_config: add "parallel_requests" instead of "all_servers" from /set_upstreams_config commit 9976723b9725ed19e0cce152d1d1198b13c4acc1 Author: Simon Zolin <s.zolin@adguard.com> Date: Mon Mar 23 10:28:25 2020 +0300 openapi commit 6f8ea16c6332606f29095b0094d71e8a91798f82 Merge: 36e4d4e8 c8285c41 Author: Simon Zolin <s.zolin@adguard.com> Date: Fri Mar 20 19:18:48 2020 +0300 Merge remote-tracking branch 'origin/master' into 715-fastest-addr commit 36e4d4e82cadeaba5a11313f0d69d66a0924c342 Author: Simon Zolin <s.zolin@adguard.com> Date: Fri Mar 20 18:13:43 2020 +0300 + DNS: add fastest_addr setting
2020-04-22 16:32:07 +00:00
language,
2018-09-21 12:20:41 +00:00
} = payload;
const newState = {
...state,
isCoreRunning: true,
processing: false,
dnsVersion: version,
dnsPort,
dnsAddresses,
protectionEnabled,
language,
httpPort,
};
return newState;
},
[actions.getVersionRequest]: state => ({ ...state, processingVersion: true }),
[actions.getVersionFailure]: state => ({ ...state, processingVersion: false }),
[actions.getVersionSuccess]: (state, { payload }) => {
const currentVersion = state.dnsVersion === 'undefined' ? 0 : state.dnsVersion;
2019-09-17 14:37:26 +00:00
if (payload && isVersionGreater(currentVersion, payload.new_version)) {
const {
announcement_url: announcementUrl,
new_version: newVersion,
can_autoupdate: canAutoUpdate,
} = payload;
const newState = {
...state,
announcementUrl,
newVersion,
canAutoUpdate,
isUpdateAvailable: true,
processingVersion: false,
};
return newState;
}
return {
...state,
2019-06-25 14:56:50 +00:00
processingVersion: false,
2018-09-21 12:20:41 +00:00
};
},
[actions.getUpdateRequest]: state => ({ ...state, processingUpdate: true }),
[actions.getUpdateFailure]: state => ({ ...state, processingUpdate: false }),
[actions.getUpdateSuccess]: (state) => {
const newState = { ...state, processingUpdate: false };
2018-09-21 12:20:41 +00:00
return newState;
},
2018-09-21 12:20:41 +00:00
[actions.toggleProtectionRequest]: state => ({ ...state, processingProtection: true }),
[actions.toggleProtectionFailure]: state => ({ ...state, processingProtection: false }),
[actions.toggleProtectionSuccess]: (state) => {
const newState = {
...state,
protectionEnabled: !state.protectionEnabled,
processingProtection: false,
};
return newState;
},
[actions.getLanguageSuccess]: (state, { payload }) => {
const newState = { ...state, language: payload };
return newState;
},
[actions.getClientsRequest]: state => ({ ...state, processingClients: true }),
[actions.getClientsFailure]: state => ({ ...state, processingClients: false }),
[actions.getClientsSuccess]: (state, { payload }) => {
const newState = {
...state,
2020-01-28 11:07:47 +00:00
...payload,
processingClients: false,
};
return newState;
},
2018-11-22 14:56:57 +00:00
2019-10-23 07:31:54 +00:00
[actions.getProfileRequest]: state => ({ ...state, processingProfile: true }),
[actions.getProfileFailure]: state => ({ ...state, processingProfile: false }),
[actions.getProfileSuccess]: (state, { payload }) => ({
...state,
name: payload.name,
processingProfile: false,
}),
2019-03-20 14:04:32 +00:00
},
{
processing: true,
isCoreRunning: true,
processingVersion: true,
processingClients: true,
processingUpdate: false,
2019-10-23 07:31:54 +00:00
processingProfile: true,
protectionEnabled: false,
processingProtection: false,
httpPort: 80,
dnsPort: 53,
dnsAddresses: [],
dnsVersion: '',
clients: [],
autoClients: [],
2020-01-28 11:07:47 +00:00
supportedTags: [],
2019-10-23 07:31:54 +00:00
name: '',
},
);
2018-08-30 14:25:33 +00:00
const dhcp = handleActions(
{
[actions.getDhcpStatusRequest]: state => ({ ...state, processing: true }),
[actions.getDhcpStatusFailure]: state => ({ ...state, processing: false }),
[actions.getDhcpStatusSuccess]: (state, { payload }) => {
const { static_leases: staticLeases, ...values } = payload;
const newState = {
...state,
staticLeases,
processing: false,
...values,
};
return newState;
},
[actions.getDhcpInterfacesRequest]: state => ({ ...state, processingInterfaces: true }),
[actions.getDhcpInterfacesFailure]: state => ({ ...state, processingInterfaces: false }),
[actions.getDhcpInterfacesSuccess]: (state, { payload }) => {
const newState = {
...state,
interfaces: payload,
processingInterfaces: false,
};
return newState;
},
2018-12-24 08:48:23 +00:00
[actions.findActiveDhcpRequest]: state => ({ ...state, processingStatus: true }),
[actions.findActiveDhcpFailure]: state => ({ ...state, processingStatus: false }),
[actions.findActiveDhcpSuccess]: (state, { payload }) => {
const { other_server: otherServer, static_ip: staticIP } = payload;
2019-04-04 13:34:46 +00:00
const newState = {
...state,
check: {
otherServer,
staticIP,
},
processingStatus: false,
};
return newState;
},
[actions.toggleDhcpRequest]: state => ({ ...state, processingDhcp: true }),
[actions.toggleDhcpFailure]: state => ({ ...state, processingDhcp: false }),
[actions.toggleDhcpSuccess]: (state) => {
const { config } = state;
const newConfig = { ...config, enabled: !config.enabled };
const newState = {
...state,
config: newConfig,
check: null,
processingDhcp: false,
};
return newState;
},
2019-01-23 14:22:04 +00:00
[actions.setDhcpConfigRequest]: state => ({ ...state, processingConfig: true }),
[actions.setDhcpConfigFailure]: state => ({ ...state, processingConfig: false }),
[actions.setDhcpConfigSuccess]: (state, { payload }) => {
const { config } = state;
const newConfig = { ...config, ...payload };
const newState = { ...state, config: newConfig, processingConfig: false };
return newState;
},
2019-05-28 12:07:46 +00:00
2019-10-15 14:14:24 +00:00
[actions.resetDhcpRequest]: state => ({ ...state, processingReset: true }),
[actions.resetDhcpFailure]: state => ({ ...state, processingReset: false }),
[actions.resetDhcpSuccess]: state => ({
...state,
processingReset: false,
config: {
enabled: false,
},
}),
[actions.toggleLeaseModal]: (state) => {
const newState = {
...state,
isModalOpen: !state.isModalOpen,
};
return newState;
},
2019-05-28 12:07:46 +00:00
[actions.addStaticLeaseRequest]: state => ({ ...state, processingAdding: true }),
[actions.addStaticLeaseFailure]: state => ({ ...state, processingAdding: false }),
[actions.addStaticLeaseSuccess]: (state, { payload }) => {
const { ip, mac, hostname } = payload;
const newLease = {
ip,
mac,
hostname: hostname || '',
};
const leases = [...state.staticLeases, newLease];
const newState = {
...state,
staticLeases: leases,
processingAdding: false,
};
return newState;
},
2019-05-28 12:07:46 +00:00
[actions.removeStaticLeaseRequest]: state => ({ ...state, processingDeleting: true }),
[actions.removeStaticLeaseFailure]: state => ({ ...state, processingDeleting: false }),
[actions.removeStaticLeaseSuccess]: (state, { payload }) => {
const leaseToRemove = payload.ip;
const leases = state.staticLeases.filter(item => item.ip !== leaseToRemove);
const newState = {
...state,
staticLeases: leases,
processingDeleting: false,
};
return newState;
},
2019-05-28 12:07:46 +00:00
},
{
processing: true,
processingStatus: false,
processingInterfaces: false,
processingDhcp: false,
processingConfig: false,
processingAdding: false,
processingDeleting: false,
config: {
enabled: false,
},
check: null,
leases: [],
staticLeases: [],
isModalOpen: false,
2018-12-13 11:38:00 +00:00
},
);
2018-08-30 14:25:33 +00:00
export default combineReducers({
settings,
dashboard,
queryLogs,
filtering,
2018-09-14 12:37:35 +00:00
toasts,
dhcp,
encryption,
2019-05-22 14:59:57 +00:00
clients,
2019-05-30 14:26:19 +00:00
access,
2019-07-22 12:32:12 +00:00
rewrites,
2019-07-18 11:52:47 +00:00
services,
stats,
2019-12-04 18:52:38 +00:00
dnsConfig,
loadingBar: loadingBarReducer,
form: formReducer,
2018-08-30 14:25:33 +00:00
});