From 2ff6d1d117c408e9d0e747eed911deb2da34edbb Mon Sep 17 00:00:00 2001 From: Milo Schwartz Date: Fri, 14 Feb 2025 13:27:34 -0500 Subject: [PATCH] allow any string as target --- server/routers/target/createTarget.ts | 56 +++++++++---------- server/routers/target/updateTarget.ts | 56 +++++++++---------- .../[resourceId]/connectivity/page.tsx | 42 +++++++------- 3 files changed, 77 insertions(+), 77 deletions(-) diff --git a/server/routers/target/createTarget.ts b/server/routers/target/createTarget.ts index b1080d87..11f3de69 100644 --- a/server/routers/target/createTarget.ts +++ b/server/routers/target/createTarget.ts @@ -13,33 +13,33 @@ import { addTargets } from "../newt/targets"; import { eq } from "drizzle-orm"; import { pickPort } from "./helpers"; -// Regular expressions for validation -const DOMAIN_REGEX = - /^[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/; -const IPV4_REGEX = - /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/; -const IPV6_REGEX = /^(?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}$/i; - -// Schema for domain names and IP addresses -const domainSchema = z - .string() - .min(1, "Domain cannot be empty") - .max(255, "Domain name too long") - .refine( - (value) => { - // Check if it's a valid IP address (v4 or v6) - if (IPV4_REGEX.test(value) || IPV6_REGEX.test(value)) { - return true; - } - - // Check if it's a valid domain name - return DOMAIN_REGEX.test(value); - }, - { - message: "Invalid domain name or IP address format", - path: ["domain"] - } - ); +// // Regular expressions for validation +// const DOMAIN_REGEX = +// /^[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/; +// const IPV4_REGEX = +// /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/; +// const IPV6_REGEX = /^(?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}$/i; +// +// // Schema for domain names and IP addresses +// const domainSchema = z +// .string() +// .min(1, "Domain cannot be empty") +// .max(255, "Domain name too long") +// .refine( +// (value) => { +// // Check if it's a valid IP address (v4 or v6) +// if (IPV4_REGEX.test(value) || IPV6_REGEX.test(value)) { +// return true; +// } +// +// // Check if it's a valid domain name +// return DOMAIN_REGEX.test(value); +// }, +// { +// message: "Invalid domain name or IP address format", +// path: ["domain"] +// } +// ); const createTargetParamsSchema = z .object({ @@ -52,7 +52,7 @@ const createTargetParamsSchema = z const createTargetSchema = z .object({ - ip: domainSchema, + ip: z.string().min(1).max(255), method: z.string().optional().nullable(), port: z.number().int().min(1).max(65535), enabled: z.boolean().default(true) diff --git a/server/routers/target/updateTarget.ts b/server/routers/target/updateTarget.ts index 2ae6222d..4dbb2f45 100644 --- a/server/routers/target/updateTarget.ts +++ b/server/routers/target/updateTarget.ts @@ -12,33 +12,33 @@ import { addPeer } from "../gerbil/peers"; import { addTargets } from "../newt/targets"; import { pickPort } from "./helpers"; -// Regular expressions for validation -const DOMAIN_REGEX = - /^[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/; -const IPV4_REGEX = - /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/; -const IPV6_REGEX = /^(?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}$/i; - -// Schema for domain names and IP addresses -const domainSchema = z - .string() - .min(1, "Domain cannot be empty") - .max(255, "Domain name too long") - .refine( - (value) => { - // Check if it's a valid IP address (v4 or v6) - if (IPV4_REGEX.test(value) || IPV6_REGEX.test(value)) { - return true; - } - - // Check if it's a valid domain name - return DOMAIN_REGEX.test(value); - }, - { - message: "Invalid domain name or IP address format", - path: ["domain"] - } - ); +// // Regular expressions for validation +// const DOMAIN_REGEX = +// /^[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/; +// const IPV4_REGEX = +// /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/; +// const IPV6_REGEX = /^(?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}$/i; +// +// // Schema for domain names and IP addresses +// const domainSchema = z +// .string() +// .min(1, "Domain cannot be empty") +// .max(255, "Domain name too long") +// .refine( +// (value) => { +// // Check if it's a valid IP address (v4 or v6) +// if (IPV4_REGEX.test(value) || IPV6_REGEX.test(value)) { +// return true; +// } +// +// // Check if it's a valid domain name +// return DOMAIN_REGEX.test(value); +// }, +// { +// message: "Invalid domain name or IP address format", +// path: ["domain"] +// } +// ); const updateTargetParamsSchema = z .object({ @@ -48,7 +48,7 @@ const updateTargetParamsSchema = z const updateTargetBodySchema = z .object({ - ip: domainSchema.optional(), + ip: z.string().min(1).max(255), method: z.string().min(1).max(10).optional().nullable(), port: z.number().int().min(1).max(65535).optional(), enabled: z.boolean().optional() diff --git a/src/app/[orgId]/settings/resources/[resourceId]/connectivity/page.tsx b/src/app/[orgId]/settings/resources/[resourceId]/connectivity/page.tsx index ea67e23e..d912b505 100644 --- a/src/app/[orgId]/settings/resources/[resourceId]/connectivity/page.tsx +++ b/src/app/[orgId]/settings/resources/[resourceId]/connectivity/page.tsx @@ -73,29 +73,29 @@ const IPV4_REGEX = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/; const IPV6_REGEX = /^(?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}$/i; -// Schema for domain names and IP addresses -const domainSchema = z - .string() - .min(1, "Domain cannot be empty") - .max(255, "Domain name too long") - .refine( - (value) => { - // Check if it's a valid IP address (v4 or v6) - if (IPV4_REGEX.test(value) || IPV6_REGEX.test(value)) { - return true; - } - - // Check if it's a valid domain name - return DOMAIN_REGEX.test(value); - }, - { - message: "Invalid domain name or IP address format", - path: ["domain"] - } - ); +// // Schema for domain names and IP addresses +// const domainSchema = z +// .string() +// .min(1, "Domain cannot be empty") +// .max(255, "Domain name too long") +// .refine( +// (value) => { +// // Check if it's a valid IP address (v4 or v6) +// if (IPV4_REGEX.test(value) || IPV6_REGEX.test(value)) { +// return true; +// } +// +// // Check if it's a valid domain name +// return DOMAIN_REGEX.test(value); +// }, +// { +// message: "Invalid domain name or IP address format", +// path: ["domain"] +// } +// ); const addTargetSchema = z.object({ - ip: domainSchema, + ip: z.string().min(1).max(255), method: z.string().nullable(), port: z.coerce.number().int().positive() // protocol: z.string(),