From 8b5f05b8c463aab4e872f8175bbc838b92a226c0 Mon Sep 17 00:00:00 2001 From: Federico Capoano Date: Fri, 20 Oct 2023 16:57:28 +0200 Subject: [PATCH] [tmp] Changes done during debugging [skip ci] --- openwisp_radius/api/freeradius_views.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/openwisp_radius/api/freeradius_views.py b/openwisp_radius/api/freeradius_views.py index 641c264c..e0293a31 100644 --- a/openwisp_radius/api/freeradius_views.py +++ b/openwisp_radius/api/freeradius_views.py @@ -113,12 +113,19 @@ def _check_client_ip_and_return(self, request, uuid): def _mac_address_roaming_auth(self, username, request): calling_station_id = RE_MAC_ADDR.match(username)[0] - # Get the open session for the roaming user + logger.warn(f'calling station id -> {calling_station_id}') + # Get the most recent open session for the roaming user open_session = ( RadiusAccounting.objects.select_related('organization__radius_settings') .filter(calling_station_id=calling_station_id, stop_time=None) + .order_by('-start_time') .first() ) + if open_session: + logger.warn(f'{open_session.username} - {open_session.called_station_id} - {open_session.calling_station_id}') + logger.warn(f'RadiusSetting - {open_session.organization.radius_settings.get_setting("mac_addr_roaming_enabled")}') + else: + logger.warn('No open session') if open_session and open_session.organization.radius_settings.get_setting( 'mac_addr_roaming_enabled' ): @@ -134,7 +141,9 @@ def _mac_address_roaming_auth(self, username, request): 86400, ) request._mac_allowed = True - return username, request + return username, request + else: + return None, request def _radius_token_authenticate(self, request): if request.data.get('status_type', None) in UNSUPPORTED_STATUS_TYPES: @@ -147,8 +156,12 @@ def _radius_token_authenticate(self, request): if cached_orgid: return self._check_client_ip_and_return(request, cached_orgid) else: + logger.warn(f'from _radius_token_authenticate: {username} - {RE_MAC_ADDR.search(username)}') if username and RE_MAC_ADDR.search(username): username, request = self._mac_address_roaming_auth(username, request) + if username is None: + # raise AuthenticationFailed(_('Mac auth roaming failed')) + return try: radtoken = RadiusToken.objects.get( user=auth_backend.get_users(username).first() @@ -540,6 +553,8 @@ def post(self, request, *args, **kwargs): return response def perform_create(self, serializer): + if self.request.auth is None: + return organization = Organization.objects.get(pk=self.request.auth) serializer.save(organization=organization)