1 #!/usr/bin/perl -w 2 3 use Config; 4 5 print "Content-type: text/plain\n\n"; 6 7 if ($ENV{'REQUEST_METHOD'} eq "POST") { 8 if ($ENV{'CONTENT_LENGTH'}) { 9 read(STDIN, $postData, $ENV{'CONTENT_LENGTH'}) || die "Could not get post data\n"; 10 } else { 11 $postData = ""; 12 } 13 14 @list = split(/&/, $ENV{'QUERY_STRING'}); 15 @values; 16 $values{'start'} = 0; 17 $values{'length'} = -1; 18 $values{'convert_newlines'} = 0; 19 foreach $element (@list) { 20 ($key, $value) = split(/=/, $element); 21 $values{$key} = $value; 22 } 23 24 # 'items' parameter would look like: 25 # <items> := <item>(','<item>)* 26 # <item> := <file> | <data> 27 # <file> := "file":<file-path> 28 # <data> := "data":<data-string> 29 @items = split(/,/, $values{'items'}); 30 $expectedData = ""; 31 $readPos = $values{'start'}; 32 $remainingLength = $values{'length'}; 33 foreach $item (@items) { 34 my ($type, $data) = split(/:/, $item); 35 my $size; 36 if ($type eq "data") { 37 $data =~ s/%([A-Fa-f0-9]{2})/pack('C', hex($1))/seg; 38 $size = length($data); 39 if ($readPos > 0) { 40 if ($readPos > $size) { 41 $readPos -= $size; 42 next; 43 } 44 $data = substr($data, $readPos); 45 } 46 $data = substr($data, 0, $remainingLength) if ($remainingLength > 0); 47 } else { 48 $path = $data; 49 open(FILE, $path) || next; 50 $size = -s $path; 51 if ($readPos > 0) { 52 if ($readPos > $size) { 53 $readPos -= $size; 54 next; 55 } 56 seek(FILE, $readPos, 0); 57 } 58 if ($remainingLength > 0) { 59 read(FILE, $data, $remainingLength); 60 } else { 61 local $/ = undef; 62 $data = <FILE>; 63 } 64 close(FILE); 65 } 66 $readPos -= $size; 67 $expectedData .= $data; 68 if ($remainingLength > 0) { 69 $remainingLength -= length($data); 70 last if $remainingLength <= 0; 71 } 72 } 73 74 if ($values{'convert_newlines'}) { 75 $nativeEnding = ($Config{osname} =~ /(MSWin|cygwin)/) ? "\r\n" : "\n"; 76 $postData =~ s/$nativeEnding/[NL]/g; 77 } 78 79 if ($postData eq $expectedData) { 80 print "OK"; 81 } else { 82 print "FAILED"; 83 } 84 } else { 85 print "Wrong method: " . $ENV{'REQUEST_METHOD'} . "\n"; 86 } 87