mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-05 01:16:27 +00:00
New DNAME model
This commit is contained in:
parent
41cd115f51
commit
fc176a60c1
9 changed files with 196 additions and 2 deletions
|
@ -37,6 +37,7 @@ from .models import (
|
||||||
Ns,
|
Ns,
|
||||||
Vlan,
|
Vlan,
|
||||||
Txt,
|
Txt,
|
||||||
|
DName,
|
||||||
Srv,
|
Srv,
|
||||||
Nas,
|
Nas,
|
||||||
Service,
|
Service,
|
||||||
|
@ -95,6 +96,10 @@ class TxtAdmin(VersionAdmin):
|
||||||
""" Admin view of a TXT object """
|
""" Admin view of a TXT object """
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class DNameAdmin(VersionAdmin):
|
||||||
|
""" Admin view of a DName object """
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class SrvAdmin(VersionAdmin):
|
class SrvAdmin(VersionAdmin):
|
||||||
""" Admin view of a SRV object """
|
""" Admin view of a SRV object """
|
||||||
|
@ -144,6 +149,7 @@ admin.site.register(SOA, SOAAdmin)
|
||||||
admin.site.register(Mx, MxAdmin)
|
admin.site.register(Mx, MxAdmin)
|
||||||
admin.site.register(Ns, NsAdmin)
|
admin.site.register(Ns, NsAdmin)
|
||||||
admin.site.register(Txt, TxtAdmin)
|
admin.site.register(Txt, TxtAdmin)
|
||||||
|
admin.site.register(DName, DNameAdmin)
|
||||||
admin.site.register(Srv, SrvAdmin)
|
admin.site.register(Srv, SrvAdmin)
|
||||||
admin.site.register(IpList, IpListAdmin)
|
admin.site.register(IpList, IpListAdmin)
|
||||||
admin.site.register(Interface, InterfaceAdmin)
|
admin.site.register(Interface, InterfaceAdmin)
|
||||||
|
|
|
@ -51,6 +51,7 @@ from .models import (
|
||||||
SOA,
|
SOA,
|
||||||
Mx,
|
Mx,
|
||||||
Txt,
|
Txt,
|
||||||
|
DName,
|
||||||
Ns,
|
Ns,
|
||||||
Service,
|
Service,
|
||||||
Vlan,
|
Vlan,
|
||||||
|
@ -409,6 +410,34 @@ class DelTxtForm(FormRevMixin, Form):
|
||||||
else:
|
else:
|
||||||
self.fields['txt'].queryset = Txt.objects.all()
|
self.fields['txt'].queryset = Txt.objects.all()
|
||||||
|
|
||||||
|
class DNameForm(FormRevMixin, ModelForm):
|
||||||
|
"""Ajout d'un DName pour une zone"""
|
||||||
|
class Meta:
|
||||||
|
model = DName
|
||||||
|
fields = '__all__'
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
||||||
|
super(DNameForm, self).__init__(*args, prefix=prefix, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class DelDNameForm(FormRevMixin, Form):
|
||||||
|
"""Suppression d'un ou plusieurs DName"""
|
||||||
|
dnames = forms.ModelMultipleChoiceField(
|
||||||
|
queryset=Txt.objects.none(),
|
||||||
|
label="Enregistrements DName actuels",
|
||||||
|
widget=forms.CheckboxSelectMultiple
|
||||||
|
)
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
instances = kwargs.pop('instances', None)
|
||||||
|
super(DelDNameForm, self).__init__(*args, **kwargs)
|
||||||
|
if instances:
|
||||||
|
self.fields['dnames'].queryset = instances
|
||||||
|
else:
|
||||||
|
self.fields['dnames'].queryset = DName.objects.all()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SrvForm(FormRevMixin, ModelForm):
|
class SrvForm(FormRevMixin, ModelForm):
|
||||||
"""Ajout d'un srv pour une zone"""
|
"""Ajout d'un srv pour une zone"""
|
||||||
|
|
|
@ -670,6 +670,27 @@ class Txt(RevMixin, AclMixin, models.Model):
|
||||||
return str(self.field1).ljust(15) + " IN TXT " + str(self.field2)
|
return str(self.field1).ljust(15) + " IN TXT " + str(self.field2)
|
||||||
|
|
||||||
|
|
||||||
|
class DName(RevMixin, AclMixin, models.Model):
|
||||||
|
""" Un enregistrement DName, qui crée un alias depuis la zone spécifié vers l'extension"""
|
||||||
|
PRETTY_NAME = "Enregistrement DName"
|
||||||
|
|
||||||
|
zone = models.ForeignKey('Extension', on_delete=models.PROTECT)
|
||||||
|
alias = models.CharField(max_length=255)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
permissions = (
|
||||||
|
("view_dname", "Peut voir un objet dname"),
|
||||||
|
)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return str(self.zone) + " : " + str(self.alias)
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def dns_entry(self):
|
||||||
|
"""Renvoie l'enregisterment DNAME complet pour le fichier de zone"""
|
||||||
|
return str(self.alias) + " IN DNAME " + str(self.zone)
|
||||||
|
|
||||||
|
|
||||||
class Srv(RevMixin, AclMixin, models.Model):
|
class Srv(RevMixin, AclMixin, models.Model):
|
||||||
""" A SRV record """
|
""" A SRV record """
|
||||||
PRETTY_NAME = "Enregistrement Srv"
|
PRETTY_NAME = "Enregistrement Srv"
|
||||||
|
@ -1680,12 +1701,21 @@ def text_post_save(**_kwargs):
|
||||||
"""Regeneration dns après modification d'un TXT"""
|
"""Regeneration dns après modification d'un TXT"""
|
||||||
regen('dns')
|
regen('dns')
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_delete, sender=Txt)
|
@receiver(post_delete, sender=Txt)
|
||||||
def text_post_delete(**_kwargs):
|
def text_post_delete(**_kwargs):
|
||||||
"""Regeneration dns après modification d'un TX"""
|
"""Regeneration dns après modification d'un TX"""
|
||||||
regen('dns')
|
regen('dns')
|
||||||
|
|
||||||
|
@receiver(post_save, sender=DName)
|
||||||
|
def dname_post_save(**_kwargs):
|
||||||
|
"""Regeneration dns après modification d'un DName"""
|
||||||
|
regen('dns')
|
||||||
|
|
||||||
|
@receiver(post_delete, sender=DName)
|
||||||
|
def DName_post_delete(**_kwargs):
|
||||||
|
"""Regeneration dns après modification d'un DName"""
|
||||||
|
regen('dns')
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=Srv)
|
@receiver(post_save, sender=Srv)
|
||||||
def srv_post_save(**_kwargs):
|
def srv_post_save(**_kwargs):
|
||||||
|
|
50
machines/templates/machines/aff_dname.html
Normal file
50
machines/templates/machines/aff_dname.html
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
{% comment %}
|
||||||
|
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
|
||||||
|
se veut agnostique au réseau considéré, de manière à être installable en
|
||||||
|
quelques clics.
|
||||||
|
|
||||||
|
Copyright © 2017 Gabriel Détraz
|
||||||
|
Copyright © 2017 Goulven Kermarec
|
||||||
|
Copyright © 2017 Augustin Lemesle
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
{% endcomment %}
|
||||||
|
|
||||||
|
{% load acl %}
|
||||||
|
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Zone concernée</th>
|
||||||
|
<th>Enregistrement</th>
|
||||||
|
<th></th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
{% for dname in dname_list %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ dname.zone }}</td>
|
||||||
|
<td>{{ dname.dns_entry }}</td>
|
||||||
|
<td class="text-right">
|
||||||
|
{% can_edit dname %}
|
||||||
|
{% include 'buttons/edit.html' with href='machines:edit-dname' id=dname.id %}
|
||||||
|
{% acl_end %}
|
||||||
|
{% include 'buttons/history.html' with href='machines:history' name='dname' id=dname.id %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
{% acl_end %}
|
{% acl_end %}
|
||||||
<a class="btn btn-danger btn-sm" role="button" href="{% url 'machines:del-txt' %}"><i class="fa fa-trash"></i> Supprimer un enregistrement TXT</a>
|
<a class="btn btn-danger btn-sm" role="button" href="{% url 'machines:del-txt' %}"><i class="fa fa-trash"></i> Supprimer un enregistrement TXT</a>
|
||||||
{% include "machines/aff_txt.html" with txt_list=txt_list %}
|
{% include "machines/aff_txt.html" with txt_list=txt_list %}
|
||||||
|
<h2>Liste des enregistrements DNAME</h2>
|
||||||
|
{% can_create DName %}
|
||||||
|
<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:add-dname' %}"><i class="fa fa-plus"></i> Ajouter un enregistrement DNAME</a>
|
||||||
|
{% acl_end %}
|
||||||
|
<a class="btn btn-danger btn-sm" role="button" href="{% url 'machines:del-dname' %}"><i class="fa fa-trash"></i> Supprimer un enregistrement DNAME</a>
|
||||||
|
{% include "machines/aff_dname.html" with dname_list=dname_list %}
|
||||||
<h2>Liste des enregistrements SRV</h2>
|
<h2>Liste des enregistrements SRV</h2>
|
||||||
{% can_create Srv %}
|
{% can_create Srv %}
|
||||||
<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:add-srv' %}"><i class="fa fa-plus"></i> Ajouter un enregistrement SRV</a>
|
<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:add-srv' %}"><i class="fa fa-plus"></i> Ajouter un enregistrement SRV</a>
|
||||||
|
|
|
@ -54,6 +54,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
{% if nsform %}
|
{% if nsform %}
|
||||||
{% bootstrap_form_errors nsform %}
|
{% bootstrap_form_errors nsform %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if dnameform %}
|
||||||
|
{% bootstrap_form_errors dnameform %}
|
||||||
|
{% endif %}
|
||||||
{% if txtform %}
|
{% if txtform %}
|
||||||
{% bootstrap_form_errors txtform %}
|
{% bootstrap_form_errors txtform %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -122,6 +125,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
<h3>Enregistrement TXT</h3>
|
<h3>Enregistrement TXT</h3>
|
||||||
{% bootstrap_form txtform %}
|
{% bootstrap_form txtform %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if dnameform %}
|
||||||
|
<h3>Enregistrement DName</h3>
|
||||||
|
{% bootstrap_form dnameform %}
|
||||||
|
{% endif %}
|
||||||
{% if srvform %}
|
{% if srvform %}
|
||||||
<h3>Enregistrement SRV</h3>
|
<h3>Enregistrement SRV</h3>
|
||||||
{% massive_bootstrap_form srvform 'target' %}
|
{% massive_bootstrap_form srvform 'target' %}
|
||||||
|
|
|
@ -73,6 +73,9 @@ urlpatterns = [
|
||||||
url(r'^add_txt/$', views.add_txt, name='add-txt'),
|
url(r'^add_txt/$', views.add_txt, name='add-txt'),
|
||||||
url(r'^edit_txt/(?P<txtid>[0-9]+)$', views.edit_txt, name='edit-txt'),
|
url(r'^edit_txt/(?P<txtid>[0-9]+)$', views.edit_txt, name='edit-txt'),
|
||||||
url(r'^del_txt/$', views.del_txt, name='del-txt'),
|
url(r'^del_txt/$', views.del_txt, name='del-txt'),
|
||||||
|
url(r'^add_dname/$', views.add_dname, name='add-dname'),
|
||||||
|
url(r'^edit_dname/(?P<dnameid>[0-9]+)$', views.edit_dname, name='edit-dname'),
|
||||||
|
url(r'^del_dname/$', views.del_dname, name='del-dname'),
|
||||||
url(r'^add_ns/$', views.add_ns, name='add-ns'),
|
url(r'^add_ns/$', views.add_ns, name='add-ns'),
|
||||||
url(r'^edit_ns/(?P<nsid>[0-9]+)$', views.edit_ns, name='edit-ns'),
|
url(r'^edit_ns/(?P<nsid>[0-9]+)$', views.edit_ns, name='edit-ns'),
|
||||||
url(r'^del_ns/$', views.del_ns, name='del-ns'),
|
url(r'^del_ns/$', views.del_ns, name='del-ns'),
|
||||||
|
|
|
@ -93,6 +93,8 @@ from .forms import (
|
||||||
DelNsForm,
|
DelNsForm,
|
||||||
TxtForm,
|
TxtForm,
|
||||||
DelTxtForm,
|
DelTxtForm,
|
||||||
|
DNameForm,
|
||||||
|
DelDNameForm,
|
||||||
MxForm,
|
MxForm,
|
||||||
DelMxForm,
|
DelMxForm,
|
||||||
VlanForm,
|
VlanForm,
|
||||||
|
@ -122,6 +124,7 @@ from .models import (
|
||||||
Vlan,
|
Vlan,
|
||||||
Nas,
|
Nas,
|
||||||
Txt,
|
Txt,
|
||||||
|
DName,
|
||||||
Srv,
|
Srv,
|
||||||
OuverturePortList,
|
OuverturePortList,
|
||||||
OuverturePort,
|
OuverturePort,
|
||||||
|
@ -815,6 +818,63 @@ def del_ns(request, instances):
|
||||||
request
|
request
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@can_create(DName)
|
||||||
|
def add_dname(request):
|
||||||
|
""" View used to add a DName object """
|
||||||
|
dname = DNameForm(request.POST or None)
|
||||||
|
if dname.is_valid():
|
||||||
|
dname.save()
|
||||||
|
messages.success(request, "Cet enregistrement DName a été ajouté")
|
||||||
|
return redirect(reverse('machines:index-extension'))
|
||||||
|
return form(
|
||||||
|
{'dnameform': dname, 'action_name': 'Créer'},
|
||||||
|
'machines/machine.html',
|
||||||
|
request
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@can_edit(DName)
|
||||||
|
def edit_dname(request, dname_instance, **_kwargs):
|
||||||
|
""" View used to edit a DName object """
|
||||||
|
dname = DNameForm(request.POST or None, instance=dname_instance)
|
||||||
|
if dname.is_valid():
|
||||||
|
if dname.changed_data:
|
||||||
|
dname.save()
|
||||||
|
messages.success(request, "DName modifié")
|
||||||
|
return redirect(reverse('machines:index-extension'))
|
||||||
|
return form(
|
||||||
|
{'dnameform': dname, 'action_name': 'Editer'},
|
||||||
|
'machines/machine.html',
|
||||||
|
request
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@can_delete_set(DName)
|
||||||
|
def del_dname(request, instances):
|
||||||
|
""" View used to delete a DName object """
|
||||||
|
dname = DelDNameForm(request.POST or None, instances=instances)
|
||||||
|
if dname.is_valid():
|
||||||
|
dname_dels = dname.cleaned_data['dname']
|
||||||
|
for dname_del in dname_dels:
|
||||||
|
try:
|
||||||
|
dname_del.delete()
|
||||||
|
messages.success(request, "Le dname a été supprimé")
|
||||||
|
except ProtectedError:
|
||||||
|
messages.error(
|
||||||
|
request,
|
||||||
|
("Erreur le dname suivant %s ne peut être supprimé"
|
||||||
|
% dname_del)
|
||||||
|
)
|
||||||
|
return redirect(reverse('machines:index-extension'))
|
||||||
|
return form(
|
||||||
|
{'dnameform': dname, 'action_name': 'Supprimer'},
|
||||||
|
'machines/machine.html',
|
||||||
|
request
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@can_create(Txt)
|
@can_create(Txt)
|
||||||
|
@ -1272,7 +1332,7 @@ def index_nas(request):
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@can_view_all(SOA, Mx, Ns, Txt, Srv, Extension)
|
@can_view_all(SOA, Mx, Ns, Txt, DName, Srv, Extension)
|
||||||
def index_extension(request):
|
def index_extension(request):
|
||||||
""" View displaying the list of existing extensions, the list of
|
""" View displaying the list of existing extensions, the list of
|
||||||
existing SOA records, the list of existing MX records , the list of
|
existing SOA records, the list of existing MX records , the list of
|
||||||
|
@ -1292,6 +1352,7 @@ def index_extension(request):
|
||||||
.select_related('zone')
|
.select_related('zone')
|
||||||
.select_related('ns__extension'))
|
.select_related('ns__extension'))
|
||||||
txt_list = Txt.objects.all().select_related('zone')
|
txt_list = Txt.objects.all().select_related('zone')
|
||||||
|
dname_list = DName.objects.all().select_related('zone')
|
||||||
srv_list = (Srv.objects
|
srv_list = (Srv.objects
|
||||||
.all()
|
.all()
|
||||||
.select_related('extension')
|
.select_related('extension')
|
||||||
|
@ -1305,6 +1366,7 @@ def index_extension(request):
|
||||||
'mx_list': mx_list,
|
'mx_list': mx_list,
|
||||||
'ns_list': ns_list,
|
'ns_list': ns_list,
|
||||||
'txt_list': txt_list,
|
'txt_list': txt_list,
|
||||||
|
'dname_list': dname_list,
|
||||||
'srv_list': srv_list
|
'srv_list': srv_list
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -102,6 +102,7 @@ MODEL_NAME = {
|
||||||
'Mx': machines.models.Mx,
|
'Mx': machines.models.Mx,
|
||||||
'Ns': machines.models.Ns,
|
'Ns': machines.models.Ns,
|
||||||
'Txt': machines.models.Txt,
|
'Txt': machines.models.Txt,
|
||||||
|
'DName': machines.models.DName,
|
||||||
'Srv': machines.models.Srv,
|
'Srv': machines.models.Srv,
|
||||||
'Interface': machines.models.Interface,
|
'Interface': machines.models.Interface,
|
||||||
'Domain': machines.models.Domain,
|
'Domain': machines.models.Domain,
|
||||||
|
|
Loading…
Reference in a new issue