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