diff --git a/src/dashboard.js b/src/dashboard.js index 5c86b6f4d..c4750de9b 100644 --- a/src/dashboard.js +++ b/src/dashboard.js @@ -22,6 +22,7 @@ const apps = require('./apps.js'), debug = require('debug')('box:dashboard'), eventlog = require('./eventlog.js'), dns = require('./dns.js'), + Location = require('./location.js'), mailServer = require('./mailserver.js'), platform = require('./platform.js'), reverseProxy = require('./reverseproxy.js'), @@ -32,11 +33,9 @@ const apps = require('./apps.js'), users = require('./users.js'); async function getLocation() { - const domain = await settings.get(settings.DASHBOARD_DOMAIN_KEY) || ''; - const subdomain = await settings.get(settings.DASHBOARD_SUBDOMAIN_KEY) || ''; - const fqdn = domain ? dns.fqdn(subdomain, domain) : ''; - - return { subdomain, domain, fqdn }; + const domain = await settings.get(settings.DASHBOARD_DOMAIN_KEY); + const subdomain = await settings.get(settings.DASHBOARD_SUBDOMAIN_KEY); + return new Location(subdomain, domain, Location.TYPE_DASHBOARD); } async function setLocation(subdomain, domain) { diff --git a/src/location.js b/src/location.js new file mode 100644 index 000000000..09fbb5ad9 --- /dev/null +++ b/src/location.js @@ -0,0 +1,22 @@ +'use strict'; + +class Location { + constructor(subdomain, domain, type, certificate) { + this.subdomain = subdomain; + this.domain = domain; + this.type = type; + this.certificate = certificate || null; + this.fqdn = domain ? (subdomain + (subdomain ? '.' : '') + domain) : ''; + } +} + +// subdomain (table) types +Location.TYPE_PRIMARY = 'primary'; +Location.TYPE_SECONDARY = 'secondary'; +Location.TYPE_REDIRECT = 'redirect'; +Location.TYPE_ALIAS = 'alias'; +Location.TYPE_DASHBOARD = 'dashboard'; +Location.TYPE_MAIL = 'mail'; +Location.TYPE_DIRECTORY_SERVER = 'directoryserver'; + +exports = module.exports = Location; diff --git a/src/mailserver.js b/src/mailserver.js index ea2d91517..f3da689f6 100644 --- a/src/mailserver.js +++ b/src/mailserver.js @@ -33,6 +33,7 @@ const assert = require('assert'), eventlog = require('./eventlog.js'), hat = require('./hat.js'), infra = require('./infra_version.js'), + Location = require('./location.js'), mail = require('./mail.js'), os = require('os'), path = require('path'), @@ -250,13 +251,10 @@ async function checkCertificate() { } async function getLocation() { - const domain = await settings.get(settings.MAIL_DOMAIN_KEY); const subdomain = await settings.get(settings.MAIL_SUBDOMAIN_KEY); + const domain = await settings.get(settings.MAIL_DOMAIN_KEY); - if (!domain || !subdomain) return {}; - - const fqdn = dns.fqdn(subdomain, domain); - return { subdomain, domain, fqdn }; + return new Location(subdomain, domain, Location.TYPE_MAIL); } async function changeLocation(auditSource, progressCallback) { diff --git a/src/reverseproxy.js b/src/reverseproxy.js index cdb5a84ab..78814c459 100644 --- a/src/reverseproxy.js +++ b/src/reverseproxy.js @@ -49,6 +49,7 @@ const acme2 = require('./acme2.js'), ejs = require('ejs'), eventlog = require('./eventlog.js'), fs = require('fs'), + Location = require('./location.js'), mailServer = require('./mailserver.js'), network = require('./network.js'), os = require('os'), @@ -246,10 +247,10 @@ async function restoreFallbackCertificates() { function getAppLocationsSync(app) { assert.strictEqual(typeof app, 'object'); - return [{ domain: app.domain, subdomain: app.subdomain, fqdn: app.fqdn, certificate: app.certificate, type: apps.LOCATION_TYPE_PRIMARY }] - .concat(app.secondaryDomains.map(sd => { return { domain: sd.domain, subdomain: sd.subdomain, certificate: sd.certificate, fqdn: sd.fqdn, type: apps.LOCATION_TYPE_SECONDARY }; })) - .concat(app.redirectDomains.map(rd => { return { domain: rd.domain, subdomain: rd.subdomain, certificate: rd.certificate, fqdn: rd.fqdn, type: apps.LOCATION_TYPE_REDIRECT }; })) - .concat(app.aliasDomains.map(ad => { return { domain: ad.domain, subdomain: ad.subdomain, certificate: ad.certificate, fqdn: ad.fqdn, type: apps.LOCATION_TYPE_ALIAS }; })); + return [new Location(app.subdomain, app.domain, Location.TYPE_PRIMARY, app.certificate)] + .concat(app.secondaryDomains.map(sd => new Location(sd.subdomin, sd.domain, Location.TYPE_SECONDARY, sd.certificate))) + .concat(app.redirectDomains.map(rd => new Location(rd.subdomin, rd.domain, Location.TYPE_REDIRECT, rd.certificate))) + .concat(app.aliasDomains.map(ad => new Location(ad.subdomin, ad.domain, Location.TYPE_ALIAS, ad.certificate))); } function getAcmeCertificateNameSync(fqdn, domainObject) { @@ -645,11 +646,11 @@ async function checkCerts(options, auditSource, progressCallback) { assert.strictEqual(typeof progressCallback, 'function'); let locations = []; - const { domain:dashboardDomain, fqdn:dashboardFqdn } = await dashboard.getLocation(); - locations.push({ domain: dashboardDomain, fqdn: dashboardFqdn, certificate: null, type: apps.LOCATION_TYPE_DASHBOARD }); + const dashboardLocation = await dashboard.getLocation(); + locations.push(dashboardLocation); - const { domain:mailDomain, fqdn:mailFqdn } = await mailServer.getLocation(); - if (dashboardFqdn !== mailFqdn) locations.push({ domain: mailDomain, fqdn: mailFqdn, certificate: null, type: apps.LOCATION_TYPE_MAIL }); + const mailLocation = await mailServer.getLocation(); + if (dashboardLocation.fqdn !== mailLocation.fqdn) locations.push(mailLocation); const allApps = (await apps.list()).filter(app => app.runState !== apps.RSTATE_STOPPED); for (const app of allApps) {