Skip to content

Commit

Permalink
[tmp] Changes done during debugging [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesifier committed Oct 20, 2023
1 parent ef2c9bf commit 8b5f05b
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions openwisp_radius/api/freeradius_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
):
Expand All @@ -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:
Expand All @@ -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()
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 8b5f05b

Please sign in to comment.