diff --git a/freeradius_utils/auth.py b/freeradius_utils/auth.py index 64ddbc9d..55964b83 100644 --- a/freeradius_utils/auth.py +++ b/freeradius_utils/auth.py @@ -273,6 +273,9 @@ def decide_vlan_and_register_switch(nas, nas_type, port_number, mac_address): return (sw_name, u'Port inconnu', VLAN_OK) port = port.first() + # Si un vlan a été précisé, on l'utilise pour VLAN_OK + if port.vlan_force: + VLAN_OK = int(port.vlan_force.vlan_id) if port.radius == 'NO': return (sw_name, u"Pas d'authentification sur ce port", VLAN_OK) @@ -317,8 +320,4 @@ def decide_vlan_and_register_switch(nas, nas_type, port_number, mac_address): else: return (sw_name, u'Machine OK', VLAN_OK) - # On gere bien tous les autres états possibles, il ne reste que le VLAN en dur - return (sw_name, u'VLAN impose', int(port.radius)) - - diff --git a/topologie/migrations/0029_auto_20171002_0334.py b/topologie/migrations/0029_auto_20171002_0334.py new file mode 100644 index 00000000..73ddff1b --- /dev/null +++ b/topologie/migrations/0029_auto_20171002_0334.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-10-02 01:34 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('topologie', '0028_auto_20170913_1503'), + ] + + operations = [ + migrations.AlterField( + model_name='port', + name='radius', + field=models.CharField(choices=[('NO', 'NO'), ('STRICT', 'STRICT'), ('BLOQ', 'BLOQ'), ('COMMON', 'COMMON'), ('3', '3'), ('7', '7'), ('8', '8'), ('13', '13'), ('20', '20'), ('42', '42'), ('69', '69')], default='NO', max_length=32), + ), + ] diff --git a/topologie/migrations/0030_auto_20171004_0235.py b/topologie/migrations/0030_auto_20171004_0235.py new file mode 100644 index 00000000..83f3b022 --- /dev/null +++ b/topologie/migrations/0030_auto_20171004_0235.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-10-04 00:35 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('topologie', '0029_auto_20171002_0334'), + ] + + operations = [ + migrations.AddField( + model_name='port', + name='vlan_force', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='machines.Vlan'), + ), + migrations.AlterField( + model_name='port', + name='radius', + field=models.CharField(choices=[('NO', 'NO'), ('STRICT', 'STRICT'), ('BLOQ', 'BLOQ'), ('COMMON', 'COMMON')], default='NO', max_length=32), + ), + ] diff --git a/topologie/models.py b/topologie/models.py index 0aafa24e..7ac10243 100644 --- a/topologie/models.py +++ b/topologie/models.py @@ -91,23 +91,20 @@ class Switch(models.Model): class Port(models.Model): PRETTY_NAME = "Port de switch" - STATES_BASE = ( + STATES = ( ('NO', 'NO'), ('STRICT', 'STRICT'), ('BLOQ', 'BLOQ'), ('COMMON', 'COMMON'), ) - try: - STATES = STATES_BASE + tuple([(str(id), str(id)) for id in list(Vlan.objects.values_list('vlan_id', flat=True).order_by('vlan_id'))]) - except: - STATES = STATES_BASE - + switch = models.ForeignKey('Switch', related_name="ports") port = models.IntegerField() room = models.ForeignKey('Room', on_delete=models.PROTECT, blank=True, null=True) machine_interface = models.ForeignKey('machines.Interface', on_delete=models.SET_NULL, blank=True, null=True) related = models.OneToOneField('self', null=True, blank=True, related_name='related_port') radius = models.CharField(max_length=32, choices=STATES, default='NO') + vlan_force = models.ForeignKey('machines.Vlan', on_delete=models.SET_NULL, blank=True, null=True) details = models.CharField(max_length=255, blank=True) class Meta: diff --git a/topologie/templates/topologie/aff_port.html b/topologie/templates/topologie/aff_port.html index 6bd84abc..609d4349 100644 --- a/topologie/templates/topologie/aff_port.html +++ b/topologie/templates/topologie/aff_port.html @@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,