Commit 12b6f74a authored by chirac's avatar chirac

Merge branch 'Dname' into 'master'

Dname

See merge request federez/re2o!192
parents 9be8ca1c 4e9b0586
...@@ -191,6 +191,13 @@ class MxSerializer(NamespacedHMSerializer): ...@@ -191,6 +191,13 @@ class MxSerializer(NamespacedHMSerializer):
fields = ('zone', 'priority', 'name', 'api_url') fields = ('zone', 'priority', 'name', 'api_url')
class DNameSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.DName` objects.
"""
class Meta:
model = machines.DName
fields = ('zone', 'alias', 'api_url')
class NsSerializer(NamespacedHMSerializer): class NsSerializer(NamespacedHMSerializer):
"""Serialize `machines.models.Ns` objects. """Serialize `machines.models.Ns` objects.
""" """
......
...@@ -52,6 +52,7 @@ router.register_viewset(r'machines/extension', views.ExtensionViewSet) ...@@ -52,6 +52,7 @@ router.register_viewset(r'machines/extension', views.ExtensionViewSet)
router.register_viewset(r'machines/mx', views.MxViewSet) router.register_viewset(r'machines/mx', views.MxViewSet)
router.register_viewset(r'machines/ns', views.NsViewSet) router.register_viewset(r'machines/ns', views.NsViewSet)
router.register_viewset(r'machines/txt', views.TxtViewSet) router.register_viewset(r'machines/txt', views.TxtViewSet)
router.register_viewset(r'machines/dname', views.DNameViewSet)
router.register_viewset(r'machines/srv', views.SrvViewSet) router.register_viewset(r'machines/srv', views.SrvViewSet)
router.register_viewset(r'machines/interface', views.InterfaceViewSet) router.register_viewset(r'machines/interface', views.InterfaceViewSet)
router.register_viewset(r'machines/ipv6list', views.Ipv6ListViewSet) router.register_viewset(r'machines/ipv6list', views.Ipv6ListViewSet)
......
...@@ -163,6 +163,12 @@ class TxtViewSet(viewsets.ReadOnlyModelViewSet): ...@@ -163,6 +163,12 @@ class TxtViewSet(viewsets.ReadOnlyModelViewSet):
queryset = machines.Txt.objects.all() queryset = machines.Txt.objects.all()
serializer_class = serializers.TxtSerializer serializer_class = serializers.TxtSerializer
class DNameViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.DName` objects.
"""
queryset = machines.DName.objects.all()
serializer_class = serializers.DNameSerializer
class SrvViewSet(viewsets.ReadOnlyModelViewSet): class SrvViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes list and details of `machines.models.Srv` objects. """Exposes list and details of `machines.models.Srv` objects.
......
...@@ -37,6 +37,7 @@ from .models import ( ...@@ -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): ...@@ -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) ...@@ -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 ( ...@@ -51,6 +51,7 @@ from .models import (
SOA, SOA,
Mx, Mx,
Txt, Txt,
DName,
Ns, Ns,
Service, Service,
Vlan, Vlan,
...@@ -410,6 +411,34 @@ class DelTxtForm(FormRevMixin, Form): ...@@ -410,6 +411,34 @@ class DelTxtForm(FormRevMixin, Form):
self.fields['txt'].queryset = Txt.objects.all() self.fields['txt'].queryset = Txt.objects.all()
class DNameForm(FormRevMixin, ModelForm):
"""Add a DNAME entry for a 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):
"""Delete a set of DNAME entries"""
dnames = forms.ModelMultipleChoiceField(
queryset=Txt.objects.none(),
label="Existing DNAME entries",
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"""
class Meta: class Meta:
......
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-06-25 14:33
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
import re2o.mixins
class Migration(migrations.Migration):
dependencies = [
('machines', '0083_remove_duplicate_rights'),
]
operations = [
migrations.CreateModel(
name='DName',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('alias', models.CharField(max_length=255)),
('zone', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='machines.Extension')),
],
options={
'permissions': (('view_dname', 'Can see a dname object'),),
'verbose_name': 'DNAME entry',
'verbose_name_plural': 'DNAME entries'
},
bases=(re2o.mixins.RevMixin, re2o.mixins.AclMixin, models.Model),
),
]
...@@ -3,9 +3,10 @@ ...@@ -3,9 +3,10 @@
# se veut agnostique au réseau considéré, de manière à être installable en # se veut agnostique au réseau considéré, de manière à être installable en
# quelques clics. # quelques clics.
# #
# Copyright © 2017 Gabriel Détraz # Copyright © 2016-2018 Gabriel Détraz
# Copyright © 2017 Goulven Kermarec # Copyright © 2017 Goulven Kermarec
# Copyright © 2017 Augustin Lemesle # Copyright © 2017 Augustin Lemesle
# Copyright © 2018 Charlie Jacomme
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
...@@ -670,6 +671,27 @@ class Txt(RevMixin, AclMixin, models.Model): ...@@ -670,6 +671,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):
"""A DNAME entry for the DNS."""
zone = models.ForeignKey('Extension', on_delete=models.PROTECT)
alias = models.CharField(max_length=255)
class Meta:
permissions = (
("view_dname", "Can see a dname object"),
)
verbose_name = "DNAME entry"
verbose_name_plural = "DNAME entries"
def __str__(self):
return str(self.zone) + " : " + str(self.alias)
@cached_property
def dns_entry(self):
"""Returns the DNAME record for the DNS zone file."""
return str(self.alias).ljust(15) + " 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"
...@@ -1687,6 +1709,18 @@ def text_post_delete(**_kwargs): ...@@ -1687,6 +1709,18 @@ def text_post_delete(**_kwargs):
regen('dns') regen('dns')
@receiver(post_save, sender=DName)
def dname_post_save(**_kwargs):
"""Updates the DNS regen after modification of a DName object."""
regen('dns')
@receiver(post_delete, sender=DName)
def dname_post_delete(**_kwargs):
"""Updates the DNS regen after deletion of a DName object."""
regen('dns')
@receiver(post_save, sender=Srv) @receiver(post_save, sender=Srv)
def srv_post_save(**_kwargs): def srv_post_save(**_kwargs):
"""Regeneration dns après modification d'un SRV""" """Regeneration dns après modification d'un SRV"""
......
{% 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 © 2018 Charlie Jacomme
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>Target zone</th>
<th>Record</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,18 @@ with this program; if not, write to the Free Software Foundation, Inc., ...@@ -61,6 +61,18 @@ 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>DNAME records</h2>
{% can_create DName %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:add-dname' %}">
<i class="fa fa-plus"></i> {% trans "Add a DNAME record" %}
</a>
{% acl_end %}
<a class="btn btn-danger btn-sm" role="button" href="{% url 'machines:del-dname' %}">
<i class="fa fa-trash"></i> {% trans "Delete DNAME records" %}
</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>
......
...@@ -57,6 +57,9 @@ with this program; if not, write to the Free Software Foundation, Inc., ...@@ -57,6 +57,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% if txtform %} {% if txtform %}
{% bootstrap_form_errors txtform %} {% bootstrap_form_errors txtform %}
{% endif %} {% endif %}
{% if dnameform %}
{% bootstrap_form_errors dnameform %}
{% endif %}
{% if srvform %} {% if srvform %}
{% bootstrap_form_errors srvform %} {% bootstrap_form_errors srvform %}
{% endif %} {% endif %}
...@@ -122,6 +125,10 @@ with this program; if not, write to the Free Software Foundation, Inc., ...@@ -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>DNAME record</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 = [ ...@@ -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'),
......
...@@ -3,10 +3,11 @@ ...@@ -3,10 +3,11 @@
# se veut agnostique au réseau considéré, de manière à être installable en # se veut agnostique au réseau considéré, de manière à être installable en
# quelques clics. # quelques clics.
# #
# Copyright © 2017 Gabriel Détraz # Copyright © 2016-2018 Gabriel Détraz
# Copyright © 2017 Goulven Kermarec # Copyright © 2017 Goulven Kermarec
# Copyright © 2017 Augustin Lemesle # Copyright © 2017 Augustin Lemesle
# Copyright © 2017 Maël Kervella # Copyright © 2017-2018 Maël Kervella
# Copyright © 2018 Charlie Jacomme
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
...@@ -93,6 +94,8 @@ from .forms import ( ...@@ -93,6 +94,8 @@ from .forms import (
DelNsForm, DelNsForm,
TxtForm, TxtForm,
DelTxtForm, DelTxtForm,
DNameForm,
DelDNameForm,
MxForm, MxForm,
DelMxForm, DelMxForm,
VlanForm, VlanForm,
...@@ -122,6 +125,7 @@ from .models import ( ...@@ -122,6 +125,7 @@ from .models import (
Vlan, Vlan,
Nas, Nas,
Txt, Txt,
DName,
Srv, Srv,
OuverturePortList, OuverturePortList,
OuverturePort, OuverturePort,
...@@ -815,6 +819,63 @@ def del_ns(request, instances): ...@@ -815,6 +819,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, "This DNAME record has been added")
return redirect(reverse('machines:index-extension'))
return form(
{'dnameform': dname, 'action_name': "Create"},
'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 successfully edited")
return redirect(reverse('machines:index-extension'))
return form(
{'dnameform': dname, 'action_name': "Edit"},
'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,
"The DNAME %s has been deleted" % dname_del)
except ProtectedError:
messages.error(
request,
"The DNAME %s can not be deleted" % dname_del
)
return redirect(reverse('machines:index-extension'))
return form(
{'dnameform': dname, 'action_name': 'Delete'},
'machines/machine.html',
request
)
@login_required @login_required
@can_create(Txt) @can_create(Txt)
...@@ -1272,7 +1333,7 @@ def index_nas(request): ...@@ -1272,7 +1333,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 +1353,7 @@ def index_extension(request): ...@@ -1292,6 +1353,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 +1367,7 @@ def index_extension(request): ...@@ -1305,6 +1367,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
} }
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment