#!/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();
@path2=(/\//,$ENV{'PATH_INFO'});
my @path=split(/\//,$ENV{'PATH_INFO'});
$location = 'Liverpool';
$page = $path[-1];
$page =~ s/Liverpool/Uxbridge/g;
$SQL = qq"select title,searchphrase from words where id = \"$page\";";
&Do_SQL;
$pointer = $sth->fetchrow_hashref;
$phrase = $pointer->{'title'};
$search = $pointer->{'searchphrase'};
$rawsearch = $search;
$search =~ y/a-zA-Z/n-za-mN-ZA-M/;
$search =~ y/0-56-9/4-90-3/;
$search =~ s/ /+/gs;
$phrase =~ s/Uxbridge/$location/g;
@id = split(" ", $phrase);
foreach $pid(@id) {
$piece = substr($pid, 0, 4);
$random = $random . $piece . "-";
};
chop($random);
$tag{'id'} = "$random";
$tag{'phrase'} = $phrase;
$SQL = qq"select name,id from tree where parent = \"0\" order by name";
&Do_SQL;
while (@data = $sth->fetchrow_array()) {
my $id = $data[1];
my $name = $data[0];
$tag{'cat'} = $tag{'cat'} . "$name
";
};
$SQL = qq"select referer,time from landing where id = \"$id\"";
&Do_SQL;
$pointer = $sth->fetchrow_hashref;
$referer2 = $pointer->{'referer'};
$referer2 =~ s/&/~t~/gs;
$landingtime = $pointer->{'time'};
$landingtime =~ s/ //gs;
$landingtime =~ s/://gs;
$landingtime =~ s/-//gs;
$tag{'header'} = "";
$useragent =~ s/\;/~e3~/g;
$tag{'feed'} = "";
navbar();
template();
sub template {
open (TEMP, "page.html");
@template = ;
close(TEMP);
foreach $line(@template) {
$line =~ s/{rosa (.*?)}/$tag{$1}/gs;
unless (($useragent =~ m/googlebot/i) || ($useragent =~ m/slurp/i) || ($useragent =~ m/msnbot/i)) {
$line =~ s/href="(.*?)">/href="$1">/gsi;
};
print $line;
};
};
sub navbar {
$back = "";
@path1 = reverse (@path);
$output1 = "Home >> ";
foreach $part(@path1) {
unless (($part eq "") || ($part eq $path[-1]) || ($part eq 'cgi-bin') || ($part eq 'rosa.pl') ) {
$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'};
};
$output = "$newpart" . $output;
unless (($part eq $path1[-1]) || ($part eq $location)) {
$output = " >> " . $output;
};
};
};
$output = $output . " >> $phrase";
$tag{'navbar'} = $output1 . $output;
};
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};
$status = "200 OK";
# 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\t$status\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);
}