Commit 4d9e7151 authored by Gabriel Detraz's avatar Gabriel Detraz Committed by root

Adaptation pour juniper

parent 690471b9
......@@ -183,11 +183,11 @@ def post_auth_fil(data):
"""Idem, mais en filaire.
"""
nas = data.get('NAS-IP-Address', None)
port = data.get('NAS-Port', None)
nas = data.get('NAS-IP-Address', data.get('NAS-Identifier', None))
port = data.get('NAS-Port-Id', data.get('NAS-Port', None))
mac = data.get('Calling-Station-Id', None)
# 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])
sw_name, reason, vlan_id = make_tuple(out)
......
......@@ -14,7 +14,8 @@ application = get_wsgi_application()
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 users.models import User
......@@ -23,9 +24,9 @@ from re2o.settings import RADIUS_VLAN_DECISION
VLAN_NOK = RADIUS_VLAN_DECISION['VLAN_NOK']
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
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:
return ('?', 'Switch inconnu', VLAN_OK)
......@@ -70,9 +71,9 @@ def decide_vlan(switch_ip, port_number, mac_address):
if __name__ == '__main__':
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('mac_address', action="store")
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))
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