Reverse v6 validation, reverse domain name generation
This commit is contained in:
parent
2fc672690f
commit
c09ba916e0
|
@ -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()
|
||||
|
||||
|
|
|
@ -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,))
|
||||
|
||||
|
|
Loading…
Reference in New Issue