parent
413228e6ec
commit
3a74dfdfa4
|
@ -113,28 +113,28 @@ export const getFiltering = () => async (dispatch) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const toggleFilteringRequest = createAction('TOGGLE_FILTERING_REQUEST');
|
export const toggleProtectionRequest = createAction('TOGGLE_PROTECTION_REQUEST');
|
||||||
export const toggleFilteringFailure = createAction('TOGGLE_FILTERING_FAILURE');
|
export const toggleProtectionFailure = createAction('TOGGLE_PROTECTION_FAILURE');
|
||||||
export const toggleFilteringSuccess = createAction('TOGGLE_FILTERING_SUCCESS');
|
export const toggleProtectionSuccess = createAction('TOGGLE_PROTECTION_SUCCESS');
|
||||||
|
|
||||||
export const toggleFiltering = status => async (dispatch) => {
|
export const toggleProtection = status => async (dispatch) => {
|
||||||
dispatch(toggleFilteringRequest());
|
dispatch(toggleProtectionRequest());
|
||||||
let successMessage = '';
|
let successMessage = '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (status) {
|
if (status) {
|
||||||
successMessage = 'Disabled filtering';
|
successMessage = 'Disabled protection';
|
||||||
await apiClient.disableFiltering();
|
await apiClient.disableGlobalProtection();
|
||||||
} else {
|
} else {
|
||||||
successMessage = 'Enabled filtering';
|
successMessage = 'Enabled protection';
|
||||||
await apiClient.enableFiltering();
|
await apiClient.enableGlobalProtection();
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(addSuccessToast(successMessage));
|
dispatch(addSuccessToast(successMessage));
|
||||||
dispatch(toggleFilteringSuccess());
|
dispatch(toggleProtectionSuccess());
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
dispatch(addErrorToast({ error }));
|
dispatch(addErrorToast({ error }));
|
||||||
dispatch(toggleFilteringFailure());
|
dispatch(toggleProtectionFailure());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,8 @@ export default class Api {
|
||||||
GLOBAL_SET_UPSTREAM_DNS = { path: 'set_upstream_dns', method: 'POST' };
|
GLOBAL_SET_UPSTREAM_DNS = { path: 'set_upstream_dns', method: 'POST' };
|
||||||
GLOBAL_TEST_UPSTREAM_DNS = { path: 'test_upstream_dns', method: 'POST' };
|
GLOBAL_TEST_UPSTREAM_DNS = { path: 'test_upstream_dns', method: 'POST' };
|
||||||
GLOBAL_VERSION = { path: 'version.json', method: 'GET' };
|
GLOBAL_VERSION = { path: 'version.json', method: 'GET' };
|
||||||
|
GLOBAL_ENABLE_PROTECTION = { path: 'enable_protection', method: 'POST' };
|
||||||
|
GLOBAL_DISABLE_PROTECTION = { path: 'disable_protection', method: 'POST' };
|
||||||
|
|
||||||
restartGlobalFiltering() {
|
restartGlobalFiltering() {
|
||||||
const { path, method } = this.GLOBAL_RESTART;
|
const { path, method } = this.GLOBAL_RESTART;
|
||||||
|
@ -123,6 +125,16 @@ export default class Api {
|
||||||
return this.makeRequest(path, method);
|
return this.makeRequest(path, method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enableGlobalProtection() {
|
||||||
|
const { path, method } = this.GLOBAL_ENABLE_PROTECTION;
|
||||||
|
return this.makeRequest(path, method);
|
||||||
|
}
|
||||||
|
|
||||||
|
disableGlobalProtection() {
|
||||||
|
const { path, method } = this.GLOBAL_DISABLE_PROTECTION;
|
||||||
|
return this.makeRequest(path, method);
|
||||||
|
}
|
||||||
|
|
||||||
// Filtering
|
// Filtering
|
||||||
FILTERING_STATUS = { path: 'filtering/status', method: 'GET' };
|
FILTERING_STATUS = { path: 'filtering/status', method: 'GET' };
|
||||||
FILTERING_ENABLE = { path: 'filtering/enable', method: 'POST' };
|
FILTERING_ENABLE = { path: 'filtering/enable', method: 'POST' };
|
||||||
|
|
|
@ -20,16 +20,15 @@ class Dashboard extends Component {
|
||||||
this.props.getStats();
|
this.props.getStats();
|
||||||
this.props.getStatsHistory();
|
this.props.getStatsHistory();
|
||||||
this.props.getTopStats();
|
this.props.getTopStats();
|
||||||
this.props.getFiltering();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getToggleFilteringButton = () => {
|
getToggleFilteringButton = () => {
|
||||||
const { isFilteringEnabled } = this.props.dashboard;
|
const { protectionEnabled } = this.props.dashboard;
|
||||||
const buttonText = isFilteringEnabled ? 'Disable' : 'Enable';
|
const buttonText = protectionEnabled ? 'Disable' : 'Enable';
|
||||||
const buttonClass = isFilteringEnabled ? 'btn-gray' : 'btn-success';
|
const buttonClass = protectionEnabled ? 'btn-gray' : 'btn-success';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button type="button" className={`btn btn-sm mr-2 ${buttonClass}`} onClick={() => this.props.toggleFiltering(isFilteringEnabled)}>
|
<button type="button" className={`btn btn-sm mr-2 ${buttonClass}`} onClick={() => this.props.toggleProtection(protectionEnabled)}>
|
||||||
{buttonText} protection
|
{buttonText} protection
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
|
@ -114,7 +113,7 @@ Dashboard.propTypes = {
|
||||||
dashboard: PropTypes.object,
|
dashboard: PropTypes.object,
|
||||||
isCoreRunning: PropTypes.bool,
|
isCoreRunning: PropTypes.bool,
|
||||||
getFiltering: PropTypes.func,
|
getFiltering: PropTypes.func,
|
||||||
toggleFiltering: PropTypes.func,
|
toggleProtection: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Dashboard;
|
export default Dashboard;
|
||||||
|
|
|
@ -26,8 +26,8 @@ class Header extends Component {
|
||||||
const { dashboard } = this.props;
|
const { dashboard } = this.props;
|
||||||
const badgeClass = classnames({
|
const badgeClass = classnames({
|
||||||
'badge dns-status': true,
|
'badge dns-status': true,
|
||||||
'badge-success': dashboard.isCoreRunning,
|
'badge-success': dashboard.protectionEnabled,
|
||||||
'badge-danger': !dashboard.isCoreRunning,
|
'badge-danger': !dashboard.protectionEnabled,
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -44,7 +44,7 @@ class Header extends Component {
|
||||||
</Link>
|
</Link>
|
||||||
{!dashboard.proccessing &&
|
{!dashboard.proccessing &&
|
||||||
<span className={badgeClass}>
|
<span className={badgeClass}>
|
||||||
{dashboard.isCoreRunning ? 'ON' : 'OFF'}
|
{dashboard.protectionEnabled ? 'ON' : 'OFF'}
|
||||||
</span>
|
</span>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -48,6 +48,7 @@ const dashboard = handleActions({
|
||||||
dns_address: dnsAddress,
|
dns_address: dnsAddress,
|
||||||
querylog_enabled: queryLogEnabled,
|
querylog_enabled: queryLogEnabled,
|
||||||
upstream_dns: upstreamDns,
|
upstream_dns: upstreamDns,
|
||||||
|
protection_enabled: protectionEnabled,
|
||||||
} = payload;
|
} = payload;
|
||||||
const newState = {
|
const newState = {
|
||||||
...state,
|
...state,
|
||||||
|
@ -58,6 +59,7 @@ const dashboard = handleActions({
|
||||||
dnsAddress,
|
dnsAddress,
|
||||||
queryLogEnabled,
|
queryLogEnabled,
|
||||||
upstreamDns: upstreamDns.join('\n'),
|
upstreamDns: upstreamDns.join('\n'),
|
||||||
|
protectionEnabled,
|
||||||
};
|
};
|
||||||
return newState;
|
return newState;
|
||||||
},
|
},
|
||||||
|
@ -134,9 +136,9 @@ const dashboard = handleActions({
|
||||||
return newState;
|
return newState;
|
||||||
},
|
},
|
||||||
|
|
||||||
[actions.toggleFilteringSuccess]: (state) => {
|
[actions.toggleProtectionSuccess]: (state) => {
|
||||||
const newSetting = { ...state, isFilteringEnabled: !state.isFilteringEnabled };
|
const newState = { ...state, protectionEnabled: !state.protectionEnabled };
|
||||||
return newSetting;
|
return newState;
|
||||||
},
|
},
|
||||||
|
|
||||||
[actions.handleUpstreamChange]: (state, { payload }) => {
|
[actions.handleUpstreamChange]: (state, { payload }) => {
|
||||||
|
@ -152,6 +154,7 @@ const dashboard = handleActions({
|
||||||
processingVersion: true,
|
processingVersion: true,
|
||||||
processingFiltering: true,
|
processingFiltering: true,
|
||||||
upstreamDns: [],
|
upstreamDns: [],
|
||||||
|
protectionEnabled: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const queryLogs = handleActions({
|
const queryLogs = handleActions({
|
||||||
|
|
Loading…
Reference in New Issue