No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

views.py 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. # This file is part of dnmgmt, a number resource management system
  2. # Licensed under GNU General Public License v3 or later
  3. # Written by Sebastian Lohff (seba@someserver.de)
  4. from django.shortcuts import render
  5. from django.urls import reverse_lazy, reverse
  6. from django.contrib.auth.decorators import login_required
  7. from django.views.generic import DetailView, CreateView, UpdateView
  8. from django.contrib.auth.mixins import LoginRequiredMixin
  9. from django.db.models import Q
  10. from whoisdb.generic import MntGenericMixin, DeleteCheckView
  11. from .models import Domain, Nameserver, ReverseZone
  12. from .forms import DomainForm, NameserverForm, ReverseZoneForm
  13. @login_required
  14. def overview(request):
  15. mnts = request.user.maintainer_set.all()
  16. # get all domains and nameservers
  17. domains = Domain.objects.filter(mnt_by__in=mnts).distinct()
  18. nameservers = Nameserver.objects.filter(mnt_by__in=mnts).distinct()
  19. reversezones = ReverseZone.objects.filter(Q(parentNet__mnt_by__in=mnts) | Q(parentNet__mnt_lower__in=mnts)).distinct()
  20. return render(request, "domains/overview.html", {"mnts": mnts, "domains": domains, "nameservers": nameservers, 'reversezones': reversezones})
  21. class DomainCreate(LoginRequiredMixin, CreateView):
  22. template_name = "domains/obj_create.html"
  23. form_class = DomainForm
  24. def get_form_kwargs(self, *args, **kwargs):
  25. kwargs = super(DomainCreate, self).get_form_kwargs(*args, **kwargs)
  26. kwargs["user"] = self.request.user
  27. return kwargs
  28. class DomainCheck(LoginRequiredMixin, DetailView):
  29. model = Domain
  30. slug_field = "name"
  31. slug_url_kwarg = "domain"
  32. context_object_name = "domain"
  33. template_name = "domains/dns_check.html"
  34. def get_context_data(self, **kwargs):
  35. ctx = super(DomainCheck, self).get_context_data(**kwargs)
  36. ctx["key"] = self.object.name
  37. ctx["apiUrl"] = reverse("api:domain-check")
  38. return ctx
  39. class DomainDetail(LoginRequiredMixin, DetailView):
  40. model = Domain
  41. slug_field = "name"
  42. slug_url_kwarg = "domain"
  43. context_object_name = "domain"
  44. template_name = "whoisdb/handle_show.html"
  45. class DomainEdit(MntGenericMixin, LoginRequiredMixin, UpdateView):
  46. model = Domain
  47. form_class = DomainForm
  48. slug_field = "name"
  49. slug_url_kwarg = "domain"
  50. template_name = "domains/obj_edit.html"
  51. def get_form_kwargs(self, *args, **kwargs):
  52. kwargs = super(DomainEdit, self).get_form_kwargs(*args, **kwargs)
  53. kwargs["user"] = self.request.user
  54. return kwargs
  55. class DomainDelete(MntGenericMixin, LoginRequiredMixin, DeleteCheckView):
  56. template_name = "domains/obj_delete.html"
  57. model = Domain
  58. slug_field = "name"
  59. slug_url_kwarg = "domain"
  60. success_url = reverse_lazy("domains:overview")
  61. class NameserverCreate(LoginRequiredMixin, CreateView):
  62. template_name = "domains/obj_create.html"
  63. form_class = NameserverForm
  64. def get_form_kwargs(self, *args, **kwargs):
  65. kwargs = super(NameserverCreate, self).get_form_kwargs(*args, **kwargs)
  66. kwargs["user"] = self.request.user
  67. return kwargs
  68. class NameserverDetail(LoginRequiredMixin, DetailView):
  69. model = Nameserver
  70. template_name = "whoisdb/handle_show.html"
  71. class NameserverEdit(MntGenericMixin, LoginRequiredMixin, UpdateView):
  72. model = Nameserver
  73. form_class = NameserverForm
  74. template_name = "domains/obj_edit.html"
  75. def get_form_kwargs(self, *args, **kwargs):
  76. kwargs = super(NameserverEdit, self).get_form_kwargs(*args, **kwargs)
  77. kwargs["user"] = self.request.user
  78. return kwargs
  79. class NameserverDelete(MntGenericMixin, LoginRequiredMixin, DeleteCheckView):
  80. template_name = "domains/obj_delete.html"
  81. model = Nameserver
  82. success_url = reverse_lazy("domains:overview")
  83. class ReverseZoneCreate(LoginRequiredMixin, CreateView):
  84. template_name = "domains/obj_create.html"
  85. form_class = ReverseZoneForm
  86. def get_form_kwargs(self, *args, **kwargs):
  87. kwargs = super(ReverseZoneCreate, self).get_form_kwargs(*args, **kwargs)
  88. kwargs["user"] = self.request.user
  89. return kwargs
  90. class ReverseZoneCheck(LoginRequiredMixin, DetailView):
  91. model = ReverseZone
  92. template_name = "domains/dns_check.html"
  93. def get_context_data(self, **kwargs):
  94. ctx = super(ReverseZoneCheck, self).get_context_data(**kwargs)
  95. ctx["key"] = self.object.id
  96. ctx["apiUrl"] = reverse("api:reversezone-check")
  97. return ctx
  98. class ReverseZoneDetail(LoginRequiredMixin, DetailView):
  99. model = ReverseZone
  100. template_name = "whoisdb/handle_show.html"
  101. class ReverseZoneEdit(MntGenericMixin, LoginRequiredMixin, UpdateView):
  102. model = ReverseZone
  103. form_class = ReverseZoneForm
  104. template_name = "domains/obj_edit.html"
  105. def get_form_kwargs(self, *args, **kwargs):
  106. kwargs = super(ReverseZoneEdit, self).get_form_kwargs(*args, **kwargs)
  107. kwargs["user"] = self.request.user
  108. if "initial" not in kwargs:
  109. kwargs["initial"] = {}
  110. kwargs["initial"]["prefix"] = self.object.prefix()
  111. return kwargs
  112. def get_queryset(self):
  113. mnts = self.request.user.maintainer_set.all()
  114. return ReverseZone.objects.filter(Q(parentNet__mnt_by__in=mnts) | Q(parentNet__mnt_lower__in=mnts)).distinct()
  115. class ReverseZoneDelete(LoginRequiredMixin, DeleteCheckView):
  116. template_name = "domains/obj_delete.html"
  117. model = ReverseZone
  118. success_url = reverse_lazy("domains:overview")
  119. def get_queryset(self):
  120. mnts = self.request.user.maintainer_set.all()
  121. return ReverseZone.objects.filter(Q(parentNet__mnt_by__in=mnts) | Q(parentNet__mnt_lower__in=mnts)).distinct()