Refactor project to transition from Rust backend to Node.js with Fastify; update Dockerfile and Docker configurations for new build process; enhance local development instructions in CONTRIBUTING.md; implement health checks in Docker Compose; update pnpm-lock.yaml with new dependencies for API and shared packages; revise README.md to reflect new stack and development setup.
Build, Test, and Push CFDM Docker Image / test (push) Has been cancelled
Build, Test, and Push CFDM Docker Image / build-and-push (push) Has been cancelled
Build, Test, and Push CFDM Docker Image / create-release (push) Has been cancelled
Build, Test, and Push CFDM Docker Image / update-wiki (push) Has been cancelled
Build, Test, and Push CFDM Docker Image / test (push) Has been cancelled
Build, Test, and Push CFDM Docker Image / build-and-push (push) Has been cancelled
Build, Test, and Push CFDM Docker Image / create-release (push) Has been cancelled
Build, Test, and Push CFDM Docker Image / update-wiki (push) Has been cancelled
This commit is contained in:
1 parent
0a0a1a92f1
commit
d11414666f
2065 files changed
+15782
-16699
No files matched your search
@@ -0,0 +1,80 @@
|
||||
import {
|
||||
CERT_EXPIRED,
|
||||
CERT_OK,
|
||||
CERT_WARNING,
|
||||
} from "./constants.js";
|
||||
|
||||
const NAME_RE =
|
||||
/^(@|\*|[a-zA-Z0-9_]([a-zA-Z0-9_-]*[a-zA-Z0-9_])?(\.[a-zA-Z0-9_]([a-zA-Z0-9_-]*[a-zA-Z0-9_])?)*)$/;
|
||||
const IPV4_RE =
|
||||
/^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$/;
|
||||
const IPV6_RE = /^([0-9a-fA-F]{0,4}:){2,7}[0-9a-fA-F]{0,4}$/;
|
||||
|
||||
const ALLOWED_TYPES = ["A", "AAAA", "CNAME", "TXT", "MX", "NS", "SRV", "CAA"];
|
||||
|
||||
export class ValidationError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = "ValidationError";
|
||||
}
|
||||
}
|
||||
|
||||
export function validateDnsRecord(
|
||||
recordType: string,
|
||||
name: string,
|
||||
content: string,
|
||||
ttl: number,
|
||||
proxied: boolean,
|
||||
): void {
|
||||
const rt = recordType.toUpperCase();
|
||||
if (!ALLOWED_TYPES.includes(rt)) {
|
||||
throw new ValidationError(`unsupported record type: ${recordType}`);
|
||||
}
|
||||
if (!NAME_RE.test(name)) {
|
||||
throw new ValidationError(`invalid record name: ${name}`);
|
||||
}
|
||||
if (ttl !== 1 && (ttl < 60 || ttl > 86400)) {
|
||||
throw new ValidationError("ttl must be 1 (auto) or 60-86400");
|
||||
}
|
||||
if (proxied && !["A", "AAAA", "CNAME"].includes(rt)) {
|
||||
throw new ValidationError("proxied only allowed for A, AAAA, CNAME");
|
||||
}
|
||||
switch (rt) {
|
||||
case "A":
|
||||
if (!IPV4_RE.test(content)) {
|
||||
throw new ValidationError("A record requires valid IPv4");
|
||||
}
|
||||
break;
|
||||
case "AAAA":
|
||||
if (!IPV6_RE.test(content)) {
|
||||
throw new ValidationError("AAAA record requires valid IPv6");
|
||||
}
|
||||
break;
|
||||
case "CNAME":
|
||||
case "NS":
|
||||
if (!content || content.includes(" ")) {
|
||||
throw new ValidationError("CNAME/NS requires valid hostname");
|
||||
}
|
||||
break;
|
||||
case "TXT":
|
||||
if (!content || content.length > 2048) {
|
||||
throw new ValidationError("TXT content length 1-2048");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
export function certStatusFromExpiry(daysLeft: number): string {
|
||||
if (daysLeft < 0) return CERT_EXPIRED;
|
||||
if (daysLeft <= 30) return CERT_WARNING;
|
||||
return CERT_OK;
|
||||
}
|
||||
|
||||
export function isValidIpv4(ip: string): boolean {
|
||||
const parts = ip.split(".");
|
||||
if (parts.length !== 4) return false;
|
||||
return parts.every((p) => {
|
||||
const n = Number(p);
|
||||
return Number.isInteger(n) && n >= 0 && n <= 255;
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user