-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc353ab
commit 7d39a58
Showing
10 changed files
with
162 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,6 +119,23 @@ export type GetDomainDNSRecordsOutput = | |
optimal: string; | ||
acceptable: string; | ||
}; | ||
mtaSts: { | ||
dns: { | ||
valid: boolean; | ||
name: string; | ||
value: string; | ||
}; | ||
tls: { | ||
valid: boolean; | ||
name: string; | ||
value: string; | ||
}; | ||
policy: { | ||
valid: boolean; | ||
name: string; | ||
value: string; | ||
}; | ||
}; | ||
} | ||
| { error: string }; | ||
|
||
|
@@ -168,6 +185,23 @@ export async function getDomainDNSRecords( | |
name: '', | ||
optimal: '', | ||
acceptable: '' | ||
}, | ||
mtaSts: { | ||
dns: { | ||
valid: false, | ||
name: '', | ||
value: '' | ||
}, | ||
tls: { | ||
valid: false, | ||
name: '', | ||
value: '' | ||
}, | ||
policy: { | ||
valid: false, | ||
name: '', | ||
value: '' | ||
} | ||
} | ||
}; | ||
|
||
|
@@ -317,7 +351,7 @@ export async function getDomainDNSRecords( | |
} | ||
records.mx.name = domainInfo.name; | ||
records.mx.priority = 1; | ||
records.mx.value = `mx.${postalServerUrl}`; | ||
records.mx.value = `${postalServerUrl}`; | ||
records.mx.valid = true; | ||
|
||
if (domainInfo.mxStatus !== 'OK' || forceReverify) { | ||
|
@@ -360,6 +394,40 @@ export async function getDomainDNSRecords( | |
records.dmarc.name = '_dmarc'; | ||
records.dmarc.optimal = buildDmarcRecord({ p: 'reject' }); | ||
records.dmarc.acceptable = buildDmarcRecord({ p: 'quarantine' }); | ||
|
||
const mtaStsDnsRecord = await lookupTXT(`_mta-sts.${domainInfo.name}`); | ||
records.mtaSts.dns.name = '_mta-sts'; | ||
records.mtaSts.dns.value = `v=STSv1; id=${Date.now()}`; | ||
if (mtaStsDnsRecord.success && mtaStsDnsRecord.data.length > 0) { | ||
records.mtaSts.dns.valid = | ||
mtaStsDnsRecord.data.filter( | ||
(_) => _.startsWith('v=STSv1;') && _.includes('id=') | ||
).length === 1; | ||
} | ||
|
||
const mtaStsTlsRecord = await lookupTXT(`_smtp._tls.${domainInfo.name}`); | ||
records.mtaSts.tls.name = '_smtp._tls'; | ||
records.mtaSts.tls.value = `v=TLSRPTv1; rua=mailto:[email protected]`; | ||
if (mtaStsTlsRecord.success && mtaStsTlsRecord.data.length > 0) { | ||
records.mtaSts.tls.valid = | ||
mtaStsTlsRecord.data.filter( | ||
(_) => | ||
_.startsWith('v=TLSRPTv1;') && | ||
_.includes('rua=') && | ||
_.includes('mailto:[email protected]') | ||
).length === 1; | ||
} | ||
|
||
const mtaStsPolicyRecord = await lookupCNAME(`mta-sts.${domainInfo.name}`); | ||
records.mtaSts.policy.name = 'mta-sts'; | ||
records.mtaSts.policy.value = `mta-sts.${postalServerUrl}`; | ||
if ( | ||
mtaStsPolicyRecord.success && | ||
mtaStsPolicyRecord.data.includes(records.mtaSts.policy.value) | ||
) { | ||
records.mtaSts.policy.valid = true; | ||
} | ||
|
||
return records; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { useRuntimeConfig } from '#imports'; | ||
import { db } from '@u22n/database'; | ||
import { eq } from '@u22n/database/orm'; | ||
import { domains } from '@u22n/database/schema'; | ||
import { | ||
eventHandler, | ||
getQuery, | ||
getRouterParam, | ||
send, | ||
setResponseStatus | ||
} from 'h3'; | ||
|
||
export default eventHandler(async (event) => { | ||
const secret = getRouterParam(event, 'secret'); | ||
if (useRuntimeConfig().platform.secret !== secret) { | ||
setResponseStatus(event, 401); | ||
return send(event, 'Unauthorized'); | ||
} | ||
|
||
const domain = getQuery(event).domain; | ||
if (!domain || typeof domain !== 'string') { | ||
setResponseStatus(event, 400); | ||
return send(event, 'Bad Request'); | ||
} | ||
|
||
if (!domain.startsWith('mta-sts.')) { | ||
setResponseStatus(event, 400); | ||
return send(event, 'Bad Request'); | ||
} | ||
|
||
const rootDomain = domain.replace(/^mta-sts\./, ''); | ||
const domainResponse = await db.query.domains.findFirst({ | ||
where: eq(domains.domain, rootDomain) | ||
}); | ||
|
||
if (!domainResponse) { | ||
setResponseStatus(event, 403); | ||
return send(event, 'Forbidden'); | ||
} | ||
|
||
setResponseStatus(event, 200); | ||
return send(event, 'Ok'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
on_demand_tls { | ||
ask {env.PLATFORM_URL}/caddy-check/{env.PLATFORM_SECRET} | ||
} | ||
} | ||
|
||
https:// { | ||
tls { | ||
on_demand | ||
} | ||
root * ./files | ||
file_server | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
version: STSv1 | ||
mode: enforce | ||
mx: *.e.uninbox.com | ||
max_age: 86400 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters