#!/cygdrive/c/Perl/bin/perl  -d
{
  $file = "access.log";
  $access = "/cygdrive/c/Program*/Apache*/Apache2.2/logs/access.log";
  @out2 = `ls $access`;
  open LOGS, "$access" or die "didn't open file\n";
  while ( <LOGS> ) {
	s/- -//;
		# first get ip and date out
	($ip, $date,undef,$access_type,$dir) = split/\s+/;
		# ignore line if attack, i.e., the directory to access is full of garbage
	next if (length $dir > 200);
		# get month and year and translate May to a 5
	(undef,$month,$year) = split/\//, $date;
	$mon = &get_month;
	($year) = split/:/, $year;
		# now get what files they accessed (Birds, family_pics)
		# get rid of beginning / in directory
	$dir =~ s,^/,,;
	($base_dir, $next) = split/\//, $dir;
		# want the directories in lower case for later compairsons
	$base_dir =~ tr/[A-Z]/[a-z]/;
		# if $base_dir equals next, we want the Barbie one
	if ($base_dir eq "nej") {
		$base_dir = $next;
		$base_dir =~ tr/[A-Z]/[a-z]/;
	}
		# ignore our own accesses
	next if ($ip =~ /192.168.0/);
		# save record for later processing
	push (@record, "$year  $mon  $base_dir $ip");
  }
  @all = sort(@record);
  		# now find out how many accesses
  $lmonth = 0;
  foreach $line (@all) {
  	($year, $mon,  $dir, $ip) = split /\s+/, $line;
		# check to see if it is a new month or not
	if ($mon ne $lmonth) {
			# if available, print previous month totals
		if ($lmonth) {
			&print_totals;
			}
			# zero out totals
		$bird = 0;
		%bird_ip = {};
		$family = 0;
		%family_ip = {};
		$barbie = 0;
		%barbie_ip = {};
		$robots = 0;
		$lmonth = $mon;
	}
	if ($dir =~ /birds/) {
		$bird ++;
		$bird_ip{$ip} ++;
	}elsif ($dir =~ /family/) {
		$family ++;
		$family_ip{$ip} ++;
	}elsif ($dir =~ /barbie/) {
		$barbie ++;
		$barbie_ip{$ip} ++;
	}elsif ($dir =~ /robot/) {
		$robots++;
	}
  }
  &print_totals;
}
sub print_totals {
  $btot = scalar (keys %bird_ip) -1;
  $ftot = scalar (keys %family_ip) -1;
  $dtot = scalar (keys %barbie_ip) -1;
  print "\nTotals for: $lmonth $year\n";
  print "                Birds     Family    Barbie\n";
  printf "# accesses %10d %10d %10d\n", $bird, $family, $barbie;
  printf "unique ips %10d %10d %10d\n", $btot, $ftot, $dtot;
}

sub get_month {
	my %mon = ('Jan' => '01',
		   'Feb' => '02',
		   'Mar' => '03',
		   'Apr' => '04',
		   'May' => '05',
		   'Jun' => '06',
		   'Jul' => '07',
		   'Aug' => '08',
		   'Sep' => '09',
		   'Oct' => '10',
		   'Nov' => '11',
		   'Dec' => '12');
	return $mon{$month};
}
