allow to set domain specific fallback certs

This commit is contained in:
Johannes Zellner
2017-11-12 00:53:28 +01:00
parent a4a3e19a92
commit bf711c6ebb
6 changed files with 121 additions and 50 deletions

View File

@@ -1163,23 +1163,27 @@ angular.module('Application').service('Client', ['$http', 'md5', 'Notification',
}).error(defaultErrorHandler(callback));
};
Client.prototype.addDomain = function (domain, config, callback) {
Client.prototype.addDomain = function (domain, config, fallbackCertificate, callback) {
var data = {
domain: domain,
config: config
};
post('/api/v1/domains', data).success(function (data, status) {
if (status !== 201 || typeof data !== 'object') return callback(new ClientError(status, data));
callback(null, data);
}).error(defaultErrorHandler(callback));
};
if (fallbackCertificate) data.fallbackCertificate = fallbackCertificate;
Client.prototype.updateDomain = function (domain, config, callback) {
post('/api/v1/domains', data).success(function (data, status) {
if (status !== 201 || typeof data !== 'object') return callback(new ClientError(status, data));
callback(null, data);
}).error(defaultErrorHandler(callback));
};
Client.prototype.updateDomain = function (domain, config, fallbackCertificate, callback) {
var data = {
config: config
config: config
};
if (fallbackCertificate) data.fallbackCertificate = fallbackCertificate;
put('/api/v1/domains/' + domain, data).success(function (data, status) {
if (status !== 204) return callback(new ClientError(status, data));
callback(null);

View File

@@ -57,33 +57,60 @@
<input type="email" class="form-control" ng-model="domainConfigure.cloudflareEmail" name="cloudflareEmail" placeholder="Cloudflare Account Email" ng-required="domainConfigure.provider === 'cloudflare'" ng-disabled="domainConfigure.busy">
</div>
<p ng-show="domainConfigure.provider === 'route53'">
This domain must be hosted on <a href="https://aws.amazon.com/route53/?nc2=h_m1" target="_blank">AWS Route53</a>.
</p>
<p ng-show="domainConfigure.provider === 'gcdns'">
This domain must be hosted on <a href="https://console.cloud.google.com/net-services/dns/zones" target="_blank">Google Cloud DNS</a>.
</p>
<p ng-show="domainConfigure.provider === 'digitalocean'">
This domain must be hosted on <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-a-host-name-with-digitalocean#step-two%E2%80%94change-your-domain-server" target="_blank">DigitalOcean</a>.
</p>
<p ng-show="domainConfigure.provider === 'cloudflare'">
This domain must be hosted on <a href="https://www.cloudflare.com" target="_blank">Cloudflare</a>.
</p>
<p ng-show="domainConfigure.provider === 'wildcard'">
Setup <i>A</i> records for <b>*.{{ domainConfigure.newDomain || domainConfigure.domain.domain }}</b> and <b>{{ domainConfigure.newDomain || domainConfigure.domain.domain }}</b> to this server's IP.
</p>
<p ng-show="domainConfigure.provider === 'manual'">
All DNS records have to be setup manually <i>before</i> each app installation.
</p>
<br/>
<!-- Wildcard certificates -->
<label class="control-label">Fallback Certificate (optional)</label>
<p>
Certificates are automatically obtained and renewed from <a href="https://letsencrypt.org/" target="_blank">Lets Encrypt</a>. See the current rate limit <a href="https://letsencrypt.org/docs/rate-limits/" target="_blank">here</a>.
If provided, this wildcard certificate will be used for apps, should getting a Lets Encrypt certificate fail.
</p>
<div class="form-group" ng-class="{ 'has-error': (!fallbackCert.cert.$dirty && fallbackCert.error) }">
<div class="input-group">
<input type="file" id="fallbackCertFileInput" style="display:none"/>
<input type="text" class="form-control" placeholder="Certificate" ng-model="domainConfigure.fallbackCert.certificateFileName" name="cert" onclick="getElementById('fallbackCertFileInput').click();" style="cursor: pointer;" ng-disabled="domainConfigure.busy">
<span class="input-group-addon">
<i class="fa fa-upload" onclick="getElementById('fallbackCertFileInput').click();"></i>
</span>
</div>
</div>
<div class="form-group" ng-class="{ 'has-error': (!fallbackCert.key.$dirty && fallbackCert.error) }">
<div class="input-group">
<input type="file" id="fallbackKeyFileInput" style="display:none"/>
<input type="text" class="form-control" placeholder="Key" ng-model="domainConfigure.fallbackCert.keyFileName" id="fallbackKeyInput" name="key" onclick="getElementById('fallbackKeyFileInput').click();" style="cursor: pointer;" ng-disabled="domainConfigure.busy">
<span class="input-group-addon">
<i class="fa fa-upload" onclick="getElementById('fallbackKeyFileInput').click();"></i>
</span>
</div>
</div>
<input class="ng-hide" type="submit" ng-disabled="domainConfigureForm.$invalid || domainConfigure.busy"/>
</fieldset>
</form>
<p ng-show="domainConfigure.provider === 'route53'">
This domain must be hosted on <a href="https://aws.amazon.com/route53/?nc2=h_m1" target="_blank">AWS Route53</a>.
</p>
<p ng-show="domainConfigure.provider === 'gcdns'">
This domain must be hosted on <a href="https://console.cloud.google.com/net-services/dns/zones" target="_blank">Google Cloud DNS</a>.
</p>
<p ng-show="domainConfigure.provider === 'digitalocean'">
This domain must be hosted on <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-a-host-name-with-digitalocean#step-two%E2%80%94change-your-domain-server" target="_blank">DigitalOcean</a>.
</p>
<p ng-show="domainConfigure.provider === 'cloudflare'">
This domain must be hosted on <a href="https://www.cloudflare.com" target="_blank">Cloudflare</a>.
</p>
<p ng-show="domainConfigure.provider === 'wildcard'">
Setup <i>A</i> records for <b>*.{{ domainConfigure.newDomain || domainConfigure.domain.domain }}</b> and <b>{{ domainConfigure.newDomain || domainConfigure.domain.domain }}</b> to this server's IP.
</p>
<p ng-show="domainConfigure.provider === 'manual'">
All DNS records have to be setup manually <i>before</i> each app installation.
</p>
</div>
<div class="modal-footer ">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>

View File

@@ -52,6 +52,13 @@ angular.module('Application').controller('DomainsController', ['$scope', '$locat
cloudflareEmail: '',
provider: 'route53',
fallbackCert: {
certificateFile: null,
certificateFileName: '',
keyFile: null,
keyFileName: ''
},
show: function (domain) {
$scope.domainConfigure.reset();
@@ -123,10 +130,18 @@ angular.module('Application').controller('DomainsController', ['$scope', '$locat
data.email = $scope.domainConfigure.cloudflareEmail;
}
var fallbackCertificate = null;
if ($scope.domainConfigure.fallbackCert.certificateFile && $scope.domainConfigure.fallbackCert.keyFile) {
fallbackCertificate = {
cert: $scope.domainConfigure.fallbackCert.certificateFile,
key: $scope.domainConfigure.fallbackCert.keyFile
};
}
// choose the right api, since we reuse this for adding and configuring domains
var func;
if ($scope.domainConfigure.adding) func = Client.addDomain.bind(Client, $scope.domainConfigure.newDomain, data);
else func = Client.updateDomain.bind(Client, $scope.domainConfigure.domain.domain, data) ;
if ($scope.domainConfigure.adding) func = Client.addDomain.bind(Client, $scope.domainConfigure.newDomain, data, fallbackCertificate);
else func = Client.updateDomain.bind(Client, $scope.domainConfigure.domain.domain, data, fallbackCertificate);
func(function (error) {
$scope.domainConfigure.busy = false;
@@ -231,6 +246,9 @@ angular.module('Application').controller('DomainsController', ['$scope', '$locat
});
document.getElementById('gcdnsKeyFileInput').onchange = readFileLocally($scope.domainConfigure.gcdnsKey, 'content', 'keyFileName');
document.getElementById('fallbackCertFileInput').onchange = readFileLocally($scope.domainConfigure.fallbackCert, 'certificateFile', 'certificateFileName');
document.getElementById('fallbackKeyFileInput').onchange = readFileLocally($scope.domainConfigure.fallbackCert, 'keyFile', 'keyFileName');
// setup all the dialog focus handling
['domainConfigureModal', 'domainRemoveModal'].forEach(function (id) {