auth.py: enregistrement de la mac en filaire
quand mac=<automatique>
This commit is contained in:
parent
599a490e5e
commit
526e57788a
1 changed files with 43 additions and 25 deletions
|
@ -26,7 +26,8 @@ test_v6 = [
|
||||||
u'00:26:c7:a6:9e:16', # cerveaulent (machine de b2moo)
|
u'00:26:c7:a6:9e:16', # cerveaulent (machine de b2moo)
|
||||||
]
|
]
|
||||||
|
|
||||||
USERNAME_SUFFIX = '.wifi.crans.org'
|
USERNAME_SUFFIX_WIFI = '.wifi.crans.org'
|
||||||
|
USERNAME_SUFFIX_FIL = '.crans.org'
|
||||||
|
|
||||||
## -*- Logging -*-
|
## -*- Logging -*-
|
||||||
# Initialisation d'un logger pour faire des stats etc
|
# Initialisation d'un logger pour faire des stats etc
|
||||||
|
@ -91,8 +92,15 @@ def radius_event(f):
|
||||||
return new_f
|
return new_f
|
||||||
|
|
||||||
@use_ldap
|
@use_ldap
|
||||||
def get_machines(data, conn):
|
def get_machines(data, conn, is_wifi=True, proprio=None):
|
||||||
"""Obtient la liste de machine essayant actuellement de se connecter"""
|
"""Obtient la liste de machine essayant actuellement de se connecter"""
|
||||||
|
if is_wifi:
|
||||||
|
suffix = USERNAME_SUFFIX_WIFI
|
||||||
|
base = u'(objectclass=machineWifi)'
|
||||||
|
else:
|
||||||
|
suffix = USERNAME_SUFFIX_FIL
|
||||||
|
base = u'(objectclass=machineFixe)'
|
||||||
|
|
||||||
mac = data.get('Calling-Station-Id', None)
|
mac = data.get('Calling-Station-Id', None)
|
||||||
if mac:
|
if mac:
|
||||||
try:
|
try:
|
||||||
|
@ -103,29 +111,34 @@ def get_machines(data, conn):
|
||||||
username = data.get('User-Name', None)
|
username = data.get('User-Name', None)
|
||||||
if username:
|
if username:
|
||||||
username = escape_ldap(username.decode('ascii', 'ignore'))
|
username = escape_ldap(username.decode('ascii', 'ignore'))
|
||||||
if username.endswith(USERNAME_SUFFIX):
|
if username.endswith(suffix):
|
||||||
username = username[:-len(USERNAME_SUFFIX)]
|
username = username[:-len(suffix)]
|
||||||
|
|
||||||
base = u'(objectclass=machine)'
|
|
||||||
|
|
||||||
if mac is None:
|
if mac is None:
|
||||||
radiusd.radlog(radiusd.L_ERR, 'Cannot read client MAC from AP !')
|
radiusd.radlog(radiusd.L_ERR, 'Cannot read client MAC from AP !')
|
||||||
if username is None:
|
if username is None:
|
||||||
radiusd.radlog(radiusd.L_ERR, 'Cannot read client User-Name !')
|
radiusd.radlog(radiusd.L_ERR, 'Cannot read client User-Name !')
|
||||||
|
|
||||||
# Liste de filtres ldap à essayer
|
# Liste de recherches ldap à essayer, dans l'ordre
|
||||||
search_strats = [
|
# ** Case 1: Search by mac
|
||||||
# Case 1: Search by mac (reported by AP)
|
res = conn.search(u'(&%s(macAddress=%s))' % (base, mac))
|
||||||
u'(&%s(macAddress=%s))' % (base, mac),
|
|
||||||
# Case 2: unregistered mac
|
|
||||||
u'(&%s(macAddress=<automatique>)(host=%s%s))' %
|
|
||||||
(base, username, USERNAME_SUFFIX),
|
|
||||||
]
|
|
||||||
|
|
||||||
for filter_s in search_strats:
|
|
||||||
res = conn.search(filter_s)
|
|
||||||
if res:
|
if res:
|
||||||
break
|
return res
|
||||||
|
|
||||||
|
# Si proprio fourni, on ne cherche désormais que parmi ses machines
|
||||||
|
# (opt est le dico des params optionnels de search)
|
||||||
|
opt = {}
|
||||||
|
if proprio is not None:
|
||||||
|
opt['dn'] = proprio.dn
|
||||||
|
# Filaire: pas de username.
|
||||||
|
if not is_wifi:
|
||||||
|
username = '*'
|
||||||
|
|
||||||
|
# ** Case 2: unregistered mac : il nous faut au moins un username ou être sûr
|
||||||
|
# du propriétaire
|
||||||
|
if username != '*' or proprio is not None:
|
||||||
|
res = conn.search(u'(&%s(macAddress=<automatique>)(host=%s%s))' %
|
||||||
|
(base, username, suffix), **opt)
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
@ -220,9 +233,6 @@ def authorize_wifi(data):
|
||||||
|
|
||||||
machine = items[0]
|
machine = items[0]
|
||||||
|
|
||||||
if '<automatique>' in machine['macAddress']:
|
|
||||||
register_mac(data, machine)
|
|
||||||
|
|
||||||
proprio = machine.proprio()
|
proprio = machine.proprio()
|
||||||
if isinstance(proprio, lc_ldap.objets.AssociationCrans):
|
if isinstance(proprio, lc_ldap.objets.AssociationCrans):
|
||||||
radiusd.radlog(radiusd.L_ERR, 'Crans machine trying to authenticate !')
|
radiusd.radlog(radiusd.L_ERR, 'Crans machine trying to authenticate !')
|
||||||
|
@ -316,21 +326,31 @@ def decide_vlan(data, is_wifi, conn):
|
||||||
"wifi" si wifi
|
"wifi" si wifi
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Switch de remplissage decision par défaut, port, hebergeurs
|
||||||
if is_wifi:
|
if is_wifi:
|
||||||
decision = 'wifi', u''
|
decision = 'wifi', u''
|
||||||
port = data.get('Called-Station-Id', '?')
|
port = data.get('Called-Station-Id', '?')
|
||||||
|
hebergeurs = []
|
||||||
else:
|
else:
|
||||||
decision = 'adherent', u''
|
decision = 'adherent', u''
|
||||||
prise, chbre = get_prise_chbre(data)
|
prise, chbre = get_prise_chbre(data)
|
||||||
port = "%s/%s" % (prise, chbre)
|
port = "%s/%s" % (prise, chbre)
|
||||||
|
|
||||||
items = get_machines(data)
|
chbre = escape_ldap(chbre)
|
||||||
|
hebergeurs = conn.search(u'(&(chbre=%s)(|(cid=*)(aid=*)))' % chbre)
|
||||||
|
|
||||||
|
# Prend la première machine candidat dans la base, ou exit
|
||||||
|
items = get_machines(data, is_wifi=is_wifi, proprio=(hebergeurs+[None])[0])
|
||||||
if not items:
|
if not items:
|
||||||
return (port, 'accueil', 'Machine inconnue')
|
return (port, 'accueil', 'Machine inconnue')
|
||||||
|
|
||||||
machine = items[0]
|
machine = items[0]
|
||||||
|
|
||||||
proprio = machine.proprio()
|
proprio = machine.proprio()
|
||||||
|
|
||||||
|
# Avant de continuer, on assigne la mac à la machine candidat
|
||||||
|
if '<automatique>' in machine['macAddress']:
|
||||||
|
register_mac(data, machine)
|
||||||
|
|
||||||
if not machine['ipHostNumber']:
|
if not machine['ipHostNumber']:
|
||||||
decision = 'v6only', u'No IPv4'
|
decision = 'v6only', u'No IPv4'
|
||||||
elif unicode(machine['macAddress'][0]) in test_v6:
|
elif unicode(machine['macAddress'][0]) in test_v6:
|
||||||
|
@ -355,8 +375,6 @@ def decide_vlan(data, is_wifi, conn):
|
||||||
if chbre is None and not is_ma:
|
if chbre is None and not is_ma:
|
||||||
decision = "accueil", u"Chambre inconnue"
|
decision = "accueil", u"Chambre inconnue"
|
||||||
elif chbre is not None:
|
elif chbre is not None:
|
||||||
chbre = escape_ldap(chbre)
|
|
||||||
hebergeurs = conn.search(u'(&(chbre=%s)(|(cid=*)(aid=*)))' % chbre)
|
|
||||||
for hebergeur in hebergeurs:
|
for hebergeur in hebergeurs:
|
||||||
# Si on est hébergé par un adhérent ok, ou que c'est notre
|
# Si on est hébergé par un adhérent ok, ou que c'est notre
|
||||||
# chambre, pas de problème
|
# chambre, pas de problème
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue