mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-24 04:13:12 +00:00
Merge branch 'affichage_chbre' into 'master'
Affichage de la chambre dans les logs radius + fix evaluation str en python2 pour freeradius See merge request federez/re2o!44
This commit is contained in:
commit
38e096b5df
2 changed files with 28 additions and 25 deletions
|
@ -205,10 +205,10 @@ def post_auth(data):
|
||||||
# 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_instance, nas_type, port, mac)
|
||||||
sw_name, 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]' % \
|
||||||
(sw_name + u":" + port, mac, vlan_id, (reason and u': ' + reason).encode('utf-8'))
|
(sw_name + u":" + port + u"/" + unicode(room), mac, vlan_id, (reason and u': ' + reason).encode('utf-8'))
|
||||||
logger.info(log_message)
|
logger.info(log_message)
|
||||||
|
|
||||||
# Filaire
|
# Filaire
|
||||||
|
@ -297,14 +297,14 @@ def decide_vlan_and_register_switch(nas, nas_type, port_number, mac_address):
|
||||||
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:
|
||||||
return ('?', u'Nas inconnu', VLAN_OK)
|
return ('?', u'Chambre inconnue', u'Nas inconnu', VLAN_OK)
|
||||||
|
|
||||||
sw_name = str(nas)
|
sw_name = str(nas)
|
||||||
|
|
||||||
port = Port.objects.filter(switch=Switch.objects.filter(switch_interface=nas), port=port_number).first()
|
port = Port.objects.filter(switch=Switch.objects.filter(switch_interface=nas), 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, u'Port inconnu', VLAN_OK)
|
return (sw_name, "Chambre inconnue", u'Port inconnu', VLAN_OK)
|
||||||
|
|
||||||
# Si un vlan a été précisé, on l'utilise pour VLAN_OK
|
# Si un vlan a été précisé, on l'utilise pour VLAN_OK
|
||||||
if port.vlan_force:
|
if port.vlan_force:
|
||||||
|
@ -314,52 +314,55 @@ def decide_vlan_and_register_switch(nas, nas_type, port_number, mac_address):
|
||||||
DECISION_VLAN = VLAN_OK
|
DECISION_VLAN = VLAN_OK
|
||||||
|
|
||||||
if port.radius == 'NO':
|
if port.radius == 'NO':
|
||||||
return (sw_name, u"Pas d'authentification sur ce port" + extra_log, DECISION_VLAN)
|
return (sw_name, "", u"Pas d'authentification sur ce port" + extra_log, DECISION_VLAN)
|
||||||
|
|
||||||
if port.radius == 'BLOQ':
|
if port.radius == 'BLOQ':
|
||||||
return (sw_name, u'Port desactive', VLAN_NOK)
|
return (sw_name, port.room, u'Port desactive', VLAN_NOK)
|
||||||
|
|
||||||
if port.radius == 'STRICT':
|
if port.radius == 'STRICT':
|
||||||
if not port.room:
|
room = port.room
|
||||||
return (sw_name, u'Chambre inconnue', VLAN_NOK)
|
if not room:
|
||||||
|
return (sw_name, "Inconnue", u'Chambre inconnue', VLAN_NOK)
|
||||||
|
|
||||||
room_user = User.objects.filter(Q(club__room=port.room) | Q(adherent__room=port.room))
|
room_user = User.objects.filter(Q(club__room=port.room) | Q(adherent__room=port.room))
|
||||||
if not room_user:
|
if not room_user:
|
||||||
return (sw_name, u'Chambre non cotisante', VLAN_NOK)
|
return (sw_name, room, u'Chambre non cotisante', VLAN_NOK)
|
||||||
for user in room_user:
|
for user in room_user:
|
||||||
if not user.has_access():
|
if not user.has_access():
|
||||||
return (sw_name, u'Chambre resident desactive', VLAN_NOK)
|
return (sw_name, room, u'Chambre resident desactive', VLAN_NOK)
|
||||||
# else: user OK, on passe à la verif MAC
|
# else: user OK, on passe à la verif MAC
|
||||||
|
|
||||||
if port.radius == 'COMMON' or port.radius == 'STRICT':
|
if port.radius == 'COMMON' or port.radius == 'STRICT':
|
||||||
# Authentification par mac
|
# Authentification par mac
|
||||||
interface = Interface.objects.filter(mac_address=mac_address).select_related('machine__user').select_related('ipv4').first()
|
interface = Interface.objects.filter(mac_address=mac_address).select_related('machine__user').select_related('ipv4').first()
|
||||||
if not interface:
|
if not interface:
|
||||||
|
room = port.room
|
||||||
# On essaye de register la mac
|
# On essaye de register la mac
|
||||||
if not nas_type.autocapture_mac:
|
if not nas_type.autocapture_mac:
|
||||||
return (sw_name, u'Machine inconnue', VLAN_NOK)
|
return (sw_name, "", u'Machine inconnue', VLAN_NOK)
|
||||||
elif not port.room:
|
elif not room:
|
||||||
return (sw_name, u'Chambre et machine inconnues', VLAN_NOK)
|
return (sw_name, "Inconnue", u'Chambre et machine inconnues', VLAN_NOK)
|
||||||
else:
|
else:
|
||||||
if not room_user:
|
if not room_user:
|
||||||
room_user = User.objects.filter(Q(club__room=port.room) | Q(adherent__room=port.room))
|
room_user = User.objects.filter(Q(club__room=port.room) | Q(adherent__room=port.room))
|
||||||
if not room_user:
|
if not room_user:
|
||||||
return (sw_name, u'Machine et propriétaire de la chambre inconnus', VLAN_NOK)
|
return (sw_name, room, u'Machine et propriétaire de la chambre inconnus', VLAN_NOK)
|
||||||
elif room_user.count() > 1:
|
elif room_user.count() > 1:
|
||||||
return (sw_name, u'Machine inconnue, il y a au moins 2 users dans la chambre/local -> ajout de mac automatique impossible', VLAN_NOK)
|
return (sw_name, room, u'Machine inconnue, il y a au moins 2 users dans la chambre/local -> ajout de mac automatique impossible', VLAN_NOK)
|
||||||
elif not room_user.first().has_access():
|
elif not room_user.first().has_access():
|
||||||
return (sw_name, u'Machine inconnue et adhérent non cotisant', VLAN_NOK)
|
return (sw_name, room, u'Machine inconnue et adhérent non cotisant', VLAN_NOK)
|
||||||
else:
|
else:
|
||||||
result, reason = room_user.first().autoregister_machine(mac_address, nas_type)
|
result, reason = room_user.first().autoregister_machine(mac_address, nas_type)
|
||||||
if result:
|
if result:
|
||||||
return (sw_name, u'Access Ok, Capture de la mac...' + extra_log, DECISION_VLAN)
|
return (sw_name, room, u'Access Ok, Capture de la mac...' + extra_log, DECISION_VLAN)
|
||||||
else:
|
else:
|
||||||
return (sw_name, u'Erreur dans le register mac %s' % reason + unicode(mac_address), VLAN_NOK)
|
return (sw_name, room, u'Erreur dans le register mac %s' % reason + unicode(mac_address), VLAN_NOK)
|
||||||
else:
|
else:
|
||||||
|
room = port.room
|
||||||
if not interface.is_active:
|
if not interface.is_active:
|
||||||
return (sw_name, u'Machine non active / adherent non cotisant', VLAN_NOK)
|
return (sw_name, room, u'Machine non active / adherent non cotisant', VLAN_NOK)
|
||||||
elif not interface.ipv4:
|
elif not interface.ipv4:
|
||||||
interface.assign_ipv4()
|
interface.assign_ipv4()
|
||||||
return (sw_name, u"Ok, Reassignation de l'ipv4" + extra_log, DECISION_VLAN)
|
return (sw_name, room, u"Ok, Reassignation de l'ipv4" + extra_log, DECISION_VLAN)
|
||||||
else:
|
else:
|
||||||
return (sw_name, u'Machine OK' + extra_log, DECISION_VLAN)
|
return (sw_name, room, u'Machine OK' + extra_log, DECISION_VLAN)
|
||||||
|
|
|
@ -115,7 +115,7 @@ class Switch(models.Model):
|
||||||
unique_together = ('stack', 'stack_member_id')
|
unique_together = ('stack', 'stack_member_id')
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.location) + ' ' + str(self.switch_interface)
|
return self.location + ' ' + str(self.switch_interface)
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
""" Verifie que l'id stack est dans le bon range"""
|
""" Verifie que l'id stack est dans le bon range"""
|
||||||
|
@ -168,7 +168,7 @@ class ModelSwitch(models.Model):
|
||||||
)
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.constructor) + ' ' + str(self.reference)
|
return str(self.constructor) + ' ' + self.reference
|
||||||
|
|
||||||
|
|
||||||
class ConstructorSwitch(models.Model):
|
class ConstructorSwitch(models.Model):
|
||||||
|
@ -177,7 +177,7 @@ class ConstructorSwitch(models.Model):
|
||||||
name = models.CharField(max_length=255)
|
name = models.CharField(max_length=255)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.name)
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class Port(models.Model):
|
class Port(models.Model):
|
||||||
|
@ -295,7 +295,7 @@ class Room(models.Model):
|
||||||
ordering = ['name']
|
ordering = ['name']
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.name)
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_delete, sender=Stack)
|
@receiver(post_delete, sender=Stack)
|
||||||
|
|
Loading…
Reference in a new issue