Re: Accounting scripts for RADIUS detail file

Mark Conway Wirt (mark@intrepid.net)
Sun, 15 Oct 1995 21:33:34 -0400

On Sat, 14 Oct 1995, Jim Covington wrote:

> I am looking for a script that will give me a client-id and account time in
> seconds or hours from the detail file created by RADIUS. I want to be able
> to dump this info into some database or accounting program and bill
> customers for time as well as unlimited access.
> Jim Covington
> TexNet Internet Services
> El Paso, Texas 79936-3710
> (915) 857-1800
>

Jim,

I just got our pormaster up yesterday (had never seen one before Friday),
so this script is a little rough -- I did it on the fly yesterday for
debugging.

One thing to note: The script must be run suid root, because of the
permissions on the detail file. It's a perl script that passed
taintperl, so it should be pretty safe, but if you feel uncomfortable
with suid scripts, just run it from root's account.

I haven't added any parsing of dates yet -- it uses the entire detail file.

=========================================================================

#!/usr/bin/perl
##########################################################################
# A little script that will figure out who is logged into the system
# by looking at the radius logs.
#
# Mark Conway Wirt
# Copyright Intrepid Technologies, 1995
# All rights reserved, because we're reserved kind-a-guys...
##########################################################################

# Do stuff for to make suid secure..

$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin';
$ENV{'SHELL'} = '/bin/sh' if $ENV{'SHELL'} ne '';
$ENV{'IFS'} = '' if $ENV{'IFS'} ne '';

# Add your path below!
$rad_file = "/var/adm/radacct/portmaster-1.intrepid.net/detail";

open(log_file,"cat $rad_file |") || die "Couldn\'t open log file";

while (<log_file>)
{
$in_line = $_;
chop($in_line);
if ($in_line =~ /User-Name/)
{
$name = (split(/=/,$in_line))[1];
$name = (split(/\"/,$name))[1];
#print "$name\n";
}
if ($in_line =~ /Acct-Session-Time/)
{
$t_time = (split(/=/,$in_line))[1];
$t_time = (split(/ /,$t_time))[1];
$time_on{$name} += $t_time;
}

}

close(log_file);

print "\nCumulative time for users: \n";

$count = 0;
foreach $name (sort(keys(%time_on)))
{
$time_on{$name} = $time_on{$name}/60.0;
printf(" Name: %10s time: %10.2f minutes \n",$name,$time_on{$name});
}

print "\n";

================Cut here================================================

-------------------------------------------------------------------------
Mark Conway Wirt | Intrepid Technologies Inc.
mark@intrepid.net | Shepherdstown West Virginia
finger mark@intrepid.net for PGP | (304) 876-1199
http://www.intrepid.net/ | A Full-Service Internet Provider
-------------------------------------------------------------------------