Add enable/disable for DHCP server
This commit is contained in:
parent
96fbf7f134
commit
d46b65f982
|
@ -138,5 +138,6 @@
|
|||
"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_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());
|
||||
try {
|
||||
await apiClient.setDhcpConfig(config);
|
||||
dispatch(addSuccessToast('dhcp_config_saved'));
|
||||
dispatch(setDhcpConfigSuccess());
|
||||
} catch (error) {
|
||||
dispatch(addErrorToast({ error }));
|
||||
|
@ -572,17 +573,17 @@ export const toggleDhcpRequest = createAction('TOGGLE_DHCP_REQUEST');
|
|||
export const toggleDhcpFailure = createAction('TOGGLE_DHCP_FAILURE');
|
||||
export const toggleDhcpSuccess = createAction('TOGGLE_DHCP_SUCCESS');
|
||||
|
||||
export const toggleDhcp = status => async (dispatch) => {
|
||||
export const toggleDhcp = config => async (dispatch) => {
|
||||
dispatch(toggleDhcpRequest());
|
||||
let successMessage = '';
|
||||
|
||||
try {
|
||||
if (status) {
|
||||
if (config.enabled) {
|
||||
successMessage = 'disabled_dhcp';
|
||||
await apiClient.disableGlobalProtection();
|
||||
await apiClient.setDhcpConfig({ ...config, enabled: false });
|
||||
} else {
|
||||
successMessage = 'enabled_dhcp';
|
||||
await apiClient.enableGlobalProtection();
|
||||
await apiClient.setDhcpConfig({ ...config, enabled: true });
|
||||
}
|
||||
|
||||
dispatch(addSuccessToast(successMessage));
|
||||
|
|
|
@ -309,64 +309,21 @@ export default class Api {
|
|||
DHCP_FIND_ACTIVE = { path: 'dhcp/find_active_dhcp', method: 'GET' };
|
||||
|
||||
getDhcpStatus() {
|
||||
// const { path, method } = this.DHCP_STATUS;
|
||||
// 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);
|
||||
});
|
||||
const { path, method } = this.DHCP_STATUS;
|
||||
return this.makeRequest(path, method);
|
||||
}
|
||||
|
||||
setDhcpConfig(config) {
|
||||
// const { path, method } = this.DHCP_SET_CONFIG;
|
||||
// const parameters = config;
|
||||
// return this.makeRequest(path, method, parameters);
|
||||
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve(window.alert(`Set config:\n\n${JSON.stringify(config, null, 2)}`));
|
||||
}, 1000);
|
||||
});
|
||||
const { path, method } = this.DHCP_SET_CONFIG;
|
||||
const parameters = {
|
||||
data: config,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
};
|
||||
return this.makeRequest(path, method, parameters);
|
||||
}
|
||||
|
||||
findActiveDhcp() {
|
||||
// const { path, method } = this.DHCP_FIND_ACTIVE;
|
||||
// return this.makeRequest(path, method);
|
||||
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve({
|
||||
gateway_ip: '127.0.0.1',
|
||||
found: true,
|
||||
});
|
||||
}, 10000);
|
||||
});
|
||||
const { path, method } = this.DHCP_FIND_ACTIVE;
|
||||
return this.makeRequest(path, method);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ const columns = [{
|
|||
|
||||
const Leases = props => (
|
||||
<ReactTable
|
||||
data={props.leases}
|
||||
data={props.leases || []}
|
||||
columns={columns}
|
||||
showPagination={false}
|
||||
noDataText={ props.t('dhcp_leases_not_found') }
|
||||
|
|
|
@ -17,12 +17,12 @@ class Dhcp extends Component {
|
|||
}
|
||||
|
||||
getToggleDhcpButton = () => {
|
||||
const { enabled } = this.props.dhcp.config;
|
||||
const buttonText = enabled ? 'dhcp_disable' : 'dhcp_enable';
|
||||
const buttonClass = enabled ? 'btn-gray' : 'btn-success';
|
||||
const { config } = this.props.dhcp;
|
||||
const buttonText = config.enabled ? 'dhcp_disable' : 'dhcp_enable';
|
||||
const buttonClass = config.enabled ? 'btn-gray' : 'btn-success';
|
||||
|
||||
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>
|
||||
</button>
|
||||
);
|
||||
|
|
|
@ -289,6 +289,10 @@ const dhcp = handleActions({
|
|||
}, {
|
||||
processing: true,
|
||||
processingStatus: false,
|
||||
config: {
|
||||
enabled: false,
|
||||
},
|
||||
leases: [],
|
||||
});
|
||||
|
||||
export default combineReducers({
|
||||
|
|
|
@ -58,7 +58,7 @@ type dhcpState struct {
|
|||
|
||||
// field ordering is important -- yaml fields will mirror ordering from here
|
||||
type dhcpConfig struct {
|
||||
Enabled bool
|
||||
Enabled bool `json:"enabled" yaml:"enabled"`
|
||||
GatewayIP string `json:"gateway_ip" yaml:"gateway_ip"`
|
||||
SubnetMask string `json:"subnet_mask" yaml:"subnet_mask"`
|
||||
RangeStart string `json:"range_start" yaml:"range_start"`
|
||||
|
|
Loading…
Reference in New Issue