Skip to content

Commit

Permalink
Merge pull request #529 from sinamics/ip-validation
Browse files Browse the repository at this point in the history
Allow ipv6 and ipv4 in member options modal
  • Loading branch information
sinamics authored Aug 28, 2024
2 parents f7f4f77 + 6f7009c commit 092d60b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
16 changes: 0 additions & 16 deletions src/components/networkByIdPage/memberOptionsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,6 @@ export const MemberOptionsModal: React.FC<ModalContentProps> = ({
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] },
Expand Down
11 changes: 11 additions & 0 deletions src/server/api/routers/memberRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}$/;
Expand Down Expand Up @@ -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 });
}
Expand Down

0 comments on commit 092d60b

Please sign in to comment.