mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-03 01:24:58 +02:00
allow any string as target
This commit is contained in:
parent
8dd30c88ab
commit
2ff6d1d117
3 changed files with 77 additions and 77 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue