diff --git a/src/components/networkByIdPage/memberOptionsModal.tsx b/src/components/networkByIdPage/memberOptionsModal.tsx index c12aeb3c..ae0127e6 100644 --- a/src/components/networkByIdPage/memberOptionsModal.tsx +++ b/src/components/networkByIdPage/memberOptionsModal.tsx @@ -137,22 +137,6 @@ export const MemberOptionsModal: React.FC = ({ return; } - const regex = new RegExp( - "^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\." + - "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\." + - "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\." + - "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$", - ); - - if (!regex.test(ipInput)) { - void toast.error( - t("networkById.memberOptionModal.handleSumbit.errorNotValidIp", { - target, - }), - ); - return; - } - updateMember( { updateParams: { ipAssignments: [...ipAssignments, ipInput] }, diff --git a/src/server/api/routers/memberRouter.ts b/src/server/api/routers/memberRouter.ts index 4f6a458a..fe0c8cd8 100644 --- a/src/server/api/routers/memberRouter.ts +++ b/src/server/api/routers/memberRouter.ts @@ -13,6 +13,7 @@ import { } from "~/types/webhooks"; import { sendWebhook } from "~/utils/webhook"; import { throwError } from "~/server/helpers/errorHandler"; +import { isValidIP } from "../utils/ipUtils"; const isValidZeroTierNetworkId = (id: string) => { const hexRegex = /^[0-9a-fA-F]{10}$/; @@ -220,6 +221,16 @@ export const networkMemberRouter = createTRPCRouter({ // update ip specified by user UI if (input.updateParams.ipAssignments) { + const ips = input.updateParams.ipAssignments; + const invalidIPs = ips.filter((ip) => !isValidIP(ip)); + + if (invalidIPs.length > 0) { + throw new TRPCError({ + message: "Invalid IP addresses provided", + code: "BAD_REQUEST", + }); + } + // update member Object.assign(payload, {}, { ipAssignments: input.updateParams.ipAssignments }); }