#!/usr/bin/perl # 08-14-02 DVA added some doc about pathing, etc. See # below and sendit_install.html ######################################################### # F R E E S O F T W A R E L I C E N S E # ######################################################### # # # This Upload Script Software (Version 3.01) # # is Copyright(C) of David W. Van Abel, 2001 & 2002. # # # # This program is free software; you can redistribute # # it and/or modify it under the terms of the GNU # # General Public License as published by the Free # # Software Foundation; either version 2 of the License, # # or (at your option) any later version. # # # # This program is distributed in the hope that it will # # be useful, but WITHOUT ANY WARRANTY; without even the # # implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # # See the GNU General Public License for more details. # # # # You should have received a copy of the GNU General # # Public License along with this program; if not, write # # to the Free Software Foundation, Inc., 59 Temple # # Place, Suite 330, Boston, MA 02111-1307 USA # # FULL LICENSE IS FOUND AT # # http://opensource.org/licenses/index.html # # # # David W. Van Abel - Author # # 2131 S. Allison Court # # Lakewood, CO USA 80227 # # 303-989-6481 (V) # # Modified by Bob to fix it. 12/20/02. # # dave@vanabel.com # # http://vanabel.com # # http://perlsources.com # # # ######################################################### # E N D O F L I C E N S E # ######################################################### ######################################################### # CREDIT - Lincoln Stein, Creator of CGI.pm # ######################################################### # 08-14-02 DVA - More Doc # Definitions ############# # $upload_dir is the variable which defines the initial # directory the script writes to as the file is uploaded # from the local PC. THIS DIRECTORY MUST HAVE FULL 777 # RIGHTS (rwxrwxrwx). # $saveit_dir is the variable which defines the final # directory the script writes the file to, after it has # been uploaded to the server. THIS DIRECTORY MUST HAVE # EITHER FULL 777 RIGHTS (rwxrwxrwx) or THE SAME RIGHTS # AS THE WEB SERVER. # WARNING-> IF YOU DO NOT UNDERSTAND PERL, WEB SERVERS # &/or LINUX (assuming hosting on a Linux Server), YOU # VERY LIKELY CAN NOT GET THIS SCRIPT INSTALLED. # ALSO, IF YOU DO NOT HAVE ADEQUATE RIGHTS (I.E., root # access) TO THE SERVER, YOU WILL NOT BE ABLE TO INSTALL # THIS SCRIPT. # LASTLY. NO EMAIL OR INSTANT MESSAGE SUPPORT IS PROVIDED # FOR THIS OR OTHER FREE SOFTWARE. use CGI qw/:standard/; $scriptname = "sendit.cgi"; $version = "3.01"; $ver_date = "08-14-02"; #################################################### # EDIT THESE VARIABLES FOR YOUR SERVER ENVIRONMENT # #################################################### $upload_dir = "/home/cluster1/data/t/w/a678436/html/uploads"; #rights are 777 $saveit_dir = "/home/cluster1/data/t/w/a678436/html/uploads"; #rights are 777 $MAXIMUM_UPLOAD = 0; #use zero (0) for no byte size limit # Unused i think $ALLOW_INDEX = 0; #use zero (0) to disallow saving files index*.* $DELFILES = 0; #delete previously uploaded files $upload_file = "saved_file.out"; #std selected filename #################################################### #################################################### ################################# # NO USER EDITS BELOW THIS LINE # ################################# #** Variables for fields **# $page_title = "Poster Software File Upload Utility"; #$page_header = "

Poster Software File Upload Utility

"; $page_header = "

Poster Software File Upload

"; print header; print start_html($page_title); print $page_header; print "

"; if ($MAXIMUM_UPLOAD > 0) { print "

(Maximum upload size is $MAXIMUM_UPLOAD bytes)
"; print "

"; } # Sub-routines # print_form() unless param; del_uploaded_files() if $DELFILES; print_results() if param; print end_html; sub print_form { print "

"; print start_multipart_form(); print filefield(-name=>'upload', -size=>60); print "

