mirror of
https://github.com/eduardogsilva/wireguard_webadmin.git
synced 2026-11-27 07:06:03 +01:00
Add DNS challenge delegation to a support domain
This commit is contained in:
@@ -128,8 +128,7 @@
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
{{ host.get_certificate_type_display }}
|
||||
{% if host.dns_credential %}<small class="text-muted">({{ host.dns_credential }})</small>{% endif %}
|
||||
{% include 'app_gateway/host_certificate.html' %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
@@ -204,6 +203,7 @@
|
||||
<tr>
|
||||
<th>{% trans 'Name' %}</th>
|
||||
<th>{% trans 'Provider' %}</th>
|
||||
<th>{% trans 'Delegation domain' %}</th>
|
||||
<th>{% trans 'Hosts' %}</th>
|
||||
<th>{% trans 'Actions' %}</th>
|
||||
</tr>
|
||||
@@ -213,6 +213,7 @@
|
||||
<tr>
|
||||
<td>{{ dns_credential.display_name|default:dns_credential.name }}</td>
|
||||
<td>{{ dns_credential.get_provider_display }}</td>
|
||||
<td>{{ dns_credential.delegation_domain|default:'-' }}</td>
|
||||
<td>{{ dns_credential.hosts.count }}</td>
|
||||
<td style="width: 15%">
|
||||
<a href="{% url 'manage_dns_credential' %}?uuid={{ dns_credential.uuid }}"
|
||||
@@ -241,3 +242,19 @@
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block page_custom_head %}
|
||||
<style>
|
||||
.tooltip-inner.host-certificate-tooltip {
|
||||
max-width: 420px;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block custom_page_scripts %}
|
||||
<script>
|
||||
$(function () {
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
@@ -84,11 +84,7 @@
|
||||
<tr>
|
||||
<td>{{ host.hostname }}</td>
|
||||
<td>
|
||||
{{ host.get_certificate_type_display }}
|
||||
{% if host.dns_credential %}<small class="text-muted">({{ host.dns_credential }})</small>{% endif %}
|
||||
{% if host.certificate_type != 'self_signed' and not host.certificate_fallback %}
|
||||
<small class="text-muted">({% trans 'no fallback' %})</small>
|
||||
{% endif %}
|
||||
{% include 'app_gateway/host_certificate.html' %}
|
||||
</td>
|
||||
{% if caddy_enabled %}
|
||||
<td class="certificate-status" data-host-uuid="{{ host.uuid }}">
|
||||
@@ -188,7 +184,20 @@
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block page_custom_head %}
|
||||
<style>
|
||||
.tooltip-inner.host-certificate-tooltip {
|
||||
max-width: 420px;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block custom_page_scripts %}
|
||||
<script>
|
||||
$(function () {
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
});
|
||||
</script>
|
||||
{% if caddy_enabled and hosts %}
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
{% extends 'generic_form.html' %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block custom_page_scripts %}
|
||||
{{ block.super }}
|
||||
<div class="modal fade" id="dnsDelegationModal" tabindex="-1" aria-labelledby="dnsDelegationModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="dnsDelegationModalLabel">{% trans 'CNAME record required' %}</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="{% trans 'Close' %}">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>{% blocktrans trimmed %}
|
||||
Make sure this record exists in the DNS zone of the hostname. The certificate is requested as
|
||||
soon as the configuration is applied, and without the record it cannot be issued.
|
||||
{% endblocktrans %}</p>
|
||||
<div class="dns-delegation-record"></div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">{% trans 'Back' %}</button>
|
||||
<button type="button" class="btn btn-primary" id="dnsDelegationConfirm">{% trans 'I created the record, save' %}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{ delegation_domains|json_script:'dns-delegation-domains' }}
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
var delegationDomains = JSON.parse(document.getElementById('dns-delegation-domains').textContent);
|
||||
var initialRecord = "{{ initial_delegation_record|escapejs }}";
|
||||
var labels = {
|
||||
type: "{% trans 'Type'|escapejs %}",
|
||||
name: "{% trans 'Name'|escapejs %}",
|
||||
target: "{% trans 'Target'|escapejs %}",
|
||||
copy: "{% trans 'Copy'|escapejs %}"
|
||||
};
|
||||
var $form = $('#id_hostname').closest('form');
|
||||
var confirmed = false;
|
||||
|
||||
function challengeBase(hostname) {
|
||||
hostname = hostname.trim().toLowerCase().replace(/\.+$/, '');
|
||||
return hostname.indexOf('*.') === 0 ? hostname.substring(2) : hostname;
|
||||
}
|
||||
|
||||
function currentRecord() {
|
||||
var hostname = challengeBase($('#id_hostname').val() || '');
|
||||
var delegationDomain = delegationDomains[$('#id_dns_credential').val()];
|
||||
if ($('#id_certificate_type').val() !== 'dns_challenge' || !delegationDomain || !hostname) {
|
||||
return null;
|
||||
}
|
||||
// Hostnames inside the delegation domain are validated directly
|
||||
if (hostname === delegationDomain || hostname.endsWith('.' + delegationDomain)) {
|
||||
return null;
|
||||
}
|
||||
return {name: '_acme-challenge.' + hostname, target: hostname + '.' + delegationDomain};
|
||||
}
|
||||
|
||||
function recordField(label, value) {
|
||||
var $group = $('<div class="input-group input-group-sm mb-2"></div>');
|
||||
$group.append($('<div class="input-group-prepend"></div>').append(
|
||||
$('<span class="input-group-text" style="min-width: 5em"></span>').text(label)
|
||||
));
|
||||
var $input = $('<input type="text" class="form-control text-monospace" readonly>').val(value);
|
||||
$group.append($input);
|
||||
var $button = $('<button type="button" class="btn btn-outline-secondary"></button>')
|
||||
.attr('title', labels.copy).html('<i class="far fa-copy"></i>');
|
||||
$button.on('click', function () {
|
||||
$input.trigger('select');
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
navigator.clipboard.writeText(value);
|
||||
} else {
|
||||
document.execCommand('copy');
|
||||
}
|
||||
});
|
||||
$group.append($('<div class="input-group-append"></div>').append($button));
|
||||
return $group;
|
||||
}
|
||||
|
||||
function renderRecord(record) {
|
||||
$('.dns-delegation-record').each(function () {
|
||||
$(this).empty()
|
||||
.append(recordField(labels.type, 'CNAME'))
|
||||
.append(recordField(labels.name, record.name))
|
||||
.append(recordField(labels.target, record.target));
|
||||
});
|
||||
}
|
||||
|
||||
function updateAlert() {
|
||||
var record = currentRecord();
|
||||
$('#dns-delegation-alert').toggleClass('d-none', !record);
|
||||
if (record) {
|
||||
renderRecord(record);
|
||||
}
|
||||
}
|
||||
|
||||
$('#id_hostname').on('input', updateAlert);
|
||||
$('#id_certificate_type, #id_dns_credential').on('change', updateAlert);
|
||||
updateAlert();
|
||||
|
||||
// Ask for confirmation only when the required record is new or changed
|
||||
$form.on('submit', function (event) {
|
||||
var record = currentRecord();
|
||||
if (confirmed || !record || record.name + ' ' + record.target === initialRecord) {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
renderRecord(record);
|
||||
$('#dnsDelegationModal').modal('show');
|
||||
});
|
||||
|
||||
$('#dnsDelegationConfirm').on('click', function () {
|
||||
confirmed = true;
|
||||
$('#dnsDelegationModal').modal('hide');
|
||||
// The submit button is named "submit", which hides the form.submit() method
|
||||
var form = $form[0];
|
||||
if (form.requestSubmit) {
|
||||
form.requestSubmit();
|
||||
} else {
|
||||
HTMLFormElement.prototype.submit.call(form);
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -28,6 +28,15 @@
|
||||
API Token with the <strong>Zone / Zone / Read</strong> and <strong>Zone / DNS / Edit</strong> permissions.
|
||||
{% endblocktrans %}</p>
|
||||
<p>{% trans 'Secret values are never displayed after saving. Leave them blank when editing to keep the current value.' %}</p>
|
||||
<h5>{% trans 'Delegation domain' %}</h5>
|
||||
<p>{% blocktrans trimmed %}
|
||||
Use a delegation domain when the zone of the hostnames is not managed by this provider, or
|
||||
to keep the token restricted to a zone used only for certificate validation. The challenge
|
||||
record is created in the delegation domain, and each hostname needs a CNAME record pointing
|
||||
to it:
|
||||
{% endblocktrans %}</p>
|
||||
<p><code>_acme-challenge.app.example.com CNAME app.example.com.acme.example.net</code></p>
|
||||
<p>{% trans 'The token must be able to edit the DNS records of the delegation domain zone. The required record of each host is shown when the host is edited and in the host list.' %}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{% load i18n %}
|
||||
<div id="dns-delegation-alert" class="alert alert-warning d-none">
|
||||
<h5><i class="icon fas fa-exclamation-triangle"></i> {% trans 'CNAME record required' %}</h5>
|
||||
<p class="mb-2">{% blocktrans trimmed %}
|
||||
This DNS credential uses a delegation domain. Create this record in the DNS zone of the hostname
|
||||
before saving, otherwise the certificate cannot be issued:
|
||||
{% endblocktrans %}</p>
|
||||
<div class="dns-delegation-record"></div>
|
||||
</div>
|
||||
@@ -0,0 +1,20 @@
|
||||
{% load i18n %}{% with record=host.dns_delegation_record %}
|
||||
{{ host.certificate_label }}
|
||||
{% if host.certificate_type != 'self_signed' %}
|
||||
{% if host.certificate_fallback %}
|
||||
<span class="badge badge-secondary">{% trans 'fallback' %}</span>
|
||||
{% else %}
|
||||
<span class="badge badge-warning">{% trans 'no fallback' %}</span>
|
||||
{% endif %}
|
||||
<i class="fas fa-info-circle text-muted ml-1" data-toggle="tooltip" data-html="true"
|
||||
data-template='<div class="tooltip" role="tooltip"><div class="arrow"></div><div class="tooltip-inner host-certificate-tooltip"></div></div>'
|
||||
title="{% filter force_escape %}
|
||||
<div class='text-left'>
|
||||
{% if host.dns_credential %}<strong>{% trans 'DNS Credential' %}:</strong> {{ host.dns_credential }}<br>{% endif %}
|
||||
{% if record %}<strong>{% trans 'Required record' %}:</strong><br><code>{{ record.0 }}</code><br>CNAME <code>{{ record.1 }}</code><br>{% endif %}
|
||||
<strong>{% trans 'Fallback' %}:</strong>
|
||||
{% if host.certificate_fallback %}{% trans 'self-signed certificate while the trusted certificate cannot be issued' %}{% else %}{% trans 'disabled, the connection fails until the certificate is issued' %}{% endif %}
|
||||
</div>
|
||||
{% endfilter %}"></i>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
Reference in New Issue
Block a user