#!/usr/bin/perl # file print/dump program in perl # fewer variabvles displayed # TS 20000703 # invoke thusly: /cgi-bin/logview.cgi?filename #$logname =$ARGV[0]; #$logname =shift; $logname =$ENV{'QUERY_STRING'}; local($errflag, $got, $buf, $amt, $count, $dquot); local($logfile, $now, $mon, $day, $year, $datestamp, $monstamp, $daystamp); local($M, $BegDate, $D, $Y, $ClientName); ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst)=localtime(time); $month=$mon+1; $year=$year+1900; $monstamp = sprintf("%.2d",$month); $daystamp = sprintf("%.2d",$mday); $datestamp = "$year/$monstamp/$daystamp"; $dquot = '"'; $prefix = 'data/'; $logfile = $prefix.$logname; #$logfile= "data/inx.log"; print < $logname Log Dump

$logname Log Dump (Printed:$datestamp)

EOF #print "Now open file: ", $logfile, " \n"; $count=0; open(LGFILE, "$logfile") || print "
Cant open $logfile for read: $!\n"; #print "opened file", $count, " \n"; while () { chop (@lines = ); } @lines = reverse @lines; foreach (@lines) { #print '
', $_, "\n"; ($HitCount, $BegDate, $AccessDateTime, $ClientIP, $ReferIP, $HostIP) = split(/:/); $count=$count+$HitCount; $D = substr($AccessDateTime,3,2); $M = substr($AccessDateTime,0,2); $Y = substr($AccessDateTime,6,4); $ClientName = 'Initial NULL'; ($IP1, $IP2, $IP3, $IP4) = split(/\./,$ClientIP); if ($IP1 == 63 and $IP2 == 17 and $IP3 == 197) { $ClientName = '$IP1.Tenacious@PeoplePC'; } else { $ClientName = &DSNLookup($ClientIP); } print "", "
"; } print "
Day DateTime of Accesse Client IP Client Name Refer OR Host IP Host IP Begin Date
", $AccessDateTime, "", $ClientIP, "", $ClientName, "", $ReferIP, "", $HostIP, "", $BegDate, "
\n"; print '

Done LogViewParm.cgi Log:', $logname, ' Record Hit Count is ', $count, "\n"; print ''; print "\n"; # end main sub DSNLookup { $IP= $_[0]; #print "here is ip: ", $_[0], "\n"; open(IPFILE, "data/ip.dat") || die "Cant open ipfile for read: $!\n"; #print "opened file", $count, " \n"; while () { #chop (@lines = ); ($IPaddress, $Name) = split(/:/); @dip = split(/\./,$IPaddress); $nodes = split(/\./,$IPaddress); @pip = split(/\./,$IP); #print $_, "\n"; if ($nodes == 4) { if ($IP == $IPaddress) { close(IPFILE); return $Name.$nodes; } } elsif ($nodes == 3 ) { if ($pip[0] == $dip[0] and $pip[1] == $dip[1] and $pip[2] == $dip[2]) { close(IPFILE); return $Name.$nodes; } } elsif ($nodes == 2 ) { if ($pip[0] == $dip[0] and $pip[1] == $dip[1]) { close(IPFILE); return $Name.$nodes; } } #if ($IP < $IPaddress) { close(IPFILE); return $IP; } } close(IPFILE); return $IP; }