"; print submit(-label=>'Upload file'); print end_form; print "

"; print "

"; } sub print_results { my $file = param('upload'); open (SAVE, ">$upload_dir/$upload_file"); #open (SAVE, "testfile"); $data = 0; $i1 = 0; $TOTAL_BYTES = 0; while ($Bytes = read($file,$data,1024)) { $TOTAL_BYTES += $Bytes; if (($TOTAL_BYTES > $MAXIMUM_UPLOAD) && ($MAXIMUM_UPLOAD > 0)) { $i1 = 1; last; } print SAVE $data; } close SAVE; $tmpfile = tmpFileName($file); if (!$i1) { # CODE TO FIND FILENAME SUBMITTED # $f1 = $file; $len = length($tmpfile); $count=0; $offset = 1; $digit = ""; $blk = 0; # WINDOWS/DOS ENVIRONMENT USES "\" FOR DIRECTORIES # if ($f1 =~ /\\/) { $x = "\\"; } # UNIX ENVIRONMENT USES "/" FOR DIRECTORIES # if ($f1 =~ /\//) { $x = "\/"; } while ($blk != 1) { $digit = substr ($f1, -$offset, 1); if ($digit eq "$x") { $blk =1; } else { $offset++; } $count++; if ($count == $len) {last} } $start = ($offset-1); $filename = substr ($f1, -$start, $start ); #$this_time = localtime(time); ($sec, $min, $hour, $day, $month, $year) = localtime(); $year = 2000 + $year - 100; $month = $month +1; $len = length($year); if ($len < 2) {$year = "0$year"} $len = length($month); if ($len < 2) {$month = "0$month"} $len = length($day); if ($len < 2) {$day = "0$day"} $len = length($sec); if ($len < 2) {$sec = "0$sec"} $len = length($min); if ($len < 2) {$min = "0$min"} $len = length($hour); if ($len < 2) {$hour = "0$hour"} $ext = "$year$month$day\-$hour$min$sec"; # DEBUG CODE LINES BELOW # #print "$sec $min $hour $day $month $year"; #print p; #print p,($ext),p; ########################## $filename = $filename . ".$ext" ; # appended filename extension $filename = lc($filename); # RENAME UPLOADED FILE # $del_file = $tmpfile; #rename $tmpfile, "$saveit_dir/$filename"; rename "$upload_dir/$upload_file", "$saveit_dir/$filename"; } # DELETE TEMP FILE # #debug unlink "$upload_dir/$upload_file"; # ERROR CODE AREA # if (!$file) { print "No File Uploaded."; return; } if ($i1) { print "

"; print "You tried to upload a file exceeding $MAXIMUM_UPLOAD bytes, this is not allowed.

"; print "Return to Upload Page"; print "

"; return; } # STANDARD OUTPUT # print "
"; print ""; print ""; print ""; print "
Your selected uploaded file $file
Your saved file on our server$filename
Your saved file length$TOTAL_BYTES bytes
"; print "
"; print "

"; print "We have saved your uploaded file with a timestamp extension = yyyymmdd-hhmmss.

"; print "Therefore, future uploads of the same filename will not be over-written.

"; print "Your upload is now complete.

"; print "Now please email us with a description of the file and the reason that you uploaded it.

"; print "Email us.

"; print "Return to Upload Page - "; print "Return to Support Page"; print "

"; print end_html; open(MAIL, "|/usr/sbin/sendmail -t"); select(MAIL); print<<"EOF"; To: usr1180\@postersw.com From: upload\@postersw.com Subject: file upload File Uploaded: $filename $TOTAL_BYTES bytes EOF } sub del_uploaded_files { if (opendir (UDF, "$saveit_dir")) { @file_list = readdir(UDF); closedir (UDF); @delete_files =(); foreach $a (@file_list) { if ($a eq ".") {next} if ($a eq "..") {next} #$a = lc($a); push (@delete_files, "$saveit_dir/$a"); } $ct = @delete_files; if ($ct) { $dcr_do_delete = unlink (@delete_files); } } } exit 0;