dns: unregister domains if type is disabled

This commit is contained in:
Girish Ramakrishnan
2024-04-27 18:43:31 +02:00
parent e00db115ad
commit efa1acddd4
2 changed files with 25 additions and 6 deletions

View File

@@ -222,6 +222,11 @@ function makeWildcard(fqdn) {
}
async function registerLocation(location, options, recordType, recordValue) {
assert.strictEqual(typeof location, 'object');
assert.strictEqual(typeof options, 'object');
assert.strictEqual(typeof recordType, 'string');
assert.strictEqual(typeof recordValue, 'string');
const overwriteDns = options.overwriteDns || false;
// get the current record before updating it
@@ -267,13 +272,28 @@ async function registerLocations(locations, options, progressCallback) {
await removeDnsRecords(location.subdomain, location.domain, 'CNAME', values);
}
if (ipv4) await registerLocation(location, options, 'A', ipv4);
if (ipv6) await registerLocation(location, options, 'AAAA', ipv6);
if (ipv4) {
await registerLocation(location, options, 'A', ipv4);
} else {
const [error, values] = await safe(getDnsRecords(location.subdomain, location.domain, 'A'));
if (!error && values.length) await safe(removeDnsRecords(location.subdomain, location.domain, 'A', values), { debug });
}
if (ipv6) {
await registerLocation(location, options, 'AAAA', ipv6);
} else {
const [error, values] = await safe(getDnsRecords(location.subdomain, location.domain, 'AAAA'));
if (!error && values.length) await safe(removeDnsRecords(location.subdomain, location.domain, 'AAAA', values), { debug });
}
});
}
}
async function unregisterLocation(location, recordType, recordValue) {
assert.strictEqual(typeof location, 'object');
assert.strictEqual(typeof recordType, 'string');
assert.strictEqual(typeof recordValue, 'string');
const [error] = await safe(removeDnsRecords(location.subdomain, location.domain, recordType, [ recordValue ]));
if (!error || error.reason === BoxError.NOT_FOUND) return;
@@ -313,9 +333,8 @@ async function syncDnsRecords(options, progressCallback) {
const { domain:mailDomain, fqdn:mailFqdn, subdomain:mailSubdomain } = await mailServer.getLocation();
const dashboardLocation = await dashboard.getLocation();
const allApps = await apps.list();
let progress = 1, errors = [];
const allApps = await apps.list(), errors = [];
let progress = 1;
// we sync by domain only to get some nice progress
for (const domain of allDomains) {