#!/usr/bin/perl

#################################################################################
# cherrypicked.pl
#
################################################################################


use CGI;
use CGI::Carp qw(fatalsToBrowser);
use strict;

my $query = new CGI;
my %in = $query->Vars;

#print $query->header (-type=>'text/plain');
print $query->header (-type=>'text/html');

my $referer = $query->referer;

my $siteName = $in {'site'};
my $password = $in {'session'};

my $error = 0;

my $message = qq (<a href=http://www.cherrypicked.co.uk><img src='http://www.cherrypicked.co.uk/images/cherrylogo.gif' border='0' alt='Click to see the Cherry Picked database'></a><br /><br /><b>  Inaccurate or Unauthorised access.</b><br /><br />
The site you arrived from, the logo and URL <br />apparently taken from web site named $siteName <br />is not a Cherry Picked business.<br /><br /> Please call 01227 281611 for confirmation.<br /><br />Visit Cherry Picked to find other CherryPicked businesses.<br /><br /> );

#Preset the values so it does not match if $siteName or $password are blank
my $fileSite = "!invalid!";
my $filePassword ="!invalid!";

$referer =~ s/http:\/\///;
($referer)=split ("\/", $referer);

open (PASSWORD_FILE, "registered.pl") || die ($query->header . " Cannot open default file");

while (my $line = <PASSWORD_FILE>)
{
	chomp $line;
	if ($line =~ "=")
	{
		($fileSite, $filePassword) = split (/=/, $line);
	}
	if (($fileSite eq $siteName) and ($filePassword eq $password))
	{
		
		if ($referer eq $fileSite)
		{
			$message = "<a href=http://www.cherrypicked.co.uk><img src='http://www.cherrypicked.co.uk/images/cherrylogo.gif' border='0'></a><br /><br />Welcome to <a href=http://www.cherrypicked.co.uk>www.CherryPicked.co.uk verification. </a><br /><br />You arrived here from a <b>`Cherry Picked` Verified</b> site, <br /><br /><a href=http://$siteName target=_blank>$siteName</a><br /><br /> Cherry Picked businesses are those we trust to give you sterling service,<br />going by either our own experience, or the experience of others.<br />This page will only be accessed correctly by those <br />sites belonging to businesses with Cherry Picked verification.<br /><br />  Further verification is a presence in the<br /> <b>`Cherry Picked`</b> or <b>`All Businesses`</b> page at <br /><br /><a href=http://www.cherrypicked.co.uk>www.CherryPicked.co.uk</a>.<br /><br /><hr width='50%'><br /><br /></div>";
		}
		else
		{
			$message = "<a href=http://www.cherrypicked.co.uk><img src='http://www.cherrypicked.co.uk/images/cherrylogo.gif' border='0'></a><br /><br /> Welcome to <a href=http://www.cherrypicked.co.uk>www.cherrypicked.co.uk</a><br /><br />You arrived here from $referer but we <br />recognise that the link belongs to URL $siteName.<br /><br /> The web site address you arrived from is therefore not valid. <br /><br />$referer is apparently <b>NOT</b> a Cherry Picked business.<br /><br /> However, if your browser is not displaying a web site address at all, i.e. no address in these brackets [$referer] then it is likely that you need to go back to the web site, refresh your browser and try again, as you may be seeing what is in your computer`s cache memory.<br /><br />Please click the link above to be taken to the main site where a <br />listing of Cherry Picked businesses is available.<br /><br /></div>";
		}
	}
}

print <<ENDHTML;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CherryPicked.co.uk Verification</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="author" content="www.i-m-k.co.uk" />
<meta name="authorwebsite" content="http://www.i-m-k.co.uk" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<link rel="stylesheet" href="../standardstyleverify.css">
</head>
<body leftmargin="0" topmargin="0">
<table width="75%" border="0" cellspacing="0" cellpadding="2" align="center">
  <tr>
    <td>
      <div align="center"><br>
        <br>
$message
</div>
    </td>
  </tr>
</table>

</body>
</html>
ENDHTML


