#!/usr/local/bin/perl # radiusreport {{ package RadiusRecord; @calllog_template = ( 'Time', 'User-Name', 'Calling-Station-Id', 'Called-Station-Id', 'Acct-Session-Time', 'NAS-Port-Type', 'Acct-Input-Packets', 'Acct-Output-Packets', 'Acct-Input-Octets', 'Acct-Output-Octets', ); sub new { shift; bless(ref $_[0] ? $_[0] : { @_ }); } sub print { my $self = shift; print "record dated ", ${$self}{"Time"}, " {\n"; for (keys %$self) { print "\t$_: ", $self->{$_}, "\n"; } print "}\n"; } sub calllog { my $self = shift; if ($self->{'Acct-Status-Type'} eq 'Stop' && $self->{'Service-Type'} eq 'Framed' && $self->{'NAS-Port-Type'} ne 'Virtual' ) { &::printjoined(@{$self}{@calllog_template}); } } }} sub printjoined { if ($::commasep) { print STDOUT "\"", join("\",\"", @_), "\"\n"; } else { print STDOUT join("\t", @_), "\n"; } } # START use Getopt::Std; getopts("c"); $commasep = 1 if defined $opt_c; # XXX log files #open(CALLLOG, ">&STDOUT"); #select(((select CALLLOG), $|=1)[0]); $/ = ""; &printjoined(@RadiusRecord::calllog_template); while (<>) { # process radius accounting log line-by-line # # log = (record empty-line)* # record = date attribute+ # attribute = name = value @F = split(/\n/m); $record = new RadiusRecord('Time', $F[0], map { (/^\t(\S+)\s*=\s*(\S+)$/) ? ($1, $2) : (); } @F[1..$#F]); $record->{'User-Name'} =~ tr/A-Z/a-z/; #$record->print; calllog $record; } 0; # vi:set ai|set sw=4: