diff --git a/src/dashboard.js b/src/dashboard.js index cc8cf400a..a88155cb7 100644 --- a/src/dashboard.js +++ b/src/dashboard.js @@ -8,7 +8,7 @@ exports = module.exports = { setupDnsAndCert, prepareLocation, - changeLocation, + setupLocation, getConfig, }; @@ -46,7 +46,7 @@ async function setLocation(domain) { await settings.set(settings.DASHBOARD_DOMAIN_KEY, domain); await settings.set(settings.DASHBOARD_FQDN_KEY, fqdn); - debug(`setLocation: ${domain}`); + debug(`setLocation: ${domain || ''}`); } async function clearLocation() { @@ -95,11 +95,11 @@ async function prepareLocation(domain, auditSource) { return taskId; } -async function changeLocation(domain, auditSource) { +async function setupLocation(domain, auditSource) { assert.strictEqual(typeof domain, 'string'); assert.strictEqual(typeof auditSource, 'object'); - debug(`changeLocation: ${domain}`); + debug(`setupLocation: ${domain}`); if (constants.DEMO) throw new BoxError(BoxError.CONFLICT, 'Not allowed in demo mode'); diff --git a/src/provision.js b/src/provision.js index a81dd1994..1672de1d1 100644 --- a/src/provision.js +++ b/src/provision.js @@ -13,7 +13,6 @@ const assert = require('assert'), BoxError = require('./boxerror.js'), dashboard = require('./dashboard.js'), constants = require('./constants.js'), - cloudron = require('./cloudron.js'), debug = require('debug')('box:provision'), domains = require('./domains.js'), eventlog = require('./eventlog.js'), @@ -77,11 +76,12 @@ async function setupTask(domain, auditSource) { try { await dashboard.setupDnsAndCert(constants.DASHBOARD_SUBDOMAIN, domain, auditSource, (progress) => setProgress('setup', progress.message)); await ensureDhparams(); - await cloudron.setLocation(domain); + await dashboard.setupLocation(domain, auditSource); setProgress('setup', 'Done'), await eventlog.add(eventlog.ACTION_PROVISION, auditSource, {}); } catch (error) { - gStatus.setup.errorMessage = error ? error.message : ''; + debug(`setupTask: error ${error.message}`); + gStatus.setup.errorMessage = error.message; } gStatus.setup.active = false; @@ -105,7 +105,7 @@ async function setup(domainConfig, ipv4Config, auditSource) { const domain = domainConfig.domain.toLowerCase(); const zoneName = domainConfig.zoneName ? domainConfig.zoneName : (tld.getDomain(domain) || domain); - debug(`setup: Setting up Cloudron with domain ${domain} and zone ${zoneName}`); + debug(`setup: domain ${domain} and zone ${zoneName}`); const data = { zoneName: zoneName, @@ -187,6 +187,7 @@ async function restoreTask(backupConfig, remotePath, ipv4Config, options, auditS setImmediate(() => safe(platform.onActivated({ skipDnsSetup: options.skipDnsSetup }), { debug })); } catch (error) { + debug('restoreTask: error. %o', error); gStatus.restore.errorMessage = error ? error.message : ''; } gStatus.restore.active = false; @@ -240,8 +241,9 @@ async function restore(backupConfig, remotePath, version, ipv4Config, options, a safe(restoreTask(backupConfig, remotePath, ipv4Config, options, auditSource), { debug }); // now that args are validated run the task in the background } catch (error) { + debug('restore: error. %o', error); gStatus.restore.active = false; - gStatus.restore.errorMessage = error ? error.message : ''; + gStatus.restore.errorMessage = error.message; throw error; } } diff --git a/src/routes/dashboard.js b/src/routes/dashboard.js index ba7a5b697..3e96403d0 100644 --- a/src/routes/dashboard.js +++ b/src/routes/dashboard.js @@ -4,7 +4,7 @@ exports = module.exports = { getConfig, prepareLocation, - changeLocation + setupLocation }; const AuditSource = require('../auditsource.js'), @@ -30,10 +30,10 @@ async function prepareLocation(req, res, next) { next(new HttpSuccess(202, { taskId })); } -async function changeLocation(req, res, next) { +async function setupLocation(req, res, next) { if (!req.body.domain || typeof req.body.domain !== 'string') return next(new HttpError(400, 'domain must be a string')); - const [error] = await safe(dashboard.changeLocation(req.body.domain, AuditSource.fromRequest(req))); + const [error] = await safe(dashboard.setupLocation(req.body.domain, AuditSource.fromRequest(req))); if (error) return next(BoxError.toHttpError(error)); next(new HttpSuccess(204, {})); diff --git a/src/server.js b/src/server.js index d0f87a9e6..d37baa2ce 100644 --- a/src/server.js +++ b/src/server.js @@ -117,7 +117,7 @@ async function initializeExpressSync() { // config route for dashboard that any auth user (not just admin) can access router.get ('/api/v1/dashboard/config', token, authorizeUser, routes.dashboard.getConfig); router.post('/api/v1/dashboard/prepare_location', json, token, authorizeAdmin, routes.dashboard.prepareLocation); - router.post('/api/v1/dashboard/location', json, token, authorizeAdmin, routes.dashboard.changeLocation); + router.post('/api/v1/dashboard/location', json, token, authorizeAdmin, routes.dashboard.setupLocation); // system (vm/server) router.get ('/api/v1/system/reboot', token, authorizeAdmin, routes.system.isRebootRequired);