mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-25 22:45:46 +03:00
Add enable/disable for DHCP server
This commit is contained in:
parent
96fbf7f134
commit
d46b65f982
7 changed files with 27 additions and 64 deletions
|
@ -138,5 +138,6 @@
|
||||||
"dhcp_disable": "Disable DHCP server",
|
"dhcp_disable": "Disable DHCP server",
|
||||||
"dhcp_not_found": "No active DHCP servers found on the network. It is safe to enable the built-in DHCP server.",
|
"dhcp_not_found": "No active DHCP servers found on the network. It is safe to enable the built-in DHCP server.",
|
||||||
"dhcp_leases": "DHCP leases",
|
"dhcp_leases": "DHCP leases",
|
||||||
"dhcp_leases_not_found": "No DHCP leases found"
|
"dhcp_leases_not_found": "No DHCP leases found",
|
||||||
|
"dhcp_config_saved": "Saved DHCP server config"
|
||||||
}
|
}
|
||||||
|
|
|
@ -546,6 +546,7 @@ export const setDhcpConfig = config => async (dispatch) => {
|
||||||
dispatch(setDhcpConfigRequest());
|
dispatch(setDhcpConfigRequest());
|
||||||
try {
|
try {
|
||||||
await apiClient.setDhcpConfig(config);
|
await apiClient.setDhcpConfig(config);
|
||||||
|
dispatch(addSuccessToast('dhcp_config_saved'));
|
||||||
dispatch(setDhcpConfigSuccess());
|
dispatch(setDhcpConfigSuccess());
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
dispatch(addErrorToast({ error }));
|
dispatch(addErrorToast({ error }));
|
||||||
|
@ -572,17 +573,17 @@ export const toggleDhcpRequest = createAction('TOGGLE_DHCP_REQUEST');
|
||||||
export const toggleDhcpFailure = createAction('TOGGLE_DHCP_FAILURE');
|
export const toggleDhcpFailure = createAction('TOGGLE_DHCP_FAILURE');
|
||||||
export const toggleDhcpSuccess = createAction('TOGGLE_DHCP_SUCCESS');
|
export const toggleDhcpSuccess = createAction('TOGGLE_DHCP_SUCCESS');
|
||||||
|
|
||||||
export const toggleDhcp = status => async (dispatch) => {
|
export const toggleDhcp = config => async (dispatch) => {
|
||||||
dispatch(toggleDhcpRequest());
|
dispatch(toggleDhcpRequest());
|
||||||
let successMessage = '';
|
let successMessage = '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (status) {
|
if (config.enabled) {
|
||||||
successMessage = 'disabled_dhcp';
|
successMessage = 'disabled_dhcp';
|
||||||
await apiClient.disableGlobalProtection();
|
await apiClient.setDhcpConfig({ ...config, enabled: false });
|
||||||
} else {
|
} else {
|
||||||
successMessage = 'enabled_dhcp';
|
successMessage = 'enabled_dhcp';
|
||||||
await apiClient.enableGlobalProtection();
|
await apiClient.setDhcpConfig({ ...config, enabled: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(addSuccessToast(successMessage));
|
dispatch(addSuccessToast(successMessage));
|
||||||
|
|
|
@ -309,64 +309,21 @@ export default class Api {
|
||||||
DHCP_FIND_ACTIVE = { path: 'dhcp/find_active_dhcp', method: 'GET' };
|
DHCP_FIND_ACTIVE = { path: 'dhcp/find_active_dhcp', method: 'GET' };
|
||||||
|
|
||||||
getDhcpStatus() {
|
getDhcpStatus() {
|
||||||
// const { path, method } = this.DHCP_STATUS;
|
const { path, method } = this.DHCP_STATUS;
|
||||||
// return this.makeRequest(path, method);
|
return this.makeRequest(path, method);
|
||||||
|
|
||||||
const example = {
|
|
||||||
config: {
|
|
||||||
enabled: false,
|
|
||||||
gateway_ip: '192.168.1.1',
|
|
||||||
subnet_mask: '255.255.255.0',
|
|
||||||
range_start: '192.168.1.2',
|
|
||||||
range_end: '192.168.10.50',
|
|
||||||
lease_duration: '43200',
|
|
||||||
},
|
|
||||||
leases: [
|
|
||||||
{
|
|
||||||
mac: '001109b3b3b8',
|
|
||||||
ip: '192.168.1.22',
|
|
||||||
hostname: 'dell',
|
|
||||||
expires: '2017-07-21T17:32:28Z',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
mac: '001109b3b3b9',
|
|
||||||
ip: '192.168.1.23',
|
|
||||||
hostname: 'dell',
|
|
||||||
expires: '2017-07-21T17:32:28Z',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
setTimeout(() => {
|
|
||||||
resolve(example);
|
|
||||||
}, 1000);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setDhcpConfig(config) {
|
setDhcpConfig(config) {
|
||||||
// const { path, method } = this.DHCP_SET_CONFIG;
|
const { path, method } = this.DHCP_SET_CONFIG;
|
||||||
// const parameters = config;
|
const parameters = {
|
||||||
// return this.makeRequest(path, method, parameters);
|
data: config,
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
return new Promise((resolve) => {
|
};
|
||||||
setTimeout(() => {
|
return this.makeRequest(path, method, parameters);
|
||||||
resolve(window.alert(`Set config:\n\n${JSON.stringify(config, null, 2)}`));
|
|
||||||
}, 1000);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
findActiveDhcp() {
|
findActiveDhcp() {
|
||||||
// const { path, method } = this.DHCP_FIND_ACTIVE;
|
const { path, method } = this.DHCP_FIND_ACTIVE;
|
||||||
// return this.makeRequest(path, method);
|
return this.makeRequest(path, method);
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
setTimeout(() => {
|
|
||||||
resolve({
|
|
||||||
gateway_ip: '127.0.0.1',
|
|
||||||
found: true,
|
|
||||||
});
|
|
||||||
}, 10000);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ const columns = [{
|
||||||
|
|
||||||
const Leases = props => (
|
const Leases = props => (
|
||||||
<ReactTable
|
<ReactTable
|
||||||
data={props.leases}
|
data={props.leases || []}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
showPagination={false}
|
showPagination={false}
|
||||||
noDataText={ props.t('dhcp_leases_not_found') }
|
noDataText={ props.t('dhcp_leases_not_found') }
|
||||||
|
|
|
@ -17,12 +17,12 @@ class Dhcp extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
getToggleDhcpButton = () => {
|
getToggleDhcpButton = () => {
|
||||||
const { enabled } = this.props.dhcp.config;
|
const { config } = this.props.dhcp;
|
||||||
const buttonText = enabled ? 'dhcp_disable' : 'dhcp_enable';
|
const buttonText = config.enabled ? 'dhcp_disable' : 'dhcp_enable';
|
||||||
const buttonClass = enabled ? 'btn-gray' : 'btn-success';
|
const buttonClass = config.enabled ? 'btn-gray' : 'btn-success';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button type="button" className={`btn btn-standart mr-2 ${buttonClass}`} onClick={() => this.props.toggleDhcp(enabled)}>
|
<button type="button" className={`btn btn-standart mr-2 ${buttonClass}`} onClick={() => this.props.toggleDhcp(config)}>
|
||||||
<Trans>{buttonText}</Trans>
|
<Trans>{buttonText}</Trans>
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
|
|
|
@ -289,6 +289,10 @@ const dhcp = handleActions({
|
||||||
}, {
|
}, {
|
||||||
processing: true,
|
processing: true,
|
||||||
processingStatus: false,
|
processingStatus: false,
|
||||||
|
config: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
leases: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
export default combineReducers({
|
export default combineReducers({
|
||||||
|
|
|
@ -58,7 +58,7 @@ type dhcpState struct {
|
||||||
|
|
||||||
// field ordering is important -- yaml fields will mirror ordering from here
|
// field ordering is important -- yaml fields will mirror ordering from here
|
||||||
type dhcpConfig struct {
|
type dhcpConfig struct {
|
||||||
Enabled bool
|
Enabled bool `json:"enabled" yaml:"enabled"`
|
||||||
GatewayIP string `json:"gateway_ip" yaml:"gateway_ip"`
|
GatewayIP string `json:"gateway_ip" yaml:"gateway_ip"`
|
||||||
SubnetMask string `json:"subnet_mask" yaml:"subnet_mask"`
|
SubnetMask string `json:"subnet_mask" yaml:"subnet_mask"`
|
||||||
RangeStart string `json:"range_start" yaml:"range_start"`
|
RangeStart string `json:"range_start" yaml:"range_start"`
|
||||||
|
|
Loading…
Reference in a new issue