#!/usr/bin/perl

$/="\n\n";
while(<>) {
        y/// == (13-1) or next; # 12 ^A'er ellers er den itu
        s/'/''/g;    # Data med ' => ''
        s/\\/\\\\/g;    # Data med \ => \\
	chomp;
	s/\n\n//g; # Record sep
	@field = split(/\n/,$_);
	$filename = shift @field; # /home/hotels/pi.dk/html/index.php3
	$IPText = shift @field; # 213.237.9.215
	$AuthUser = shift @field; # -
	$AuthName = shift @field; # -
	$hitDatetime = shift @field; # 2002-01-21 14:54:49
	$HostText = shift @field; # www.pi.dk
	$URLText = shift @field; # /
	$Status = shift @field; # 200
	$Status = $Status eq "-" ? 0 : $Status;
	$Size = shift @field; # 458
	$Size = $Size eq "-" ? 0 : $Size;
	$referer = shift @field; # http://www.sslug.dk/sponsor.html
	if($referer =~ m:[^/]+//([^/]+)(/\S*)?:) {
	    $RefererHostText = $1; # www.sslug.dk
	    $RefererURLText = $2; # /sponsor.html
	} else {
	    $RefererHostText = ""; # -
	    $RefererURLText = ""; # 
	}
	$BrowserText = shift @field; # Mozilla/5.0
	$XferTime = shift @field; # 1
	$MimeTypeText = shift @field; # text/html
	# if($RefererHostText and $MimeTypeText eq "text/html") {
	if($RefererHostText) {
	    $find_referer = 1;
	} else {  $find_referer = 0;}

	if($filename =~ m:/home/hotels/([^/]+): or 
	   $filename =~ m:/home/(httpd)/: or
	   $filename =~ m:.*?/hotel/([^/]+): or
	   $filename =~ m:.*?/person/([^/]+): or
	   $URLText =~ m:/~([^/]+): or # pi.dk/~tange
	   $Status == 408 or
	   $Status == 404 or
	   $Status == 400 or # www.=%&#.dk
	   $filename =~ /^proxy:/
	   ) { } else { die("Costumer not found in $_"); }
	$CostumerText = $1; # pi.dk
        print ("select addhit('",
	       join("','", $CostumerText, $IPText, $AuthUser, $AuthName,
		    $hitDatetime, $HostText, $URLText, $Status, $Size,
		    $RefererHostText, $RefererURLText, $BrowserText, $XferTime,
		    $MimeTypeText, $find_referer),
	       "');\n");
	#++$commit % 100 or do { print "commit;begin;"; };
    }
