#!/usr/bin/perl
#
# wrtten by Yuichi Koike ($Id: add.pl,v 1.1 2000/10/05 21:31:06 koike Exp $) with great help of Ted
#

# Modules
use strict;
require "mylib.pl";

# Init
my %params = &read_params("GET");
my $url = $params{"url"};
my $name = $params{"name"};
my $email = $params{"email"};

# check if this request is from validator.w3.org
unless($ENV{"HTTP_REFERER"} =~ /http:\/\/validator\.w3\.org(?::|\/)/) {
	print("Content-type: text/html

<html><body>
<h1>Illegal Access</h1>
This attempt for the registration is denied.</body></html>");
	exit;
}

# insert data into DB
my $db_result = `echo \"select * from p3psites where uri = '$url';\" | /usr/bin/mysql -u p3p -h db p3p`;
if($db_result) {
	print ("Content-type: text/html

<html><body>
<h1>Information</h1>
Your site is already registered in our list.
</body></html>");
	exit;
}

$url =~ s/\'/\\\'/g;
$name =~ s/\'/\\\'/g;
$email =~ s/\'/\\\'/g;
`echo \"insert into p3psites (uri, name, email) values ('$url', '$name', '$email') \"| /usr/bin/mysql -u p3p -h db p3p`;

open MAIL, "| mail -s P3P_Compliant_Site_added koike\@w3.org";
print MAIL "url = $url\nname = $name\nemail = $email\n";
close MAIL;

#open MAIL, "| mail -s P3P_Compliant_Site_added feng\@w3.org";
#print MAIL "url = $url\nname = $name\nemail = $email\n";
#close MAIL;

print "Status: 302
Location: http://www.w3.org/P3P/compliant_sites
Content-type: text/html

<html><body>moved</body></html>";
exit;
1;

