Добавил policy HY2XS_DNS_AAAA_POLICY и управляемое AAAA-поведение в preflight
This commit is contained in:
@@ -127,6 +127,14 @@ function normalizeAcmeType(value: string): "http" | "tls" | "dns" {
|
||||
throw new Error(`invalid HY2XS_ACME_TYPE: ${value}`);
|
||||
}
|
||||
|
||||
function normalizeDnsAaaaPolicy(value: string | undefined): "strict" | "warn" | "off" {
|
||||
const policy = value || "strict";
|
||||
if (policy === "strict" || policy === "warn" || policy === "off") {
|
||||
return policy;
|
||||
}
|
||||
throw new Error(`invalid HY2XS_DNS_AAAA_POLICY: ${value}`);
|
||||
}
|
||||
|
||||
function normalizeFixedHysteriaAuthMode(value: string | undefined): "http" {
|
||||
const mode = value || "http";
|
||||
if (mode !== "http") {
|
||||
@@ -180,12 +188,14 @@ export function parseRuntimeEnv(content: string): RuntimeConfig {
|
||||
const trafficStatsPort = parsePort("HY2XS_HYSTERIA_TRAFFIC_STATS_PORT", env.HY2XS_HYSTERIA_TRAFFIC_STATS_PORT, 36712);
|
||||
const tlsMode = normalizeTlsMode(env.HY2XS_TLS_MODE || "acme");
|
||||
const acmeType = normalizeAcmeType(env.HY2XS_ACME_TYPE || "http");
|
||||
const dnsAaaaPolicy = normalizeDnsAaaaPolicy(env.HY2XS_DNS_AAAA_POLICY);
|
||||
const firewallMode = normalizeFirewallMode(env);
|
||||
const hysteriaAuthMode = normalizeFixedHysteriaAuthMode(env.HY2XS_HYSTERIA_AUTH_MODE);
|
||||
const hysteriaObfsType = normalizeFixedHysteriaObfsType(env.HY2XS_HYSTERIA_OBFS_TYPE);
|
||||
|
||||
const config: RuntimeConfig = {
|
||||
domain: env.HY2XS_DOMAIN || "",
|
||||
dnsAaaaPolicy,
|
||||
publicHost: normalizePublicHost(env.HY2XS_PUBLIC_HOST || env.HY2XS_DOMAIN || ""),
|
||||
publicPort: parsePort("HY2XS_PUBLIC_PORT", env.HY2XS_PUBLIC_PORT, hysteriaPort),
|
||||
ipv6Enabled: parseBool("HY2XS_IPV6_ENABLED", env.HY2XS_IPV6_ENABLED, false),
|
||||
@@ -289,6 +299,7 @@ export function renderRuntimeEnv(config: RuntimeConfig): string {
|
||||
"# HY2XS runtime config (editable)",
|
||||
"HY2XS_IPV6_ENABLED=false",
|
||||
`HY2XS_DOMAIN=${config.domain}`,
|
||||
`HY2XS_DNS_AAAA_POLICY=${config.dnsAaaaPolicy}`,
|
||||
`HY2XS_PUBLIC_HOST=${config.publicHost}`,
|
||||
`HY2XS_PUBLIC_PORT=${config.publicPort}`,
|
||||
`HY2XS_SSH_PORT=${config.sshPort}`,
|
||||
|
||||
@@ -143,9 +143,16 @@ export async function preflight(context: RuntimeContext): Promise<void> {
|
||||
}
|
||||
}
|
||||
if (aaaa.length > 0) {
|
||||
fail(
|
||||
`domain ${context.config.domain} has DNS AAAA record while HY2XS profile is IPv4-only; remove AAAA record before install`
|
||||
);
|
||||
if (context.config.dnsAaaaPolicy === "strict") {
|
||||
fail(
|
||||
`domain ${context.config.domain} has DNS AAAA record while HY2XS profile is IPv4-only; remove AAAA record before install`
|
||||
);
|
||||
}
|
||||
if (context.config.dnsAaaaPolicy === "warn") {
|
||||
info(
|
||||
`warning: domain ${context.config.domain} has DNS AAAA record while HY2XS profile is IPv4-only; continuing due to HY2XS_DNS_AAAA_POLICY=warn`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,8 +22,11 @@ export type RunMode = "install" | "reconfigure";
|
||||
|
||||
export type TlsMode = "acme" | "file" | "self_signed_dev";
|
||||
|
||||
export type DnsAaaaPolicy = "strict" | "warn" | "off";
|
||||
|
||||
export type RuntimeConfig = {
|
||||
domain: string;
|
||||
dnsAaaaPolicy: DnsAaaaPolicy;
|
||||
publicHost: string;
|
||||
publicPort: number;
|
||||
ipv6Enabled: boolean;
|
||||
|
||||
Reference in New Issue
Block a user