#!/usr/bin/perl -w



use strict;
use Template;
use CGI;

my $cgi = new CGI;
my $cgiVars = $cgi->Vars ();
my $action = $cgiVars->{action};

my $dir = $1 if ($0 =~ m!(.+)/!);
chdir ($dir) if $dir;

my $template = Template->new ({
	INCLUDE_PATH => [".", "Templates"],
	COMPILE_EXT => ".ttc",
	COMPILE_DIR => "../tmp/TTcache",
	INTERPOLATE => 1,
	START_TAG => quotemeta('<%'),
	END_TAG => quotemeta('%>'),
});

my $page = $cgiVars->{p};
$page = "1" unless $page;
$page =~ s@(\.\.|/)@@g;
$page = "notfound" unless ( -f "Templates/$page.html");
my $vars = { page => $page };
my $output;
$template->process ("template.html", $vars, \$output)
	|| die $template->error();

print "Status: 404 Not Found\r\n" if $page eq "notfound";
print "Content-type: text/html; charset=utf-8\r\n\r\n";
print $output;
