Verified Commit 8ac9e64a authored by erdnaxe's avatar erdnaxe 🎇

Move VLAN to admin site

parent 6bb2f9a5
Pipeline #1098 passed with stage
in 3 minutes and 3 seconds
......@@ -15,9 +15,10 @@ from __future__ import unicode_literals
from django.contrib import admin
from reversion.admin import VersionAdmin
from .models import MachineType
from .models import (
MachineType,
Nas,
Vlan,
)
......@@ -33,3 +34,10 @@ class NasAdmin(VersionAdmin):
list_display = ('nas_type', 'machine_type', 'port_access_mode',
'autocapture_mac')
list_filter = ('port_access_mode', 'autocapture_mac')
@admin.register(Vlan)
class VlanAdmin(VersionAdmin):
"""Admin view of a VLAN object"""
list_display = ('vlan_id', 'name', 'comment')
list_filter = ('dhcp_snooping', 'dhcpv6_snooping', 'igmp', 'mld')
......@@ -522,22 +522,48 @@ class IpType(RevMixin, AclMixin, models.Model):
class Vlan(RevMixin, AclMixin, models.Model):
""" Un vlan : vlan_id et nom
On limite le vlan id entre 0 et 4096, comme défini par la norme"""
vlan_id = models.PositiveIntegerField(validators=[MaxValueValidator(4095)])
name = models.CharField(max_length=256)
comment = models.CharField(max_length=256, blank=True)
#Réglages supplémentaires
arp_protect = models.BooleanField(default=False)
dhcp_snooping = models.BooleanField(default=False)
dhcpv6_snooping = models.BooleanField(default=False)
"""A VLAN
We limit VLAN from 0 to 4096, as the standard defines
"""
vlan_id = models.PositiveIntegerField(
verbose_name=_('identifier'),
validators=[MaxValueValidator(4095)],
)
name = models.CharField(
verbose_name=_('name'),
max_length=256,
)
comment = models.CharField(
verbose_name=_('comment'),
max_length=256,
blank=True,
)
# Réglages supplémentaires
arp_protect = models.BooleanField(
verbose_name=_('ARP protection'),
default=False,
help_text=_('Prevent ARP Poisonning (man in the middle attacks…).'),
)
dhcp_snooping = models.BooleanField(
verbose_name=_('DHCP snooping'),
default=False,
help_text=_('Drop DHCPv4 traffic determined to be unacceptable.'),
)
dhcpv6_snooping = models.BooleanField(
verbose_name=_('DHCPv6 snooping'),
default=False,
help_text=_('Drop DHCPv6 traffic determined to be unacceptable.'),
)
igmp = models.BooleanField(
verbose_name=_('Internet Group Management Protocol (IGMP)'),
default=False,
help_text=_("v4 multicast management")
help_text=_("IPv4 multicast management")
)
mld = models.BooleanField(
verbose_name=_('Multicast Listener Discovery (MLD)'),
default=False,
help_text=_("v6 multicast management")
help_text=_("IPv6 multicast management")
)
class Meta:
......
{% 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 %}
{% load logs_extra %}
{% load i18n %}
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>{% trans "ID" %}</th>
<th>{% trans "Name" %}</th>
<th>{% trans "Comment" %}</th>
<th>{% trans "IP ranges" %}</th>
<th></th>
</tr>
</thead>
{% for vlan in vlan_list %}
<tr>
<td>{{ vlan.vlan_id }}</td>
<td>{{ vlan.name }}</td>
<td>{{ vlan.comment }}</td>
<td>{% for range in vlan.iptype_set.all %}{{ range }}, {% endfor %}</td>
<td class="text-right">
{% can_edit vlan %}
{% include 'buttons/edit.html' with href='machines:edit-vlan' id=vlan.id %}
{% acl_end %}
{% history_button vlan %}
</td>
</tr>
{% endfor %}
</table>
</div>
{% extends 'machines/sidebar.html' %}
{% 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 bootstrap3 %}
{% load acl %}
{% load i18n %}
{% block title %}{% trans "Machines" %}{% endblock %}
{% block content %}
<h2>{% trans "List of VLANs" %}</h2>
{% can_create Vlan %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:add-vlan' %}"><i
class="fa fa-plus"></i>{% trans " Add a VLAN" %}</a>
{% acl_end %}
<a class="btn btn-danger btn-sm" role="button" href="{% url 'machines:del-vlan' %}"><i
class="fa fa-trash"></i>{% trans " Delete one or several VLANs" %}</a>
{% include 'machines/aff_vlan.html' with vlan_list=vlan_list %}
{% endblock %}
......@@ -45,12 +45,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% trans "IP ranges" %}
</a>
{% acl_end %}
{% can_view_all Vlan %}
<a class="list-group-item list-group-item-info" href="{% url 'machines:index-vlan' %}">
<i class="fa fa-list-ul"></i>
{% trans "VLANs" %}
</a>
{% acl_end %}
{% can_view_all machines.Service %}
<a class="list-group-item list-group-item-info" href="{% url 'machines:index-service' %}">
<i class="fa fa-list-ul"></i>
......
......@@ -110,10 +110,6 @@ urlpatterns = [
name='edit-role'),
url(r'^del_role/$', views.del_role, name='del-role'),
url(r'^index_role/$', views.index_role, name='index-role'),
url(r'^add_vlan/$', views.add_vlan, name='add-vlan'),
url(r'^edit_vlan/(?P<vlanid>[0-9]+)$', views.edit_vlan, name='edit-vlan'),
url(r'^del_vlan/$', views.del_vlan, name='del-vlan'),
url(r'^index_vlan/$', views.index_vlan, name='index-vlan'),
url(r'^$', views.index, name='index'),
url(r'^rest/mac-ip/$', views.mac_ip, name='mac-ip'),
url(r'^rest/regen-achieved/$',
......
......@@ -1181,63 +1181,6 @@ def regen_service(request, service, **_kwargs):
return index_service(request)
@login_required
@can_create(Vlan)
def add_vlan(request):
""" View used to add a VLAN object """
vlan = VlanForm(request.POST or None)
if vlan.is_valid():
vlan.save()
messages.success(request, _("The VLAN was created."))
return redirect(reverse('machines:index-vlan'))
return form(
{'vlanform': vlan, 'action_name': _("Create a VLAN")},
'machines/machine.html',
request
)
@login_required
@can_edit(Vlan)
def edit_vlan(request, vlan_instance, **_kwargs):
""" View used to edit a VLAN object """
vlan = VlanForm(request.POST or None, instance=vlan_instance)
if vlan.is_valid():
if vlan.changed_data:
vlan.save()
messages.success(request, _("The VLAN was edited."))
return redirect(reverse('machines:index-vlan'))
return form(
{'vlanform': vlan, 'action_name': _("Edit")},
'machines/machine.html',
request
)
@login_required
@can_delete_set(Vlan)
def del_vlan(request, instances):
""" View used to delete a VLAN object """
vlan = DelVlanForm(request.POST or None, instances=instances)
if vlan.is_valid():
vlan_dels = vlan.cleaned_data['vlan']
for vlan_del in vlan_dels:
try:
vlan_del.delete()
messages.success(request, _("The VLAN was deleted."))
except ProtectedError:
messages.error(
request,
(_("Error: the VLAN %s can't be deleted.") % vlan_del)
)
return redirect(reverse('machines:index-vlan'))
return form(
{'vlanform': vlan, 'action_name': _("Delete")},
'machines/machine.html',
request
)
@login_required
@can_view_all(Machine)
def index(request):
......@@ -1287,18 +1230,6 @@ def index_iptype(request):
)
@login_required
@can_view_all(Vlan)
def index_vlan(request):
""" View displaying the list of existing VLANs """
vlan_list = Vlan.objects.prefetch_related('iptype_set').order_by('vlan_id')
return render(
request,
'machines/index_vlan.html',
{'vlan_list': vlan_list}
)
@login_required
@can_view_all(SOA, Mx, Ns, Txt, DName, Srv, Extension)
def index_extension(request):
......
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