#!/usr/bin/perl -- # Installation Instructions # http://www.perlservices.net/en/programs/psupload/users_guide.shtml # To order a custom installation # https://www.perlscriptsjavascripts.com/psinstallation.html #################################################################### # # PS Upload # ©2002, PerlServices.net # # Requires: Perl5+ # Created: March 12, 2002 # Author: PerlServices # Version: 4.1 # # This script / program is copyright material! # #################################################################### # Start PS Upload Configuration #################################################################### # ================================================================ # # Var: $send_mail_path # ================================================================ # # for unix/linux servers only. enter your server's sendmail path. # it usually looks something like : # /usr/sbin/sendmail or # /usr/lib/sendmail $send_mail_path = "/usr/sbin/sendmail"; # ================================================================ # # Var: $smtp_path # ================================================================ # # for windows servers only. enter your server's mail program path. # it usually looks something like : # mail.yourdomainname.com or # smtp.yourdomainname.com # note: if you set a value in the next variable, it will be used in # place of the $send_mail_path . Leave blank if you uploaded this # script to a linux, unix or mac type server with sendmail, qmail # or postfix installed $smtp_path = "smtp.xxxxx.com"; # if your SMTP server requires authentication, enter the email # account's username and password below $smtp_user = "xxxxxx"; $smtp_pass = "xxxxxx"; # ================================================================ # # Var: $notify # ================================================================ # # if you would like to be notified of uploads, enter your # email address between the SINGLE quotes. if you do not wish # to be notified, leave this blank. only one e-mail address can # be set here $notify = 'xxxxx@hotmail.com'; # ================================================================ # # Var: $adminName # ================================================================ # # your name. the name that appears in the To: header in the e-mail # sent to the address specified in the $notify variable. enter the # name between the single quotes. $adminName = 'PS Upload'; # ================================================================ # # Var: $subject # ================================================================ # # the subject of the e-mail notification. if you have a field in # your form named "subject" in lowercase, that will over-ride this $subject = 'Objet uploader'; # ================================================================ # # Var: $dir # ================================================================ # # enter your server's path (not your website address) to the # directory files will be uploaded to. # note : this script does not auto-delete uploaded files. # consider one of our other scripts if auto-deletion is required # # on most unix/linux server $ENV{DOCUMENT_ROOT}/ points to the # folder your homepage resides in. however, sometimes you need to # also add www or htdocs to the path # # on windows servers, start the path with the drive letter and # separate each folder with two backslashes. # e.g. $dir = "F:\\webpath\\wwwroot\\uploads # # if you get this wrong, the script will print the correct path $dir = "$ENV{DOCUMENT_ROOT}/ipload"; # ================================================================ # # Var: $folder # ================================================================ # # absolute URL (website address starting with http://) to folder # files will be uploaded to. this variable correlates to the # previous variable. $folder = "http://www.xxxxxxx.com/ipload"; # ================================================================ # # Var: $max # ================================================================ # # maximum file size (in kilobytes) you will accept as an upload. # your host can, and often, does override this setting. if you # cannot upload very large files, contact your host. it's not the # the script, it's the server. this script has successfully uploaded # files larger than the Windows XP operating system! # 1024 kilobytes is equal to 1 megabyte $max = 102400; # ================================================================ # # Var: $print_contents # ================================================================ # # set to 1 if you would like the contents of your upload directory # ($dir) printed after a successful upload. set to 0 if you do not # want filenames printed. note: this is ignored if redirecting the # submitter to another page upon successful submission $print_contents = 1; # ================================================================ # # Var: $overwrite # ================================================================ # # if the name of the file being uploaded already exists in your # upload directory ($dir) and you DO NOT WANT it over-written, # set this variable to 0 (zero). the script will then automatically # rename the file by appending a unique number to it. # if you DO WANT existing files to be over-written by the new upload, # then set this variable to 1 $overwrite = 0; # ================================================================ # # Var: $domain # ================================================================ # # to ensure this script only processes forms that reside on your # website, enter your domain name in this variable. the http://www # portion is not required and best not be used. # # this helps prevent "hi-jacking" of your form. a technique # practiced by hackers to have a program on their website or local # computer programatically send out spam. # # note: this security measure is not fool proof and can be easily # circumvented by hackers. additionally, some web surfers may # unknowingly have the "referrer" variable cloaked, in which case, # if you have this variable set, they will not be able to submit # your form. # # we suggest you make use of the next security measure: @recipients $domain = "www.xxxxxxx.com"; # ================================================================ # # Var: $domain # ================================================================ # # # if a file is successfully uploaded, enter a URL to redirect to. # use an absolute website address, as in : # http://www.google.com # leave this blank to have the default message printed. $redirect = "http://www.xxxxxxx.com/upload.html"; # ================================================================ # # Var: @types # ================================================================ # # enter the file extensions for the file types you will accept. # this script can upload any type of file. each file extension on # a new line, or enter "ALL" in uppercase, to accept all file types @types = qw~ mp3 gif jpg jpeg xls pdf doc txt tx ~; #################################################################### # END USER EDITS #################################################################### $folder =~ s/(\/|\\)+$//ig; $dir =~ s/(\/|\\)+$//ig; $OS = $^O; # operating system name if($OS =~ /darwin/i) { $isUNIX = 1; } elsif($OS =~ /win/i) { $isWIN = 1; } else {$isUNIX = 1;} if($isWIN){ $S{S} = "\\\\"; } else { $S{S} = "/";} # seperator used in paths $ScriptURL = "http://$ENV{'SERVER_NAME'}$ENV{'SCRIPT_NAME'}"; unless (-d "$dir"){ mkdir ("$dir", 0777); chmod(0777, "$dir"); } unless (-d "$dir"){ # if there still is no dir, the path entered by the user is wrong and the upload will fail &PrintHead; #print the header # get the Win root $ENV{PATH_INFO} =~ s/\//$S{S}/gi; $ENV{PATH_TRANSLATED} =~ s/$ENV{PATH_INFO}//i; print qq~
The path you entered is incorrect. You entered : "$dir"
Your root path is (UNIX): $ENV{DOCUMENT_ROOT} Your root path is (WINDOWS): $ENV{PATH_TRANSLATED} Your path should contain your root path followed by a slash followed by the destination folder's name. If you are on a WINDOWS server, each slash should be escaped. Eg. each seperator should look like this : \\\\ Sometimes, the root returned is not the full path to your web space. In this case you should either check with your host or if you are using an FTP client such as CuteFTP, change to the folder you are trying to upload to and look at the path you have taken. You can see this just above the list of files on your server. You must use the same path in the \$dir variable. |
This script must be called using a form. Your form should point to this script. Your form tag must contain the following attributes :
<form action="$ScriptURL" method="post" enctype="multipart/form-data"> The method must equal post and the enctype must equal multipart/form-data. The action has to point to this script (on your server). If you are reading this, copy and paste the example above. It has the correct values. |
Invalid referrer. |
One or more files failed to upload. The reasons returned are:
$failed ~; if($success[0]){ # send email if valid email was entered if(check_email($notify)){ # enter the message you would like to receive my $message = qq~ The following files were uploaded to your server : ~; $folder =~ s/(\/|\\)$//ig; foreach(@success){ $message .= qq~ $folder/$_ ~; } if(&send_mail($notify, $adminName, $notify, $adminName, $subject, $message)){ $VAR{emailsuccess} = qq~Sent~; } } print qq~ The following files were successfully uploaded : ~; foreach(@success){ print qq~ $_ ~; } } print qq~ |
Success |
---|
The following files were successfully uploaded :
~; foreach(@success){ print qq~ $_ ~; } print qq~ |
Current files in folder | |
~;
opendir(DIR, "$dir");
@current = readdir(DIR);
closedir(DIR);
foreach(@current){
unless($_ eq '.' || $_ eq '..' || -d qq~$dir/$_~){
push(@currentfiles, $_);
}
}
@currentfiles = sort { uc($a) cmp uc($b) } @currentfiles;
for($aa = 0; $aa <= int($#currentfiles / 2); $aa++){
print qq~
$currentfiles[$aa] ~; } print qq~ | ~;
for($bb = $aa; $bb < @currentfiles; $bb++){
print qq~
$currentfiles[$bb] ~; } print qq~ |
~; #} } $VAR{message} =~ s/\r+//ig; $VAR{message} =~ s/\n{3,300}/$VAR{CRLF}$VAR{CRLF}/ig; $VAR{message} =~ s/\n/$VAR{CRLF}/ig; $VAR{attPths} =~ s/\s+//ig; $VAR{HTMLmess} = $VAR{message}; $VAR{TEXTmess} = $VAR{message}; if($CONFIG{mail_format} == 2){ $VAR{TEXTmess} =~ s/\"/\"/g; $VAR{TEXTmess} =~ s/\</\ 5 ? SOCK_STREAM : 1; $VAR{AFinet} = $] > 5 ? AF_INET : 2; $VAR{protocol} = (getprotobyname('tcp'))[2]; $VAR{hostName} = (gethostbyname($VAR{SMTPserver}))[4]; $VAR{bindSock} = pack('S n a4 x8', $VAR{AFinet}, 0, $VAR{hostName}); $VAR{connSock} = pack('S n a4 x8', $VAR{AFinet}, $VAR{SMTPport}, $VAR{hostName}); unless(socket(M, $VAR{AFinet}, $VAR{Stream}, $VAR{protocol})){ if($VAR{debug}){ print qq~No socket established\n\n~; } return; } bind(M, $VAR{bindSock}); unless(connect(M, $VAR{connSock})){ if($VAR{debug}){ print qq~No connection established\n\n~; } return; } $VAR{selected} = select(M); $| = 1; select($VAR{selected}); select(undef, undef, undef, 1); sysread(M, $_, 1024); if($VAR{debug}){ print qq~Connection accepted:$_ \n\n~; } print M qq~HELO $VAR{SMTPserver}$VAR{CRLF}~; sysread(M, $_, 1024); if($VAR{debug}){ print qq~HELO:$_ \n\n~; } if(!/^\s*250/){ if($VAR{debug}){ print qq~HELO failed\n\n~;} return; } # authenticate ourselves? if($CONFIG{mailuser} =~ /\w+/ && $CONFIG{mailpass} =~ /\w+/){ $VAR{SMTPuser} = $CONFIG{mailuser}; $VAR{SMTPpass} = $CONFIG{mailpass}; $VAR{length} = $VAR{SMTPuser}; $VAR{encoded} = substr(pack('u57', $VAR{SMTPuser}), 1); chop($VAR{encoded}); $VAR{encoded} =~ tr| -_`|A-Za-z0-9+/A|; $VAR{buff} = (3 - ($VAR{length} % 3)) % 3; substr($VAR{encoded}, -$VAR{buff}, $VAR{buff}) = '=' x $VAR{buff}; $VAR{SMTPuser} = $VAR{encoded}; $VAR{length} = $VAR{SMTPpass}; $VAR{encoded} = substr(pack('u57', $VAR{SMTPpass}), 1); chop($VAR{encoded}); $VAR{encoded} =~ tr| -_`|A-Za-z0-9+/A|; $VAR{buff} = (3 - ($VAR{length} % 3)) % 3; substr($VAR{encoded}, -$VAR{buff}, $VAR{buff}) = '=' x $VAR{buff}; $VAR{SMTPpass} = $VAR{encoded}; print M qq~AUTH LOGIN$VAR{CRLF}~; sysread(M, $_, 1024); if($VAR{debug}){ print qq~AUTH LOGIN: $_\n\n~; } print M qq~$VAR{SMTPuser}$VAR{CRLF}~; sysread(M, $_, 1024); if($VAR{debug}){ print qq~Auth Username: $_\n\n~; } print M qq~$VAR{SMTPpass}$VAR{CRLF}~; sysread(M, $_, 1024); if($VAR{debug}){ print qq~Auth Password: $_\n\n~; } } print M qq~MAIL FROM:$VAR{sndrEml}$VAR{CRLF}~; sysread(M, $_, 1024); if($VAR{debug}){ print qq~MAIL FROM:$_\n\n~; } if(!/[^0-9]*250/){ if($VAR{debug}){ print qq~Denied.\n\n~; } return; } print M qq~RCPT TO:$VAR{rcvrEml}$VAR{CRLF}~; sysread(M, $_, 1024); /[^0-9]*(\d\d\d)/; if($VAR{debug}){ print qq~RCPT TO:$_\n\n~; } if(!/[^0-9]*250/){ if($VAR{debug}){ print qq~Denied. Auth required?\n\n~; } return; } if($VAR{ccrcEml}){ print M qq~RCPT TO:$VAR{ccrcEml}$VAR{CRLF}~; sysread(SMTP, $_, 1024); /[^0-9]*(\d\d\d)/; if($VAR{debug}){ print qq~RCPT TO CC:$_\n\n~; } if(!/[^0-9]*250/){ if($VAR{debug}){ print qq~Denied. Auth required?\n\n~; } return; } } print M qq~DATA$VAR{CRLF}~; sysread(M, $_, 1024); if($VAR{debug}){ print qq~Ready to send DATA:$_\n\n~; } if(!/[^0-9]*354/){ if($VAR{debug}){ print qq~Denied.\n\n~; } return; } print M qq~From: $VAR{fm}$VAR{CRLF}~; print M qq~To: $VAR{to}$VAR{CRLF}~; print M qq~CC: $VAR{cc}$VAR{CRLF}~ if $VAR{ccrcEml}; print M qq~Subject: $VAR{subject}$VAR{CRLF}~; print M qq~MIME-Version: 1.0$VAR{CRLF}~; if($CONFIG{mail_format} == 1){ print M qq~$VAR{fileHeaders}~; print M qq~$VAR{embedHeaders}~; print M qq~Content-Type: multipart/alternative;$VAR{CRLF}~; print M qq~\tboundary="$VAR{bound1}"$VAR{CRLF}$VAR{CRLF}$VAR{CRLF}~; print M qq~--$VAR{bound1}$VAR{CRLF}~; print M qq~Content-Type: text/plain;$VAR{CRLF}~; print M qq~Content-Transfer-Encoding: 7bit$VAR{CRLF}$VAR{CRLF}~; print M qq~$VAR{TEXTmess}$VAR{CRLF}$VAR{CRLF}~; print M qq~--$VAR{bound1}$VAR{CRLF}~; print M qq~Content-Type: text/html; $VAR{charset2}$VAR{CRLF}$VAR{CRLF}~; print M qq~$VAR{HTMLmess}$VAR{CRLF}~; print M qq~$VAR{CRLF}$VAR{CRLF}--$VAR{bound1}--$VAR{files}~; } else { print M qq~$VAR{fileHeaders}~; print M qq~Content-Type: text/plain;$VAR{CRLF}~; print M qq~Content-Transfer-Encoding: 7bit$VAR{CRLF}$VAR{CRLF}~; print M qq~$VAR{TEXTmess}$VAR{CRLF}$VAR{CRLF}$VAR{files}~; } print M qq~$VAR{CRLF}.$VAR{CRLF}~; sysread(M, $_, 1024); if($VAR{debug}){ print qq~Message ended:$_\n\n~; } if(!/[^0-9]*250/){ if($VAR{debug}){ print qq~Message failed.\n\n~; } return; } if(!shutdown(M, 2)){ if($VAR{debug}){ print qq~Shutdown failed:$_\n\n~; } return; } else { return 1; } } #################################################################### #################################################################### sub PrintHead { print qq~Content-type: text/html\n\n~; print qq~PerlServices.net Free upload utility ~; } #################################################################### #################################################################### sub PrintFoot { print qq~ ~; } #################################################################### #################################################################### sub check_email { my($fe_email) = $_[0]; if($fe_email) { if(($fe_email =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|(\.$)/) || ($fe_email !~ /^.+@\[?(\w|[-.])+\.[a-zA-Z]{2,3}|[0-9]{1,3}\]?$/)) { return; } else { return(1) } } else { return; } } ##################################################################### ##################################################################### sub gethostname { $ipnum = $ENV{'REMOTE_ADDR'}; @digits = split (/\./, $ipnum); $address = pack ("C4", @digits); $host = gethostbyaddr ($address, 2); return ($host); }