From 6224a16e179ae5b89b452623c3f2c7095b59f4cd Mon Sep 17 00:00:00 2001 From: Nigel Kukard <nkukard@lbsd.net> Date: Sat, 22 Jun 2013 21:54:18 +0000 Subject: [PATCH] Cleaned up radius statuses --- opentrafficshaper/plugins/radius/radius.pm | 58 ++++++++++++++-------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/opentrafficshaper/plugins/radius/radius.pm b/opentrafficshaper/plugins/radius/radius.pm index 1c1be38..6cc7d7c 100644 --- a/opentrafficshaper/plugins/radius/radius.pm +++ b/opentrafficshaper/plugins/radius/radius.pm @@ -188,44 +188,58 @@ sub server_read { 'ClassName' => "Class A", 'Limits' => "$trafficLimitTx / $trafficLimitRx", 'BurstLimits' => "$trafficLimitTxBurst / $trafficLimitRxBurst", - 'Status' => $pkt->rawattr('Acct-Status-Type'), + 'Status' => getStatus($pkt->rawattr('Acct-Status-Type')), }; $globals->{'users'}->{$username} = $user; - $logger->log(LOG_DEBUG,"=> Code: $user->{'status'}, User: $user->{'username'}, IP: $user->{'ip'}, Group: $user->{'group'}, Class: $user->{'class'}, Limits: $user->{'limits'}, Burst: $user->{'burstlimits'}"); + $logger->log(LOG_DEBUG,"=> Code: $user->{'Status'}, User: $user->{'Username'}, IP: $user->{'IP'}, Group: $user->{'Group'}, Class: $user->{'Class'}, Limits: $user->{'Limits'}, Burst: $user->{'BurstLimits'}"); } +# Convert status into something easy to useful +sub getStatus +{ + my $status = shift; + + if ($status == 1) { + return "new"; + } elsif ($status == 2) { + return "offline"; + } elsif ($status == 3) { + return "online"; + } else { + return "unknown"; + } +} +# Simple function to reduce everything to kbit +sub getKbit +{ + my ($counter,$quantifier) = @_; + # If there is no counter, return 0 + return 0 if (!defined($counter)); + # We need a quantifier + return undef if (!defined($quantifier)); + # Initialize counter + my $newCounter = $counter; + if ($quantifier =~ /^m$/i) { + $newCounter = $counter * 1024; + } elsif ($quantifier =~ /^k$/i) { + $newCounter = $counter * 1; + } else { + return undef; + } - - - - - - - - - - - - - - - - - - - - + return $newCounter; +} 1; # vim: ts=4 -- GitLab