diff --git a/src/dashboard.js b/src/dashboard.js index 41914badc..ce4cc74fc 100644 --- a/src/dashboard.js +++ b/src/dashboard.js @@ -126,7 +126,7 @@ async function setupLocation(subdomain, domain, auditSource) { if (constants.DEMO) throw new BoxError(BoxError.BAD_STATE, 'Not allowed in demo mode'); await setLocation(subdomain, domain); - await platform.onDashboardLocationSet(domain); + await platform.onDashboardLocationSet(subdomain, domain); } async function changeLocation(subdomain, domain, auditSource) { @@ -142,5 +142,5 @@ async function changeLocation(subdomain, domain, auditSource) { await safe(appstore.updateCloudron({ domain }), { debug }); await platform.onDashboardLocationChanged(auditSource); - await safe(reverseProxy.removeDashboardConfig(oldLocation.domain), { debug }); + await safe(reverseProxy.removeDashboardConfig(oldLocation.subdomain, oldLocation.domain), { debug }); } diff --git a/src/dns.js b/src/dns.js index 85da36db6..1d06eae98 100644 --- a/src/dns.js +++ b/src/dns.js @@ -311,7 +311,7 @@ async function syncDnsRecords(options, progressCallback) { if (options.domain) allDomains = allDomains.filter(d => d.domain === options.domain); const { domain:mailDomain, fqdn:mailFqdn, subdomain:mailSubdomain } = await mailServer.getLocation(); - const { domain:dashboardDomain, fqdn:dashboardFqdn } = await dashboard.getLocation(); + const dashboardLocation = await dashboard.getLocation(); const allApps = await apps.list(); @@ -323,8 +323,8 @@ async function syncDnsRecords(options, progressCallback) { progress += Math.round(100/(1+allDomains.length)); let locations = []; - if (domain.domain === dashboardDomain) locations.push({ subdomain: constants.DASHBOARD_SUBDOMAIN, domain: dashboardDomain }); - if (domain.domain === mailDomain && mailFqdn !== dashboardFqdn) locations.push({ subdomain: mailSubdomain, domain: mailDomain }); + if (domain.domain === dashboardLocation.domain) locations.push({ subdomain: dashboardLocation.subdomain, domain: dashboardLocation.domain }); + if (domain.domain === mailDomain && mailFqdn !== dashboardLocation.fqdn) locations.push({ subdomain: mailSubdomain, domain: mailDomain }); for (const app of allApps) { const appLocations = [{ subdomain: app.subdomain, domain: app.domain }] diff --git a/src/platform.js b/src/platform.js index 1c321f35f..3e19e0836 100644 --- a/src/platform.js +++ b/src/platform.js @@ -197,8 +197,8 @@ async function initialize() { await tasks.stopAllTasks(); // always generate webadmin config since we have no versioning mechanism for the ejs - const { domain:dashboardDomain } = await dashboard.getLocation(); - if (dashboardDomain) await onDashboardLocationSet(dashboardDomain); + const dashboardLocation = await dashboard.getLocation(); + if (dashboardLocation.domain) await onDashboardLocationSet(dashboardLocation.subdomain, dashboardLocation.domain); // configure nginx to be reachable by IP when not activated. for the moment, the IP based redirect exists even after domain is setup // just in case user forgot or some network error happenned in the middle (then browser refresh takes you to activation page) @@ -253,10 +253,11 @@ async function onDeactivated() { await oidc.stop(); } -async function onDashboardLocationSet(dashboardDomain) { - assert.strictEqual(typeof dashboardDomain, 'string'); +async function onDashboardLocationSet(subdomain, domain) { + assert.strictEqual(typeof subdomain, 'string'); + assert.strictEqual(typeof domain, 'string'); - await safe(reverseProxy.writeDashboardConfig(dashboardDomain), { debug }); // ok to fail if no disk space + await safe(reverseProxy.writeDashboardConfig(subdomain, domain), { debug }); // ok to fail if no disk space await oidc.start(); } diff --git a/src/reverseproxy.js b/src/reverseproxy.js index 5f6c9e3bf..eb2226751 100644 --- a/src/reverseproxy.js +++ b/src/reverseproxy.js @@ -469,24 +469,26 @@ async function writeDashboardNginxConfig(vhost, certificatePath) { } // also syncs the certs to disk -async function writeDashboardConfig(domain) { +async function writeDashboardConfig(subdomain, domain) { + assert.strictEqual(typeof subdomain, 'string'); assert.strictEqual(typeof domain, 'string'); debug(`writeDashboardConfig: writing dashboard config for ${domain}`); - const dashboardFqdn = dns.fqdn(constants.DASHBOARD_SUBDOMAIN, domain); + const dashboardFqdn = dns.fqdn(subdomain, domain); const location = { domain, fqdn: dashboardFqdn, certificate: null }; const certificatePath = await writeCertificate(location); await writeDashboardNginxConfig(dashboardFqdn, certificatePath); await reload(); } -async function removeDashboardConfig(domain) { +async function removeDashboardConfig(subdomain, domain) { + assert.strictEqual(typeof subdomain, 'string'); assert.strictEqual(typeof domain, 'string'); debug(`removeDashboardConfig: removing dashboard config of ${domain}`); - const vhost = dns.fqdn(constants.DASHBOARD_SUBDOMAIN, domain); + const vhost = dns.fqdn(subdomain, domain); const nginxConfigFilename = path.join(paths.NGINX_APPCONFIG_DIR, `dashboard/${vhost}.conf`); if (!safe.fs.unlinkSync(nginxConfigFilename)) throw new BoxError(BoxError.FS_ERROR, safe.error.message); @@ -686,8 +688,7 @@ async function checkCerts(options, auditSource, progressCallback) { for (const app of allApps) { await writeAppConfigs(app); } - const { domain:dashboardDomain } = await dashboard.getLocation(); - await writeDashboardConfig(dashboardDomain); + await writeDashboardConfig(dashboardLocation.subdomain, dashboardLocation.domain); await notifyCertChange(); // this allows user to "rebuild" using UI just in case we crashed and went out of sync safe.fs.unlinkSync(paths.REVERSE_PROXY_REBUILD_FILE); } else {