Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: disable domain if DNS records not found (NXDOMAIN) #748

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions apps/mail-bridge/postal-db/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export type GetDomainDNSRecordsOutput =
acceptable: string;
};
}
| { error: string };
| { error: string; errorCode: number };

export async function getDomainDNSRecords(
domainId: string,
Expand All @@ -179,7 +179,7 @@ export async function getDomainDNSRecords(
});

if (!domainInfo) {
return { error: 'Domain not found, Contact Support' };
return { error: 'Domain not found, Contact Support', errorCode: 3 };
}

const records: GetDomainDNSRecordsOutput = {
Expand Down Expand Up @@ -222,7 +222,8 @@ export async function getDomainDNSRecords(

if (txtRecords.success === false && txtRecords.code !== 0) {
return {
error: `${txtRecords.error} Please retry after sometime, if the problem persists contact Support`
error: `${txtRecords.error} Please retry after sometime, if the problem persists contact Support`,
errorCode: txtRecords.code
};
}

Expand Down
11 changes: 11 additions & 0 deletions apps/platform/utils/updateDnsRecords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ export async function updateDnsRecords(
});

if ('error' in currentDNSRecords) {
if (currentDNSRecords.errorCode === 3) {
// Domain does not exist, disable the domain
await db
.update(domains)
.set({
disabled: true,
disabledAt: new Date(),
lastDnsCheckAt: new Date()
})
.where(eq(domains.id, domainResponse.id));
}
throw new TRPCError({
code: 'INTERNAL_SERVER_ERROR',
message: currentDNSRecords.error
Expand Down
3 changes: 3 additions & 0 deletions apps/worker/services/dns-check-queue.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { createQueue, createWorker } from '../utils/queue-helpers';
import { checkDns } from '../functions/check-dns';
import type { TypeId } from '@u22n/utils/typeid';
import { domains } from '@u22n/database/schema';
import { discord } from '@u22n/utils/discord';
import { eq } from '@u22n/database/orm';
import { db } from '@u22n/database';
import { CronJob } from 'cron';

Expand Down Expand Up @@ -33,6 +35,7 @@ export async function addImmediateDnsCheckJob(
export const masterCronJob = new CronJob('0 6,14,22 * * *', async () => {
await discord.info('Running Daily DNS Cron Job');
const activeDomains = await db.query.domains.findMany({
where: eq(domains.disabled, false),
columns: { publicId: true }
});
await dnsCheckQueue.addBulk(
Expand Down
Loading