mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-25 22:22:26 +00:00
Adapte auth.py au nouveau système de switchs + optimisations forms
This commit is contained in:
parent
3ce73a7a46
commit
fc7f985392
3 changed files with 34 additions and 20 deletions
|
@ -192,19 +192,21 @@ def post_auth(data):
|
||||||
|
|
||||||
mac = data.get('Calling-Station-Id', None)
|
mac = data.get('Calling-Station-Id', None)
|
||||||
|
|
||||||
|
# Switch et bornes héritent de machine et peuvent avoir plusieurs interfaces filles
|
||||||
|
nas_machine = nas_instance.machine
|
||||||
# Si il s'agit d'un switch
|
# Si il s'agit d'un switch
|
||||||
if hasattr(nas_instance, 'switch'):
|
if hasattr(nas_machine, 'switch'):
|
||||||
port = data.get('NAS-Port-Id', data.get('NAS-Port', None))
|
port = data.get('NAS-Port-Id', data.get('NAS-Port', None))
|
||||||
#Pour les infrastructures possédant des switchs Juniper :
|
#Pour les infrastructures possédant des switchs Juniper :
|
||||||
#On vérifie si le switch fait partie d'un stack Juniper
|
#On vérifie si le switch fait partie d'un stack Juniper
|
||||||
instance_stack = nas_instance.switch.stack
|
instance_stack = nas_machine.switch.stack
|
||||||
if instance_stack:
|
if instance_stack:
|
||||||
# Si c'est le cas, on resélectionne le bon switch dans la stack
|
# Si c'est le cas, on resélectionne le bon switch dans la stack
|
||||||
id_stack_member = port.split("-")[1].split('/')[0]
|
id_stack_member = port.split("-")[1].split('/')[0]
|
||||||
nas_instance = Switch.objects.filter(stack=instance_stack).filter(stack_member_id=id_stack_member).select_related('domain__extension').first()
|
nas_machine = Switch.objects.filter(stack=instance_stack).filter(stack_member_id=id_stack_member).prefetch_related('interface_set__domain__extension').first()
|
||||||
# On récupère le numéro du port sur l'output de freeradius. La ligne suivante fonctionne pour cisco, HP et Juniper
|
# On récupère le numéro du port sur l'output de freeradius. La ligne suivante fonctionne pour cisco, HP et Juniper
|
||||||
port = port.split(".")[0].split('/')[-1][-2:]
|
port = port.split(".")[0].split('/')[-1][-2:]
|
||||||
out = decide_vlan_and_register_switch(nas_instance, nas_type, port, mac)
|
out = decide_vlan_and_register_switch(nas_machine, nas_type, port, mac)
|
||||||
sw_name, room, reason, vlan_id = out
|
sw_name, room, reason, vlan_id = out
|
||||||
|
|
||||||
log_message = '(fil) %s -> %s [%s%s]' % \
|
log_message = '(fil) %s -> %s [%s%s]' % \
|
||||||
|
@ -271,7 +273,7 @@ def check_user_machine_and_register(nas_type, username, mac_address):
|
||||||
return (False, u"Machine inconnue", '')
|
return (False, u"Machine inconnue", '')
|
||||||
|
|
||||||
|
|
||||||
def decide_vlan_and_register_switch(nas, nas_type, port_number, mac_address):
|
def decide_vlan_and_register_switch(nas_machine, nas_type, port_number, mac_address):
|
||||||
"""Fonction de placement vlan pour un switch en radius filaire auth par mac.
|
"""Fonction de placement vlan pour un switch en radius filaire auth par mac.
|
||||||
Plusieurs modes :
|
Plusieurs modes :
|
||||||
- nas inconnu, port inconnu : on place sur le vlan par defaut VLAN_OK
|
- nas inconnu, port inconnu : on place sur le vlan par defaut VLAN_OK
|
||||||
|
@ -296,12 +298,12 @@ def decide_vlan_and_register_switch(nas, nas_type, port_number, mac_address):
|
||||||
# Get port from switch and port number
|
# Get port from switch and port number
|
||||||
extra_log = ""
|
extra_log = ""
|
||||||
# Si le NAS est inconnu, on place sur le vlan defaut
|
# Si le NAS est inconnu, on place sur le vlan defaut
|
||||||
if not nas:
|
if not nas_machine:
|
||||||
return ('?', u'Chambre inconnue', u'Nas inconnu', VLAN_OK)
|
return ('?', u'Chambre inconnue', u'Nas inconnu', VLAN_OK)
|
||||||
|
|
||||||
sw_name = str(nas)
|
sw_name = str(nas_machine)
|
||||||
|
|
||||||
port = Port.objects.filter(switch=Switch.objects.filter(interface_ptr=nas), port=port_number).first()
|
port = Port.objects.filter(switch=Switch.objects.filter(machine_ptr=nas_machine), port=port_number).first()
|
||||||
#Si le port est inconnu, on place sur le vlan defaut
|
#Si le port est inconnu, on place sur le vlan defaut
|
||||||
if not port:
|
if not port:
|
||||||
return (sw_name, "Chambre inconnue", u'Port inconnu', VLAN_OK)
|
return (sw_name, "Chambre inconnue", u'Port inconnu', VLAN_OK)
|
||||||
|
|
|
@ -40,6 +40,7 @@ from machines.forms import (
|
||||||
)
|
)
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.forms import ModelForm, Form
|
from django.forms import ModelForm, Form
|
||||||
|
from django.db.models import Prefetch
|
||||||
from .models import (
|
from .models import (
|
||||||
Port,
|
Port,
|
||||||
Switch,
|
Switch,
|
||||||
|
@ -82,9 +83,10 @@ class EditPortForm(ModelForm):
|
||||||
self.fields['machine_interface'].queryset = Interface.objects.all()\
|
self.fields['machine_interface'].queryset = Interface.objects.all()\
|
||||||
.select_related('domain__extension')
|
.select_related('domain__extension')
|
||||||
self.fields['related'].queryset = Port.objects.all()\
|
self.fields['related'].queryset = Port.objects.all()\
|
||||||
.select_related('switch')\
|
.prefetch_related(Prefetch(
|
||||||
.prefetch_related('switch__interface_set__domain__extension')\
|
'switch__interface_set',
|
||||||
.order_by('switch', 'port')
|
queryset=Interface.objects.select_related('ipv4__ip_type__extension').select_related('domain__extension')
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
class AddPortForm(ModelForm):
|
class AddPortForm(ModelForm):
|
||||||
|
@ -100,9 +102,10 @@ class AddPortForm(ModelForm):
|
||||||
self.fields['machine_interface'].queryset = Interface.objects.all()\
|
self.fields['machine_interface'].queryset = Interface.objects.all()\
|
||||||
.select_related('domain__extension')
|
.select_related('domain__extension')
|
||||||
self.fields['related'].queryset = Port.objects.all()\
|
self.fields['related'].queryset = Port.objects.all()\
|
||||||
.select_related('switch')\
|
.prefetch_related(Prefetch(
|
||||||
.prefetch_related('switch__interface_set__domain__extension')\
|
'switch__interface_set',
|
||||||
.order_by('switch', 'port')
|
queryset=Interface.objects.select_related('ipv4__ip_type__extension').select_related('domain__extension')
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
class StackForm(ModelForm):
|
class StackForm(ModelForm):
|
||||||
|
|
|
@ -41,7 +41,7 @@ from django.contrib import messages
|
||||||
from django.contrib.auth.decorators import login_required, permission_required
|
from django.contrib.auth.decorators import login_required, permission_required
|
||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.db.models import ProtectedError
|
from django.db.models import ProtectedError, Prefetch
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
||||||
from reversion import revisions as reversion
|
from reversion import revisions as reversion
|
||||||
|
@ -84,6 +84,7 @@ from machines.forms import (
|
||||||
AddInterfaceForm
|
AddInterfaceForm
|
||||||
)
|
)
|
||||||
from machines.views import generate_ipv4_mbf_param
|
from machines.views import generate_ipv4_mbf_param
|
||||||
|
from machines.models import Interface
|
||||||
from preferences.models import AssoOption, GeneralOption
|
from preferences.models import AssoOption, GeneralOption
|
||||||
|
|
||||||
|
|
||||||
|
@ -92,9 +93,10 @@ from preferences.models import AssoOption, GeneralOption
|
||||||
def index(request):
|
def index(request):
|
||||||
""" Vue d'affichage de tous les swicthes"""
|
""" Vue d'affichage de tous les swicthes"""
|
||||||
switch_list = Switch.objects\
|
switch_list = Switch.objects\
|
||||||
.prefetch_related('interface_set__domain__extension')\
|
.prefetch_related(Prefetch(
|
||||||
.prefetch_related('interface_set__ipv4__ip_type')\
|
'interface_set',
|
||||||
.prefetch_related('interface_set__type__ip_type__extension')\
|
queryset=Interface.objects.select_related('ipv4__ip_type__extension').select_related('domain__extension')
|
||||||
|
))\
|
||||||
.select_related('stack')
|
.select_related('stack')
|
||||||
switch_list = SortTable.sort(
|
switch_list = SortTable.sort(
|
||||||
switch_list,
|
switch_list,
|
||||||
|
@ -128,7 +130,10 @@ def index_port(request, switch, switch_id):
|
||||||
.select_related('machine_interface__domain__extension')\
|
.select_related('machine_interface__domain__extension')\
|
||||||
.select_related('machine_interface__machine__user')\
|
.select_related('machine_interface__machine__user')\
|
||||||
.select_related('related__switch')\
|
.select_related('related__switch')\
|
||||||
.prefetch_related('related__switch__interface_set__domain__extension')\
|
.prefetch_related(Prefetch(
|
||||||
|
'related__switch__interface_set',
|
||||||
|
queryset=Interface.objects.select_related('domain__extension')
|
||||||
|
))\
|
||||||
.select_related('switch')
|
.select_related('switch')
|
||||||
port_list = SortTable.sort(
|
port_list = SortTable.sort(
|
||||||
port_list,
|
port_list,
|
||||||
|
@ -174,7 +179,11 @@ def index_room(request):
|
||||||
@can_view_all(AccessPoint)
|
@can_view_all(AccessPoint)
|
||||||
def index_ap(request):
|
def index_ap(request):
|
||||||
""" Affichage de l'ensemble des bornes"""
|
""" Affichage de l'ensemble des bornes"""
|
||||||
ap_list = AccessPoint.objects
|
ap_list = AccessPoint.objects\
|
||||||
|
.prefetch_related(Prefetch(
|
||||||
|
'interface_set',
|
||||||
|
queryset=Interface.objects.select_related('ipv4__ip_type__extension').select_related('domain__extension')
|
||||||
|
))
|
||||||
ap_list = SortTable.sort(
|
ap_list = SortTable.sort(
|
||||||
ap_list,
|
ap_list,
|
||||||
request.GET.get('col'),
|
request.GET.get('col'),
|
||||||
|
|
Loading…
Reference in a new issue