settings: move mailFqdn/Domain into mailServer

This commit is contained in:
Girish Ramakrishnan
2023-08-04 21:37:38 +05:30
parent 946e5caacb
commit 4cdf37b060
15 changed files with 78 additions and 73 deletions
+10 -10
View File
@@ -77,7 +77,6 @@ const assert = require('assert'),
path = require('path'),
safe = require('safetydance'),
services = require('./services.js'),
settings = require('./settings.js'),
shell = require('./shell.js'),
superagent = require('superagent'),
validator = require('validator'),
@@ -294,7 +293,7 @@ async function checkSpf(domain, mailFqdn) {
name: '@',
type: 'TXT',
value: null,
expected: 'v=spf1 a:' + mailFqdn + ' ~all',
expected: `v=spf1 a:${mailFqdn} ~all`,
status: false,
errorMessage: ''
};
@@ -310,14 +309,14 @@ async function checkSpf(domain, mailFqdn) {
let txtRecord = txtRecords[i].join(''); // https://agari.zendesk.com/hc/en-us/articles/202952749-How-long-can-my-SPF-record-be-
if (txtRecord.indexOf('v=spf1 ') !== 0) continue; // not SPF
spf.value = txtRecord;
spf.status = spf.value.indexOf(' a:' + settings.mailFqdn()) !== -1;
spf.status = spf.value.indexOf(` a:${mailFqdn}`) !== -1;
break;
}
if (spf.status) {
spf.expected = spf.value;
} else if (i !== txtRecords.length) {
spf.expected = 'v=spf1 a:' + settings.mailFqdn() + ' ' + spf.value.slice('v=spf1 '.length);
spf.expected = `v=spf1 a:${mailFqdn} ` + spf.value.slice('v=spf1 '.length);
}
return spf;
@@ -332,7 +331,7 @@ async function checkMx(domain, mailFqdn) {
name: '@',
type: 'MX',
value: null,
expected: '10 ' + mailFqdn + '.',
expected: `10 ${mailFqdn}.`,
status: false,
errorMessage: ''
};
@@ -532,7 +531,7 @@ async function getStatus(domain) {
relay: {} // { status, value } always checked
};
const mailFqdn = settings.mailFqdn();
const { fqdn } = await mailServer.getLocation();
const mailDomain = await getDomain(domain);
if (!mailDomain) throw new BoxError(BoxError.NOT_FOUND, 'mail domain not found');
@@ -540,7 +539,7 @@ async function getStatus(domain) {
const checks = [];
if (mailDomain.enabled) {
checks.push(
{ what: 'dns.mx', promise: checkMx(domain, mailFqdn) },
{ what: 'dns.mx', promise: checkMx(domain, fqdn) },
{ what: 'dns.dmarc', promise: checkDmarc(domain) }
);
}
@@ -548,9 +547,9 @@ async function getStatus(domain) {
if (mailDomain.relay.provider === 'cloudron-smtp') {
// these tests currently only make sense when using Cloudron's SMTP server at this point
checks.push(
{ what: 'dns.spf', promise: checkSpf(domain, mailFqdn) },
{ what: 'dns.spf', promise: checkSpf(domain, fqdn) },
{ what: 'dns.dkim', promise: checkDkim(mailDomain) },
{ what: 'dns.ptr', promise: checkPtr(mailFqdn) },
{ what: 'dns.ptr', promise: checkPtr(fqdn) },
{ what: 'relay', promise: checkOutboundPort25() },
{ what: 'rbl', promise: checkRblStatus(domain) },
);
@@ -719,7 +718,8 @@ async function upsertDnsRecords(domain, mailFqdn) {
async function setDnsRecords(domain) {
assert.strictEqual(typeof domain, 'string');
await upsertDnsRecords(domain, settings.mailFqdn());
const { fqdn } = await mailServer.getLocation();
await upsertDnsRecords(domain, fqdn);
}
async function clearDomains() {