1 |
#!/usr/bin/perl |
2 |
|
3 |
# Remember that CGI programs have to close out the HTTP header |
4 |
# (with a pair of newlines), after giving the Content-type: |
5 |
# and any other relevant or available header information. |
6 |
|
7 |
# This test program always reports success (200 OK), and |
8 |
# correctly uses SERVER_PROTOCOL and REQUEST_METHOD to decide |
9 |
# whether or not to send the headers and content. |
10 |
|
11 |
# Feb 3, 2000 -- updated to support POST, and avoid passing |
12 |
# Malicious HTML Tags as described in CERT's CA-2000-02 advisory. |
13 |
|
14 |
$now=`date`; |
15 |
chomp($now); |
16 |
if ($ENV{"SERVER_PROTOCOL"} ne "HTTP/0.9") { |
17 |
print "HTTP/1.0 200 OK\r\nDate: $now\r\n"; |
18 |
print "Connection: close\r\n"; |
19 |
print "Content-type: text/html; charset=ISO-8859-1\r\n\r\n"; |
20 |
} |
21 |
|
22 |
exit 0 if ($ENV{"REQUEST_METHOD"} eq "HEAD"); |
23 |
|
24 |
print "<html><head><title>Boa nph-CGI test</title></head><body>\n"; |
25 |
print "<H2>Boa nph-CGI test</H2>\n\n"; |
26 |
|
27 |
print "Date: $now\n"; |
28 |
|
29 |
print "<P>\n\n<UL>\n"; |
30 |
|
31 |
foreach (keys %ENV) { |
32 |
$a= $ENV{$_}; |
33 |
$a=~s/&/&/g; |
34 |
$a=~s/</</g; |
35 |
$a=~s/>/>/g; |
36 |
print "<LI>$_ == $a\n"; |
37 |
} |
38 |
|
39 |
print "</UL>\n"; |
40 |
|
41 |
if ($ENV{REQUEST_METHOD} eq "POST") { |
42 |
print "Input stream:<br><hr><pre>\n"; |
43 |
while (<stdin>) { |
44 |
s/&/&/g; |
45 |
s/</</g; |
46 |
s/>/>/g; |
47 |
print "$_"; |
48 |
} |
49 |
print "</pre><hr>\n"; |
50 |
} |
51 |
|
52 |
print "id: ", `id`, "\n<p>\n"; |
53 |
|
54 |
if ($ENV{"QUERY_STRING"}=~/ident/ && $ENV{"REMOTE_PORT"} ne "") { |
55 |
|
56 |
# Uses idlookup-1.2 from Peter Eriksson <pen@lysator.liu.se> |
57 |
# ftp://coast.cs.purdue.edu/pub/tools/unix/ident/tools/idlookup-1.2.tar.gz |
58 |
# Could use modification to timeout and trap stderr messages |
59 |
$a="idlookup ". |
60 |
$ENV{"REMOTE_ADDR"}." ".$ENV{"REMOTE_PORT"}." ".$ENV{"SERVER_PORT"}; |
61 |
$b=qx/$a/; |
62 |
print "ident output:<br><pre>\n$b</pre>\n"; |
63 |
} |
64 |
|
65 |
print "\n<EM>Boa http server</EM>\n"; |
66 |
print "</body></html>\n"; |
67 |
|
68 |
exit 0; |
69 |
|