From 06d60d5aeae8b26c8de4e21181defa7a732a469d Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Tue, 8 Feb 2022 21:52:03 +0100 Subject: [PATCH] Implement dns overwrite and pre-flight checks for multi domain clone --- src/translation/en.json | 2 +- src/views/app.html | 9 +++--- src/views/app.js | 61 ++++++++++++++++++++++++++++------------- 3 files changed, 48 insertions(+), 24 deletions(-) diff --git a/src/translation/en.json b/src/translation/en.json index ed5ec3c1e..04dffe25e 100644 --- a/src/translation/en.json +++ b/src/translation/en.json @@ -1546,7 +1546,7 @@ "title": "Clone {{ app }}", "description": "Using backup from {{ creationTime }} and version v{{ packageVersion }}", "location": "Location", - "cloneAction": "Clone" + "cloneAction": "Clone {{ dnsOverwrite ? 'and overwrite DNS' : '' }}" }, "states": { "running": "Running", diff --git a/src/views/app.html b/src/views/app.html index bf6243adc..e329f85e0 100644 --- a/src/views/app.html +++ b/src/views/app.html @@ -441,9 +441,9 @@

-
+
-
{{ clone.error.location }}
+
{{ clone.error.location.message }}
@@ -463,7 +463,7 @@
{{ clone.error.secondaryDomain }}
-
+
+
{{ clone.error.location.message }}
@@ -513,7 +514,7 @@
diff --git a/src/views/app.js b/src/views/app.js index ffc644538..82146e149 100644 --- a/src/views/app.js +++ b/src/views/app.js @@ -1520,6 +1520,8 @@ angular.module('Application').controller('AppController', ['$scope', '$location' subdomain: '', domain: null, secondaryDomains: {}, + needsOverwrite: false, + overwriteDns: false, portBindings: {}, portBindingsInfo: {}, portBindingsEnabled: {}, @@ -1531,6 +1533,9 @@ angular.module('Application').controller('AppController', ['$scope', '$location' $scope.clone.backup = backup; $scope.clone.domain = $scope.domains.find(function (d) { return app.domain === d.domain; }); // pre-select the app's domain + $scope.clone.needsOverwrite = false; + $scope.clone.overwriteDns = false; + $scope.clone.secondaryDomains = {}; app.secondaryDomains.forEach(function (sd) { $scope.clone.secondaryDomains[sd.environmentVariable] = { @@ -1573,28 +1578,46 @@ angular.module('Application').controller('AppController', ['$scope', '$location' domain: $scope.clone.domain.domain, secondaryDomains: secondaryDomains, portBindings: finalPortBindings, - backupId: $scope.clone.backup.id + backupId: $scope.clone.backup.id, + overwriteDns: $scope.clone.overwriteDns }; - Client.checkDNSRecords(data.domain, data.subdomain, function (error, result) { - if (error) { - Client.error(error); - $scope.clone.busy = false; - return; - } - if (result.error) { - if (result.error.reason === ERROR.ACCESS_DENIED) { - $scope.clone.error.location = 'DNS credentials for ' + data.domain + ' are invalid. Update it in Domains & Certs view'; - } else { - $scope.clone.error.location = result.error.message; + var allDomains = [{ domain: data.domain, subdomain: data.subdomain }].concat(Object.keys(secondaryDomains).map(function (k) { + return { + domain: secondaryDomains[k].domain, + subdomain: secondaryDomains[k].subdomain + }; + })); + async.eachSeries(allDomains, function (domain, callback) { + if ($scope.clone.overwriteDns) return callback(); + + Client.checkDNSRecords(domain.domain, domain.subdomain, function (error, result) { + if (error) return callback(error); + + var fqdn = domain.subdomain + '.' + domain.domain; + + if (result.error) { + if (result.error.reason === ERROR.ACCESS_DENIED) return callback({ type: 'provider', fqdn: fqdn, message: 'DNS credentials for ' + domain.domain + ' are invalid. Update it in Domains & Certs view' }); + return callback({ type: 'provider', fqdn: fqdn, message: result.error.message }); } - $scope.clone.needsOverwrite = true; - $scope.clone.busy = false; - return; - } - if (result.needsOverwrite) { - $scope.clone.error.location = 'DNS Record already exists. Confirm that the domain is not in use for services external to Cloudron'; - $scope.clone.needsOverwrite = true; + if (result.needsOverwrite) { + $scope.clone.needsOverwrite = true; + $scope.clone.overwriteDns = true; + return callback({ type: 'exists', fqdn: fqdn, message: 'DNS Record already exists. Confirm that the domain is not in use for services external to Cloudron' }); + } + + callback(); + }); + }, function (error) { + if (error) { + if (error.type) { + $scope.clone.error.location = error; + $scope.clone.busy = false; + } else { + Client.error(error); + } + + $scope.clone.error.location = error; $scope.clone.busy = false; return; }