diff --git a/gestion/ldap_crans.py b/gestion/ldap_crans.py index 8e2fc175..99da146c 100755 --- a/gestion/ldap_crans.py +++ b/gestion/ldap_crans.py @@ -157,7 +157,14 @@ def format_mac(mac) : Retourne la mac formatée. """ l, mac = preattr(mac) - mac= mac.replace(':','').replace('-','').replace(' ','').lower() + mac = mac.strip() + if mac.count(":") + mac.count("-") == 5: + # On a une adresse de la forme 0:01:02:18:d1:90 + # On va compléter s'il manque des 0 + for car in (":", "-"): + mac = car.join(map(lambda x: x.replace(' ', '0'), + map(lambda x: "%02s" % x, mac.split(car)))) + mac= mac.replace(':','').replace('-','').lower() if len(mac)!=12 : raise ValueError(u'Longueur adresse mac incorrecte.') for c in mac[:] : @@ -455,8 +462,7 @@ class crans_ldap : el = '(%s=%s*)' % ( champ, expr) elif champ == 'macAddress' : # Formatage adresse mac - try : el = '(macAddress=%s)' % format_mac(expr) - except : return '' + el = '(macAddress=%s)' % format_mac(expr) elif champ == 'paiement' and expr == 'ok' : # Paiement donnant droit à une connexion maintenant ? # Deux cas :