fix(dns): update DnsManager to use new DNS configuration properties
The DnsManager was still checking for the old dnsDomain property that was replaced by dnsNsDomains and dnsScopes in the DNS Architecture Improvements. Changes: - Replace dnsDomain checks with dnsNsDomains and dnsScopes validation - Add check to ensure email domain is included in dnsScopes array - Update NS delegation check to work with multiple nameservers - Update error messages to guide users to the new configuration format
This commit is contained in:
parent
a2b413a78f
commit
ae73de19b2
@ -108,46 +108,82 @@ export class DnsManager {
|
||||
requiredChanges: []
|
||||
};
|
||||
|
||||
// Check if dnsDomain is configured
|
||||
const dnsDomain = (this.dcRouter as any).options?.dnsDomain;
|
||||
if (!dnsDomain) {
|
||||
// Check if DNS configuration is set up
|
||||
const dnsNsDomains = this.dcRouter.options?.dnsNsDomains;
|
||||
const dnsScopes = this.dcRouter.options?.dnsScopes;
|
||||
|
||||
if (!dnsNsDomains || dnsNsDomains.length === 0) {
|
||||
result.valid = false;
|
||||
result.errors.push(
|
||||
`Domain "${config.domain}" is configured to use internal DNS, but dnsDomain is not set in DcRouter configuration.`
|
||||
`Domain "${config.domain}" is configured to use internal DNS, but dnsNsDomains is not set in DcRouter configuration.`
|
||||
);
|
||||
console.error(
|
||||
`❌ ERROR: Domain "${config.domain}" is configured to use internal DNS,\n` +
|
||||
' but dnsDomain is not set in DcRouter configuration.\n' +
|
||||
' Please configure dnsDomain to enable the DNS server.\n' +
|
||||
' Example: dnsDomain: "ns.myservice.com"'
|
||||
' but dnsNsDomains is not set in DcRouter configuration.\n' +
|
||||
' Please configure dnsNsDomains to enable the DNS server.\n' +
|
||||
' Example: dnsNsDomains: ["ns1.myservice.com", "ns2.myservice.com"]'
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (!dnsScopes || dnsScopes.length === 0) {
|
||||
result.valid = false;
|
||||
result.errors.push(
|
||||
`Domain "${config.domain}" is configured to use internal DNS, but dnsScopes is not set in DcRouter configuration.`
|
||||
);
|
||||
console.error(
|
||||
`❌ ERROR: Domain "${config.domain}" is configured to use internal DNS,\n` +
|
||||
' but dnsScopes is not set in DcRouter configuration.\n' +
|
||||
' Please configure dnsScopes to define authoritative domains.\n' +
|
||||
' Example: dnsScopes: ["myservice.com", "mail.myservice.com"]'
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Check if the email domain is in dnsScopes
|
||||
if (!dnsScopes.includes(config.domain)) {
|
||||
result.valid = false;
|
||||
result.errors.push(
|
||||
`Domain "${config.domain}" is configured to use internal DNS, but is not included in dnsScopes.`
|
||||
);
|
||||
console.error(
|
||||
`❌ ERROR: Domain "${config.domain}" is configured to use internal DNS,\n` +
|
||||
` but is not included in dnsScopes: [${dnsScopes.join(', ')}].\n` +
|
||||
' Please add this domain to dnsScopes to enable internal DNS.\n' +
|
||||
` Example: dnsScopes: [..., "${config.domain}"]`
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
const primaryNameserver = dnsNsDomains[0];
|
||||
|
||||
// Check NS delegation
|
||||
try {
|
||||
const nsRecords = await this.resolveNs(config.domain);
|
||||
const isDelegated = nsRecords.includes(dnsDomain);
|
||||
const delegatedNameservers = dnsNsDomains.filter(ns => nsRecords.includes(ns));
|
||||
const isDelegated = delegatedNameservers.length > 0;
|
||||
|
||||
if (!isDelegated) {
|
||||
result.warnings.push(
|
||||
`NS delegation not found for ${config.domain}. Please add NS record at your registrar.`
|
||||
);
|
||||
result.requiredChanges.push(
|
||||
`Add NS record: ${config.domain}. NS ${dnsDomain}.`
|
||||
`NS delegation not found for ${config.domain}. Please add NS records at your registrar.`
|
||||
);
|
||||
dnsNsDomains.forEach(ns => {
|
||||
result.requiredChanges.push(
|
||||
`Add NS record: ${config.domain}. NS ${ns}.`
|
||||
);
|
||||
});
|
||||
|
||||
console.log(
|
||||
`📋 DNS Delegation Required for ${config.domain}:\n` +
|
||||
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n' +
|
||||
'Please add this NS record at your domain registrar:\n' +
|
||||
` ${config.domain}. NS ${dnsDomain}.\n` +
|
||||
'Please add these NS records at your domain registrar:\n' +
|
||||
dnsNsDomains.map(ns => ` ${config.domain}. NS ${ns}.`).join('\n') + '\n' +
|
||||
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n' +
|
||||
'This delegation is required for internal DNS mode to work.'
|
||||
);
|
||||
} else {
|
||||
console.log(
|
||||
`✅ NS delegation verified: ${config.domain} -> ${dnsDomain}`
|
||||
`✅ NS delegation verified: ${config.domain} -> [${delegatedNameservers.join(', ')}]`
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user