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

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

#
# Main routine
#
my %params = &read_params("GET");
my $buffer;
my $url;

if($params{"url"}) {
	my %ret = &retrieve($params{"url"});
	$buffer = $ret{"response"}->content;
	$url = $params{"url"};
} else {
	my $count = 1;
	my $delim = "";
	while(<STDIN>) {
		if($count eq 1) {
			$delim = $_;
			chop($delim);
			chop($delim);
			$count = 2;
		} elsif($count eq 2) {
			/filename=\"(.*?)\"/;
			$url = $1;
			$url =~ s/\\/\//g;
			$url = "file:///".$url;
			$count = 3;
		} elsif($count eq 3) {
			$count = 4;
		} elsif(! /$delim/) {
			$buffer = $buffer.$_;
		}
	}

	if($buffer eq "" || $buffer eq "\n") {
	print "Status: 302
Location: http://www.w3.org/P3P/validator.html
Content-type: text/html

<html><body>Please input URL</body></html>
"
	}
}


# Logging
open AAA, ">> /home/koike/validator/20000510/policy.log";
print AAA scalar(localtime()), " ", $url, "\n";
close AAA;

# HTTP headers
my $pr = new P3P::Print;
$pr->pri("Content-type: text/html\n\n");

# HTML headers
$pr->pri("<!DOCTYPE HTML PUBLIC '-//IETF//DTD HTML//EN'>\n");
$pr->pri("<html>\n");
$pr->pri("<head>\n");
$pr->pri("<title>P3P Validator</title>\n");
$pr->pri("<Style type='text/css'>
BODY {
	margin: 2em 1em 2em 30px;
	font-family: 'Arial', 'Helvetica', sans-serif;
	font-size: 11pt;
	color: black;
	background: white;
	background-position: top left;
	background-attachment: fixed;
	background-repeat: no-repeat;
}

A:hover {
	background: #FFFF90
} 

H1 {
	font-family: 'Arial', 'Helvetica', sans-serif;
	font-size: 24pt;
	font-weight: normal;
	color: #0050B2; 
}

H2 {
	font-family: 'Arial', 'Helvetica', sans-serif;
	font-size: 18pt;
	font-weight: normal;
	color: #0050B2; 
}

H3 {
	font-family: 'Arial', 'Helvetica', sans-serif;
	font-size: 14pt;
	font-weight: normal;
	color: #0050B2; 
}

H4{
	font-family: 'Arial', 'Helvetica', sans-serif;
	font-size: 12pt;
	font-weight: normal;
	color: #0050B2; 
}

DL DT {
	font-weight: bold;
}

DL DD {
	margin-bottom: 0.7em;
}

PRE {
	font-family: 'Courier New', 'Courier';
}

TT {
	font-family: 'Courier New', 'Courier';
	color: brown;
}

.big {
	font-size: 15pt;
	font-weight: bold;
}

.step {
	font-size: 15pt;
	color: #0050B2; 
}

.result {
	font-size: 13pt;
	font-weight: bold;
}

.result2 {
	font-size: 12pt;
	font-weight: normal;
}

.mes {
	font-size: 10pt;
	margin-left: 30px;
}
</style>\n");
$pr->pri("</head>\n");
$pr->pri("<body>\n");

# Title
$pr->pri("<h2>Results of Policy  validation</h2>\n");

# policy check
my $step4 = new P3P::PolicyCheck;
my $result4 = $step4->check2($buffer, $url, $pr, 1);

$pr->pri("<hr>\n</body>\n</html>\n");

1;
