Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions web/src/pages/AddLocationPage/steps/AddLocationInternalVpnStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,35 @@ const formSchema = z.object({
(value) => Validate.any(value, [Validate.CIDRv4, Validate.CIDRv6], true),
m.form_error_invalid(),
),
allowed_ips: z.string(m.form_error_required()).trim(),
dns: z.string().nullable(),
allowed_ips: z
.string()
.trim()
.nullable()
.refine((val) => {
if (!val) return true;
return Validate.any(
val,
[
Validate.IPv4,
Validate.IPv6,
(v) => Validate.CIDRv4(v, true),
(v) => Validate.CIDRv6(v, true),
],
true,
);
}, m.form_error_invalid()),
dns: z
.string()
.trim()
.nullable()
.refine((val) => {
if (!val) return true;
return Validate.any(
val,
[Validate.IPv4, Validate.IPv6, Validate.Domain, Validate.Hostname],
true,
);
}),
});

type FormFields = z.infer<typeof formSchema>;
Expand All @@ -48,6 +75,7 @@ export const AddLocationInternalVpnStep = () => {
onSubmit: ({ value }) => {
useAddLocationStore.setState({
...value,
allowed_ips: value.allowed_ips ?? '',
activeStep: AddLocationPageStep.NetworkSettings,
});
},
Expand Down Expand Up @@ -96,6 +124,7 @@ export const AddLocationInternalVpnStep = () => {
useAddLocationStore.setState({
activeStep: AddLocationPageStep.Start,
...form.state.values,
allowed_ips: form.state.values.allowed_ips ?? '',
});
}}
/>
Expand Down
13 changes: 11 additions & 2 deletions web/src/pages/AddLocationPage/steps/AddLocationStartStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,19 @@ const formSchema = z.object({
.trim()
.min(1, m.form_error_required())
.refine(
(value) => Validate.any(value, [Validate.IPv4, Validate.IPv6, Validate.Domain]),
(value) =>
Validate.any(value, [
Validate.IPv4,
Validate.IPv6,
Validate.Domain,
Validate.Hostname,
]),
m.form_error_invalid(),
),
port: z.number(m.form_error_required()).max(65535, m.form_error_port_max()),
port: z
.number(m.form_error_required())
.min(1, m.form_min_value({ value: 1 }))
.max(65535, m.form_error_port_max()),
});

type FormFields = z.infer<typeof formSchema>;
Expand Down
10 changes: 8 additions & 2 deletions web/src/pages/EdgeSetupPage/steps/SetupEdgeComponentStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { SizedBox } from '../../../shared/defguard-ui/components/SizedBox/SizedB
import { ThemeSpacing } from '../../../shared/defguard-ui/types';
import { useAppForm } from '../../../shared/form';
import { formChangeLogic } from '../../../shared/formLogic';
import { validateIpOrDomain } from '../../../shared/validators';
import { Validate } from '../../../shared/validate';
import { EdgeSetupStep } from '../types';
import { useEdgeWizardStore } from '../useEdgeWizardStore';

Expand Down Expand Up @@ -53,7 +53,13 @@ export const SetupEdgeComponentStep = () => {
ip_or_domain: z
.string()
.min(1, m.edge_setup_component_error_ip_or_domain_required())
.refine((val) => validateIpOrDomain(val, false, true)),
.refine((val) =>
Validate.any(
val,
[Validate.IPv4, Validate.IPv6, Validate.Domain, Validate.Hostname],
false,
),
),
grpc_port: z
.number()
.min(1, m.edge_setup_component_error_grpc_port_required())
Expand Down
45 changes: 40 additions & 5 deletions web/src/pages/EditLocationPage/EditLocationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
canUseBusinessFeature,
canUseEnterpriseFeature,
} from '../../shared/utils/license';
import { validateIpList, validateIpOrDomainList } from '../../shared/validators';
import { Validate } from '../../shared/validate';

