1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#!/usr/bin/perl
use strict;
use warnings;
use IPC::Run qw(run);
use Time::HiRes qw( time );
chdir('%%DEST%%');
my ($buffer, @pairs, $pair, $name, $val, %FORM);
if ($ENV{'REQUEST_METHOD'} eq "GET") {
$buffer = $ENV{'QUERY_STRING'};
}
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $val) = split(/=/, $pair);
$val =~ tr/+/ /;
$val =~ s/%(..)/pack("C", hex($1))/eg;
$FORM{$name} = $val;
}
my ($in, $out);
$in = "\n";
if (index($ENV{'PATH_INFO'},'award.pdf') != -1){
$in .= "\\award{$FORM{'committee'}}{$FORM{'country'}}{$FORM{'award'}}{$FORM{'school'}}";
}
elsif (index($ENV{'PATH_INFO'},'room.pdf') != -1){
$in .= "\\room{$FORM{'committee'}}";
}
else{
print "Content-type: text/html\n";
print "Status: 404 File Not Found Error\n";
print "\n";
print '<a href="/">404 Error. Go back.</a>';
die;
}
$in .= "\\bye\n";
my $timestamp = time;
run ['/usr/bin/pdftex', '-jobname', "$timestamp", 'format.tex'], '<', \$in, '>', \$out;
print "Content-type: application/pdf\n\n";
open(DOC, '<', "$timestamp.pdf");
while (<DOC>){
print;
}
close(DOC);
unlink "$timestamp.pdf", "$timestamp.log";
|