#!/usr/bin/perl
use strict;
use warnings;
use MIME::Base64;
my $put_file;
my $max_slice = 1048576;
my $tmp = "/tmp";
die "Malformed Query - Missing PART" unless (defined $ENV{HTTP_FILEPUT_PART} && $ENV{HTTP_FILEPUT_PART} =~ /^\d+$/);
if ($ENV{HTTP_FILEPUT_PART}) {
$put_file = "$tmp/$ENV{HTTP_FILEPUT_USER}.$ENV{HTTP_FILEPUT_SSID}.$ENV{HTTP_FILEPUT_NAME}.$ENV{HTTP_FILEPUT_PART}";
} else {
$put_file = "$tmp/$ENV{HTTP_FILEPUT_USER}.$ENV{HTTP_FILEPUT_SSID}.$ENV{HTTP_FILEPUT_NAME}";
}
open PUT,">$put_file" || die "Cannot open $put_file - $!";
while (<STDIN>) { print PUT decode_base64($_) }
close PUT;
if ( $ENV{HTTP_FILEPUT_PART} && $ENV{HTTP_FILEPUT_PART} * $max_slice >= $ENV{HTTP_FILEPUT_SIZE} ) {
$put_file = "$tmp/$ENV{HTTP_FILEPUT_USER}.$ENV{HTTP_FILEPUT_SSID}.$ENV{HTTP_FILEPUT_NAME}";
open PUT,">$put_file" || die "Cannot open $put_file - $!";
foreach my $part(1 .. $ENV{HTTP_FILEPUT_PART}) {
my $part_file = "$tmp/$ENV{HTTP_FILEPUT_USER}.$ENV{HTTP_FILEPUT_SSID}.$ENV{HTTP_FILEPUT_NAME}.$part";
open PART,"$part_file" || die "Cannot open $part_file - $!";
while (<PART>) { print PUT }
close PART;
unlink $part_file || die "Cannot unlink $part_file - $!";
}
}
print "Content-Type: text/html; charset=ISO-8859-1
<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
<head>
<title>Put File</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />
</head>
<body>
<h1>$ENV{HTTP_FILEPUT_NAME} Part $ENV{HTTP_FILEPUT_PART}</h1>
</body>
</html>
";
exit 0;