#!/usr/bin/perl
print "Content-type: text/html \n\n";

##################################################################
## Script to fill file for the top10 attackers presentation	##
## The data is taken from the file /attacks/ids/<ban_ip.txt>	##
## The FORMAT:							##
## IP-address attack type Date-Time				##
##################################################################

use IO::File;
use Socket;
use File::Copy;
use strict;

my ($i,$j,$p,$pp,$ppp,$N,$M,$k,$m,$y,$line,$ref,$ref0,$where,$string,$str,$str1,$new_max);
my (@lines,@words,@records);
$j=0;
$y=0;		# records index

$p="/home/httpd/htdocs/saturn/attacks/ids/ban_ip.txt";

open(LN,$p) or die "Can't open : $!";	# Open file with largest RFC number
while(!eof(LN))		{		#########################
$line=readline(LN);						# Read file lines
$records[$y]=$line;						# Write records array
chomp($line);							#
$y++;							 	#
			}		#########################
print "N=",$y,"\n";
close(LN);

$ppp="/home/httpd/top10_1.txt";

sysopen(EDT,$ppp, O_RDWR|O_TRUNC|O_CREAT) or die "Can't open : $!";	# Open top10 to edit
$j=0;
for($i=($y-10);$i<$y;$i++)	{				#########################
		$line=$records[$i];							#
print "L=",$line,"\n";
		@words=split / /,$line;							#
		chomp($words[3]);							#
		$lines[$j]=$words[3]." ".$words[2]." ".$words[0]." ".$words[1];		#
	print "FL=",$lines[$j],"\n";							#
print EDT $lines[$j],"\n";		# Write to >top10_1.txt>			#
					$j++;						#
					}			#########################
close(EDT);

print "END\n";
