2018-01-17 00:23:00 +01:00
|
|
|
# This file is part of dnmgmt, a number resource management system
|
|
|
|
# Licensed under GNU General Public License v3 or later
|
|
|
|
# Written by Sebastian Lohff (seba@someserver.de)
|
|
|
|
|
2017-03-14 20:18:57 +01:00
|
|
|
from django.shortcuts import render
|
2017-05-01 06:41:29 +02:00
|
|
|
from django.urls import reverse_lazy, reverse
|
2017-03-14 20:18:57 +01:00
|
|
|
from django.contrib.auth.decorators import login_required
|
|
|
|
from django.views.generic import DetailView, CreateView, UpdateView
|
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
2017-03-21 02:36:07 +01:00
|
|
|
from django.db.models import Q
|
2017-03-14 20:18:57 +01:00
|
|
|
|
2017-03-15 02:22:08 +01:00
|
|
|
from whoisdb.generic import MntGenericMixin, DeleteCheckView
|
2017-03-14 20:18:57 +01:00
|
|
|
|
2017-03-21 02:36:07 +01:00
|
|
|
from .models import Domain, Nameserver, ReverseZone
|
|
|
|
from .forms import DomainForm, NameserverForm, ReverseZoneForm
|
2017-03-14 20:18:57 +01:00
|
|
|
|
2017-03-15 02:22:08 +01:00
|
|
|
|
2017-03-14 20:18:57 +01:00
|
|
|
@login_required
|
|
|
|
def overview(request):
|
2019-05-30 22:10:55 +02:00
|
|
|
mnts = request.user.maintainer_set.all()
|
2017-03-14 20:18:57 +01:00
|
|
|
|
2019-05-30 22:10:55 +02:00
|
|
|
# get all domains and nameservers
|
|
|
|
domains = Domain.objects.filter(mnt_by__in=mnts).distinct()
|
|
|
|
nameservers = Nameserver.objects.filter(mnt_by__in=mnts).distinct()
|
|
|
|
reversezones = ReverseZone.objects.filter(Q(parentNet__mnt_by__in=mnts) | Q(parentNet__mnt_lower__in=mnts)).distinct()
|
2017-03-14 20:18:57 +01:00
|
|
|
|
2019-05-30 22:10:55 +02:00
|
|
|
return render(request, "domains/overview.html", {"mnts": mnts, "domains": domains, "nameservers": nameservers, 'reversezones': reversezones})
|
2017-03-14 20:18:57 +01:00
|
|
|
|
2017-03-15 02:22:08 +01:00
|
|
|
|
2017-03-14 20:18:57 +01:00
|
|
|
class DomainCreate(LoginRequiredMixin, CreateView):
|
2019-05-30 22:10:55 +02:00
|
|
|
template_name = "domains/obj_create.html"
|
|
|
|
form_class = DomainForm
|
2017-03-14 20:18:57 +01:00
|
|
|
|
2019-05-30 22:10:55 +02:00
|
|
|
def get_form_kwargs(self, *args, **kwargs):
|
|
|
|
kwargs = super(DomainCreate, self).get_form_kwargs(*args, **kwargs)
|
|
|
|
kwargs["user"] = self.request.user
|
2017-03-14 20:18:57 +01:00
|
|
|
|
2019-05-30 22:10:55 +02:00
|
|
|
return kwargs
|
2017-03-14 20:18:57 +01:00
|
|
|
|
2017-03-15 02:22:08 +01:00
|
|
|
|
2017-05-01 06:11:54 +02:00
|
|
|
class DomainCheck(LoginRequiredMixin, DetailView):
|
2019-05-30 22:10:55 +02:00
|
|
|
model = Domain
|
|
|
|
slug_field = "name"
|
|
|
|
slug_url_kwarg = "domain"
|
|
|
|
context_object_name = "domain"
|
|
|
|
template_name = "domains/dns_check.html"
|
2017-05-01 06:41:29 +02:00
|
|
|
|
2019-05-30 22:10:55 +02:00
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
ctx = super(DomainCheck, self).get_context_data(**kwargs)
|
|
|
|
ctx["key"] = self.object.name
|
|
|
|
ctx["apiUrl"] = reverse("api:domain-check")
|
2017-05-01 06:41:29 +02:00
|
|
|
|
2019-05-30 22:10:55 +02:00
|
|
|
return ctx
|
2017-05-01 06:11:54 +02:00
|
|
|
|
|
|
|
|
2017-03-14 20:18:57 +01:00
|
|
|
class DomainDetail(LoginRequiredMixin, DetailView):
|
2019-05-30 22:10:55 +02:00
|
|
|
model = Domain
|
|
|
|
slug_field = "name"
|
|
|
|
slug_url_kwarg = "domain"
|
|
|
|
context_object_name = "domain"
|
2017-03-15 02:22:08 +01:00
|
|
|
|
2019-05-30 22:10:55 +02:00
|
|
|
template_name = "whoisdb/handle_show.html"
|
2017-03-21 02:36:07 +01:00
|
|
|
|
2017-03-14 20:18:57 +01:00
|
|
|
|
|
|
|
class DomainEdit(MntGenericMixin, LoginRequiredMixin, UpdateView):
|
2019-05-30 22:10:55 +02:00
|
|
|
model = Domain
|
|
|
|
form_class = DomainForm
|
|
|
|
slug_field = "name"
|
|
|
|
slug_url_kwarg = "domain"
|
|
|
|
template_name = "domains/obj_edit.html"
|
2017-03-15 02:22:08 +01:00
|
|
|
|
2019-05-30 22:10:55 +02:00
|
|
|
def get_form_kwargs(self, *args, **kwargs):
|
|
|
|
kwargs = super(DomainEdit, self).get_form_kwargs(*args, **kwargs)
|
|
|
|
kwargs["user"] = self.request.user
|
|
|
|
return kwargs
|
2017-03-15 02:22:08 +01:00
|
|
|
|
|
|
|
|
|
|
|
class DomainDelete(MntGenericMixin, LoginRequiredMixin, DeleteCheckView):
|
2019-05-30 22:10:55 +02:00
|
|
|
template_name = "domains/obj_delete.html"
|
|
|
|
model = Domain
|
|
|
|
slug_field = "name"
|
|
|
|
slug_url_kwarg = "domain"
|
|
|
|
success_url = reverse_lazy("domains:overview")
|
2017-03-14 20:18:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
class NameserverCreate(LoginRequiredMixin, CreateView):
|
2019-05-30 22:10:55 +02:00
|
|
|
template_name = "domains/obj_create.html"
|
|
|
|
form_class = NameserverForm
|
2017-03-14 20:18:57 +01:00
|
|
|
|
2019-05-30 22:10:55 +02:00
|
|
|
def get_form_kwargs(self, *args, **kwargs):
|
|
|
|
kwargs = super(NameserverCreate, self).get_form_kwargs(*args, **kwargs)
|
|
|
|
kwargs["user"] = self.request.user
|
2017-03-14 20:18:57 +01:00
|
|
|
|
2019-05-30 22:10:55 +02:00
|
|
|
return kwargs
|
2017-03-14 20:18:57 +01:00
|
|
|
|
2017-03-15 02:22:08 +01:00
|
|
|
|
2017-03-14 20:18:57 +01:00
|
|
|
class NameserverDetail(LoginRequiredMixin, DetailView):
|
2019-05-30 22:10:55 +02:00
|
|
|
model = Nameserver
|
|
|
|
template_name = "whoisdb/handle_show.html"
|
2017-03-15 02:22:08 +01:00
|
|
|
|
|
|
|
|
|
|
|
class NameserverEdit(MntGenericMixin, LoginRequiredMixin, UpdateView):
|
2019-05-30 22:10:55 +02:00
|
|
|
model = Nameserver
|
|
|
|
form_class = NameserverForm
|
|
|
|
template_name = "domains/obj_edit.html"
|
2017-03-14 20:18:57 +01:00
|
|
|
|
2019-05-30 22:10:55 +02:00
|
|
|
def get_form_kwargs(self, *args, **kwargs):
|
|
|
|
kwargs = super(NameserverEdit, self).get_form_kwargs(*args, **kwargs)
|
|
|
|
kwargs["user"] = self.request.user
|
|
|
|
return kwargs
|
2017-03-15 02:22:08 +01:00
|
|
|
|
|
|
|
|
|
|
|
class NameserverDelete(MntGenericMixin, LoginRequiredMixin, DeleteCheckView):
|
2019-05-30 22:10:55 +02:00
|
|
|
template_name = "domains/obj_delete.html"
|
|
|
|
model = Nameserver
|
|
|
|
success_url = reverse_lazy("domains:overview")
|
2017-03-21 02:36:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ReverseZoneCreate(LoginRequiredMixin, CreateView):
|
2019-05-30 22:10:55 +02:00
|
|
|
template_name = "domains/obj_create.html"
|
|
|
|
form_class = ReverseZoneForm
|
2017-03-21 02:36:07 +01:00
|
|
|
|
2019-05-30 22:10:55 +02:00
|
|
|
def get_form_kwargs(self, *args, **kwargs):
|
|
|
|
kwargs = super(ReverseZoneCreate, self).get_form_kwargs(*args, **kwargs)
|
|
|
|
kwargs["user"] = self.request.user
|
2017-03-21 02:36:07 +01:00
|
|
|
|
2019-05-30 22:10:55 +02:00
|
|
|
return kwargs
|
2017-03-21 02:36:07 +01:00
|
|
|
|
|
|
|
|
2017-05-01 06:41:29 +02:00
|
|
|
class ReverseZoneCheck(LoginRequiredMixin, DetailView):
|
2019-05-30 22:10:55 +02:00
|
|
|
model = ReverseZone
|
|
|
|
template_name = "domains/dns_check.html"
|
2017-05-01 06:41:29 +02:00
|
|
|
|
2019-05-30 22:10:55 +02:00
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
ctx = super(ReverseZoneCheck, self).get_context_data(**kwargs)
|
|
|
|
ctx["key"] = self.object.id
|
|
|
|
ctx["apiUrl"] = reverse("api:reversezone-check")
|
2017-05-01 06:41:29 +02:00
|
|
|
|
2019-05-30 22:10:55 +02:00
|
|
|
return ctx
|
2017-05-01 06:41:29 +02:00
|
|
|
|
2017-03-21 02:36:07 +01:00
|
|
|
class ReverseZoneDetail(LoginRequiredMixin, DetailView):
|
2019-05-30 22:10:55 +02:00
|
|
|
model = ReverseZone
|
|
|
|
template_name = "whoisdb/handle_show.html"
|
2017-03-21 02:36:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ReverseZoneEdit(MntGenericMixin, LoginRequiredMixin, UpdateView):
|
2019-05-30 22:10:55 +02:00
|
|
|
model = ReverseZone
|
|
|
|
form_class = ReverseZoneForm
|
|
|
|
template_name = "domains/obj_edit.html"
|
2017-03-21 02:36:07 +01:00
|
|
|
|
2019-05-30 22:10:55 +02:00
|
|
|
def get_form_kwargs(self, *args, **kwargs):
|
|
|
|
kwargs = super(ReverseZoneEdit, self).get_form_kwargs(*args, **kwargs)
|
|
|
|
kwargs["user"] = self.request.user
|
2017-03-21 02:36:07 +01:00
|
|
|
|
2019-05-30 22:10:55 +02:00
|
|
|
if "initial" not in kwargs:
|
|
|
|
kwargs["initial"] = {}
|
2017-03-21 02:36:07 +01:00
|
|
|
|
2019-05-30 22:10:55 +02:00
|
|
|
kwargs["initial"]["prefix"] = self.object.prefix()
|
|
|
|
return kwargs
|
2017-03-21 02:36:07 +01:00
|
|
|
|
2019-05-30 22:10:55 +02:00
|
|
|
def get_queryset(self):
|
|
|
|
mnts = self.request.user.maintainer_set.all()
|
|
|
|
return ReverseZone.objects.filter(Q(parentNet__mnt_by__in=mnts) | Q(parentNet__mnt_lower__in=mnts)).distinct()
|
2017-03-21 02:36:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ReverseZoneDelete(LoginRequiredMixin, DeleteCheckView):
|
2019-05-30 22:10:55 +02:00
|
|
|
template_name = "domains/obj_delete.html"
|
|
|
|
model = ReverseZone
|
|
|
|
success_url = reverse_lazy("domains:overview")
|
2017-03-21 02:36:07 +01:00
|
|
|
|
2019-05-30 22:10:55 +02:00
|
|
|
def get_queryset(self):
|
|
|
|
mnts = self.request.user.maintainer_set.all()
|
|
|
|
return ReverseZone.objects.filter(Q(parentNet__mnt_by__in=mnts) | Q(parentNet__mnt_lower__in=mnts)).distinct()
|