diff --git a/src/certificates.js b/src/certificates.js index 648dfce0e..7ea7e6896 100644 --- a/src/certificates.js +++ b/src/certificates.js @@ -9,6 +9,7 @@ exports = module.exports = { validateCertificate: validateCertificate, ensureCertificate: ensureCertificate, getAdminCertificatePath: getAdminCertificatePath, + adminCertificateExists: adminCertificateExists, // exported for testing _getApi: getApi @@ -327,6 +328,14 @@ function getAdminCertificatePath(callback) { getFallbackCertificatePath(callback); } +function adminCertificateExists() { + var vhost = config.adminFqdn(); + var certFilePath = path.join(paths.APP_CERTS_DIR, vhost + '.cert'); + var keyFilePath = path.join(paths.APP_CERTS_DIR, vhost + '.key'); + + return (fs.existsSync(certFilePath) && fs.existsSync(keyFilePath)); +} + function ensureCertificate(app, callback) { assert.strictEqual(typeof app, 'object'); assert.strictEqual(typeof callback, 'function'); diff --git a/src/routes/cloudron.js b/src/routes/cloudron.js index 54d590936..9c856b781 100644 --- a/src/routes/cloudron.js +++ b/src/routes/cloudron.js @@ -3,6 +3,7 @@ exports = module.exports = { activate: activate, dnsSetup: dnsSetup, + dnsReady: dnsReady, setupTokenAuth: setupTokenAuth, getStatus: getStatus, reboot: reboot, @@ -16,6 +17,7 @@ exports = module.exports = { var assert = require('assert'), async = require('async'), + certificates = require('../certificates.js'), cloudron = require('../cloudron.js'), CloudronError = cloudron.CloudronError, config = require('../config.js'), @@ -105,6 +107,17 @@ function dnsSetup(req, res, next) { }); } +function dnsReady(req, res, next) { + if (config.provider() === 'caas') return next(new HttpError(410, 'Not availabe for caas')); + + if (!config.fqdn()) return next(new HttpSuccess(200, { domain: false, ssl: false, dns: false })); + if (!certificates.adminCertificateExists()) return next(new HttpSuccess(200, { domain: true, ssl: false, dns: false })); + + // TODO also check for DNS + + next(new HttpSuccess(200, { domain: true, ssl: true, dns: false })); +} + function setupTokenAuth(req, res, next) { assert.strictEqual(typeof req.query, 'object'); diff --git a/src/server.js b/src/server.js index b14b8a534..505444e17 100644 --- a/src/server.js +++ b/src/server.js @@ -81,7 +81,8 @@ function initializeExpressSync() { // public routes router.post('/api/v1/cloudron/activate', routes.cloudron.setupTokenAuth, routes.cloudron.activate); - router.post('/api/v1/cloudron/setup_dns', routes.cloudron.dnsSetup); // only available pre-activation + router.post('/api/v1/cloudron/dns_setup', routes.cloudron.dnsSetup); // only available pre-activation + router.get ('/api/v1/cloudron/dns_ready', routes.cloudron.dnsReady); router.get ('/api/v1/cloudron/progress', routes.cloudron.getProgress); router.get ('/api/v1/cloudron/status', routes.cloudron.getStatus); router.get ('/api/v1/cloudron/avatar', routes.settings.getCloudronAvatar); // this is a public alias for /api/v1/settings/cloudron_avatar diff --git a/webadmin/src/js/client.js b/webadmin/src/js/client.js index cf06feab0..56e9acc1a 100644 --- a/webadmin/src/js/client.js +++ b/webadmin/src/js/client.js @@ -616,12 +616,19 @@ angular.module('Application').service('Client', ['$http', 'md5', 'Notification', }; Client.prototype.setupDnsConfig = function (dnsConfig, callback) { - post('/api/v1/cloudron/setup_dns', dnsConfig).success(function(data, status) { + post('/api/v1/cloudron/dns_setup', dnsConfig).success(function(data, status) { if (status !== 200) return callback(new ClientError(status, data)); callback(null); }).error(defaultErrorHandler(callback)); }; + Client.prototype.getDnsReady = function (callback) { + get('/api/v1/cloudron/dns_ready').success(function(data, status) { + if (status !== 200) return callback(new ClientError(status, data)); + callback(null, data); + }).error(defaultErrorHandler(callback)); + }; + Client.prototype.createAdmin = function (username, password, email, displayName, setupToken, callback) { var that = this;