#!/usr/bin/perl use CGI; $q = new CGI; $| = 1; require ("./common.cgi"); ############################################### # Script by Ewan J. Fisher # # (c) 2005 Platinum Horizons Limited ############################################### &Create_DB_Connection; &log(); $ip = $ENV{REMOTE_ADDR}; $other = join(":", sort(keys(%ENV))); $other = ":" . $other; my @path=split(/\//,$ENV{'PATH_INFO'}); $location = $path[1]; $location =~ tr/_/ /; if ($location eq "") { open (INDEX, "../index.html") || die print "cant open index.html $_"; @index3 = ; close(INDEX); print @index3; exit(0); }; $SQL = qq"select name from tree where id = \"$path[-1]\""; &Do_SQL; $pointer = $sth->fetchrow_hashref; $parent = $pointer->{'name'}; $parent =~ s/Uxbridge/$location/gsi; $SQL = qq"select name from tree where id = \"$path[2]\""; &Do_SQL; $pointer = $sth->fetchrow_hashref; $main = $pointer->{'name'}; $main =~ s/Uxbridge/$location/gsi; $tag{'phrase'} = "$location $main"; tree(); results(); navbar(); template(); sub tree { $counter = 1; $tag{'listings'} = $tag{'listings'} . ""; if ($path[2] eq "") { $path[2] = "0"; }; $SQL = qq"select id,name from tree where parent = \"$path[-1]\" order by name;"; &Do_SQL; while (@data = $sth->fetchrow_array()) { my $id = $data[0]; my $name = $data[1]; $name =~ s/Uxbridge/$location/gsi; $tag{'listings'} = $tag{'listings'} . "\n"; if (($counter % 3) == 0) { $tag{'listings'} = $tag{'listings'} . ""; }; $counter ++; } $tag{'listings'} = $tag{'listings'} . "
$location $name
"; }; sub results { $SQL = qq"select id,title from words where parent = \"$path[-1]\" order by title;"; &Do_SQL; $counter = 1; $tag{'listings'} = $tag{'listings'} . ""; while (@data = $sth->fetchrow_array()) { my $id = $data[0]; my $name = $data[1]; $name =~ s/Uxbridge/$location/gsi; $id =~ s/Uxbridge/$location/gsi; $id =~ tr/ /_/; $tag{'listings'} = $tag{'listings'} . "\n"; if (($counter % 3) == 0) { $tag{'listings'} = $tag{'listings'} . ""; }; $counter ++; } $tag{'listings'} = $tag{'listings'} . "
$name
"; }; sub navbar { $back = "../"; @path1 = reverse (@path); $output = "Home >> "; foreach $part(@path1) { unless (($part eq "") || ($part eq $path[-1]) || ($part eq 'cgi-bin') || ($part eq '0') || ($part eq 'Liverpool')){ $back = $back . "../"; if ($part eq $location) { $newpart = $part; } else { $SQL = qq"select name from tree where id = \"$part\""; &Do_SQL; $pointer = $sth->fetchrow_hashref; $newpart = $pointer->{'name'}; }; if ("0" eq $path[-1]) { $output = $output . " >> $newpart"; } else { $output = $output . "$newpart "; } unless (($part eq $path1[-1]) || ($part eq $location) || ($part eq 'Liverpool')) { # $output = " $part>> " . $output; }; }; }; $tag{'navbar'} = $output; unless ("0" eq $path[-1]) { $tag{'navbar'} = $tag{'navbar'} . ">> $parent"; }; $tag{'navbar'} =~ s/>> >>/>>/gsi; }; sub template { open (TEMP, "cat.html"); @template = ; close(TEMP); foreach $line(@template) { $line =~ s/{rosa (.*?)}/$tag{$1}/gs; print $line; }; }; sub log { $cookie = $q->cookie('elmo'); if ($cookie ne "") { $flag = "N"; # cookie exists ### Read the Cookie ID $id = $q->cookie('elmo'); print $q->header; } else { $flag = "Y"; # cookie created $id = rand(); $id = substr($id, 2, ); my $cookie = $q->cookie(-name=>'elmo', -value=>"$id", -domain=>"liverpoolcollege.co.uk", -expires=>'+3y', -path=>'/'); $createcookie = 1; print $q->header(-cookie=>$cookie); } $ip = $ENV{REMOTE_ADDR}; $other = join(":", sort(keys(%ENV))); $other = ":" . $other; # Read the other HTTP Headers $referer = $ENV{HTTP_REFERER}; $other =~ s/\:HTTP_REFERER//; $useragent = $ENV{HTTP_USER_AGENT}; $useragent =~ s/\t/ /; $other =~ s/\:HTTP_USER_AGENT//; $a1 = $ENV{HTTP_ACCEPT}; $other =~ s/\:HTTP_ACCEPT//; $a2 = $ENV{HTTP_ACCEPT_CHARSET}; $other =~ s/\:HTTP_ACCEPT_CHARSET//; $a3 = $ENV{HTTP_ACCEPT_ENCODING}; $other =~ s/\:HTTP_ACCEPT_ENCODING//; $a4 = $ENV{HTTP_ACCEPT_LANGUAGE}; $other =~ s/\:HTTP_ACCEPT_LANGUAGE//; $a5 = $ENV{HTTP_CACHE_CONTROL}; $other =~ s/\:HTTP_CACHE_CONTROL//; $a6 = $ENV{HTTP_CLIENT_IP}; $other =~ s/\:HTTP_CLIENT_IP//; $a7 = $ENV{HTTP_CNEONCTION}; $other =~ s/\:HTTP_CNEONCTION//; $a8 = $ENV{HTTP_CONNECTION}; $other =~ s/\:HTTP_CONNECTION//; $a9 = $ENV{HTTP_COOKIE}; $other =~ s/\:HTTP_COOKIE//; $a10 = $ENV{HTTP_HOST}; $other =~ s/\:HTTP_HOST//; $a11 = $ENV{HTTP_IF_MODIFIED_SINCE}; $other =~ s/\:HTTP_IF_MODIFIED_SINCE//; $a12 = $ENV{HTTP_KEEP_ALIVE}; $other =~ s/\:HTTP_KEEP_ALIVE//; $a14 = $ENV{HTTP_SWF_HDR_MSG}; $other =~ s/\:HTTP_SWF_HDR_MSG//; $a15 = $ENV{HTTP_UA_COLOR}; $other =~ s/\:HTTP_UA_COLOR//; $a16 = $ENV{HTTP_UA_CPU}; $other =~ s/\:HTTP_UA_CPU//; $a17 = $ENV{HTTP_UA_LANGUAGE}; $other =~ s/\:HTTP_UA_LANGUAGE//; $a18 = $ENV{HTTP_UA_OS}; $other =~ s/\:HTTP_UA_OS//; $a19 = $ENV{HTTP_UA_PIXELS}; $other =~ s/\:HTTP_UA_PIXELS//; $a20 = $ENV{HTTP_UA_VOICE}; $other =~ s/\:HTTP_UA_VOICE//; $a22 = $ENV{HTTP_VIA}; $other =~ s/\:HTTP_VIA//; $a23 = $ENV{HTTP_X_BLUECOAT_VIA}; $other =~ s/\:HTTP_X_BLUECOAT_VIA//; $a24 = $ENV{HTTP_FORWARDED_FOR}; $other =~ s/\:HTTP_FORWARDED_FOR//; $a25 = $ENV{HTTP_X_MOZ}; $other =~ s/\:HTTP_X_MOZ//; $a26 = $ENV{HTTP_X_NOVINET}; $other =~ s/\:HTTP_X_NOVINET//; # Set the date and time. @months = qw(01 02 03 04 05 06 07 08 09 10 11 12); @weekDays = qw(Sun Mon Tue Wed Thu Fri Sat Sun); ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime(); $year = 1900 + $yearOffset; $theTime = "$hour:$minute:$second, $weekDays[$dayOfWeek] $months[$month] $dayOfMonth, $year"; if ($dayOfMonth < 10) { $dayOfMonth = "0" . $dayOfMonth; }; $date = "$year$months[$month]$dayOfMonth"; if ($hour < 10) { $hour = "0" . $hour; }; if ($minute < 10) { $minute = "0" . $minute; }; if ($second < 10) { $second = "0" . $second; }; $time = "$hour$minute$second"; # Find out whats to be displayed. $request = $ENV{REQUEST_URI}; $server = $ENV{SERVER_NAME}; $protocol = $ENV{SERVER_PROTOCOL}; # LOG IT! open(LOG, ">>log.txt"); print LOG "$id\t\t$flag\t$ip\t$useragent\t$date\t$time\t$protocol\t$server\t$request\t$referer\t200 OK\t$a1\t$a2\t$a3\t$a4\t$a5\t$a6\t$a7\t$a8\t$a9\t$a10\t$a11\t$a12\t$a14\t$a15\t$a16\t$a17\t$a18\t$a19\t$a20\t$a22\t$a23\t$a24\t$a25\t$a26\t$other2\n"; close(LOG); }