8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-09 11:26:27 +00:00

Adaptation pour juniper

This commit is contained in:
Gabriel Detraz 2017-01-16 00:02:54 +00:00 committed by root
parent 690471b974
commit 4d9e71514c
2 changed files with 9 additions and 8 deletions

View file

@ -183,11 +183,11 @@ def post_auth_fil(data):
"""Idem, mais en filaire. """Idem, mais en filaire.
""" """
nas = data.get('NAS-IP-Address', None) nas = data.get('NAS-IP-Address', data.get('NAS-Identifier', None))
port = data.get('NAS-Port', None) port = data.get('NAS-Port-Id', data.get('NAS-Port', None))
mac = data.get('Calling-Station-Id', None) mac = data.get('Calling-Station-Id', None)
# Hack, à cause d'une numérotation cisco baroque # Hack, à cause d'une numérotation cisco baroque
port = port[-2:] port = port.split(".")[0].split('/')[-1][-2:]
out = subprocess.check_output(['/usr/bin/python3', '/var/www/re2o/freeradius_utils/authenticate_filaire.py', nas, port, mac]) out = subprocess.check_output(['/usr/bin/python3', '/var/www/re2o/freeradius_utils/authenticate_filaire.py', nas, port, mac])
sw_name, reason, vlan_id = make_tuple(out) sw_name, reason, vlan_id = make_tuple(out)

11
freeradius_utils/authenticate_filaire.py Normal file → Executable file
View file

@ -14,7 +14,8 @@ application = get_wsgi_application()
import argparse import argparse
from machines.models import Interface, IpList from django.db.models import Q
from machines.models import Interface, IpList, Domain
from topologie.models import Room, Port, Switch from topologie.models import Room, Port, Switch
from users.models import User from users.models import User
@ -23,9 +24,9 @@ from re2o.settings import RADIUS_VLAN_DECISION
VLAN_NOK = RADIUS_VLAN_DECISION['VLAN_NOK'] 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_id, 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(Q(ipv4=IpList.objects.filter(ipv4=switch_id)) | Q(domain=Domain.objects.filter(name=switch_id))))
if not switch: if not switch:
return ('?', 'Switch inconnu', VLAN_OK) return ('?', 'Switch inconnu', VLAN_OK)
@ -70,9 +71,9 @@ def decide_vlan(switch_ip, port_number, mac_address):
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Decide radius vlan attribution') parser = argparse.ArgumentParser(description='Decide radius vlan attribution')
parser.add_argument('switch_ip', action="store") parser.add_argument('switch_id', action="store")
parser.add_argument('port_number', action="store", type=int) parser.add_argument('port_number', action="store", type=int)
parser.add_argument('mac_address', action="store") parser.add_argument('mac_address', action="store")
args = parser.parse_args() args = parser.parse_args()
print(decide_vlan(args.switch_ip, args.port_number, args.mac_address)) print(decide_vlan(args.switch_id, args.port_number, args.mac_address))