mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 03:13:12 +00:00
Revert "Simplify logic & improve readability. Harmonize log string language"
This reverts commit 365f163ab3
.
This commit is contained in:
parent
365f163ab3
commit
782cb76769
1 changed files with 46 additions and 42 deletions
88
freeradius_utils/authenticate_filaire.py
Normal file → Executable file
88
freeradius_utils/authenticate_filaire.py
Normal file → Executable file
|
@ -24,49 +24,53 @@ VLAN_NOK = RADIUS_VLAN_DECISION['VLAN_NOK']
|
||||||
VLAN_OK = RADIUS_VLAN_DECISION['VLAN_OK']
|
VLAN_OK = RADIUS_VLAN_DECISION['VLAN_OK']
|
||||||
|
|
||||||
def decide_vlan(switch_ip, port_number, mac_address):
|
def decide_vlan(switch_ip, port_number, mac_address):
|
||||||
# Get port from switch and port number
|
# Get port from switch and port number
|
||||||
switch = Switch.objects.filter(switch_interface=Interface.objects.filter(ipv4=IpList.objects.filter(ipv4=switch_ip)))
|
switch = Switch.objects.filter(switch_interface=Interface.objects.filter(ipv4=IpList.objects.filter(ipv4=switch_ip)))
|
||||||
if not switch:
|
if switch:
|
||||||
return ('?', 'Switch inconnu', VLAN_OK)
|
sw_name = str(switch[0].switch_interface)
|
||||||
|
port = Port.objects.filter(switch=switch[0], port=port_number)
|
||||||
sw_name = str(switch[0].switch_interface)
|
if port:
|
||||||
|
port = port[0]
|
||||||
port = Port.objects.filter(switch=switch[0], port=port_number)
|
if port.radius == 'NO':
|
||||||
if not port:
|
# Aucune authentification sur ce port
|
||||||
return (sw_name, 'Port inconnu', VLAN_OK)
|
decision = (sw_name, "Pas d'authentification sur ce port", VLAN_OK)
|
||||||
|
elif port.radius == 'BLOQ':
|
||||||
port = port[0]
|
# Prise désactivée
|
||||||
|
decision = (sw_name, 'Port desactive', VLAN_NOK)
|
||||||
if port.radius == 'NO':
|
elif port.radius == 'COMMON':
|
||||||
return (sw_name, "Pas d'authentification sur ce port", VLAN_OK)
|
# Authentification par mac
|
||||||
|
interface = Interface.objects.filter(mac_address=mac_address)
|
||||||
if port.radius == 'BLOQ':
|
if not interface:
|
||||||
return (sw_name, 'Port desactive', VLAN_NOK)
|
decision = (sw_name, 'Mac not found', VLAN_NOK)
|
||||||
|
elif not interface[0].is_active():
|
||||||
if port.radius == 'STRICT':
|
decision = (sw_name, 'Machine non active / adherent non cotisant', VLAN_NOK)
|
||||||
if not port.room:
|
else:
|
||||||
return (sw_name, 'Chambre inconnue', VLAN_NOK)
|
decision = (sw_name, 'Machine OK', VLAN_OK)
|
||||||
|
elif port.radius == 'STRICT':
|
||||||
room_user = User.objects.filter(room=Room.objects.filter(name=port.room))
|
if port.room:
|
||||||
if not room_user:
|
user = User.objects.filter(room=Room.objects.filter(name=port.room))
|
||||||
return (sw_name, 'Chambre non cotisante', VLAN_NOK)
|
if not user:
|
||||||
elif not room_user[0].has_access():
|
decision = (sw_name, 'Chambre non cotisante', VLAN_NOK)
|
||||||
return (sw_name, 'Chambre resident desactive', VLAN_NOK)
|
elif not user[0].has_access():
|
||||||
# else: user OK, on passe à la verif MAC
|
decision = (sw_name, 'Resident desactive', VLAN_NOK)
|
||||||
|
else:
|
||||||
if port.radius == 'COMMON' or port.radius == 'STRICT':
|
# Verification de la mac
|
||||||
# Authentification par mac
|
interface = Interface.objects.filter(mac_address=mac_address)
|
||||||
interface = Interface.objects.filter(mac_address=mac_address)
|
if not interface:
|
||||||
if not interface:
|
decision = (sw_name, 'Chambre Ok, but mac not found', VLAN_NOK)
|
||||||
return (sw_name, 'Machine inconnue', VLAN_NOK)
|
elif not interface[0].is_active():
|
||||||
elif not interface[0].is_active():
|
decision = (sw_name, 'Chambre Ok, but machine non active / adherent non cotisant', VLAN_NOK)
|
||||||
return (sw_name, 'Machine non active / adherent non cotisant', VLAN_NOK)
|
else:
|
||||||
|
decision = (sw_name, 'Machine OK, Proprio OK', VLAN_OK)
|
||||||
|
else:
|
||||||
|
decision = (sw_name, 'Chambre inconnue', VLAN_NOK)
|
||||||
|
else:
|
||||||
|
decision = (sw_name, 'VLAN forced', int(port.radius))
|
||||||
|
else:
|
||||||
|
decision = (sw_name, 'port not found!', VLAN_OK)
|
||||||
else:
|
else:
|
||||||
return (sw_name, 'Machine OK', VLAN_OK)
|
decision = ('?', 'switch not found!', VLAN_OK)
|
||||||
|
return decision
|
||||||
# On gere bien tous les autres états possibles, il ne reste que le VLAN en dur
|
|
||||||
return (sw_name, 'VLAN impose', int(port.radius))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = argparse.ArgumentParser(description='Decide radius vlan attribution')
|
parser = argparse.ArgumentParser(description='Decide radius vlan attribution')
|
||||||
|
|
Loading…
Reference in a new issue