export const EditLocationPage = () => {
const { locationId: paramsId } = useParams({
Expand Down Expand Up @@ -76,17 +76,51 @@ const formSchema = z
.string(m.form_error_required())
.trim()
.min(1, m.form_error_required())
.refine((value) => validateIpList(value, ',', true), m.form_error_invalid()),
endpoint: z.string(m.form_error_required()).trim().min(1, m.form_error_required()),
.refine(
(val) => Validate.any(val, [Validate.CIDRv4, Validate.CIDRv6], true),
m.form_error_invalid(),
),
endpoint: z
.string(m.form_error_required())
.trim()
.min(1, m.form_error_required())
.refine((val) =>
Validate.any(val, [
Validate.IPv4,
Validate.IPv6,
Validate.Domain,
Validate.Hostname,
]),
),
port: z.number(m.form_error_required()).max(65535, m.form_error_port_max()),
allowed_ips: z.string(m.form_error_required()).trim(),
allowed_ips: z
.string()
.trim()
.nullable()
.refine((val) => {
if (!val) return true;
return Validate.any(
val,
[
Validate.IPv4,
Validate.IPv6,
(v) => Validate.CIDRv4(v, true),
(v) => Validate.CIDRv6(v, true),
],
true,
);
}, m.form_error_invalid()),
dns: z
.string()
.trim()
.nullable()
.refine((val) => {
if (!val) return true;
return validateIpOrDomainList(val, ',', true, true);
return Validate.any(
val,
[Validate.IPv4, Validate.IPv6, Validate.Domain, Validate.Hostname],
true,
);
}),
peer_disconnect_threshold: z.number().nullable(),
keepalive_interval: z
Expand Down Expand Up @@ -237,6 +271,7 @@ const EditLocationForm = ({ location }: { location: NetworkLocation }) => {
...omit(clone, ['firewall']),
allow_all_groups: clone.allow_all_groups,
allowed_groups: clone.allowed_groups,
allowed_ips: clone.allowed_ips ?? '',
acl_default_allow: clone.firewall === LocationFirewall.Allow,
acl_enabled: !(clone.firewall === LocationFirewall.Disabled),
peer_disconnect_threshold: peerDisconnectThreshold,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { formChangeLogic } from '../../../shared/formLogic';
import { GatewaySetupStep } from '../types';
import { useGatewayWizardStore } from '../useGatewayWizardStore';
import './style.scss';
import { validateIpOrDomain } from '../../../shared/validators';
import { Validate } from '../../../shared/validate';

type FormFields = StoreValues;

Expand Down Expand Up @@ -54,7 +54,13 @@ export const SetupGatewayComponentStep = () => {
ip_or_domain: z
.string()
.min(1, m.edge_setup_component_error_ip_or_domain_required())
.refine((val) => validateIpOrDomain(val, false, true)),
.refine((val) =>
Validate.any(
val,
[Validate.IPv4, Validate.IPv6, Validate.Domain, Validate.Hostname],
false,
),
),
grpc_port: z
.number()
.min(1, m.edge_setup_component_error_grpc_port_required())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { SizedBox } from '../../../shared/defguard-ui/components/SizedBox/SizedB
import { ThemeSpacing } from '../../../shared/defguard-ui/types';
import { useAppForm } from '../../../shared/form';
import { formChangeLogic } from '../../../shared/formLogic';
import { validateIpOrDomain } from '../../../shared/validators';
import { Validate } from '../../../shared/validate';
import { useMigrationWizardStore } from '../store/useMigrationWizardStore';

type FormFields = StoreValues;
Expand Down Expand Up @@ -41,7 +41,13 @@ export const MigrationWizardEdgeComponentStep = () => {
ip_or_domain: z
.string()
.min(1, m.edge_setup_component_error_ip_or_domain_required())
.refine((val) => validateIpOrDomain(val, false, true)),
.refine((val) =>
Validate.any(
val,
[Validate.IPv4, Validate.IPv6, Validate.Domain, Validate.Hostname],
false,
),
),
grpc_port: z
.number()
.min(1, m.edge_setup_component_error_grpc_port_required())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ const formSchema = z.object({
.trim()
.min(1, m.form_error_required())
.refine(
(value) => Validate.any(value, [Validate.IPv4, Validate.IPv6, Validate.Domain]),
(value) =>
Validate.any(value, [
Validate.IPv4,
Validate.IPv6,
Validate.Domain,
Validate.Hostname,
]),
m.initial_setup_auto_adoption_vpn_error_invalid_value(),
),
vpn_wireguard_port: z
Expand All @@ -37,8 +43,35 @@ const formSchema = z.object({
(value) => Validate.any(value, [Validate.CIDRv4, Validate.CIDRv6], true),
m.initial_setup_auto_adoption_vpn_error_invalid_value(),
),
vpn_allowed_ips: z.string().trim(),
vpn_dns_server_ip: z.string().trim(),
vpn_allowed_ips: z
.string()
.trim()
.nullable()
.refine((val) => {
if (!val) return true;
return Validate.any(
val,
[
Validate.IPv4,
Validate.IPv6,
(v) => Validate.CIDRv4(v, true),
(v) => Validate.CIDRv6(v, true),
],
true,
);
}, m.form_error_invalid()),
vpn_dns_server_ip: z
.string()
.trim()
.nullable()
.refine((val) => {
if (!val) return true;
return Validate.any(
val,
[Validate.IPv4, Validate.IPv6, Validate.Domain, Validate.Hostname],
true,
);
}),
});

type FormFields = z.infer<typeof formSchema>;
Expand Down Expand Up @@ -72,8 +105,13 @@ export const AutoAdoptionVpnSettingsStep = () => {
onChange: formSchema,
},
onSubmit: ({ value }) => {
useAutoAdoptionSetupWizardStore.setState(value);
setVpnSettings(value);
const storeValue = {
...value,
vpn_allowed_ips: value.vpn_allowed_ips ?? '',
vpn_dns_server_ip: value.vpn_dns_server_ip ?? '',
};
useAutoAdoptionSetupWizardStore.setState(storeValue);
setVpnSettings(storeValue);
},
});

Expand Down Expand Up @@ -144,7 +182,11 @@ export const AutoAdoptionVpnSettingsStep = () => {
variant="outlined"
text={m.initial_setup_controls_back()}
onClick={() => {
useAutoAdoptionSetupWizardStore.setState(form.state.values);
useAutoAdoptionSetupWizardStore.setState({
...form.state.values,
vpn_allowed_ips: form.state.values.vpn_allowed_ips ?? '',
vpn_dns_server_ip: form.state.values.vpn_dns_server_ip ?? '',
});
setActiveStep(AutoAdoptionSetupStep.UrlSettings);
}}
/>
Expand Down
10 changes: 8 additions & 2 deletions web/src/pages/SetupPage/initial/steps/SetupEdgeComponentStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { SizedBox } from '../../../../shared/defguard-ui/components/SizedBox/Siz
import { ThemeSpacing } from '../../../../shared/defguard-ui/types';
import { useAppForm } from '../../../../shared/form';
import { formChangeLogic } from '../../../../shared/formLogic';
import { validateIpOrDomain } from '../../../../shared/validators';
import { Validate } from '../../../../shared/validate';
import { SetupPageStep } from '../types';
import { useSetupWizardStore } from '../useSetupWizardStore';

Expand Down Expand Up @@ -47,7 +47,13 @@ export const SetupEdgeComponentStep = () => {
ip_or_domain: z
.string()
.min(1, m.edge_setup_component_error_ip_or_domain_required())
.refine((val) => validateIpOrDomain(val, false, true)),
.refine((val) =>
Validate.any(
val,
[Validate.IPv4, Validate.IPv6, Validate.Domain, Validate.Hostname],
false,
),
),
grpc_port: z
.number()
.min(1, m.edge_setup_component_error_grpc_port_required())
Expand Down
12 changes: 10 additions & 2 deletions web/src/pages/settings/SettingsSmtpPage/SettingsSmtpPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { ModalName } from '../../../shared/hooks/modalControls/modalTypes';
import { useApp } from '../../../shared/hooks/useApp';
import { patternValidEmail } from '../../../shared/patterns';
import { getSettingsQueryOptions } from '../../../shared/query';
import { validateIpOrDomain } from '../../../shared/validators';
import { Validate } from '../../../shared/validate';
import { configuredBadge, notConfiguredBadge } from '../SettingsIndexPage/types';
import { SendTestEmailModal } from './SendTestEmailModal';

Expand Down Expand Up @@ -109,7 +109,15 @@ const Content = ({ settings }: { settings: Settings }) => {
.string()
.trim()
.min(1, m.form_error_required())
.refine((val) => (!val ? true : validateIpOrDomain(val, false, true))),
.refine((val) =>
!val
? true
: Validate.any(
val,
[Validate.IPv4, Validate.IPv6, Validate.Domain, Validate.Hostname],
false,
),
),
smtp_port: z.number(m.form_error_required()).max(65535, m.form_error_port_max()),
smtp_password: z.string().trim(),
smtp_user: z.string().trim(),
Expand Down
5 changes: 3 additions & 2 deletions web/src/shared/patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ export const ipv4Pattern = /^(\d{1,3}\.){3}\d{1,3}$/;
export const ipv4WithPortPattern = /^(\d{1,3}\.){3}\d{1,3}:\d{1,5}$/;
export const ipv4WithCIDRPattern = /^(\d{1,3}\.){3}\d{1,3}\/([0-9]|[1-2][0-9]|3[0-2])$/;
export const domainPattern =
/^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i;

/^(?:(?:(?:[A-Za-z-]+):\/{1,3})?(?:[A-Za-z0-9])(?:[A-Za-z0-9-]*[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)*(?:\.[A-Za-z]{2,})+|\[(?:(?:(?:[a-fA-F0-9]){1,4})(?::(?:[a-fA-F0-9]){1,4}){7}|::1|::)\])$/;
export const domainWithPortPattern =
/^(?:(?:(?:[A-Za-z-]+):\/{1,3})?(?:[A-Za-z0-9])(?:[A-Za-z0-9\-.]){1,61}(?:\.[A-Za-z]{2,})+|\[(?:(?:(?:[a-fA-F0-9]){1,4})(?::(?:[a-fA-F0-9]){1,4}){7}|::1|::)\]|(?:(?:[0-9]{1,3})(?:\.[0-9]{1,3}){3})):[0-9]{1,5}$/;

export const hostnamePattern = /^[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?$/;

export const patternSafeUsernameCharacters = /^[a-zA-Z0-9]+[a-zA-Z0-9.\-_]*$/;

export const patternLoginCharacters = /^[a-zA-Z0-9]+[a-zA-Z0-9.\-_@]*$/;
Expand Down
Loading
Loading