Commit 1e6de0ec authored by Gabriel Detraz's avatar Gabriel Detraz

Affichage de la chambre prise dans les logs

parent bda8ae7d
......@@ -457,7 +457,7 @@ class RadiusEventHandler(object):
return radiusd.RLM_MODULE_INVALID
logger.debug('[pre-auth] Supplicant treated as a %s machine', m_type)
owner, machine, _ = self.find_match(request, m_type)
owner, machine, _, _, _ = self.find_match(request, m_type)
if (owner is None) or (machine is None):
logger.info('[pre-auth] No match found for %s/%s', mac, username)
return radiusd.RLM_MODULE_NOTFOUND
......@@ -496,7 +496,7 @@ class RadiusEventHandler(object):
def authenticate(self, request):
"""Authentification de l'utilisateur et de sa machine"""
m_type = type_of_machine(request)
_, machine, _ = self.find_match(request, m_type)
_, machine, _, _, _ = self.find_match(request, m_type)
remote_mac = request.get('Calling-Station-Id', None)
if machine is None:
# Il s'agit d'une machine inconnue, on la mettra sur le VLAN accueil
......@@ -593,7 +593,7 @@ class RadiusEventHandler(object):
session_info = self.retrieve_session(mac)
vlan_id = session_info['vlan'] if session_info else None
owner, machine, _ = self.find_match(request, m_type)
owner, machine, _, _, _ = self.find_match(request, m_type)
new_vlan_id, why = assign_vlan(machine, owner, m_type)
if vlan_id is None:
# Le VLAN n'a pas été renvoyé par le NAS, on a donc
......@@ -656,7 +656,10 @@ class RadiusEventHandler(object):
"""Traitement de la requête après l'authentification"""
m_type = type_of_machine(request)
nas_id = request.get('NAS-IP-Address', request.get('NAS-IPv6-Address', 'Unknown'))
owner, machine, hosts = self.find_match(request, m_type)
owner, machine, hosts, plug, room = self.find_match(request, m_type)
if room and plug:
mac = request.get('Calling-Station-Id', request.get('User-Name', None))
logger.info("[post-auth] Mac-address %s auth on room %s/%s" % (mac, room, plug))
room = ldap_unpack(hosts[0]['chbre']) if hosts else None
if machine is None:
# La machine est inconnue : si on fait de l'assignation dynamique,
......@@ -913,8 +916,8 @@ class RadiusEventHandler(object):
mac = request.get('Calling-Station-Id', None)
if (mac, m_type) in self.__cache:
logger.debug("%s found in module cache", mac)
owner, machine, hosts, _ = self.__cache[(mac, m_type)]
return (owner, machine, hosts)
owner, machine, hosts, plug, room, _ = self.__cache[(mac, m_type)]
return (owner, machine, hosts, plug, room)
else:
logger.debug("%s not found in module cache", mac)
result = self.__find_match(request, m_type)
......@@ -944,10 +947,10 @@ class RadiusEventHandler(object):
if room:
room = room[0]
logger.debug('Found room %s%s', building.upper(), crans_utils.escape(room))
return self.ldap.search('(&(chbre=%s%s)(!(chbre=EXT)))' % (building, room))
return building.lower() + plug, building.upper()+room, self.ldap.search('(&(chbre=%s%s)(!(chbre=EXT)))' % (building, room))
else:
logger.debug('No room for plug %s%s', building, plug)
return []
return None, None, []
def __find_match(self, request, m_type):
"""Renvoie un triplet (propriétaire, machine, hébergeurs) à partir
......@@ -987,6 +990,7 @@ class RadiusEventHandler(object):
})
m_list = self.ldap.search(LDAP_FILTER % params)
hosts = []
room, plug = None, None
else:
# Si la requête n'utilise pas IEEE 802.1X, on cherche la machine via sa MAC.
......@@ -996,14 +1000,14 @@ class RadiusEventHandler(object):
logger.debug('Trying to find a match by MAC (%s)', mac)
params.update({'af' : 'macAddress', 'address' : crans_utils.escape(mac)})
m_list = self.ldap.search(LDAP_FILTER % params)
hosts = self._plug_info(nas_id, port) if m_type == TYPE_WIRED else []
plug, room, hosts = self._plug_info(nas_id, port) if m_type == TYPE_WIRED else []
if not m_list and not is_ieee8021X(request) and m_type == TYPE_WIRED and nas_id and port:
# La recherche n'a rien donné, IEEE 802.1X n'est pas utilisé
# mais on est en présence d'une machine filaire : on essaie de voir si
# le locataire de la chambre a une nouvelle machine
params.update({'af' : 'macAddress', 'address' : MAC_PLACEHOLDER})
hosts = self._plug_info(nas_id, port)
plug, room, hosts = self._plug_info(nas_id, port)
owner = hosts[0] if hosts else None
m_list = self.ldap.search(LDAP_FILTER % params, dn=owner.dn, scope=1) if owner else []
......@@ -1018,10 +1022,10 @@ class RadiusEventHandler(object):
machine = m_list[0]
logger.debug('Match found (machine %s)', ldap_unpack(machine['mid']))
owner = machine.proprio()
return (owner, machine, hosts)
return (owner, machine, hosts, plug, room)
else:
logger.debug("No match for %s", mac)
return (None, None, [])
return (None, None, [], None, None)
def __cleaner(self):
"""Retire périodiquement les entrées inutiles dans les caches"""
......
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