#!/usr/bin/perl

# sqtimelog.pl (C)1998 by Miles Lott (milos@insync.net)
# Parse Squid access.log file, converting time field to a readable
# format, and laying out necessary fields.
#
# Usage:
#       sqtimelog access.conf > acc.log
#
#
# Your local network(s) - Define the second as "1.1.1" or some other
# bogus network if none is appropriate.  It will be ignored.
$localnet1 = "192.168.0";
$localnet2 = "192.168.1";

# Main works
open ( FILE, "<$ARGV[0]") || die "Couldn't open $ARGV[0]\n";
while (<FILE>) {
	@field = $_;

	# Print Date and time
	$timecon = scalar ( localtime ( $field[0]) );
	
	# Print username, user IP, website visited, and local IP addr
	if ( /$localnet1\.(.*?)\ http:\/\/(.*?)\ (.*?)\ (.*?)\ / ) { print "$timecon $3 GET http://$2 $localnet1\.$1" }
	if ( /$localnet2\.(.*?)\ http:\/\/(.*?)\ (.*?)\ (.*?)\ / ) { print "$timecon $3 GET http://$2 $localnet2\.$1" }
	if ( /$localnet1\.(.*?)\ CONNECT(.*?)\ (.*?)\ (.*?)\ (.*?)\ / ) { print "$timecon $4 CONNECT http://$3 $localnet1\.$1" }
	if ( /$localnet2\.(.*?)\ CONNECT(.*?)\ (.*?)\ (.*?)\ (.*?)\ / ) { print "$timecon $4 CONNECT http://$3 $localnet2\.$1" }

	# Add newline
	print"\n";
}
close FILE;


