#!/usr/bin/perl alarm(600); use CGI; use Fcntl qw( :DEFAULT :flock); use File::Basename; use constant UPLOAD_DIR => "/usr2/home/undernet/losts/public_html/playeruploads/"; use constant BUFFER_SIZE => 16_384; use constant MAX_FILE_SIZE => 2 * 1_048_576; # Limit each upload to 10mb use constant MAX_DIR_SIZE => 100 * 1_048_576; # Limit total uploads to 500mb use constant MAX_OPEN_TRIES => 100; $CGI::DISABLE_UPLOADS = 0; $CGI::POST_MAX = -1; $in = new CGI; $img1 = $in->param('image'); $action = $in->param('action'); $imgdir = '/usr2/home/undernet/losts/public_html/playeruploads'; print "Content-type: text/html\n\n"; &headers; &body; if ($action eq "uploadfile") { &uploadfile; } else { &displayform; } &footer; sub displayform { print << "!!!EOF!!!";

Please fill in the file-upload form below

UserName: $ENV{'REMOTE_USER'}
File to upload:

to upload the file!

NOTE: All Files older then 1 month old will be deleted over time. This is so I can save Web Space. This is NOT an archieving site.

Click Here to View Files !!!EOF!!! } sub headers { print "\n"; print "RallosZek.Net Members Only\n"; print "\n"; } sub body { print "\n"; print "\n"; print "

RallosZek.Net File Uploads

\n"; print "
\n"; print "
\n"; } sub footer { print "
\n"; print "
Powered by RallosZek.Net
\n"; print "\n"; print "\n"; } sub uploadfile { if ($img1) { &uploadimage; &displayurl; } else { &displayerror; } } sub displayurl { print "

Thank You

\n"; print "Your file has successfully been uplaoded. Below is your URL information

\n"; if (($type eq ".bmp") or ($type eq ".jpg") or ($type eq ".gif")) { print "Display Image HTML: <\;img src=\"http://www.ralloszek.net/playeruploads/$imgurl1\">\;

\n"; } print "To Link People Directly to file: <\;a href=\"http://www.ralloszek.net/playeruploads/$imgurl1\">\;$imgurl1</a>

\n"; } sub uploadimage { $in->cgi_error and error( $in, "Error transfering file: " . $in->cgi_error ); $file = $in->param('image'); $filename = $in->param('image'); $fh = $in->upload('image'); $buffer = ""; $filename =~ s//>/g; fileparse_set_fstype("MSWin32"); ($base,$path,$type) = fileparse($filename,'\..*'); $type = lc $type; $uploadedfile = $base . $type; if ( dir_size( UPLOAD_DIR ) + $ENV{'CONTENT_LENGTH'} > MAX_DIR_SIZE ) { error( $in, "Upload directory is fully." ); } $uploadedfile =~ s/[^\w.-]/_/g; if ( $uploadedfile =~ /^(\w[\w.-]*)/ ) { $uploadedfile = $1; } else { error( $in, "Invalid file name; files must start with a letter or number." ); } until ( sysopen OUTPUT, UPLOAD_DIR . $uploadedfile, O_RDWR|O_CREAT|O_EXCL, 0777 ) { $uploadedfile =~ s/(\d*)(\.\w+)$/($1||0) + 1 . $2/e; $1 >= MAX_OPEN_TRIES and error( $in, "Unable to save your file. File 1" ); } while ( read($fh,$buffer,BUFFER_SIZE)) { print OUTPUT $buffer; } close OUTPUT; if ($type eq ".bmp") { ($basej,$pathj,$typej) = fileparse($uploadedfile,'\..*'); system("/usr/X11R6/bin/convert $imgdir/$uploadedfile $imgdir/$basej.jpg"); system("rm -f $imgdir/$uploadedfile"); $imgurl1 = $basej . ".jpg"; system("chmod 777 $imgurl/$basej.jpg"); } else { $imgurl1 = $uploadedfile; system("chmod 777 $imgurl/$uploadedfile"); } open(DAT, ">>/usr2/home/undernet/losts/files.dat"); $time = time; print DAT "$uploadedfile\t$ENV{'REMOTE_USER'}\t$ENV{'REMOTE_ADDR'}\t$ENV{'REMOTE_HOST'}\t$time\n"; close DAT; } sub displayerror { print "Error: $ENV{QUERY_STRING}\n"; } sub dir_size { my $dir = shift; my $dir_size = 0; open DIR, $dir or die "Unable to open $dir: $!"; while ( readdir DIR ) { $dir_size += -s "$dir/$_"; } return $dir_size; } sub error { my( $in, $reason ) = @_; print $in->h1( "Error" ), $in->p( "Your upload was not processed because the following error occured: " ), $in->p( $in->i( $reason ) ); exit; }