Skip to content

Commit

Permalink
- Added additional info to accounting packets.
Browse files Browse the repository at this point in the history
- Corrected account-session-time value
  • Loading branch information
Oooska committed Jan 17, 2014
1 parent 4630410 commit 0d0da06
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
18 changes: 14 additions & 4 deletions Plugins/Contrib/RADIUS/Client.cs
Expand Up @@ -27,7 +27,7 @@ class RADIUSClient
public Packet lastReceievedPacket { get; private set; } //Last packet received from server
public bool authenticated { get; private set; } //Whether username was successfully authenticated

private DateTime accountingStartTime { get; set; }
public DateTime accountingStartTime { get; set; }

public byte[] NAS_IP_Address { get; set; }
public string NAS_Identifier { get; set; }
Expand Down Expand Up @@ -168,7 +168,8 @@ public bool startAccounting(string username, Packet.Acct_Authentic authType)
accountingRequest.addAttribute(Packet.AttributeType.NAS_IP_Address, NAS_IP_Address);
if (!String.IsNullOrEmpty(NAS_Identifier))
accountingRequest.addAttribute(Packet.AttributeType.NAS_Identifier, NAS_Identifier);

if (!String.IsNullOrEmpty(called_station_id))
accountingRequest.addAttribute(Packet.AttributeType.Called_Station_Id, called_station_id);

if (authType != Packet.Acct_Authentic.Not_Specified)
accountingRequest.addAttribute(Packet.AttributeType.Acct_Authentic, (int)authType);
Expand Down Expand Up @@ -232,12 +233,14 @@ public bool interimUpdate(string username)
p.addAttribute(Packet.AttributeType.Acct_Session_Id, sessionId);
p.addAttribute(Packet.AttributeType.Acct_Status_Type, (int)Packet.Acct_Status_Type.Interim_Update);

p.addAttribute(Packet.AttributeType.Acct_Session_Time, (DateTime.Now - accountingStartTime).Seconds);
p.addAttribute(Packet.AttributeType.Acct_Session_Time, (int)(DateTime.Now - accountingStartTime).TotalSeconds);

if (NAS_IP_Address != null)
p.addAttribute(Packet.AttributeType.NAS_IP_Address, NAS_IP_Address);
if (!String.IsNullOrEmpty(NAS_Identifier))
p.addAttribute(Packet.AttributeType.NAS_Identifier, NAS_Identifier);
if (!String.IsNullOrEmpty(called_station_id))
p.addAttribute(Packet.AttributeType.Called_Station_Id, called_station_id);


m_logger.DebugFormat("Attempting to send interim-update for user {0}", username);
Expand Down Expand Up @@ -297,7 +300,14 @@ public bool stopAccounting(string username, Packet.Acct_Terminate_Cause? termina
if(terminateCause != null)
accountingRequest.addAttribute(Packet.AttributeType.Acct_Terminate_Cause, (int) Packet.Acct_Terminate_Cause.User_Request);

accountingRequest.addAttribute(Packet.AttributeType.Acct_Session_Time, (DateTime.Now - accountingStartTime).Seconds);
if (NAS_IP_Address != null)
accountingRequest.addAttribute(Packet.AttributeType.NAS_IP_Address, NAS_IP_Address);
if (!String.IsNullOrEmpty(NAS_Identifier))
accountingRequest.addAttribute(Packet.AttributeType.NAS_Identifier, NAS_Identifier);
if (!String.IsNullOrEmpty(called_station_id))
accountingRequest.addAttribute(Packet.AttributeType.Called_Station_Id, called_station_id);

accountingRequest.addAttribute(Packet.AttributeType.Acct_Session_Time, (int)(DateTime.Now - accountingStartTime).TotalSeconds);

m_logger.DebugFormat("Attempting to send session-stop for user {0}", username);

Expand Down
1 change: 1 addition & 0 deletions Plugins/Contrib/RADIUS/PluginImpl.cs
Expand Up @@ -415,6 +415,7 @@ public void SessionChange(System.ServiceProcess.SessionChangeDescription changeD

try
{
m_logger.DebugFormat("About to send accounting stop packet. Session has been active {0} seconds.", (DateTime.Now - session.client.accountingStartTime).TotalSeconds);
session.client.stopAccounting(session.username, session.terminate_cause);
}
catch (RADIUSException re)
Expand Down
2 changes: 1 addition & 1 deletion Plugins/Contrib/RADIUS/SessionManager.cs
Expand Up @@ -81,7 +81,7 @@ public void Set_Session_Terminate(DateTime time, TimerCallback tcb)
{
this.session_terminate = time;

int ms = (time - DateTime.Now).Seconds;
int ms = (int)(time - DateTime.Now).TotalSeconds;

this.session_terminate_timer = new Timer(tcb, this, ms * 1000, 30000);
//Create timer
Expand Down

0 comments on commit 0d0da06

Please sign in to comment.