#!/bin/perl ## # Lineparser - this program turns the silly livingston detail file # in to something more compact and more easily read # by computer (and human!). It also reduces the size # of the files by about 1/10th, greatly facilitating # storage. # # Copyright (C) 1995 # -Dave Andersen ## open(IN, $ARGV[0]) || die "Could not open file $ARGV[0]\n"; $begin_record = 1; $end_record = 0; # Variables # $date - 09/11/75 format $username $time - time online # $port -physical portmaster port $service - log or net # $host - their IP or machine connected to while () { chop; if (!length($_)) { if ($end_record) { printf("%-8.8s %-8.8s %-8.8s %-7.7s %-2.2d %-3.3s %-s\n", $date, $daytime, $username, $time, $port, $service, $host); } $end_record = 0; $begin_record = 1; next; } if ($begin_record && /^[a-zA-Z]/) { ($wday, $month, $mday, $daytime, $year) = split; $month = &convert_month($month); $year =~ s/19//; $date = sprintf("%2.2d/%2.2d/%2.2d", $month, $mday, $year); $begin_record = 0; $end_record = 1; next; } if ($begin_record) { next; } if (/User-Name/) { s/[^\"]*"([^\"]*).*/$1/; s/\s+//g; $username = sprintf("%-8s", $_); next; } if (/Acct-Status-Type/) { if (!/Stop/) { $begin_record = $end_record = 0; next; } } if (/Client-Port-Id/) { s/Client-Port-Id = //; $port = sprintf("%2.2d", $_); next; } if (/User-Service-Type/) { if (/Framed/) { $service = "net"; } else { $service = "log"; } next; } if (/Framed-Address/) { s/Framed-Address = //; $host = $_; } if (/Login-Host/) { s/Login-Host = //; $host = $_; } if (/Acct-Session-Time/) { s/Acct-Session-Time = //; s/\s+//g; $time = $_; next; } } sub convert_month { local($_) = $_[0]; if ($_ eq "Jan") { "01"; } elsif ($_ eq "Feb") { "02"; } elsif ($_ eq "Mar") { "03"; } elsif ($_ eq "Apr") { "04"; } elsif ($_ eq "May") { "05"; } elsif ($_ eq "Jun") { "06"; } elsif ($_ eq "Jul") { "07"; } elsif ($_ eq "Aug") { "08"; } elsif ($_ eq "Sep") { "09"; } elsif ($_ eq "Oct") { "10"; } elsif ($_ eq "Nov") { "11"; } elsif ($_ eq "Dec") { "12"; } else { "-1"; } }