aboutsummaryrefslogtreecommitdiff
path: root/orig/minimun
blob: a61a4cab90b7a4fff047e08526d27e4147bd7d79 (plain)
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
52
53
54
55
56
#!/usr/bin/perl
use strict;
use warnings;

use File::Temp qw( tempfile );
use File::Copy;

chdir('/tmp');

my($buffer, %FORM);

if ($ENV{'REQUEST_METHOD'} eq "GET") {
    $buffer = $ENV{'QUERY_STRING'};
}
my @pairs = split(/&/, $buffer);

foreach my $pair (@pairs) {
    my ($name, $val) = split(/=/, $pair);
    $val =~ tr/+/ /;
    $val =~ s/%(..)/pack("C", hex($1))/eg;
    $val =~ s/([#%_\$^&{}\\])//g;
    $FORM{$name} = $val;
}

my ($fh, $filename) = tempfile(UNLINK => 1);
copy("%%DEST%%/format.tex",$fh);

print $fh "\n";

if (index($ENV{'PATH_INFO'},'award') != -1){
    say $fh "\\award{$FORM{'committee'}}{$FORM{'country'}}{$FORM{'award'}}{$FORM{'school'}}";
}
elsif (index($ENV{'PATH_INFO'},'room') != -1){
    say $fh "\\room{$FORM{'committee'}}";
}
else{
    print "Content-type: text/html\n";
    print "Status: 404 File Not Found Error\n\n"; 
    print '<a href="/">404 Error. Go back.</a>';
    die;
}

say $fh "\\bye";

`/usr/bin/pdftex "$filename"`;
unlink "$filename.log";
open(DOC, '<', "$filename.pdf") or do {
    print "Content-type: text/html\n";
    print "Status: 400 Bad Request Error\n\n";
    print '<h1>400 Bad Request</h1>';
    die;
};
print "Content-type: application/pdf\n\n";
print <DOC>;
close(DOC);
unlink "$filename.pdf";