remove usage of constants.DASHBOARD_SUBDOMAIN

This commit is contained in:
Girish Ramakrishnan
2024-04-27 11:10:24 +02:00
parent 5420630453
commit 2a6368af60
4 changed files with 18 additions and 16 deletions

View File

@@ -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 });
}

View File

@@ -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 }]

View File

@@ -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();
}

View File

@@ -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 {