merge domaindb.js into domains.js

This commit is contained in:
Girish Ramakrishnan
2021-08-13 17:22:28 -07:00
parent 74febcd30a
commit 5bcf1bc47b
40 changed files with 2233 additions and 2395 deletions
+11 -8
View File
@@ -69,7 +69,7 @@ const assert = require('assert'),
constants = require('./constants.js'),
database = require('./database.js'),
debug = require('debug')('box:mail'),
dns = require('./native-dns.js'),
dns = require('./dns.js'),
docker = require('./docker.js'),
domains = require('./domains.js'),
eventlog = require('./eventlog.js'),
@@ -102,6 +102,9 @@ const REMOVE_MAILBOX = path.join(__dirname, 'scripts/rmmailbox.sh');
const MAILDB_FIELDS = [ 'domain', 'enabled', 'mailFromValidation', 'catchAllJson', 'relayJson', 'dkimSelector', 'bannerJson' ].join(',');
const domainsGet = util.callbackify(domains.get),
domainsList = util.callbackify(domains.list);
function postProcess(data) {
data.enabled = !!data.enabled; // int to boolean
data.mailFromValidation = !!data.mailFromValidation; // int to boolean
@@ -544,7 +547,7 @@ function checkConfiguration(callback) {
let messages = {};
domains.getAll(function (error, allDomains) {
domainsList(function (error, allDomains) {
if (error) return callback(error);
async.eachSeries(allDomains, function (domainObject, iteratorCallback) {
@@ -810,7 +813,7 @@ function txtRecordsWithSpf(domain, mailFqdn, callback) {
assert.strictEqual(typeof mailFqdn, 'string');
assert.strictEqual(typeof callback, 'function');
domains.getDnsRecords('', domain, 'TXT', function (error, txtRecords) {
dns.getDnsRecords('', domain, 'TXT', function (error, txtRecords) {
if (error) return callback(error);
debug('txtRecordsWithSpf: current txt records - %j', txtRecords);
@@ -927,7 +930,7 @@ function upsertDnsRecords(domain, mailFqdn, callback) {
if (txtRecords) records.push({ subdomain: '', domain: domain, type: 'TXT', values: txtRecords });
domains.getDnsRecords('_dmarc', domain, 'TXT', function (error, dmarcRecords) { // only update dmarc if absent. this allows user to set email for reporting
dns.getDnsRecords('_dmarc', domain, 'TXT', function (error, dmarcRecords) { // only update dmarc if absent. this allows user to set email for reporting
if (error) return callback(error);
if (dmarcRecords.length === 0) records.push({ subdomain: '_dmarc', domain: domain, type: 'TXT', values: [ '"v=DMARC1; p=reject; pct=100"' ] });
@@ -935,7 +938,7 @@ function upsertDnsRecords(domain, mailFqdn, callback) {
debug('upsertDnsRecords: will update %j', records);
async.mapSeries(records, function (record, iteratorCallback) {
domains.upsertDnsRecords(record.subdomain, record.domain, record.type, record.values, iteratorCallback);
dns.upsertDnsRecords(record.subdomain, record.domain, record.type, record.values, iteratorCallback);
}, function (error, changeIds) {
if (error) {
debug(`upsertDnsRecords: failed to update: ${error}`);
@@ -981,7 +984,7 @@ function changeLocation(auditSource, progressCallback, callback) {
cloudron.setupDnsAndCert(subdomain, domain, auditSource, progressCallback, function (error) {
if (error) return callback(error);
domains.getAll(function (error, allDomains) {
domainsList(function (error, allDomains) {
if (error) return callback(error);
async.eachOfSeries(allDomains, function (domainObject, idx, iteratorDone) {
@@ -1010,10 +1013,10 @@ function setLocation(subdomain, domain, auditSource, callback) {
assert.strictEqual(typeof auditSource, 'object');
assert.strictEqual(typeof callback, 'function');
domains.get(domain, function (error, domainObject) {
domainsGet(domain, function (error, domainObject) {
if (error) return callback(error);
const fqdn = domains.fqdn(subdomain, domainObject);
const fqdn = dns.fqdn(subdomain, domainObject);
settings.setMailLocation(domain, fqdn, async function (error) {
if (error) return callback(error);