Zwischencommit
This commit is contained in:
parent
26ff25bfd3
commit
8dbd77dc79
|
@ -2,8 +2,9 @@ from django.shortcuts import render
|
|||
from django.contrib.auth.decorators import login_required
|
||||
from django.db.models import Q
|
||||
from django.views.generic import CreateView
|
||||
from django.urls import reverse_lazy
|
||||
from django.urls import reverse_lazy, reverse
|
||||
from django.contrib import messages
|
||||
from django.http import HttpResponseRedirect
|
||||
|
||||
|
||||
from whoisdb.models import ASNumber, InetNum
|
||||
|
@ -30,6 +31,9 @@ def dashboard(request):
|
|||
|
||||
|
||||
def index(request):
|
||||
if request.user.is_authenticated():
|
||||
return HttpResponseRedirect(reverse("dashboard"))
|
||||
|
||||
return render(request, "index.html", {})
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
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
|
||||
|
||||
if not found:
|
||||
raise forms.ValidationError("This nameserver is not under a domain you control.")
|
||||
#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
|
||||
|
||||
|
||||
|
|
|
@ -15,21 +15,25 @@ class Nameserver(MntdObject):
|
|||
# ip address, if glue
|
||||
# ipv4/ipv6 address?
|
||||
handle = None
|
||||
name = models.CharField(max_length=256, unique=True)
|
||||
name = models.CharField(max_length=256)
|
||||
glueIPv4 = models.GenericIPAddressField(protocol='IPv4', blank=True, null=True)
|
||||
glueIPv6 = models.GenericIPAddressField(protocol='IPv6', blank=True, null=True)
|
||||
|
||||
admin_c = models.ManyToManyField(Contact)
|
||||
|
||||
def getPK(self):
|
||||
return self.name
|
||||
return self.pk
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse("domains:nameserver-show", args=(self.name,))
|
||||
return reverse("domains:nameserver-show", args=(self.pk,))
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def getNoDeleteReasons(self):
|
||||
# nameservers can always be deleted
|
||||
return []
|
||||
|
||||
|
||||
class Domain(MntdObject):
|
||||
handle = None
|
||||
|
@ -53,6 +57,7 @@ class Domain(MntdObject):
|
|||
|
||||
nameservers = Nameserver.objects.filter(name__endswith="." + self.name)
|
||||
for ns in nameservers:
|
||||
# FIXME: check if the nameserver has a glue record.... and also if it is maintained by us
|
||||
reasons.append("Nameserver %s depends on this domain" % ns.name)
|
||||
|
||||
return reasons
|
||||
|
|
|
@ -11,9 +11,9 @@ urlpatterns = [
|
|||
url(r'domain/delete/(?P<domain>[a-z0-9.-]+)/$', domains_views.DomainDelete.as_view(), name='domain-delete'),
|
||||
|
||||
url(r'nameserver/create/$', domains_views.NameserverCreate.as_view(), name='nameserver-create'),
|
||||
url(r'nameserver/show/(?P<domain>[a-z0-9.-]+)/$', domains_views.NameserverDetail.as_view(), name='nameserver-show'),
|
||||
url(r'nameserver/edit/(?P<domain>[a-z0-9.-]+)/$', domains_views.NameserverEdit.as_view(), name='nameserver-edit'),
|
||||
url(r'nameserver/delete/(?P<domain>[a-z0-9.-]+)/$', domains_views.NameserverDelete.as_view(), name='nameserver-delete'),
|
||||
url(r'nameserver/show/(?P<pk>[0-9]+)/$', domains_views.NameserverDetail.as_view(), name='nameserver-show'),
|
||||
url(r'nameserver/edit/(?P<pk>[0-9]+)/$', domains_views.NameserverEdit.as_view(), name='nameserver-edit'),
|
||||
url(r'nameserver/delete/(?P<pk>[0-9]+)/$', domains_views.NameserverDelete.as_view(), name='nameserver-delete'),
|
||||
|
||||
url(r'reversezone/create/$', domains_views.ReverseZoneCreate.as_view(), name='reversezone-create'),
|
||||
url(r'reversezone/show/(?P<pk>[0-9]+)/$', domains_views.ReverseZoneDetail.as_view(), name='reversezone-show'),
|
||||
|
|
|
@ -77,8 +77,8 @@ class NameserverCreate(LoginRequiredMixin, CreateView):
|
|||
|
||||
class NameserverDetail(LoginRequiredMixin, DetailView):
|
||||
model = Nameserver
|
||||
slug_field = "name"
|
||||
slug_url_kwarg = "domain"
|
||||
#slug_field = "name"
|
||||
#slug_url_kwarg = "domain"
|
||||
#context_object_name = "nameserver"
|
||||
template_name = "domains/handle_show.html"
|
||||
|
||||
|
@ -86,8 +86,8 @@ class NameserverDetail(LoginRequiredMixin, DetailView):
|
|||
class NameserverEdit(MntGenericMixin, LoginRequiredMixin, UpdateView):
|
||||
model = Nameserver
|
||||
form_class = NameserverForm
|
||||
slug_field = "name"
|
||||
slug_url_kwarg = "domain"
|
||||
#slug_field = "name"
|
||||
#slug_url_kwarg = "domain"
|
||||
template_name = "domains/obj_edit.html"
|
||||
|
||||
def get_form_kwargs(self, *args, **kwargs):
|
||||
|
@ -99,8 +99,8 @@ class NameserverEdit(MntGenericMixin, LoginRequiredMixin, UpdateView):
|
|||
class NameserverDelete(MntGenericMixin, LoginRequiredMixin, DeleteCheckView):
|
||||
template_name = "domains/obj_delete.html"
|
||||
model = Nameserver
|
||||
slug_field = "name"
|
||||
slug_url_kwarg = "domain"
|
||||
#slug_field = "name"
|
||||
#slug_url_kwarg = "domain"
|
||||
success_url = reverse_lazy("domains:overview")
|
||||
|
||||
|
||||
|
@ -117,9 +117,9 @@ class ReverseZoneCreate(LoginRequiredMixin, CreateView):
|
|||
|
||||
class ReverseZoneDetail(LoginRequiredMixin, DetailView):
|
||||
model = ReverseZone
|
||||
slug_field = "name"
|
||||
slug_url_kwarg = "domain"
|
||||
context_object_name = "nameserver"
|
||||
#slug_field = "name"
|
||||
#slug_url_kwarg = "domain"
|
||||
#context_object_name = "nameserver"
|
||||
template_name = "domains/handle_show.html"
|
||||
|
||||
|
||||
|
|
|
@ -19,11 +19,11 @@
|
|||
</tr>
|
||||
{% for nameserver in nameservers %}
|
||||
<tr>
|
||||
<td><a href="{% url "domains:nameserver-show" nameserver.name %}">{{ nameserver.name }}</a></td>
|
||||
<td><a href="{% url "domains:nameserver-show" nameserver.getPK %}">{{ nameserver.name }}</a></td>
|
||||
<td>{{ nameserver.glueIPv4|default:"-" }}</td>
|
||||
<td>{{ nameserver.glueIPv6|default:"-" }}</td>
|
||||
<td>{{ nameserver.mnt_by.all|linkObjects }}</td>
|
||||
<td><a href="{% url "domains:nameserver-edit" nameserver.name %}">Edit</a> <a href="{% url "domains:nameserver-delete" nameserver.name %}">Delete</a></td>
|
||||
<td><a href="{% url "domains:nameserver-edit" nameserver.getPK %}">Edit</a> <a href="{% url "domains:nameserver-delete" nameserver.getPK %}">Delete</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
|
|
@ -67,7 +67,7 @@ class WhoisObject(models.Model):
|
|||
return handle % i
|
||||
|
||||
def getNoDeleteReasons(self):
|
||||
raise NotImplementedError()
|
||||
raise NotImplementedError("Delete reason checking is not implemented for this model")
|
||||
|
||||
def canBeDeleted(self):
|
||||
return not bool(self.getNoDeleteReasons())
|
||||
|
|
Loading…
Reference in New Issue