|
|
|
@ -62,6 +62,10 @@ class NameserverForm(MntFormMixin, forms.ModelForm):
|
|
|
|
|
model = Nameserver
|
|
|
|
|
fields = ['name', 'glueIPv4', 'glueIPv6', 'mnt_by', 'admin_c']
|
|
|
|
|
|
|
|
|
|
help_texts = {
|
|
|
|
|
"glueIPv4": "Note: You can only set a glue record if the base domain of this nameserver belongs to you!"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def __init__(self, user, *args, **kwargs):
|
|
|
|
|
self._user = user
|
|
|
|
|
|
|
|
|
@ -78,24 +82,51 @@ class NameserverForm(MntFormMixin, forms.ModelForm):
|
|
|
|
|
if name.count(".") <= 2:
|
|
|
|
|
raise forms.ValidationError("Nameserver must be inside a domain (e.g. ns1.noot.dn.)")
|
|
|
|
|
|
|
|
|
|
zone = ".".join(name.split(".")[-3:])
|
|
|
|
|
|
|
|
|
|
mnts = self._user.maintainer_set.all()
|
|
|
|
|
domains = Domain.objects.filter(mnt_by__in=mnts)
|
|
|
|
|
found = False
|
|
|
|
|
for domain in domains:
|
|
|
|
|
if domain.name == zone:
|
|
|
|
|
found = True
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
if not found:
|
|
|
|
|
raise forms.ValidationError("This nameserver is not under a domain you control.")
|
|
|
|
|
try:
|
|
|
|
|
obj = Nameserver.objects.get(name=name, mnt_by__in=mnts)
|
|
|
|
|
if self._create or not self._create and obj.pk != self.instance.pk:
|
|
|
|
|
raise forms.ValidationError("You already have a nameserver with this name under your control")
|
|
|
|
|
except Nameserver.DoesNotExist:
|
|
|
|
|
pass
|
|
|
|
|
except Nameserver.MultipleObjectsReturned:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
#zone = ".".join(name.split(".")[-3:])
|
|
|
|
|
#mnts = self._user.maintainer_set.all()
|
|
|
|
|
#domains = Domain.objects.filter(mnt_by__in=mnts)
|
|
|
|
|
#found = False
|
|
|
|
|
#for domain in domains:
|
|
|
|
|
# if domain.name == zone:
|
|
|
|
|
# found = True
|
|
|
|
|
# break
|
|
|
|
|
|
|
|
|
|
#if not found:
|
|
|
|
|
# raise forms.ValidationError("This nameserver is not under a domain you control.")
|
|
|
|
|
|
|
|
|
|
return name
|
|
|
|
|
|
|
|
|
|
def clean(self):
|
|
|
|
|
cleaned_data = super(NameserverForm, self).clean()
|
|
|
|
|
|
|
|
|
|
if not self.errors:
|
|
|
|
|
name = cleaned_data.get("name")
|
|
|
|
|
zone = ".".join(name.split(".")[-3:])
|
|
|
|
|
ipv4 = cleaned_data.get("glueIPv4")
|
|
|
|
|
ipv6 = cleaned_data.get("glueIPv6")
|
|
|
|
|
|
|
|
|
|
if (ipv4 or ipv6) and self._create or not (self.instance.glueIPv4 == ipv4 and self.instance.glueIPv6 == ipv6):
|
|
|
|
|
mnts = self._user.maintainer_set.all()
|
|
|
|
|
domains = Domain.objects.filter(mnt_by__in=mnts)
|
|
|
|
|
found = False
|
|
|
|
|
for domain in domains:
|
|
|
|
|
if domain.name == zone:
|
|
|
|
|
found = True
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
if not found:
|
|
|
|
|
raise forms.ValidationError("This nameserver is not under a domain you control.")
|
|
|
|
|
|
|
|
|
|
return cleaned_data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|