From c09ba916e016724e8a907e23c03db96244351588 Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Thu, 6 Apr 2017 11:56:55 +0200 Subject: [PATCH] Reverse v6 validation, reverse domain name generation --- domains/forms.py | 9 +++++++++ domains/models.py | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/domains/forms.py b/domains/forms.py index 87c3731..fb9c23a 100644 --- a/domains/forms.py +++ b/domains/forms.py @@ -175,6 +175,15 @@ class ReverseZoneForm(forms.ModelForm): self.fields['nameservers'].queryset = self.fields['nameservers'].queryset.distinct() + def clean_prefix(self): + prefix = self.cleaned_data['prefix'] + + net = ipaddress.ip_network(prefix) + if net.version == 6 and net.prefixlen % 4 != 0: + raise forms.ValidationError("IPv6 reverse zone prefix length has to be a multiple of 4") + + return prefix + def clean(self): cleaned_data = super(ReverseZoneForm, self).clean() diff --git a/domains/models.py b/domains/models.py index 911a6c8..d406c50 100644 --- a/domains/models.py +++ b/domains/models.py @@ -49,6 +49,9 @@ class Domain(MntdObject): def getPK(self): return self.name + def getZone(self): + return self.name + def get_absolute_url(self): return reverse("domains:domain-show", args=(self.name,)) @@ -94,6 +97,24 @@ class ReverseZone(WhoisObject): def getNetwork(self): return ipaddress.ip_network(self.prefix()) + def getZone(self): + net = self.parentNet.getNetwork() + if net.version == 4: + # for these we delegate the full domain + if 0 < net.prefixlen < 32 and net.prefixlen % 8 == 0: + zoneParts = net.reverse_pointer.split(".") + + return ".".join(zoneParts[1:]) + else: + # return RFC2317 compliant zone + return net.reverse_pointer + else: + # ipv6 + # thefuck ipaddress lib... _the_ _fuck_ + zoneParts = net.reverse_pointer.split(".")[-2 - net.prefixlen // 4:] + + return ".".join(zoneParts) + def get_absolute_url(self): return reverse("domains:reversezone-show", args=(self.pk,))