2019-05-07 10:21:25 +02:00
|
|
|
|
// /**
|
|
|
|
|
// * File: SessionManager.cs
|
|
|
|
|
// * Author: haraldwolff
|
|
|
|
|
// *
|
|
|
|
|
// * This file and it's content is copyrighted by the Author and / or copyright holder.
|
|
|
|
|
// * Any use wihtout proper permission is illegal and may lead to legal actions.
|
|
|
|
|
// *
|
|
|
|
|
// *
|
|
|
|
|
// **/
|
|
|
|
|
using System;
|
2019-05-07 10:21:50 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using ln.types.net;
|
|
|
|
|
using ln.types.btree;
|
|
|
|
|
using ln.radius;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using ln.logging;
|
|
|
|
|
using ln.types.odb;
|
|
|
|
|
using ln.types.odb.mapped;
|
2019-05-07 12:54:48 +02:00
|
|
|
|
using skyspot.radius;
|
2019-05-10 13:27:06 +02:00
|
|
|
|
using System.Text;
|
|
|
|
|
using skyspot.hotspot;
|
2019-05-07 10:21:25 +02:00
|
|
|
|
namespace skyspot.session
|
|
|
|
|
{
|
|
|
|
|
public class SessionManager
|
|
|
|
|
{
|
2019-05-10 13:27:06 +02:00
|
|
|
|
public HotspotManager HotspotManager { get; }
|
|
|
|
|
public RadiusSecretsStore SecretsStore => HotspotManager.SecretsStore;
|
|
|
|
|
|
2019-05-07 12:54:48 +02:00
|
|
|
|
|
|
|
|
|
RadiusServer accountingRadius;
|
|
|
|
|
RadiusServer locatorRadius;
|
2019-05-07 10:21:50 +02:00
|
|
|
|
|
2019-05-10 13:27:06 +02:00
|
|
|
|
public SessionManager(HotspotManager hotspotManager)
|
2019-05-07 10:21:25 +02:00
|
|
|
|
{
|
2019-05-10 13:27:06 +02:00
|
|
|
|
HotspotManager = hotspotManager;
|
2019-05-07 10:21:50 +02:00
|
|
|
|
InitializeRadius();
|
2019-05-07 10:21:25 +02:00
|
|
|
|
}
|
2019-05-07 10:21:50 +02:00
|
|
|
|
|
|
|
|
|
public void Start()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void InitializeRadius()
|
|
|
|
|
{
|
2019-05-07 12:54:48 +02:00
|
|
|
|
accountingRadius= new RadiusServer(new IPEndPoint(IPAddress.Any,1812));
|
2019-05-09 09:53:48 +02:00
|
|
|
|
locatorRadius = new RadiusServer(new IPEndPoint(IPAddress.Any, 1816));
|
|
|
|
|
|
|
|
|
|
accountingRadius.LookupSecret = (endPoint) => SecretsStore.LookupSecret(endPoint);
|
|
|
|
|
locatorRadius.LookupSecret = (endPoint) => SecretsStore.LookupSecret(endPoint);
|
|
|
|
|
|
|
|
|
|
locatorRadius.MessageReceived = LocatorMessageReceived;
|
|
|
|
|
accountingRadius.MessageReceived = AccountingMessageReceived;
|
2019-05-07 10:21:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-10 13:27:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-05-09 09:53:48 +02:00
|
|
|
|
/**
|
|
|
|
|
* Locator Service
|
|
|
|
|
*
|
|
|
|
|
**/
|
|
|
|
|
void LocatorMessageReceived(RadiusServer radiusServer, RadiusMessage radiusMessage)
|
2019-05-07 10:21:50 +02:00
|
|
|
|
{
|
2019-05-09 09:53:48 +02:00
|
|
|
|
Logging.Log(LogLevel.INFO, "Radius Message received: {0}", radiusMessage);
|
|
|
|
|
switch (radiusMessage.Code)
|
|
|
|
|
{
|
|
|
|
|
case RadiusCode.AccessRequest:
|
|
|
|
|
LocatorAccessRequest(radiusServer, radiusMessage);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-05-07 10:21:50 +02:00
|
|
|
|
}
|
2019-05-09 09:53:48 +02:00
|
|
|
|
|
|
|
|
|
void LocatorAccessRequest(RadiusServer radiusServer, RadiusMessage radiusMessage)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* Accounting Service
|
|
|
|
|
*
|
|
|
|
|
**/
|
|
|
|
|
void AccountingMessageReceived(RadiusServer radiusServer, RadiusMessage radiusMessage)
|
2019-05-07 10:21:50 +02:00
|
|
|
|
{
|
|
|
|
|
Logging.Log(LogLevel.INFO, "Radius Message received: {0}", radiusMessage);
|
2019-05-09 09:53:48 +02:00
|
|
|
|
switch (radiusMessage.Code)
|
2019-05-07 10:21:50 +02:00
|
|
|
|
{
|
|
|
|
|
case RadiusCode.AccessRequest:
|
2019-05-09 09:53:48 +02:00
|
|
|
|
AccountingAccessRequest(radiusServer, radiusMessage);
|
2019-05-07 10:21:50 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-09 09:53:48 +02:00
|
|
|
|
void AccountingAccessRequest(RadiusServer radiusServer, RadiusMessage radiusMessage)
|
2019-05-07 10:21:50 +02:00
|
|
|
|
{
|
2019-05-09 09:53:48 +02:00
|
|
|
|
RadiusAttribute.UserName userName = radiusMessage.GetAttribute<RadiusAttribute.UserName>();
|
|
|
|
|
RadiusAttribute.UserPassword userPassword = radiusMessage.GetAttribute<RadiusAttribute.UserPassword>();
|
|
|
|
|
RadiusAttribute.CalledStationID calledStationID = radiusMessage.GetAttribute<RadiusAttribute.CalledStationID>();
|
|
|
|
|
|
|
|
|
|
if ((userName == null) || (calledStationID == null))
|
|
|
|
|
{
|
|
|
|
|
Logging.Log(LogLevel.WARNING, "InvalidRequest: UserName={0} CalledStationID={1}",userName,calledStationID);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MAC clientMac = new MAC(userName.AsText);
|
2019-05-10 13:27:06 +02:00
|
|
|
|
String networkName = calledStationID.AsText;
|
2019-05-09 09:53:48 +02:00
|
|
|
|
|
2019-05-10 13:27:06 +02:00
|
|
|
|
HotspotNetworkRuntime hotspotNetworkRuntime = HotspotManager.GetHotspotNetworkRuntime(networkName);
|
|
|
|
|
ClientSession clientSession = hotspotNetworkRuntime.GetSession(clientMac);
|
2019-05-09 09:53:48 +02:00
|
|
|
|
|
2019-05-10 13:27:06 +02:00
|
|
|
|
if (clientSession.CurrentProfile == null)
|
|
|
|
|
clientSession.CurrentProfile = hotspotNetworkRuntime.HotspotNetwork.DefaultClientProfile;
|
2019-05-09 09:53:48 +02:00
|
|
|
|
|
2019-05-10 13:27:06 +02:00
|
|
|
|
Logging.Log(LogLevel.INFO, "Accounting: Session start for client {0} on Network {1}",clientMac, networkName);
|
2019-05-07 10:21:50 +02:00
|
|
|
|
|
2019-05-10 13:27:06 +02:00
|
|
|
|
RadiusMessage reply = radiusMessage.ConstructReply(RadiusCode.AccessAccept);
|
|
|
|
|
reply.AddAttribute(new RadiusAttribute.FramedIPAddress().SetIP(IPv4.Parse("10.123.0.4")));
|
|
|
|
|
if (clientSession.CurrentProfile != null)
|
|
|
|
|
reply.AddAttribute(new RadiusAttribute.FilterID().SetText(clientSession.CurrentProfile.Name));
|
2019-05-07 10:21:50 +02:00
|
|
|
|
|
2019-05-10 13:27:06 +02:00
|
|
|
|
radiusServer.Send(reply);
|
|
|
|
|
}
|
2019-05-07 10:21:50 +02:00
|
|
|
|
|
2019-05-07 10:21:25 +02:00
|
|
|
|
}
|
|
|
|
|
}
|