diff --git a/src/cloudron.js b/src/cloudron.js index c682160f0..296dc3af6 100644 --- a/src/cloudron.js +++ b/src/cloudron.js @@ -11,6 +11,8 @@ exports = module.exports = { onActivated, + setupDnsAndCert, + prepareDashboardDomain, setDashboardDomain, updateDashboardDomain, @@ -44,6 +46,7 @@ var addons = require('./addons.js'), shell = require('./shell.js'), spawn = require('child_process').spawn, split = require('split'), + sysinfo = require('./sysinfo.js'), tasks = require('./tasks.js'), users = require('./users.js'); @@ -346,3 +349,34 @@ function renewCerts(options, auditSource, callback) { callback(null, taskId); }); } + +function setupDnsAndCert(subdomain, domain, auditSource, progressCallback, callback) { + assert.strictEqual(typeof subdomain, 'string'); + assert.strictEqual(typeof domain, 'string'); + assert.strictEqual(typeof auditSource, 'object'); + assert.strictEqual(typeof progressCallback, 'function'); + assert.strictEqual(typeof callback, 'function'); + + domains.get(domain, function (error, domainObject) { + if (error) return callback(error); + + const adminFqdn = domains.fqdn(subdomain, domainObject); + + sysinfo.getServerIp(function (error, ip) { + if (error) return callback(error); + + async.series([ + (done) => { progressCallback({ percent: 10, message: `Updating DNS of ${adminFqdn}` }); done(); }, + domains.upsertDnsRecords.bind(null, subdomain, domain, 'A', [ ip ]), + (done) => { progressCallback({ percent: 40, message: `Waiting for DNS of ${adminFqdn}` }); done(); }, + domains.waitForDnsRecord.bind(null, subdomain, domain, 'A', ip, { interval: 30000, times: 50000 }), + (done) => { progressCallback({ percent: 70, message: `Getting certificate of ${adminFqdn}` }); done(); }, + reverseProxy.ensureCertificate.bind(null, domains.fqdn(subdomain, domainObject), domain, auditSource) + ], function (error) { + if (error) return callback(error); + + callback(null); + }); + }); + }); +} diff --git a/src/domains.js b/src/domains.js index 7a2c9c865..7db222705 100644 --- a/src/domains.js +++ b/src/domains.js @@ -26,13 +26,10 @@ module.exports = exports = { parentDomain: parentDomain, - checkDnsRecords: checkDnsRecords, - - setupDashboardDnsAndCert: setupDashboardDnsAndCert + checkDnsRecords: checkDnsRecords }; var assert = require('assert'), - async = require('async'), BoxError = require('./boxerror.js'), constants = require('./constants.js'), debug = require('debug')('box:domains'), @@ -453,33 +450,3 @@ function makeWildcard(hostname) { parts[0] = '*'; return parts.join('.'); } - -function setupDashboardDnsAndCert(domain, auditSource, progressCallback, callback) { - assert.strictEqual(typeof domain, 'string'); - assert.strictEqual(typeof auditSource, 'object'); - assert.strictEqual(typeof progressCallback, 'function'); - assert.strictEqual(typeof callback, 'function'); - - get(domain, function (error, domainObject) { - if (error) return callback(error); - - const adminFqdn = fqdn(constants.ADMIN_LOCATION, domainObject); - - sysinfo.getServerIp(function (error, ip) { - if (error) return callback(error); - - async.series([ - (done) => { progressCallback({ percent: 10, message: `Updating DNS of ${adminFqdn}` }); done(); }, - upsertDnsRecords.bind(null, constants.ADMIN_LOCATION, domain, 'A', [ ip ]), - (done) => { progressCallback({ percent: 40, message: `Waiting for DNS of ${adminFqdn}` }); done(); }, - waitForDnsRecord.bind(null, constants.ADMIN_LOCATION, domain, 'A', ip, { interval: 30000, times: 50000 }), - (done) => { progressCallback({ percent: 70, message: `Getting certificate of ${adminFqdn}` }); done(); }, - reverseProxy.ensureCertificate.bind(null, fqdn(constants.ADMIN_LOCATION, domainObject), domain, auditSource) - ], function (error) { - if (error) return callback(error); - - callback(null); - }); - }); - }); -} diff --git a/src/provision.js b/src/provision.js index 2b3fff3ae..5d89e76f1 100644 --- a/src/provision.js +++ b/src/provision.js @@ -108,7 +108,7 @@ function setup(dnsConfig, sysinfoConfig, auditSource, callback) { async.series([ settings.setSysinfoConfig.bind(null, sysinfoConfig), - domains.setupDashboardDnsAndCert.bind(null, domain, auditSource, (progress) => setProgress('setup', progress.message, NOOP_CALLBACK)), + cloudron.setupDnsAndCert.bind(null, constants.ADMIN_LOCATION, domain, auditSource, (progress) => setProgress('setup', progress.message, NOOP_CALLBACK)), cloudron.setDashboardDomain.bind(null, domain, auditSource), setProgress.bind(null, 'setup', 'Done'), eventlog.add.bind(null, eventlog.ACTION_PROVISION, auditSource, { }) @@ -202,7 +202,7 @@ function restore(backupConfig, backupId, version, sysinfoConfig, auditSource, ca (done) => { const adminDomain = settings.adminDomain(); // load this fresh from after the backup.restore async.series([ - domains.setupDashboardDnsAndCert.bind(null, adminDomain, auditSource, (progress) => setProgress('restore', progress.message, NOOP_CALLBACK)), + cloudron.setupDnsAndCert.bind(null, constants.ADMIN_LOCATION, adminDomain, auditSource, (progress) => setProgress('restore', progress.message, NOOP_CALLBACK)), cloudron.setDashboardDomain.bind(null, adminDomain, auditSource) ], done); }, diff --git a/src/tasks.js b/src/tasks.js index 2d1a21052..6dac2aeb4 100644 --- a/src/tasks.js +++ b/src/tasks.js @@ -21,7 +21,7 @@ exports = module.exports = { TASK_BACKUP: 'backup', TASK_UPDATE: 'update', TASK_RENEW_CERTS: 'renewcerts', - TASK_SETUP_DASHBOARD_DNS_AND_CERT: 'setupDashboardDnsAndCert', + TASK_SETUP_DNS_AND_CERT: 'setupDnsAndCert', TASK_CLEAN_BACKUPS: 'cleanBackups', TASK_SYNC_EXTERNAL_LDAP: 'syncExternalLdap', diff --git a/src/taskworker.js b/src/taskworker.js index 0ef6a9177..efd63e6a8 100755 --- a/src/taskworker.js +++ b/src/taskworker.js @@ -5,8 +5,8 @@ var apptask = require('./apptask.js'), async = require('async'), backups = require('./backups.js'), + cloudron = require('./cloudron.js'), database = require('./database.js'), - domains = require('./domains.js'), externalLdap = require('./externalldap.js'), fs = require('fs'), reverseProxy = require('./reverseproxy.js'), @@ -20,7 +20,7 @@ const TASKS = { // indexed by task type backup: backups.backupBoxAndApps, update: updater.update, renewcerts: reverseProxy.renewCerts, - setupDashboardDnsAndCert: domains.setupDashboardDnsAndCert, + setupDnsAndCert: cloudron.setupDnsAndCert, cleanBackups: backups.cleanup, syncExternalLdap: externalLdap.sync,