Offer configured hosting IP addresses in the DNS editor #226
No files matched your search
@@ -2305,6 +2305,10 @@ Each request captures the reviewed SOA serial and records. You can edit the
|
||||
zone while it publishes. Publish the newer revision after the current request
|
||||
finishes. Use **Retry publishing** if the current revision failed.
|
||||
|
||||
In the DNS editor, **Use hosting IP** fills an A or AAAA record with a
|
||||
matching address from the effective DNS zone template. Choose an address
|
||||
when more than one is available. You can edit the value before saving.
|
||||
|
||||
To let the customer edit a zone's records, enable
|
||||
**Delegate record editing** on that zone. They can also publish the zone when
|
||||
Coulobre publishing is enabled. The operator controls the authoritative
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from ipaddress import ip_address
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from .models import DnsZoneDefaults
|
||||
@@ -8,3 +10,17 @@ def zone_defaults():
|
||||
saved.nameservers = saved.nameservers or settings.HOSTING_NAMESERVERS
|
||||
saved.addresses = saved.addresses or settings.HOSTING_PUBLIC_ADDRESSES
|
||||
return saved
|
||||
|
||||
|
||||
def hosting_address_choices():
|
||||
choices = {"A": [], "AAAA": []}
|
||||
for configured in zone_defaults().addresses:
|
||||
try:
|
||||
address = ip_address(configured)
|
||||
except ValueError:
|
||||
continue
|
||||
addresses = choices["A" if address.version == 4 else "AAAA"]
|
||||
value = str(address)
|
||||
if value not in addresses:
|
||||
addresses.append(value)
|
||||
return choices
|
||||
@@ -8,6 +8,7 @@ const valueLabels = {
|
||||
MX: "Mail server hostname", TXT: "Text", SRV: "Priority, weight, port and target",
|
||||
CAA: "Flags, tag and value",
|
||||
};
|
||||
const hostingAddresses = JSON.parse(document.getElementById("dns-hosting-addresses").textContent);
|
||||
|
||||
function numberRows() {
|
||||
Array.from(rows.children).forEach((row, index) => {
|
||||
@@ -23,6 +24,11 @@ function appendRecord(record) {
|
||||
const priority = row.querySelector("[data-record-priority]");
|
||||
const priorityLabel = row.querySelector("[data-priority-label]");
|
||||
const valueLabel = row.querySelector("[data-record-value-label]");
|
||||
const hostingAddress = row.querySelector("[data-hosting-address]");
|
||||
const onlyAddress = row.querySelector("[data-only-hosting-address]");
|
||||
const addressSelect = row.querySelector("[data-hosting-address-select]");
|
||||
const useAddress = row.querySelector("[data-use-hosting-address]");
|
||||
const missingAddress = row.querySelector("[data-missing-hosting-address]");
|
||||
name.value = record.name;
|
||||
type.value = record.type;
|
||||
value.value = record.value;
|
||||
@@ -42,8 +48,31 @@ function appendRecord(record) {
|
||||
value.rows = type.value === "TXT" ? 4 : 1;
|
||||
value.classList.toggle("dns-txt-value", type.value === "TXT");
|
||||
valueLabel.textContent = valueLabels[type.value];
|
||||
|
||||
const addresses = hostingAddresses[type.value];
|
||||
hostingAddress.hidden = !addresses;
|
||||
if (!addresses) return;
|
||||
addressSelect.replaceChildren(...addresses.map((address) => new Option(address, address)));
|
||||
if (addresses.length > 1) {
|
||||
addressSelect.add(new Option("Choose a hosting IP", ""), 0);
|
||||
addressSelect.selectedIndex = 0;
|
||||
}
|
||||
onlyAddress.hidden = addresses.length !== 1;
|
||||
onlyAddress.textContent = addresses.length === 1 ? addresses[0] : "";
|
||||
addressSelect.hidden = addresses.length < 2;
|
||||
useAddress.hidden = addresses.length === 0;
|
||||
useAddress.disabled = !addressSelect.value;
|
||||
missingAddress.hidden = addresses.length > 0;
|
||||
missingAddress.textContent = `No hosting ${valueLabels[type.value]} is configured.`;
|
||||
};
|
||||
type.addEventListener("change", updateFields);
|
||||
addressSelect.addEventListener("change", () => {
|
||||
useAddress.disabled = !addressSelect.value;
|
||||
});
|
||||
useAddress.addEventListener("click", () => {
|
||||
value.value = addressSelect.value;
|
||||
value.focus();
|
||||
});
|
||||
row.querySelector("[data-remove-record]").addEventListener("click", () => {
|
||||
const nextFocus = row.nextElementSibling?.querySelector("input") || add;
|
||||
row.remove();
|
||||
|
||||
@@ -1061,8 +1061,19 @@ dd {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
.dns-edit-value > label { flex: 1; }
|
||||
.dns-record-value-field { flex: 1; min-width: 0; }
|
||||
.dns-edit-value > [data-priority-label] { flex: 0 0 5rem; }
|
||||
.dns-hosting-address {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.4rem;
|
||||
margin-top: 0.4rem;
|
||||
}
|
||||
.dns-hosting-address[hidden], .dns-hosting-address > [hidden] { display: none; }
|
||||
.dns-hosting-address > select { width: auto; max-width: 100%; }
|
||||
.dns-hosting-address > code { overflow-wrap: anywhere; }
|
||||
.dns-hosting-address > .heading-meta { margin: 0; }
|
||||
.dns-edit-row textarea {
|
||||
display: block;
|
||||
min-height: 2.45rem;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{{ form.editor_rows|json_script:"dns-record-data" }}
|
||||
{{ hosting_addresses|json_script:"dns-hosting-addresses" }}
|
||||
<div data-dns-editor hidden>
|
||||
<h2>DNS records</h2>
|
||||
<p class="heading-meta">Use @ for the zone name, or enter a name such as www.</p>
|
||||
@@ -13,7 +14,15 @@
|
||||
</select></label>
|
||||
<div class="dns-edit-value">
|
||||
<label data-priority-label hidden>Priority<input data-record-priority type="number" min="0" max="65535" inputmode="numeric"></label>
|
||||
<label><span data-record-value-label>Value</span><textarea rows="1" data-record-value required></textarea></label>
|
||||
<div class="dns-record-value-field">
|
||||
<label><span data-record-value-label>Value</span><textarea rows="1" data-record-value required></textarea></label>
|
||||
<div class="dns-hosting-address" data-hosting-address hidden>
|
||||
<code data-only-hosting-address hidden></code>
|
||||
<select data-hosting-address-select aria-label="Configured hosting IP"></select>
|
||||
<button class="button secondary" type="button" data-use-hosting-address>Use hosting IP</button>
|
||||
<p class="heading-meta" data-missing-hosting-address hidden></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button class="button secondary" type="button" data-remove-record>Remove</button>
|
||||
</fieldset>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{% extends "hosting/workspace_page.html" %}
|
||||
{% load static %}
|
||||
{% load panel_assets %}
|
||||
{% block title %}{{ page_title }} · Coulobre Panel{% endblock %}
|
||||
{% block page_header %}
|
||||
<header class="page-heading">
|
||||
@@ -38,7 +38,7 @@
|
||||
</div>
|
||||
{% if not form.is_bound or form.record_rows.value %}
|
||||
{% include "hosting/dns_record_editor.html" %}
|
||||
<script src="{% static 'hosting/dns-record-editor.js' %}" defer></script>
|
||||
<script src="{% panel_asset 'hosting/dns-record-editor.js' %}" defer></script>
|
||||
{% endif %}
|
||||
<div class="form-actions">
|
||||
<button class="button primary" type="submit">{% if publish_on_create %}Save and publish zone{% else %}Save zone{% endif %}</button>
|
||||
|
||||
@@ -7,7 +7,7 @@ from django.urls import reverse
|
||||
|
||||
from coulobre.dns_node import MAX_SOA_SERIAL, DnsZone
|
||||
|
||||
from .models import HostingAccount, HostingDnsZone, Reseller
|
||||
from .models import DnsZoneDefaults, HostingAccount, HostingDnsZone, Reseller
|
||||
|
||||
|
||||
class DnsZonePanelTests(TestCase):
|
||||
@@ -191,6 +191,35 @@ class DnsZonePanelTests(TestCase):
|
||||
self.client.get(self.account.get_absolute_url()), "2001:db8::21"
|
||||
)
|
||||
|
||||
def test_address_suggestions_use_effective_dns_defaults_by_family(self):
|
||||
zone = self.create_zone()
|
||||
edit = reverse("panel:dns_zone_edit", args=[zone.pk])
|
||||
with self.settings(HOSTING_PUBLIC_ADDRESSES=()):
|
||||
self.assertEqual(
|
||||
self.client.get(edit).context["hosting_addresses"],
|
||||
{"A": [], "AAAA": []},
|
||||
)
|
||||
with self.settings(HOSTING_PUBLIC_ADDRESSES=("192.0.2.90",)):
|
||||
self.assertEqual(
|
||||
self.client.get(self.add_url).context["hosting_addresses"],
|
||||
{"A": ["192.0.2.90"], "AAAA": []},
|
||||
)
|
||||
DnsZoneDefaults.objects.create(
|
||||
pk=1,
|
||||
addresses=[
|
||||
"192.0.2.40",
|
||||
"2001:db8:0::10",
|
||||
"2001:db8::10",
|
||||
"192.0.2.50",
|
||||
],
|
||||
)
|
||||
response = self.client.get(edit)
|
||||
self.assertContains(response, 'id="dns-hosting-addresses"')
|
||||
self.assertEqual(
|
||||
response.context["hosting_addresses"],
|
||||
{"A": ["192.0.2.40", "192.0.2.50"], "AAAA": ["2001:db8::10"]},
|
||||
)
|
||||
|
||||
def test_invalid_mail_records_leave_existing_zone_unchanged(self):
|
||||
zone = self.create_zone()
|
||||
edit = reverse("panel:dns_zone_edit", args=[zone.pk])
|
||||
|
||||
@@ -72,7 +72,7 @@ from .backup_restores import (
|
||||
retry_remote_mail_restore,
|
||||
)
|
||||
from .backup_retention import change_backup_retention, protect_backup
|
||||
from .dns_defaults import zone_defaults
|
||||
from .dns_defaults import hosting_address_choices, zone_defaults
|
||||
from .dns_forms import (
|
||||
DnsZoneEditForm,
|
||||
DnsZoneForm,
|
||||
@@ -2179,7 +2179,10 @@ class DnsZoneEditor(PermissionRequiredMixin, FormView):
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
return super().get_context_data(
|
||||
account=self.account, domain=self.domain, **kwargs
|
||||
account=self.account,
|
||||
domain=self.domain,
|
||||
hosting_addresses=hosting_address_choices(),
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
def get_success_url(self):
|
||||
|
||||
Reference in new issue
Block a user