mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-27 07:02:26 +00:00
Adaptation pour juniper
This commit is contained in:
parent
334e65c379
commit
dd2a49b39a
2 changed files with 9 additions and 8 deletions
|
@ -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)
|
||||
|
||||
|
|
11
freeradius_utils/authenticate_filaire.py
Normal file → Executable file
11
freeradius_utils/authenticate_filaire.py
Normal file → Executable file
|
@ -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))
|
||||
|
||||
|
|
Loading…
Reference in a new issue