Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that ip should be different from gateway #1669

Merged
merged 8 commits into from
Dec 26, 2023
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
27 changes: 24 additions & 3 deletions packages/playground/src/dashboard/components/public_config.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,16 @@

<input-validator
:value="$props.modelValue.gw4"
:rules="[validators.required('Gateway is required.'), validators.isIP('Gateway is not valid.', 4)]"
:rules="[
validators.required('Gateway is required.'),
validators.isIP('Gateway is not valid.', 4),
value =>
validators.ipNotEqualGateway(
$props.modelValue.ipv4,
$props.modelValue.gw4,
'Gateway IPv4 should not be equal to IPv4.',
)(value),
]"
#="{ props }"
>
<input-tooltip tooltip="Gateway for the IP in ipv4 format">
Expand All @@ -42,7 +51,10 @@
</input-validator>
<input-validator
:value="$props.modelValue.ipv6"
:rules="[value => validators.isIPRange('IP is not valid.', 6)(value)]"
:rules="[
value => ($props.modelValue.gw6 !== '' ? validators.required('IPv6 is required.')(value) : '') as RuleReturn,
value => validators.isIPRange('IP is not valid.', 6)(value),
]"
#="{ props }"
>
<input-tooltip tooltip="IPV6 address in format x:x:x:x:x:x:x:x">
Expand All @@ -52,7 +64,15 @@

<input-validator
:value="$props.modelValue.gw6"
:rules="[value => validators.isIP('Gateway is not valid.', 6)(value)]"
:rules="[
value => ($props.modelValue.ipv6 !== '' ? validators.required('Gateway is required.')(value) : '') as RuleReturn,
value => validators.isIP('Gateway is not valid.', 6)(value),
value => validators.ipNotEqualGateway(
$props.modelValue.ipv6!,
$props.modelValue.gw6!,
'Gateway IPv6 should not be equal to IPv6.',
)(value),
]"
#="{ props }"
>
<input-tooltip tooltip="Gateway for the IP in ipv6 format">
Expand Down Expand Up @@ -139,6 +159,7 @@ import _ from "lodash";
import { onMounted, type PropType, ref, watch } from "vue";

import { gridProxyClient } from "@/clients";
import type { RuleReturn } from "@/components/input_validator.vue";
import { useFormRef } from "@/hooks/form_validator";
import type { IPublicConfig } from "@/utils/types";

Expand Down
9 changes: 9 additions & 0 deletions packages/playground/src/utils/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,15 @@ export function isString(msg: string) {
};
}

export function ipNotEqualGateway(ip: string, gw: string, msg: string) {
return (value: string) => {
const address = ip.split("/")[0];
if (gw === address) {
return { message: msg, isNotEqualStrings: true };
}
};
}

export interface RegexPattern {
pattern: string | RegExp;
flags?: string | undefined;
Expand Down
Loading