8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 03:13:12 +00:00
re2o/freeradius_utils/auth.py

539 lines
20 KiB
Python
Raw Normal View History

2018-04-13 20:11:55 +00:00
# -*- mode: python; coding: utf-8 -*-
# Re2o est un logiciel d'administration développé initiallement au Rézo Metz. Il
2017-01-15 23:01:18 +00:00
# se veut agnostique au réseau considéré, de manière à être installable en
# quelques clics.
#
# Copyirght © 2017 Daniel Stan
2017-01-15 23:01:18 +00:00
# Copyright © 2017 Gabriel Détraz
# Copyright © 2017 Lara Kermarec
2017-01-15 23:01:18 +00:00
# Copyright © 2017 Augustin Lemesle
2020-11-28 14:42:08 +00:00
# Copyright © 2020 Corentin Canebier
2017-01-15 23:01:18 +00:00
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2016-12-08 14:13:41 +00:00
"""
2020-05-16 01:57:29 +00:00
Python backend for freeradius.
2016-12-08 14:13:41 +00:00
2020-05-16 10:56:09 +00:00
This file contains definition of some functions called by freeradius backend
2020-05-16 01:57:29 +00:00
during auth for wifi, wired device and nas.
2016-12-08 14:13:41 +00:00
2020-05-16 01:57:29 +00:00
Other examples can be found here :
2016-12-08 14:13:41 +00:00
https://github.com/FreeRADIUS/freeradius-server/blob/master/src/modules/rlm_python/
2020-05-16 01:57:29 +00:00
Inspired by Daniel Stan in Crans
2016-12-08 14:13:41 +00:00
"""
2020-11-28 14:42:08 +00:00
from configparser import ConfigParser
from re2oapi import Re2oAPIClient
2018-04-13 20:11:55 +00:00
import sys
from pathlib import Path
2020-11-28 14:42:08 +00:00
import subprocess
2018-04-14 15:30:14 +00:00
import logging
2019-01-23 20:30:17 +00:00
import traceback
2020-11-28 14:42:08 +00:00
import radiusd
from requests import HTTPError
2020-11-28 14:42:08 +00:00
import urllib.parse
2018-04-26 07:19:10 +00:00
2016-12-08 14:13:41 +00:00
class RadiusdHandler(logging.Handler):
2020-11-29 09:33:40 +00:00
"""Logs handler for freeradius"""
2016-12-08 14:13:41 +00:00
def emit(self, record):
2020-11-29 09:33:40 +00:00
"""Log message processing, level are converted"""
2016-12-08 14:13:41 +00:00
if record.levelno >= logging.WARN:
rad_sig = radiusd.L_ERR
elif record.levelno >= logging.INFO:
rad_sig = radiusd.L_INFO
else:
rad_sig = radiusd.L_DBG
radiusd.radlog(rad_sig, str(record.msg))
2016-12-08 14:13:41 +00:00
2018-04-13 20:11:55 +00:00
2020-11-29 09:33:40 +00:00
# Init for logging
logger = logging.getLogger("auth.py")
2016-12-08 14:13:41 +00:00
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(name)s: [%(levelname)s] %(message)s")
2016-12-08 14:13:41 +00:00
handler = RadiusdHandler()
handler.setFormatter(formatter)
logger.addHandler(handler)
2018-04-13 20:11:55 +00:00
2016-12-08 14:13:41 +00:00
def radius_event(fun):
2020-11-29 09:33:40 +00:00
"""Decorator for freeradius fonction with radius.
This function take a unique argument which is a list of tuples (key, value)
and return a tuple of 3 values which are:
* return code (see radiusd.RLM_MODULE_* )
* a tuple of 2 elements for response value (access ok , etc)
* a tuple of 2 elements for internal value to update (password for example)
Here, we convert the list of tuples into a dictionnary.
"""
2016-12-08 14:13:41 +00:00
def new_f(auth_data):
2018-04-14 15:30:14 +00:00
""" The function transforming the tuples as dict """
if isinstance(auth_data, dict):
2016-12-08 14:13:41 +00:00
data = auth_data
else:
data = dict()
for (key, value) in auth_data or []:
# Beware: les valeurs scalaires sont entre guillemets
# Ex: Calling-Station-Id: "une_adresse_mac"
data[key] = value.replace('"', "")
2016-12-08 14:13:41 +00:00
try:
2020-11-28 14:42:08 +00:00
# TODO s'assurer ici que les tuples renvoy s sont bien des
# (str,str) : rlm_python ne dig re PAS les unicodes
2016-12-08 14:13:41 +00:00
return fun(data)
except Exception as err:
2019-09-10 17:11:14 +00:00
exc_type, exc_instance, exc_traceback = sys.exc_info()
formatted_traceback = "".join(traceback.format_tb(exc_traceback))
logger.error("Failed %r on data %r" % (err, auth_data))
2020-11-28 14:42:08 +00:00
logger.error("Function %r, Traceback : %r" %
(fun, formatted_traceback))
return radiusd.RLM_MODULE_FAIL
2016-12-08 14:13:41 +00:00
return new_f
2016-12-08 14:13:41 +00:00
@radius_event
def instantiate(*_):
2020-11-29 09:33:40 +00:00
"""Instantiate api connection
"""
logger.info("Instantiation")
2016-12-08 14:13:41 +00:00
path = Path(__file__).resolve(strict=True).parent
2020-11-29 09:33:40 +00:00
config = ConfigParser()
config.read(path / 'config.ini')
2020-11-29 09:33:40 +00:00
api_hostname = config.get('Re2o', 'hostname')
api_password = config.get('Re2o', 'password')
api_username = config.get('Re2o', 'username')
def get_api_client():
"""Gets a Re2o, or tries to initialize one"""
if get_api_client.client is None:
get_api_client.client = Re2oAPIClient(
api_hostname, api_username, api_password, use_tls=True)
return get_api_client.client
get_api_client.client = None
2020-11-29 09:33:40 +00:00
global api_client
api_client = get_api_client
2020-11-29 09:33:40 +00:00
2018-04-13 20:11:55 +00:00
2016-12-08 14:13:41 +00:00
@radius_event
def authorize(data):
2020-11-29 09:33:40 +00:00
"""Here, we test if the Nas is known.
- If the nas is unknown, we assume that it is a 802.1X request,
- If the nas is known, we apply the 802.1X if enabled,
- It the nas is known AND nas auth is enabled with mac address, returns accept here
"""
nas = data.get("NAS-IP-Address", data.get("NAS-Identifier", None))
username = data.get("User-Name", "")
2020-11-29 09:33:40 +00:00
# For proxified request, split
username = username.split("@", 1)[0]
2020-11-28 14:42:08 +00:00
mac = data.get("Calling-Station-Id", "")
2020-11-29 09:33:40 +00:00
# Get all required objects from API
data_from_api = api_client().view(
"radius/authorize/{0}/{1}/{2}".format(
urllib.parse.quote(nas or "None", safe=""),
urllib.parse.quote(username or "None", safe=""),
urllib.parse.quote(mac or "None", safe="")
))
2020-11-28 14:42:08 +00:00
nas_type = data_from_api["nas"]
user = data_from_api["user"]
user_interface = data_from_api["user_interface"]
2020-11-29 09:33:40 +00:00
if not nas_type or nas_type and nas_type["port_access_mode"] == "802.1X":
2020-11-28 14:42:08 +00:00
result, log, password = check_user_machine_and_register(
nas_type, user, user_interface, nas, username, mac)
2020-11-28 14:42:08 +00:00
logger.info(log.encode("utf-8"))
logger.info(username.encode("utf-8"))
if not result:
return radiusd.RLM_MODULE_REJECT
else:
2018-04-13 20:11:55 +00:00
return (
radiusd.RLM_MODULE_UPDATED,
(),
((str("NT-Password"), str(password)),),
)
2016-12-08 14:13:41 +00:00
else:
return (radiusd.RLM_MODULE_UPDATED, (), (("Auth-Type", "Accept"),))
2016-12-08 14:13:41 +00:00
2018-04-13 20:11:55 +00:00
2016-12-08 14:13:41 +00:00
@radius_event
def post_auth(data):
2018-04-14 15:30:14 +00:00
""" Function called after the user is authenticated
"""
nas = data.get("NAS-IP-Address", data.get("NAS-Identifier", None))
2020-11-28 14:42:08 +00:00
nas_port = data.get("NAS-Port-Id", data.get("NAS-Port", None))
mac = data.get("Calling-Station-Id", None)
2020-11-29 09:33:40 +00:00
# Get all required objects from API
data_from_api = api_client().view(
2020-11-28 14:42:08 +00:00
"radius/post_auth/{0}/{1}/{2}".format(
urllib.parse.quote(nas or "None", safe=""),
urllib.parse.quote(nas_port or "None", safe=""),
urllib.parse.quote(mac or "None", safe="")
2020-11-28 14:42:08 +00:00
))
nas_type = data_from_api["nas"]
port = data_from_api["port"]
switch = data_from_api["switch"]
2020-11-29 09:33:40 +00:00
# If proxified request
2017-09-14 15:24:12 +00:00
if not nas_type:
2020-11-28 14:42:08 +00:00
logger.info("Proxified request, nas unknown")
2017-09-14 15:24:12 +00:00
return radiusd.RLM_MODULE_OK
2020-11-29 09:33:40 +00:00
# If the request is from a switch (wired connection)
2020-11-28 14:42:08 +00:00
if switch:
2020-11-29 09:33:40 +00:00
# For logging
2020-11-28 14:42:08 +00:00
sw_name = switch["name"] or "?"
2020-11-29 21:37:42 +00:00
room = port["room"] or "Unknown room" if port else "Unknown port"
2020-11-28 14:42:08 +00:00
out = decide_vlan_switch(data_from_api, mac, nas_port)
reason, vlan_id, decision, attributes = out
2018-08-30 00:11:14 +00:00
if decision:
2020-05-16 01:57:29 +00:00
log_message = "(wired) %s -> %s [%s%s]" % (
2020-11-28 15:24:36 +00:00
sw_name + ":" + nas_port + "/" + str(room),
2018-08-30 00:11:14 +00:00
mac,
vlan_id,
2020-05-16 01:57:29 +00:00
(reason and ": " + reason),
2018-08-30 00:11:14 +00:00
)
logger.info(log_message)
2020-11-29 09:33:40 +00:00
# Apply vlan from decide_vlan_switch
2018-08-30 00:11:14 +00:00
return (
radiusd.RLM_MODULE_UPDATED,
(
("Tunnel-Type", "VLAN"),
("Tunnel-Medium-Type", "IEEE-802"),
("Tunnel-Private-Group-Id", "%d" % int(vlan_id)),
)
+ tuple(attributes),
(),
2018-08-30 00:11:14 +00:00
)
else:
2020-11-28 15:24:36 +00:00
log_message = "(wired) %s -> %s [Reject %s]" % (
sw_name + ":" + nas_port + "/" + str(room),
2018-08-30 00:11:14 +00:00
mac,
2020-05-16 01:57:29 +00:00
(reason and ": " + reason),
2018-08-30 00:11:14 +00:00
)
logger.info(log_message)
return (radiusd.RLM_MODULE_REJECT, tuple(attributes), ())
2016-12-08 14:13:41 +00:00
2020-11-29 09:33:40 +00:00
# Else it is from wifi
else:
return radiusd.RLM_MODULE_OK
2016-12-08 14:13:41 +00:00
2018-04-13 20:11:55 +00:00
def check_user_machine_and_register(nas_type, user, user_interface, nas_id, username, mac_address):
2020-05-16 01:57:29 +00:00
"""Check if username and mac are registered. Register it if unknown.
Return the user ntlm password if everything is ok.
2020-11-29 09:33:40 +00:00
Used for 802.1X auth
"""
if not user:
2020-11-29 09:33:40 +00:00
# No username provided
2020-05-16 01:57:29 +00:00
return (False, "User unknown", "")
2020-11-29 09:33:40 +00:00
2020-11-28 14:42:08 +00:00
if not user["access"]:
2020-05-16 01:57:29 +00:00
return (False, "Invalid connexion (non-contributing user)", "")
2020-11-29 09:33:40 +00:00
2020-11-28 14:42:08 +00:00
if user_interface:
if user_interface["user_pk"] != user["pk"]:
return (
False,
2020-05-16 01:57:29 +00:00
"Mac address registered on another user account",
"",
)
2020-11-29 09:33:40 +00:00
2020-11-28 14:42:08 +00:00
elif not user_interface["active"]:
2020-05-16 01:57:29 +00:00
return (False, "Interface/Machine disabled", "")
2020-11-29 09:33:40 +00:00
2020-11-28 14:42:08 +00:00
elif not user_interface["ipv4"]:
2020-11-29 09:33:40 +00:00
# Try to autoassign ip
try:
api_client().view(
"radius/assign_ip/{0}".format(
urllib.parse.quote(mac_address or "None", safe="")
))
return (True, "Ok, new ipv4 assignement...", user.get("pwd_ntlm", ""))
except HTTPError as err:
return (False, "Error during ip assignement %s" % err.response.text, "")
else:
2020-11-28 14:42:08 +00:00
return (True, "Access ok", user.get("pwd_ntlm", ""))
2020-11-29 09:33:40 +00:00
elif nas_type:
2020-11-29 09:33:40 +00:00
# The interface is not yet registred, try to autoregister if enabled
2020-11-28 14:42:08 +00:00
if nas_type["autocapture_mac"]:
try:
api_client().view(
"radius/autoregister/{0}/{1}/{2}".format(
urllib.parse.quote(nas_id or "None", safe=""),
urllib.parse.quote(username or "None", safe=""),
urllib.parse.quote(mac_address or "None", safe="")
))
return (True, "Access Ok, Registering mac...", user["pwd_ntlm"])
except HTTPError as err:
return (False, "Error during mac register %s" % err.response.text, "")
2020-11-29 09:33:40 +00:00
return (False, "Autoregistering is disabled", "")
2017-10-04 11:50:12 +00:00
else:
2020-05-16 01:57:29 +00:00
return (False, "Unknown interface/machine", "")
else:
2020-05-16 01:57:29 +00:00
return (False, "Unknown interface/machine", "")
2020-11-28 14:42:08 +00:00
def set_radius_attributes_values(attributes, values):
2020-11-29 09:33:40 +00:00
"""Set values of parameters in radius attributes"""
2020-11-28 14:42:08 +00:00
return (
2020-11-28 15:24:36 +00:00
(str(attribute["attribute"]), str(attribute["value"] % values))
2020-11-28 14:42:08 +00:00
for attribute in attributes
)
def decide_vlan_switch(data_from_api, user_mac, nas_port):
2020-05-16 01:57:29 +00:00
"""Function for selecting vlan for a switch with wired mac auth radius.
2020-11-29 09:33:40 +00:00
Two modes exist : in strict mode, a registered user cannot connect with
their machines in a non-registered user room
Sequentially :
2020-05-16 01:57:29 +00:00
- all modes:
2020-11-29 09:33:40 +00:00
- unknown NAS : VLAN_OK,
- unknown port : Decision set in Re2o RadiusOption
- No radius on this port : VLAN_OK
- force : replace VLAN_OK with vlan provided by the database
2018-12-04 19:00:18 +00:00
- mode strict:
2020-05-16 01:57:29 +00:00
- no room : Decision set in Re2o RadiusOption,
- no user in this room : Reject,
- user of this room is banned or disable : Reject,
- user of this room non-contributor and not whitelisted:
2020-11-29 09:33:40 +00:00
Decision set in Re2o RadiusOption
- all modes :
2020-05-16 01:57:29 +00:00
- mac-address already registered:
- related user non contributor / interface disabled:
2020-11-29 09:33:40 +00:00
Decision set in Re2o RadiusOption
2020-05-16 01:57:29 +00:00
- related user is banned:
2020-11-29 09:33:40 +00:00
Decision set in Re2o RadiusOption
2020-05-16 01:57:29 +00:00
- user contributing : VLAN_OK (can assign ipv4 if needed)
- unknown interface :
- register mac disabled : Decision set in Re2o RadiusOption
2020-11-29 09:33:40 +00:00
- register mac enabled : redirect to webauth (not implemented)
2018-12-04 19:00:18 +00:00
Returns:
2020-05-16 01:57:29 +00:00
tuple with :
- Reason of the decision (str)
2018-12-04 19:00:18 +00:00
- vlan_id (int)
- decision (bool)
2020-11-29 09:33:40 +00:00
- Other Attributs (attribut:str, value:str)
"""
2020-11-28 14:42:08 +00:00
2020-11-29 09:33:40 +00:00
# Get values from api
2020-11-28 14:42:08 +00:00
nas_type = data_from_api["nas"]
room_users = data_from_api["room_users"]
port = data_from_api["port"]
port_profile = data_from_api["port_profile"]
switch = data_from_api["switch"]
user_interface = data_from_api["user_interface"]
radius_option = data_from_api["radius_option"]
EMAIL_STATE_UNVERIFIED = data_from_api["EMAIL_STATE_UNVERIFIED"]
RADIUS_OPTION_REJECT = data_from_api["RADIUS_OPTION_REJECT"]
USER_STATE_ACTIVE = data_from_api["USER_STATE_ACTIVE"]
2020-11-29 09:33:40 +00:00
# Values which can be used as parameters in radius attributes
2019-09-10 17:11:14 +00:00
attributes_kwargs = {
2020-11-28 14:42:08 +00:00
"client_mac": str(user_mac),
2020-11-29 09:33:40 +00:00
# magic split
2020-11-28 14:42:08 +00:00
"switch_port": str(nas_port.split(".")[0].split("/")[-1][-2:]),
2020-11-28 15:24:36 +00:00
"switch_ip": str(switch["ipv4"])
2019-09-10 17:11:14 +00:00
}
2020-11-28 14:42:08 +00:00
extra_log = ""
2018-07-11 17:37:22 +00:00
2020-11-29 09:33:40 +00:00
# If the port is unknown, do as in RadiusOption
2020-11-28 14:42:08 +00:00
if not port or not port_profile:
2018-12-04 19:00:18 +00:00
return (
2020-05-16 01:57:29 +00:00
"Unknown port",
2020-11-28 14:42:08 +00:00
radius_option["unknown_port_vlan"] and radius_option["unknown_port_vlan"]["vlan_id"] or None,
radius_option["unknown_port"] != RADIUS_OPTION_REJECT,
set_radius_attributes_values(
radius_option["unknown_port_attributes"], attributes_kwargs),
2018-12-04 19:00:18 +00:00
)
2020-11-29 09:33:40 +00:00
# If a vlan is precised in port config, we use it in place of VLAN_OK
2020-11-28 14:42:08 +00:00
if port_profile["vlan_untagged"]:
DECISION_VLAN = int(port_profile["vlan_untagged"]["vlan_id"])
2020-11-29 21:37:42 +00:00
extra_log = "Force sur vlan %s" % str(DECISION_VLAN)
2019-09-09 15:59:43 +00:00
attributes = ()
else:
2020-11-28 14:42:08 +00:00
DECISION_VLAN = radius_option["vlan_decision_ok"]["vlan_id"]
attributes = set_radius_attributes_values(
radius_option["ok_attributes"], attributes_kwargs)
2020-05-16 01:57:29 +00:00
# If the port is disabled in re2o, REJECT
2020-11-28 14:42:08 +00:00
if not port["state"]:
return ("Port disabled", None, False, ())
2020-05-16 01:57:29 +00:00
# If radius is disabled, decision is OK
2020-11-28 14:42:08 +00:00
if port_profile["radius_type"] == "NO":
return (
2020-05-16 01:57:29 +00:00
"No Radius auth enabled on this port" + extra_log,
DECISION_VLAN,
True,
attributes,
)
2020-05-16 01:57:29 +00:00
# If 802.1X is enabled, people has been previously accepted.
# Go to the decision vlan
2020-11-28 14:42:08 +00:00
if (nas_type["port_access_mode"], port_profile["radius_type"]) == ("802.1X", "802.1X"):
2018-12-04 19:00:18 +00:00
return (
2020-05-16 01:57:29 +00:00
"Accept authentication 802.1X",
2018-12-04 19:00:18 +00:00
DECISION_VLAN,
2019-09-09 15:59:43 +00:00
True,
attributes,
2018-12-04 19:00:18 +00:00
)
2018-06-30 22:17:24 +00:00
2020-05-16 01:57:29 +00:00
# Otherwise, we are in mac radius.
# If strict mode is enabled, we check every user related with this port. If
2020-11-29 09:33:40 +00:00
# all users and clubs are disabled, we reject to prevent from sharing or
2020-05-16 01:57:29 +00:00
# spoofing mac.
2020-11-28 14:42:08 +00:00
if port_profile["radius_mode"] == "STRICT":
if not port["room"]:
2018-12-04 19:00:18 +00:00
return (
2020-05-16 01:57:29 +00:00
"Unkwown room",
2020-11-28 14:42:08 +00:00
radius_option["unknown_room_vlan"] and radius_option["unknown_room_vlan"]["vlan_id"] or None,
radius_option["unknown_room"] != RADIUS_OPTION_REJECT,
set_radius_attributes_values(
radius_option["unknown_room_attributes"], attributes_kwargs),
2018-12-04 19:00:18 +00:00
)
2020-11-28 14:42:08 +00:00
if not room_users:
2018-12-04 19:00:18 +00:00
return (
2020-05-16 01:57:29 +00:00
"Non-contributing room",
2020-11-28 14:42:08 +00:00
radius_option["non_member_vlan"] and radius_option["non_member_vlan"]["vlan_id"] or None,
radius_option["non_member"] != RADIUS_OPTION_REJECT,
set_radius_attributes_values(
radius_option["non_member_attributes"], attributes_kwargs),
)
all_user_ban = True
at_least_one_active_user = False
for user in room_users:
if not user["is_ban"] and user["state"] == USER_STATE_ACTIVE:
all_user_ban = False
if user["email_state"] != EMAIL_STATE_UNVERIFIED and (user["is_connected"] or user["is_whitelisted"]):
2020-11-28 14:42:08 +00:00
at_least_one_active_user = True
if all_user_ban:
return (
"User is banned or disabled",
radius_option["banned_vlan"] and radius_option["banned_vlan"]["vlan_id"] or None,
radius_option["banned"] != RADIUS_OPTION_REJECT,
set_radius_attributes_values(
radius_option["banned_attributes"], attributes_kwargs),
)
if not at_least_one_active_user:
return (
"Non-contributing member or unconfirmed mail",
radius_option["non_member_vlan"] and radius_option["non_member_vlan"]["vlan_id"] or None,
radius_option["non_member"] != RADIUS_OPTION_REJECT,
set_radius_attributes_values(
radius_option["non_member_attributes"], attributes_kwargs),
2018-12-04 19:00:18 +00:00
)
2020-05-16 01:57:29 +00:00
# else: user OK, so we check MAC now
2020-11-29 09:33:40 +00:00
# If mac is unknown,
if not user_interface:
# We try to register mac, if autocapture is enabled
# Final decision depend on RADIUSOption set in re2o
# Something is not implemented here...
if nas_type["autocapture_mac"]:
return (
"Unknown mac/interface",
radius_option["unknown_machine_vlan"] and radius_option["unknown_machine_vlan"]["vlan_id"] or None,
radius_option["unknown_machine"] != RADIUS_OPTION_REJECT,
set_radius_attributes_values(
radius_option["unknown_machine_attributes"], attributes_kwargs),
)
# Otherwise, if autocapture mac is not enabled,
else:
2020-11-29 09:33:40 +00:00
return (
"Unknown mac/interface",
radius_option["unknown_machine_vlan"] and radius_option["unknown_machine_vlan"]["vlan_id"] or None,
radius_option["unknown_machine"] != RADIUS_OPTION_REJECT,
set_radius_attributes_values(
radius_option["unknown_machine_attributes"], attributes_kwargs),
)
# Mac/Interface is found, check if related user is contributing and ok
# If needed, set ipv4 to it
else:
if user_interface["is_ban"]:
return (
"Banned user",
radius_option["banned_vlan"] and radius_option["banned_vlan"]["vlan_id"] or None,
radius_option["banned"] != RADIUS_OPTION_REJECT,
set_radius_attributes_values(
radius_option["banned_attributes"], attributes_kwargs),
)
if not user_interface["active"]:
return (
"Disabled interface / non-contributing member",
radius_option["non_member_vlan"] and radius_option["non_member_vlan"]["vlan_id"] or None,
radius_option["non_member"] != RADIUS_OPTION_REJECT,
set_radius_attributes_values(
radius_option["non_member_attributes"], attributes_kwargs),
)
# If settings is set to related interface vlan policy based on interface type:
if radius_option["radius_general_policy"] == "MACHINE":
DECISION_VLAN = user_interface["vlan_id"]
if not user_interface["ipv4"]:
try:
api_client().view(
2020-11-29 09:33:40 +00:00
"radius/assign_ip/{0}".format(
urllib.parse.quote(user_mac or "None", safe="")
))
2018-12-04 19:00:18 +00:00
return (
2020-11-29 09:33:40 +00:00
"Ok, assigning new ipv4" + extra_log,
DECISION_VLAN,
True,
attributes,
2018-12-04 19:00:18 +00:00
)
2020-11-29 09:33:40 +00:00
except HTTPError as err:
2018-12-04 19:00:18 +00:00
return (
2020-11-29 09:33:40 +00:00
"Error during ip assignement %s" % err.response.text + extra_log,
2018-12-04 19:00:18 +00:00
DECISION_VLAN,
2019-09-09 15:59:43 +00:00
True,
attributes,
2018-12-04 19:00:18 +00:00
)
2020-11-29 09:33:40 +00:00
else:
return (
"Interface OK" + extra_log,
DECISION_VLAN,
True,
attributes,
)