2018-12-12 15:12:51 +00:00
|
|
|
import React, { Component, Fragment } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import { Trans, withNamespaces } from 'react-i18next';
|
|
|
|
|
|
|
|
import Form from './Form';
|
|
|
|
import Leases from './Leases';
|
2018-12-29 15:43:17 +00:00
|
|
|
import Interface from './Interface';
|
2018-12-12 15:12:51 +00:00
|
|
|
import Card from '../../ui/Card';
|
2019-03-28 13:30:22 +00:00
|
|
|
import Accordion from '../../ui/Accordion';
|
2018-12-12 15:12:51 +00:00
|
|
|
|
|
|
|
class Dhcp extends Component {
|
|
|
|
handleFormSubmit = (values) => {
|
|
|
|
this.props.setDhcpConfig(values);
|
|
|
|
};
|
|
|
|
|
2018-12-29 15:43:17 +00:00
|
|
|
handleToggle = (config) => {
|
|
|
|
this.props.toggleDhcp(config);
|
2018-12-12 15:12:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getToggleDhcpButton = () => {
|
2019-01-23 14:22:04 +00:00
|
|
|
const {
|
|
|
|
config, active, processingDhcp, processingConfig,
|
|
|
|
} = this.props.dhcp;
|
2018-12-29 15:43:17 +00:00
|
|
|
const activeDhcpFound = active && active.found;
|
|
|
|
const filledConfig = Object.keys(config).every((key) => {
|
2019-03-28 13:32:22 +00:00
|
|
|
if (key === 'enabled' || key === 'icmp_timeout_msec') {
|
2018-12-29 15:43:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return config[key];
|
|
|
|
});
|
|
|
|
|
|
|
|
if (config.enabled) {
|
|
|
|
return (
|
|
|
|
<button
|
|
|
|
type="button"
|
2019-01-18 17:17:48 +00:00
|
|
|
className="btn btn-standard mr-2 btn-gray"
|
2018-12-29 15:43:17 +00:00
|
|
|
onClick={() => this.props.toggleDhcp(config)}
|
2019-01-23 14:22:04 +00:00
|
|
|
disabled={processingDhcp || processingConfig}
|
2018-12-29 15:43:17 +00:00
|
|
|
>
|
|
|
|
<Trans>dhcp_disable</Trans>
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|
2018-12-12 15:12:51 +00:00
|
|
|
|
|
|
|
return (
|
2018-12-28 16:48:02 +00:00
|
|
|
<button
|
|
|
|
type="button"
|
2019-01-18 17:17:48 +00:00
|
|
|
className="btn btn-standard mr-2 btn-success"
|
2018-12-29 15:43:17 +00:00
|
|
|
onClick={() => this.handleToggle(config)}
|
2019-01-23 14:22:04 +00:00
|
|
|
disabled={
|
|
|
|
!filledConfig
|
|
|
|
|| activeDhcpFound
|
|
|
|
|| processingDhcp
|
|
|
|
|| processingConfig
|
|
|
|
}
|
2018-12-28 16:48:02 +00:00
|
|
|
>
|
2018-12-29 15:43:17 +00:00
|
|
|
<Trans>dhcp_enable</Trans>
|
2018-12-12 15:12:51 +00:00
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-03-28 13:30:22 +00:00
|
|
|
getActiveDhcpMessage = (t, active) => {
|
2018-12-29 15:43:17 +00:00
|
|
|
if (active) {
|
|
|
|
if (active.error) {
|
|
|
|
return (
|
2019-01-28 11:19:31 +00:00
|
|
|
<div className="text-danger mb-2">
|
2019-03-28 13:30:22 +00:00
|
|
|
<Trans>dhcp_error</Trans>
|
|
|
|
<div className="mt-2 mb-2">
|
|
|
|
<Accordion label={t('error_details')}>
|
|
|
|
<span>{active.error}</span>
|
|
|
|
</Accordion>
|
|
|
|
</div>
|
2018-12-29 15:43:17 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2019-01-28 11:19:31 +00:00
|
|
|
<div className="mb-2">
|
2018-12-29 15:43:17 +00:00
|
|
|
{active.found ? (
|
|
|
|
<div className="text-danger">
|
|
|
|
<Trans>dhcp_found</Trans>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className="text-secondary">
|
|
|
|
<Trans>dhcp_not_found</Trans>
|
|
|
|
</div>
|
|
|
|
)}
|
2019-01-28 11:19:31 +00:00
|
|
|
</div>
|
2018-12-29 15:43:17 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2019-03-28 13:30:22 +00:00
|
|
|
getDhcpWarning = (active) => {
|
|
|
|
if (active && active.found === false) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="text-danger">
|
|
|
|
<Trans>dhcp_warning</Trans>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-12-12 15:12:51 +00:00
|
|
|
render() {
|
|
|
|
const { t, dhcp } = this.props;
|
|
|
|
const statusButtonClass = classnames({
|
2019-01-18 17:17:48 +00:00
|
|
|
'btn btn-primary btn-standard': true,
|
|
|
|
'btn btn-primary btn-standard btn-loading': dhcp.processingStatus,
|
2018-12-12 15:12:51 +00:00
|
|
|
});
|
2019-01-23 14:22:04 +00:00
|
|
|
const {
|
2019-01-25 16:07:46 +00:00
|
|
|
enabled,
|
2019-01-23 14:22:04 +00:00
|
|
|
interface_name,
|
2019-01-25 16:05:50 +00:00
|
|
|
...values
|
2019-01-23 14:22:04 +00:00
|
|
|
} = dhcp.config;
|
2018-12-12 15:12:51 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Fragment>
|
2018-12-29 15:43:17 +00:00
|
|
|
<Card title={ t('dhcp_title') } subtitle={ t('dhcp_description') } bodyType="card-body box-body--settings">
|
|
|
|
<div className="dhcp">
|
|
|
|
{!dhcp.processing &&
|
|
|
|
<Fragment>
|
|
|
|
<Interface
|
2019-01-23 14:22:04 +00:00
|
|
|
onChange={this.handleFormSubmit}
|
2019-01-25 16:05:50 +00:00
|
|
|
initialValues={{ interface_name }}
|
2018-12-29 15:43:17 +00:00
|
|
|
interfaces={dhcp.interfaces}
|
|
|
|
processing={dhcp.processingInterfaces}
|
|
|
|
enabled={dhcp.config.enabled}
|
|
|
|
/>
|
2018-12-28 16:48:02 +00:00
|
|
|
<Form
|
|
|
|
onSubmit={this.handleFormSubmit}
|
2019-01-25 16:05:50 +00:00
|
|
|
initialValues={{ ...values }}
|
2018-12-28 16:48:02 +00:00
|
|
|
interfaces={dhcp.interfaces}
|
2019-01-23 14:22:04 +00:00
|
|
|
processingConfig={dhcp.processingConfig}
|
2018-12-28 16:48:02 +00:00
|
|
|
/>
|
|
|
|
<hr/>
|
|
|
|
<div className="card-actions mb-3">
|
2018-12-12 15:12:51 +00:00
|
|
|
{this.getToggleDhcpButton()}
|
|
|
|
<button
|
|
|
|
type="button"
|
2018-12-29 15:43:17 +00:00
|
|
|
className={statusButtonClass}
|
|
|
|
onClick={() =>
|
|
|
|
this.props.findActiveDhcp(dhcp.config.interface_name)
|
|
|
|
}
|
2019-01-28 11:19:31 +00:00
|
|
|
disabled={
|
|
|
|
!dhcp.config.interface_name
|
|
|
|
|| dhcp.processingConfig
|
|
|
|
}
|
2018-12-12 15:12:51 +00:00
|
|
|
>
|
2018-12-29 15:43:17 +00:00
|
|
|
<Trans>check_dhcp_servers</Trans>
|
2018-12-12 15:12:51 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
2019-03-28 13:30:22 +00:00
|
|
|
{this.getActiveDhcpMessage(t, dhcp.active)}
|
|
|
|
{this.getDhcpWarning(dhcp.active)}
|
2018-12-29 15:43:17 +00:00
|
|
|
</Fragment>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
</Card>
|
2018-12-12 15:12:51 +00:00
|
|
|
{!dhcp.processing && dhcp.config.enabled &&
|
|
|
|
<Card title={ t('dhcp_leases') } bodyType="card-body box-body--settings">
|
|
|
|
<div className="row">
|
|
|
|
<div className="col">
|
|
|
|
<Leases leases={dhcp.leases} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Card>
|
|
|
|
}
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Dhcp.propTypes = {
|
|
|
|
dhcp: PropTypes.object,
|
|
|
|
toggleDhcp: PropTypes.func,
|
|
|
|
getDhcpStatus: PropTypes.func,
|
|
|
|
setDhcpConfig: PropTypes.func,
|
|
|
|
findActiveDhcp: PropTypes.func,
|
|
|
|
handleSubmit: PropTypes.func,
|
|
|
|
t: PropTypes.func,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default withNamespaces()(Dhcp);
|