From 92f30fbe19cea3d14f5830b68595209949b12f41 Mon Sep 17 00:00:00 2001 From: chirac Date: Tue, 26 Jun 2018 23:29:40 +0000 Subject: [PATCH] =?UTF-8?q?Ajout=20reglages=20s=C3=A9curit=C3=A9=20+=20fro?= =?UTF-8?q?ntend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- topologie/forms.py | 43 -------------- .../migrations/0062_auto_20180627_0123.py | 25 ++++++++ topologie/models.py | 8 +++ .../templates/topologie/aff_port_profile.html | 59 +++++++------------ topologie/views.py | 5 +- 5 files changed, 55 insertions(+), 85 deletions(-) create mode 100644 topologie/migrations/0062_auto_20180627_0123.py diff --git a/topologie/forms.py b/topologie/forms.py index 377a39b3..3ed9e8b3 100644 --- a/topologie/forms.py +++ b/topologie/forms.py @@ -265,34 +265,6 @@ class EditBuildingForm(FormRevMixin, ModelForm): prefix = kwargs.pop('prefix', self.Meta.model.__name__) super(EditBuildingForm, self).__init__(*args, prefix=prefix, **kwargs) - -class NewPortProfileForm(FormRevMixin, ModelForm): - """Form to create a port profile""" - class Meta: - model = PortProfile - fields = '__all__' - - def __init__(self, *args, **kwargs): - prefix = kwargs.pop('prefix', self.Meta.model.__name__) - super(NewPortProfileForm, self).__init__(*args, - prefix=prefix, - **kwargs) - - def clean(self): - cleaned_data = super(NewPortProfileForm, self).clean() - radius_type = cleaned_data.get('radius_type') - radius_mode = cleaned_data.get('radius_mode') - - if radius_type == 'NO' and radius_mode: - raise forms.ValidationError(_("You can't specify a RADIUS mode" - " with RADIUS type NO")) - elif radius_type != 'NO' and not radius_mode: - raise forms.ValidationError(_("You have to specify a RADIUS" - " mode")) - - return cleaned_data - - class EditPortProfileForm(FormRevMixin, ModelForm): """Form to edit a port profile""" class Meta: @@ -305,18 +277,3 @@ class EditPortProfileForm(FormRevMixin, ModelForm): prefix=prefix, **kwargs) - def clean(self): - cleaned_data = super(EditPortProfileForm, self).clean() - radius_type = cleaned_data.get('radius_type') - radius_mode = cleaned_data.get('radius_mode') - - if radius_type == 'NO' and radius_mode: - raise forms.ValidationError(_("You can't specify a RADIUS mode" - " with RADIUS type NO")) - elif radius_type != 'NO' and not radius_mode: - raise forms.ValidationError(_("You have to specify a RADIUS" - " mode")) - - return cleaned_data - - diff --git a/topologie/migrations/0062_auto_20180627_0123.py b/topologie/migrations/0062_auto_20180627_0123.py new file mode 100644 index 00000000..b8135de8 --- /dev/null +++ b/topologie/migrations/0062_auto_20180627_0123.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2018-06-26 23:23 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('topologie', '0061_portprofile'), + ] + + operations = [ + migrations.AlterField( + model_name='portprofile', + name='radius_mode', + field=models.CharField(choices=[('STRICT', 'STRICT'), ('COMMON', 'COMMON')], default='COMMON', help_text="En cas d'auth par mac, auth common ou strcit sur le port", max_length=32, verbose_name='RADIUS mode'), + ), + migrations.AlterField( + model_name='portprofile', + name='radius_type', + field=models.CharField(choices=[('NO', 'NO'), ('802.1X', '802.1X'), ('MAC-radius', 'MAC-radius')], help_text="Choix du type d'authentification radius : non actif, mac ou 802.1X", max_length=32, verbose_name='RADIUS type'), + ), + ] diff --git a/topologie/models.py b/topologie/models.py index 86beed71..d3400e41 100644 --- a/topologie/models.py +++ b/topologie/models.py @@ -542,12 +542,14 @@ class PortProfile(AclMixin, RevMixin, models.Model): radius_type = models.CharField( max_length=32, choices=TYPES, + help_text="Choix du type d'authentification radius : non actif, mac ou 802.1X", verbose_name=_("RADIUS type") ) radius_mode = models.CharField( max_length=32, choices=MODES, default='COMMON', + help_text="En cas d'auth par mac, auth common ou strcit sur le port", verbose_name=_("RADIUS mode") ) speed = models.CharField( @@ -601,6 +603,12 @@ class PortProfile(AclMixin, RevMixin, models.Model): verbose_name = _("Port profile") verbose_name_plural = _("Port profiles") + security_parameters_fields = ['loop_protect', 'ra_guard', 'arp_protect', 'dhcpv6_snooping', 'dhcp_snooping', 'flow_control'] + + @cached_property + def security_parameters_enabled(self): + return [parameter for parameter in self.security_parameters_fields if getattr(self, parameter)] + def __str__(self): return self.name diff --git a/topologie/templates/topologie/aff_port_profile.html b/topologie/templates/topologie/aff_port_profile.html index 0c1ca622..7e044c0a 100644 --- a/topologie/templates/topologie/aff_port_profile.html +++ b/topologie/templates/topologie/aff_port_profile.html @@ -9,53 +9,34 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + {% for port_profile in port_profile_list %} - + - - + + {% endif %} + + +
{% trans "Name" %} - {% trans "VLAN untagged" %}{% trans "VLAN(s) tagged" %}
{% trans "RADIUS type" %}{% trans "RADIUS mode" %}{% trans "RADIUS type" %}
{% trans "speed" %}{% trans "Mac limit" %}{% trans "Flow control" %}
{% trans "dhcp snooping" %}{% trans "dhcpv6 snooping" %}{% trans "arp protect" %}
{% trans "ra guard" %}{% trans "loop protect" %}{% trans "Nom" %}{% trans "Default pour" %}{% trans "VLANs" %}{% trans "Réglages RADIUS" %}{% trans "Vitesse" %}{% trans "Mac address limit" %}{% trans "Sécurité" %}
{{port_profile.name}}{{port_profile.vlan_untagged}}{{port_profile.profil_default}} - {{port_profile.vlan_tagged.all|join:", "}} + Untagged : {{port_profile.vlan_untagged}} +
+ Tagged : {{port_profile.vlan_tagged.all|join:", "}}
{{port_profile.radius_type}}{{port_profile.radius_mode}} + Type : {{port_profile.radius_type}} + {% if port_profile.radius_type == "MAC-radius" %} +
+ Mode : {{port_profile.radius_mode}}
{{port_profile.speed}}{{port_profile.mac_limit}}{{port_profile.security_parameters_enabled|join:"
"}}
{% include 'buttons/history.html' with href='topologie:history' name='portprofile' id=port_profile.pk %} {% can_edit port_profile %} diff --git a/topologie/views.py b/topologie/views.py index eb86ce9c..4b21c651 100644 --- a/topologie/views.py +++ b/topologie/views.py @@ -97,7 +97,6 @@ from .forms import ( EditAccessPointForm, EditSwitchBayForm, EditBuildingForm, - NewPortProfileForm, EditPortProfileForm, ) @@ -135,7 +134,7 @@ def index(request): switch_list = re2o_paginator(request, switch_list, pagination_number) port_profile_list = re2o_paginator(request, port_profile_list, pagination_number) - if any(service_link.need_regen() for service_link in Service_link.objects.filter(service__service_type='graph_topo')): + if any(service_link.need_regen for service_link in Service_link.objects.filter(service__service_type='graph_topo')): make_machine_graph() for service_link in Service_link.objects.filter(service__service_type='graph_topo'): service_link.done_regen() @@ -967,7 +966,7 @@ def del_constructor_switch(request, constructor_switch, **_kwargs): @can_create(PortProfile) def new_port_profile(request): """Create a new port profile""" - port_profile = NewPortProfileForm(request.POST or None) + port_profile = EditPortProfileForm(request.POST or None) if port_profile.is_valid(): port_profile.save() messages.success(request, _("Port profile created"))