| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
use CGI; |
| 4 |
use Digest::MD5 qw(md5_hex); |
| 5 |
|
| 6 |
$q = new CGI; |
| 7 |
print $q->header(); |
| 8 |
|
| 9 |
$contentType = $ENV{"CONTENT_TYPE"}; |
| 10 |
print "content type: $contentType\n"; |
| 11 |
|
| 12 |
if ($contentType =~ /^multipart\/form-data/) { |
| 13 |
foreach my $key ($q->param) { |
| 14 |
foreach my $value (scalar $q->param($key)) { |
| 15 |
if ($key =~ /text/) { |
| 16 |
$retValue = $value; |
| 17 |
} else { |
| 18 |
$retValue = md5_hex($value); |
| 19 |
} |
| 20 |
print "key: $key, value: $retValue\n"; |
| 21 |
} |
| 22 |
} |
| 23 |
} else { |
| 24 |
#$contentLength = $ENV{"CONTENT_LENGTH"}; |
| 25 |
#print "content length: $contentLength\r\n"; |
| 26 |
|
| 27 |
$data = $q->param('POSTDATA'); |
| 28 |
$data =~ s/--\S*--$//; # remove ending boundary |
| 29 |
@parts = split(/--\S*\r\n/, $data); |
| 30 |
shift(@parts); |
| 31 |
foreach (@parts) { |
| 32 |
#print "raw: $_"; |
| 33 |
($header, $content) = split("\r\n\r\n"); |
| 34 |
@headerFields = split("\r\n", $header); |
| 35 |
foreach (@headerFields) { |
| 36 |
($fieldName, $value) = split(": "); |
| 37 |
print "header: $fieldName, value: '$value'\n"; |
| 38 |
} |
| 39 |
$content =~ s/\r\n//; |
| 40 |
print "content: $content\n\n"; |
| 41 |
} |
| 42 |
} |