Merge in DNS/adguard-home from 3529-validate-dhcpv4 to master Squashed commit of the following: commit 2f2455aa13a41398cd2846f31be96da9d34ba95d Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Tue Oct 19 19:18:12 2021 +0300 dhcpv4: better test && fix changelog commit ec4ff9180e8390fb739b3be0fc76fd2c715fe691 Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Mon Oct 18 19:08:44 2021 +0300 dhcpv4: better tests commit e0e2f27b7a063ed84af170b16c3f87636cb738d2 Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Mon Oct 18 18:55:47 2021 +0300 dhcpv4: better tests commit 73e1d08e1265e336ee6339d5021f90883fe3e395 Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Mon Oct 18 18:47:21 2021 +0300 dhcpv4: better tests commit f636fc316123f26b6e2930afb4b22c18024ec93d Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Mon Oct 18 18:47:07 2021 +0300 all: updated golibs commit 86dd107a1d483ac24bd8c26422324eb8b9c3d086 Merge: 51aaf6d9b296fa22Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Mon Oct 18 17:18:17 2021 +0300 Merge branch 'master' into 3529-validate-dhcpv4 commit 51aaf6d9eb5fbe2b4304254dc6782305a19c53fa Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Mon Oct 18 17:18:02 2021 +0300 dhcpv4: better changelog commit 720b896bb595c57fab6d376f88c8a4b1d131db40 Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Mon Oct 18 17:14:25 2021 +0300 dhcpv4: better tests commit 1098beffca8d5feb2ec104d26419210962c9a97d Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Mon Oct 18 12:08:26 2021 +0300 dhcp: changelog commit d1f6c89d68657431fb261658133c67e9e3135c1c Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Mon Oct 18 12:03:06 2021 +0300 dhcpv4: fixed tests commit 8b6713468fc04321c5238300df90bbb2d67ee679 Merge: 9991e9cb3fa38fb4Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Mon Oct 18 11:57:57 2021 +0300 Merge branch 'master' into 3529-validate-dhcpv4 commit 9991e9cbee7dc87d8fa1d7e86e6cc7e09ab6938c Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Mon Oct 18 11:55:40 2021 +0300 dhcpv4: added tests commit 5798a80de6c060365c1c647326d46cc13ccf28cb Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Mon Oct 18 11:46:03 2021 +0300 dhcpv4: validate subnet mask and ip range
166 lines
6.3 KiB
JavaScript
166 lines
6.3 KiB
JavaScript
import React, { useCallback } from 'react';
|
|
import { shallowEqual, useSelector } from 'react-redux';
|
|
import PropTypes from 'prop-types';
|
|
import { Field, reduxForm } from 'redux-form';
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import {
|
|
renderInputField,
|
|
toNumber,
|
|
} from '../../../helpers/form';
|
|
import { FORM_NAME, UINT32_RANGE } from '../../../helpers/constants';
|
|
import {
|
|
validateIpv4,
|
|
validateRequiredValue,
|
|
validateIpv4RangeEnd,
|
|
validateGatewaySubnetMask,
|
|
validateIpForGatewaySubnetMask,
|
|
validateNotInRange,
|
|
} from '../../../helpers/validators';
|
|
|
|
const FormDHCPv4 = ({
|
|
handleSubmit,
|
|
submitting,
|
|
processingConfig,
|
|
ipv4placeholders,
|
|
}) => {
|
|
const { t } = useTranslation();
|
|
const dhcp = useSelector((state) => state.form[FORM_NAME.DHCPv4], shallowEqual);
|
|
const interfaces = useSelector((state) => state.form[FORM_NAME.DHCP_INTERFACES], shallowEqual);
|
|
const interface_name = interfaces?.values?.interface_name;
|
|
|
|
const isInterfaceIncludesIpv4 = useSelector(
|
|
(state) => !!state.dhcp?.interfaces?.[interface_name]?.ipv4_addresses,
|
|
);
|
|
|
|
const isEmptyConfig = !Object.values(dhcp?.values?.v4 ?? {})
|
|
.some(Boolean);
|
|
|
|
const invalid = dhcp?.syncErrors || interfaces?.syncErrors || !isInterfaceIncludesIpv4
|
|
|| isEmptyConfig || submitting || processingConfig;
|
|
|
|
const validateRequired = useCallback((value) => {
|
|
if (isEmptyConfig) {
|
|
return undefined;
|
|
}
|
|
return validateRequiredValue(value);
|
|
}, [isEmptyConfig]);
|
|
|
|
return <form onSubmit={handleSubmit}>
|
|
<div className="row">
|
|
<div className="col-lg-6">
|
|
<div className="form__group form__group--settings">
|
|
<label>{t('dhcp_form_gateway_input')}</label>
|
|
<Field
|
|
name="v4.gateway_ip"
|
|
component={renderInputField}
|
|
type="text"
|
|
className="form-control"
|
|
placeholder={t(ipv4placeholders.gateway_ip)}
|
|
validate={[
|
|
validateIpv4,
|
|
validateRequired,
|
|
validateNotInRange,
|
|
]}
|
|
disabled={!isInterfaceIncludesIpv4}
|
|
/>
|
|
</div>
|
|
<div className="form__group form__group--settings">
|
|
<label>{t('dhcp_form_subnet_input')}</label>
|
|
<Field
|
|
name="v4.subnet_mask"
|
|
component={renderInputField}
|
|
type="text"
|
|
className="form-control"
|
|
placeholder={t(ipv4placeholders.subnet_mask)}
|
|
validate={[
|
|
validateIpv4,
|
|
validateRequired,
|
|
validateGatewaySubnetMask,
|
|
]}
|
|
disabled={!isInterfaceIncludesIpv4}
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div className="col-lg-6">
|
|
<div className="form__group form__group--settings">
|
|
<div className="row">
|
|
<div className="col-12">
|
|
<label>{t('dhcp_form_range_title')}</label>
|
|
</div>
|
|
<div className="col">
|
|
<Field
|
|
name="v4.range_start"
|
|
component={renderInputField}
|
|
type="text"
|
|
className="form-control"
|
|
placeholder={t(ipv4placeholders.range_start)}
|
|
validate={[
|
|
validateIpv4,
|
|
validateGatewaySubnetMask,
|
|
validateIpForGatewaySubnetMask,
|
|
]}
|
|
disabled={!isInterfaceIncludesIpv4}
|
|
/>
|
|
</div>
|
|
<div className="col">
|
|
<Field
|
|
name="v4.range_end"
|
|
component={renderInputField}
|
|
type="text"
|
|
className="form-control"
|
|
placeholder={t(ipv4placeholders.range_end)}
|
|
validate={[
|
|
validateIpv4,
|
|
validateIpv4RangeEnd,
|
|
validateGatewaySubnetMask,
|
|
validateIpForGatewaySubnetMask,
|
|
]}
|
|
disabled={!isInterfaceIncludesIpv4}
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div className="form__group form__group--settings">
|
|
<label>{t('dhcp_form_lease_title')}</label>
|
|
<Field
|
|
name="v4.lease_duration"
|
|
component={renderInputField}
|
|
type="number"
|
|
className="form-control"
|
|
placeholder={t(ipv4placeholders.lease_duration)}
|
|
validate={validateRequired}
|
|
normalize={toNumber}
|
|
min={1}
|
|
max={UINT32_RANGE.MAX}
|
|
disabled={!isInterfaceIncludesIpv4}
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div className="btn-list">
|
|
<button
|
|
type="submit"
|
|
className="btn btn-success btn-standard"
|
|
disabled={invalid}
|
|
>
|
|
{t('save_config')}
|
|
</button>
|
|
</div>
|
|
</form>;
|
|
};
|
|
|
|
FormDHCPv4.propTypes = {
|
|
handleSubmit: PropTypes.func.isRequired,
|
|
submitting: PropTypes.bool.isRequired,
|
|
initialValues: PropTypes.object.isRequired,
|
|
processingConfig: PropTypes.bool.isRequired,
|
|
change: PropTypes.func.isRequired,
|
|
reset: PropTypes.func.isRequired,
|
|
ipv4placeholders: PropTypes.object.isRequired,
|
|
};
|
|
|
|
export default reduxForm({
|
|
form: FORM_NAME.DHCPv4,
|
|
})(FormDHCPv4);
|