Hi All.

As you probably all know, searching through radius detail files can be a
tedious task. I hope this makes you lives a little easier.

It probably isn't the best perl program ever written, but I'm sure some of
you will find it useful.

This program is licensed under the GPL, so feel free to modify it and send
any improvements back to me.

Andrew Tait
System Administrator
Country NetLink Pty, Ltd
E-Mail: [EMAIL PROTECTED]
WWW: http://www.cnl.com.au
30 Bank St Cobram, VIC 3644, Australia
Ph: +61 (03) 58 711 000
Fax: +61 (03) 58 711 874

"It's the smell! If there is such a thing." Agent Smith - The Matrix


# Radgrep v1.00
# Radgrep is to radius detail files what exigrep is to exim mainlog files.
# Don't run with scissors.
# Copyright � 2002 Andrew Tait. All rights reserved.
# Last modifed 26th April 2002.
# E-mail: [EMAIL PROTECTED]
# WWW: http://www.arduous.net/projects/radgrep/
#
# This program is designed to accept radius detail files from STDIN and
# either display a record if $pattern appears in it. You can use this to
# find all records that belong to a particular user, IP address, etc.
#
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

$pattern;
$reverse = "false";
$rdup = "false";
$acctsessionid;
$username;
$timestamp;


while ($arg = shift(@ARGV)) {
        if ($pattern ne "") {die "Unexpected argument $arg.\n";}
        if ($arg eq "-v") {$reverse = "true";}
        elsif ($arg eq "--help")
                {
                print "Usage: radgrep [-v] pattern\n";
                print "Options\n";
                print " -v          Invert pattern matching\n";
                print " -d          Remove duplicate entries\n";
                print " --help      Display this help and exit\n";
                exit 0;
                }
        elsif ($arg eq "-d") {$rdup = "true";}
        else {$pattern = $arg;}

}

while ($radline = <>)
        {
        $radentry = $radentry.$radline;
        if ($radline eq "\n")
                {
                ($temp1,$temp2) = split(/Acct-Session-Id = "/,$radentry);
                ($acctsessionid,$temp3) = split(/\"/,$temp2);
                ($temp1,$temp2) = split(/User-Name = "/,$radentry);
                ($username,$temp3) = split(/\"/,$temp2);
                ($temp1,$temp2) = split(/Timestamp = /,$radentry);
                ($timestamp,$temp3) = split(/\n/,$temp2);
                $key=join($acctsessionid,$username,$timestamp);
                if ($sessions{$key})
                        {
                        #print STDERR "Duplicate entry $key\n";
                        #Duplicate entry, ignore
                        if ($rdup eq "true")
                                {
                                $radentry = "";
                                next;
                                }
                        }
                $sessions{$key}=1;
                if ($radentry =~ /$pattern/)
                        {
                        if($reverse eq "false") {print STDOUT $radentry}
                        }
                else
                        {
                        if ($reverse eq "true") {print STDOUT $radentry}
                        }
                $radentry = "";
                }
        }

if (!($radentry eq ""))
        {
        #radius fragment left, better process that too!

                ($temp1,$temp2) = split(/Acct-Session-Id = "/,$radentry);
                ($acctsessionid,$temp3) = split(/\"/,$temp2);
                ($temp1,$temp2) = split(/User-Name = "/,$radentry);
                ($username,$temp3) = split(/\"/,$temp2);
                ($temp1,$temp2) = split(/Timestamp = /,$radentry);
                ($timestamp,$temp3) = split(/\n/,$temp2);
                $key=join($acctsessionid,$username,$timestamp);
                if ($sessions{$key})
                        {
                        #print STDERR "Duplicate entry $key\n";
                        #Duplicate entry, ignore
                        if ($rdup eq "true")
                                {
                                $radentry = "";
                                exit 0;
                                }
                        }

                if ($radentry =~ /$pattern/)
                        {
                        if($reverse eq "false") {print STDOUT $radentry}
                        }
                else
                        {
                        if ($reverse eq "true") {print STDOUT $radentry}
                        }
                $radentry = "";
        }





- 
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html

Reply via email to