Files
cloudron-box/webadmin/src/js/setupdns.js

79 lines
2.4 KiB
JavaScript
Raw Normal View History

2017-01-05 11:02:43 +01:00
'use strict';
// create main application module
var app = angular.module('Application', ['angular-md5', 'ui-notification']);
2017-01-05 11:53:45 +01:00
app.controller('SetupDNSController', ['$scope', '$http', 'Client', function ($scope, $http, Client) {
2017-01-05 11:02:43 +01:00
$scope.initialized = false;
$scope.busy = false;
$scope.error = null;
$scope.provider = '';
$scope.showDNSSetup = false;
$scope.dnsProvider = [
{ name: 'AWS Route53', value: 'route53' },
2017-01-05 12:08:52 +01:00
{ name: 'Digital Ocean', value: 'digitalocean' },
{ name: 'Manual', value: 'manual' },
{ name: 'Wildcard', value: 'wildcard' },
{ name: 'No-op (only for development)', value: 'noop' }
2017-01-05 11:02:43 +01:00
];
$scope.dnsCredentials = {
error: null,
busy: false,
domain: '',
accessKeyId: '',
secretAccessKey: '',
digitalOceanToken: '',
provider: 'route53'
};
2017-01-05 12:31:37 +01:00
$scope.setDnsCredentials = function () {
$scope.dnsCredentials.busy = true;
2017-01-05 11:02:43 +01:00
var data = {
domain: $scope.dnsCredentials.domain,
provider: $scope.dnsCredentials.provider,
accessKeyId: $scope.dnsCredentials.accessKeyId,
secretAccessKey: $scope.dnsCredentials.secretAccessKey,
token: $scope.dnsCredentials.digitalOceanToken
};
// special case the wildcard provider
if (data.provider === 'wildcard') {
data.provider = 'manual';
data.wildcard = true;
}
2017-01-05 11:53:45 +01:00
Client.setupDnsConfig(data, function (error) {
2017-01-05 11:02:43 +01:00
if (error) {
2017-01-05 12:31:37 +01:00
$scope.dnsCredentials.busy = false;
2017-01-05 11:02:43 +01:00
$scope.dnsCredentials.error = error.message;
return;
}
2017-01-05 12:31:37 +01:00
$scope.busy = true;
2017-01-05 11:02:43 +01:00
setTimeout(function () {
// TODO wait until domain is propagated and cert got acquired
2017-01-05 11:53:45 +01:00
window.location.href = 'https://my.' + $scope.dnsCredentials.domain + '/setup.html';
2017-01-05 16:35:38 +01:00
}, 10000);
2017-01-05 11:02:43 +01:00
});
};
Client.getStatus(function (error, status) {
if (error) {
window.location.href = '/error.html';
return;
}
if (status.activated || status.provider === 'caas') {
window.location.href = '/';
return;
}
2017-01-05 16:32:34 +01:00
if (status.provider === 'digitalocean') $scope.dnsCredentials.provider = 'digitalocean';
2017-01-05 11:02:43 +01:00
$scope.provider = status.provider;
$scope.initialized = true;
});
}]);