From 15cf0c3c190879828227eb6b3516a0b44961bd4f Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Sun, 4 Feb 2018 15:08:46 -0800 Subject: [PATCH] Do not allow dns setup and restore to run in parallel In the e2e, we did not check the webadminStatus after a dnsSetup and immediately rushed into restore. This ended up mangling the cert/key files of the admin domain. --- src/setup.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/setup.js b/src/setup.js index 9e7670ceb..fd3995fce 100644 --- a/src/setup.js +++ b/src/setup.js @@ -73,7 +73,7 @@ function SetupError(reason, errorOrMessage) { } util.inherits(SetupError, Error); SetupError.BAD_FIELD = 'Field error'; -SetupError.BAD_STATE = 'Field error'; +SetupError.BAD_STATE = 'Bad State'; SetupError.ALREADY_SETUP = 'Already Setup'; SetupError.INTERNAL_ERROR = 'Internal Error'; SetupError.EXTERNAL_ERROR = 'External Error'; @@ -184,6 +184,8 @@ function dnsSetup(adminFqdn, domain, zoneName, provider, dnsConfig, tlsConfig, c if (config.adminDomain()) return callback(new SetupError(SetupError.ALREADY_SETUP)); + if (gWebadminStatus.configuring || gWebadminStatus.restoring) return callback(new SetupError(SetupError.BAD_STATE, 'Already restoring or configuring')); + if (!zoneName) zoneName = tld.getDomain(domain) || domain; debug('dnsSetup: Setting up Cloudron with domain %s and zone %s', domain, zoneName); @@ -291,6 +293,8 @@ function restore(backupConfig, backupId, version, callback) { if (!semver.valid(version)) return callback(new SetupError(SetupError.BAD_STATE, 'version is not a valid semver')); if (semver.major(config.version()) !== semver.major(version) || semver.minor(config.version()) !== semver.minor(version)) return callback(new SetupError(SetupError.BAD_STATE, `Run cloudron-setup with --version ${version} to restore from this backup`)); + if (gWebadminStatus.configuring || gWebadminStatus.restoring) return callback(new SetupError(SetupError.BAD_STATE, 'Already restoring or configuring')); + user.count(function (error, count) { if (error) return callback(new SetupError(SetupError.INTERNAL_ERROR, error)); if (count) return callback(new SetupError(SetupError.ALREADY_PROVISIONED, 'Already activated'));