#!perl -w
use strict;
$|++;
my $GO_LOG = 'c:\inetpub\scripts\log-dbweb.txt';
my ($day, $month, $year) = (localtime) [3,4,5];
my $location=$ENV{REMOTE_ADDR};
my $result = eval {
die unless defined (my $res = $ENV{PATH_INFO});
       die unless $res =~ s/^\///;
      my $query = $ENV{QUERY_STRING};
      if (defined $query and length $query) {
        $res = "$query";
      }
      $res;
    };
    if ($@) {
      print "Status: 404 Not Found\n\n";
      exit 0;
    }

if ($location=~/192.168.1/){
   $location="inside";
} else {
   $location="outside";
}

$month=$month+1;
$year=$year+1900;

    print "Location: $result\n\n";
    my $pid = fork;
    $pid = 0 unless defined $pid;   # be the kid if fork failed
    exit 0 if $pid;
    ## child...
    close(STDOUT);

if ($ENV{HTTP_REFERER}) {
    open GOLOG, ">>$GO_LOG" or die "Cannot open $GO_LOG: $!";
    flock(GOLOG,2);                 # wait for exclusive
    seek GOLOG, 0,2;  # seek to end, refresh buffers

 print GOLOG join("\t",
    "$month/$day/$year",",",$result,",",$ENV{HTTP_REFERER},",",$location),"\n";
    close GOLOG;

}
