Minor code style changes

This commit is contained in:
Johannes Zellner
2016-12-14 14:54:17 +01:00
parent 55d306c938
commit e7fc40cfdd
3 changed files with 27 additions and 11 deletions
+1 -3
View File
@@ -467,8 +467,6 @@ function addDnsRecords() {
}
gUpdatingDns = true;
var DKIM_SELECTOR = 'cloudron';
var dkimKey = readDkimPublicKeySync();
if (!dkimKey) return callback(new CloudronError(CloudronError.INTERNAL_ERROR, new Error('Failed to read dkim public key')));
@@ -477,7 +475,7 @@ function addDnsRecords() {
var webadminRecord = { subdomain: constants.ADMIN_LOCATION, type: 'A', values: [ ip ] };
// t=s limits the domainkey to this domain and not it's subdomains
var dkimRecord = { subdomain: DKIM_SELECTOR + '._domainkey', type: 'TXT', values: [ '"v=DKIM1; t=s; p=' + dkimKey + '"' ] };
var dkimRecord = { subdomain: constants.DKIM_SELECTOR + '._domainkey', type: 'TXT', values: [ '"v=DKIM1; t=s; p=' + dkimKey + '"' ] };
var records = [ ];
if (config.isCustomDomain()) {
+3 -1
View File
@@ -32,6 +32,8 @@ exports = module.exports = {
DEFAULT_MEMORY_LIMIT: (256 * 1024 * 1024), // see also client.js
DEMO_USERNAME: 'cloudron'
DEMO_USERNAME: 'cloudron',
DKIM_SELECTOR: 'cloudron'
};
+23 -7
View File
@@ -58,6 +58,7 @@ exports = module.exports = {
var assert = require('assert'),
backups = require('./backups.js'),
config = require('./config.js'),
constants = require('./constants.js'),
CronJob = require('cron').CronJob,
DatabaseError = require('./databaseerror.js'),
debug = require('debug')('box:settings'),
@@ -131,24 +132,39 @@ function getEmailDnsRecords(callback) {
var records = {};
// DKIM
var DKIM_SELECTOR = 'cloudron';
var dkimKey = cloudron.readDkimPublicKeySync();
if (!dkimKey) return callback(new CloudronError(CloudronError.INTERNAL_ERROR, new Error('Failed to read dkim public key')));
records.dkim = {subdomain: DKIM_SELECTOR + '._domainkey', type: 'TXT', expected: 'v=DKIM1; t=s; p=' + dkimKey, value: null, status: false};
records.dkim = {
subdomain: constants.DKIM_SELECTOR + '._domainkey',
type: 'TXT',
expected: 'v=DKIM1; t=s; p=' + dkimKey,
value: null,
status: false
};
records.spf = {
subdomain: '',
type: 'TXT',
value: null,
expected: null,
status: false
};
// check if DKIM is already setup
dns.resolveTxt(records.dkim.subdomain + '.' + config.fqdn(), function (error, txtRecords) {
if (error) return callback(error);
for (var i = 0; i < txtRecords.length; i++) {
records.dkim.value = txtRecords[i].join(' ');
records.dkim.status = (records.dkim.value == records.dkim.value);
break;
}
// SPF
records.spf = {subdomain: '', type: 'TXT', value: null, expected: null, status: false};
// check if SPF is already setup
dns.resolveTxt(config.fqdn(), function (error, txtRecords) {
if (error) return callback(error);
var i;
for (i = 0; i < txtRecords.length; i++) {
if (txtRecords[i].join(' ').indexOf('v=spf1 ') !== 0) continue; // not SPF
@@ -159,14 +175,14 @@ function getEmailDnsRecords(callback) {
if (records.spf.status) {
records.spf.expected = records.spf.value;
} else if (i == txtRecords.length) {
} else if (i === txtRecords.length) {
records.spf.expected = 'v=spf1 a:' + config.adminFqdn() + ' ~all';
} else {
records.spf.expected = 'v=spf1 a:' + config.adminFqdn() + ' ' + records.spf.value.slice('v=spf1 '.length);
}
return callback(null, records);
});
});
}