mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-18 00:09:34 +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 { eq } from "drizzle-orm";
|
||||||
import { pickPort } from "./helpers";
|
import { pickPort } from "./helpers";
|
||||||
|
|
||||||
// Regular expressions for validation
|
// // Regular expressions for validation
|
||||||
const DOMAIN_REGEX =
|
// 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])?)*$/;
|
// /^[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 =
|
// 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]?)$/;
|
// /^(?:(?: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;
|
// const IPV6_REGEX = /^(?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}$/i;
|
||||||
|
//
|
||||||
// Schema for domain names and IP addresses
|
// // Schema for domain names and IP addresses
|
||||||
const domainSchema = z
|
// const domainSchema = z
|
||||||
.string()
|
// .string()
|
||||||
.min(1, "Domain cannot be empty")
|
// .min(1, "Domain cannot be empty")
|
||||||
.max(255, "Domain name too long")
|
// .max(255, "Domain name too long")
|
||||||
.refine(
|
// .refine(
|
||||||
(value) => {
|
// (value) => {
|
||||||
// Check if it's a valid IP address (v4 or v6)
|
// // Check if it's a valid IP address (v4 or v6)
|
||||||
if (IPV4_REGEX.test(value) || IPV6_REGEX.test(value)) {
|
// if (IPV4_REGEX.test(value) || IPV6_REGEX.test(value)) {
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// Check if it's a valid domain name
|
// // Check if it's a valid domain name
|
||||||
return DOMAIN_REGEX.test(value);
|
// return DOMAIN_REGEX.test(value);
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
message: "Invalid domain name or IP address format",
|
// message: "Invalid domain name or IP address format",
|
||||||
path: ["domain"]
|
// path: ["domain"]
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
|
|
||||||
const createTargetParamsSchema = z
|
const createTargetParamsSchema = z
|
||||||
.object({
|
.object({
|
||||||
|
@ -52,7 +52,7 @@ const createTargetParamsSchema = z
|
||||||
|
|
||||||
const createTargetSchema = z
|
const createTargetSchema = z
|
||||||
.object({
|
.object({
|
||||||
ip: domainSchema,
|
ip: z.string().min(1).max(255),
|
||||||
method: z.string().optional().nullable(),
|
method: z.string().optional().nullable(),
|
||||||
port: z.number().int().min(1).max(65535),
|
port: z.number().int().min(1).max(65535),
|
||||||
enabled: z.boolean().default(true)
|
enabled: z.boolean().default(true)
|
||||||
|
|
|
@ -12,33 +12,33 @@ import { addPeer } from "../gerbil/peers";
|
||||||
import { addTargets } from "../newt/targets";
|
import { addTargets } from "../newt/targets";
|
||||||
import { pickPort } from "./helpers";
|
import { pickPort } from "./helpers";
|
||||||
|
|
||||||
// Regular expressions for validation
|
// // Regular expressions for validation
|
||||||
const DOMAIN_REGEX =
|
// 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])?)*$/;
|
// /^[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 =
|
// 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]?)$/;
|
// /^(?:(?: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;
|
// const IPV6_REGEX = /^(?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}$/i;
|
||||||
|
//
|
||||||
// Schema for domain names and IP addresses
|
// // Schema for domain names and IP addresses
|
||||||
const domainSchema = z
|
// const domainSchema = z
|
||||||
.string()
|
// .string()
|
||||||
.min(1, "Domain cannot be empty")
|
// .min(1, "Domain cannot be empty")
|
||||||
.max(255, "Domain name too long")
|
// .max(255, "Domain name too long")
|
||||||
.refine(
|
// .refine(
|
||||||
(value) => {
|
// (value) => {
|
||||||
// Check if it's a valid IP address (v4 or v6)
|
// // Check if it's a valid IP address (v4 or v6)
|
||||||
if (IPV4_REGEX.test(value) || IPV6_REGEX.test(value)) {
|
// if (IPV4_REGEX.test(value) || IPV6_REGEX.test(value)) {
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// Check if it's a valid domain name
|
// // Check if it's a valid domain name
|
||||||
return DOMAIN_REGEX.test(value);
|
// return DOMAIN_REGEX.test(value);
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
message: "Invalid domain name or IP address format",
|
// message: "Invalid domain name or IP address format",
|
||||||
path: ["domain"]
|
// path: ["domain"]
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
|
|
||||||
const updateTargetParamsSchema = z
|
const updateTargetParamsSchema = z
|
||||||
.object({
|
.object({
|
||||||
|
@ -48,7 +48,7 @@ const updateTargetParamsSchema = z
|
||||||
|
|
||||||
const updateTargetBodySchema = z
|
const updateTargetBodySchema = z
|
||||||
.object({
|
.object({
|
||||||
ip: domainSchema.optional(),
|
ip: z.string().min(1).max(255),
|
||||||
method: z.string().min(1).max(10).optional().nullable(),
|
method: z.string().min(1).max(10).optional().nullable(),
|
||||||
port: z.number().int().min(1).max(65535).optional(),
|
port: z.number().int().min(1).max(65535).optional(),
|
||||||
enabled: z.boolean().optional()
|
enabled: z.boolean().optional()
|
||||||
|
|
|
@ -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]?)$/;
|
/^(?:(?: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;
|
const IPV6_REGEX = /^(?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}$/i;
|
||||||
|
|
||||||
// Schema for domain names and IP addresses
|
// // Schema for domain names and IP addresses
|
||||||
const domainSchema = z
|
// const domainSchema = z
|
||||||
.string()
|
// .string()
|
||||||
.min(1, "Domain cannot be empty")
|
// .min(1, "Domain cannot be empty")
|
||||||
.max(255, "Domain name too long")
|
// .max(255, "Domain name too long")
|
||||||
.refine(
|
// .refine(
|
||||||
(value) => {
|
// (value) => {
|
||||||
// Check if it's a valid IP address (v4 or v6)
|
// // Check if it's a valid IP address (v4 or v6)
|
||||||
if (IPV4_REGEX.test(value) || IPV6_REGEX.test(value)) {
|
// if (IPV4_REGEX.test(value) || IPV6_REGEX.test(value)) {
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// Check if it's a valid domain name
|
// // Check if it's a valid domain name
|
||||||
return DOMAIN_REGEX.test(value);
|
// return DOMAIN_REGEX.test(value);
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
message: "Invalid domain name or IP address format",
|
// message: "Invalid domain name or IP address format",
|
||||||
path: ["domain"]
|
// path: ["domain"]
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
|
|
||||||
const addTargetSchema = z.object({
|
const addTargetSchema = z.object({
|
||||||
ip: domainSchema,
|
ip: z.string().min(1).max(255),
|
||||||
method: z.string().nullable(),
|
method: z.string().nullable(),
|
||||||
port: z.coerce.number().int().positive()
|
port: z.coerce.number().int().positive()
|
||||||
// protocol: z.string(),
|
// protocol: z.string(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue