#!/usr/bin/perl # # File Upload Script Version 6.00 # Created by Jeff Carnahan jeffc@terminalp.com # Created on: 4/8/95 Last Modified on: 01/23/98 23:06 # Scripts Archive: http://www.terminalp.com/scripts/ # # --------------------------------------------------------------------- # # Copyright (C) 1996 Jeffrey D. Carnahan # # 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. # # A full copy of the GNU General Public License can be retrieved from # http://www.terminalp.com/scripts/license.shtml # # - Jeff Carnahan Variable: # $SAVE_DIRECTORY # --> Function: # Defines the path to the directory # on the server that should be used # as the folder to save files into. # --> Directory Permissions: # a+rwx # --> Additional Notes: # This path should not have a # trailing forward slash. Also # remember that this is a path, not # a URL. Use something similar to: # # /home/myself/www/uploads # $MAXIMUM_UPLOAD = 0; # # --> Variable: # $MAXIMUM_UPLOAD # --> Function: # Defines the number of bytes that # can be uploaded. Files that exceed # this limit will not be saved on the # server. # --> Additional Notes: # Set this to zero in order to # disable size checking. # $ALLOW_INDEX = 0; # # --> Variable: # $ALLOW_INDEX # --> Function: # If set to zero, files whose # names begin with the word # index will not be saved. # # Set to one to allow files # named index* to be uploaded. # --> Additional Notes: # $SUCCESS_LOCATION = "" # # --> Variable: # $SUCCESS_LOCATION # --> Function: # Defines the URL that users # should be redirected to if # the script works properly. If # this is left blank, a default # page will be returned to the # user. # --> Additional Notes: # This is a COMPLETE URL, not # a path. } # # End of Configurable Options. # --------------------------------------------------------------------- # --------------------------------------------------------------------- # --> Do Not Change Anything Below This Line. <-- # # --------------------------------------------------------------------- # --------------------------------------------------------------------- $| = 1; chop $SAVE_DIRECTORY if ($SAVE_DIRECTORY =~ /\/$/); use CGI qw(:standard); $query = new CGI; if ( (!(-e $SAVE_DIRECTORY)) || (!(-W $SAVE_DIRECTORY)) || (!(-d $SAVE_DIRECTORY)) ) { print header; print <<__END_OF_HTML_CODE__; Error: Bad Directory

Bad Directory

The directory you specified:

\$SAVE_DIRECTORY = "$SAVE_DIRECTORY";

is invalid. This problem is caused by one of the three following reasons:
  1. The directory doesn't exist. Make sure that this directory is a complete path name, not a URL or something similar. It should look similar to /home/username/public_html/uploads

  2. The directory isn't writable. Make sure that this directory is writable by all users. At your UNIX command prompt, type chmod 777 $SAVE_DIRECTORY

  3. The directory you specified isn't really a directory. Make sure that this is indeed a directory and not a file.

__END_OF_HTML_CODE__ exit; } foreach $key (sort {$a <=> $b} $query->param()) { next if ($key =~ /^\s*$/); next if ($query->param($key) =~ /^\s*$/); next if ($key !~ /^file-to-upload-(\d+)$/); $Number = $1; if ($query->param($key) =~ /([^\/\\]+)$/) { $Filename = $1; $Filename =~ s/^\.+//; $File_Handle = $query->param($key); if (!$ALLOW_INDEX && $Filename =~ /^index/i) { print header; print <<__END_OF_HTML_CODE__; Error: Filename Problem

Filename Problem

You attempted to upload a file that isn't properly formatted. The system administrator has decided that you can't upload files that begin with the word 'index'. Please rename the file on your computer, and try uploading it again.


__END_OF_HTML_CODE__ exit; } } else { $FILENAME_IN_QUESTION = $query->param($key); print header; print <<__END_OF_HTML_CODE__; Error: Filename Problem

Filename Problem

You attempted to upload a file that isn't properly formatted. The file in question is $FILENAME_IN_QUESTION Please rename the file on your computer, and attempt to upload it again. Files may not have forward or backward slashes in their names. Also, they may not be prefixed with one (or more) periods.


__END_OF_HTML_CODE__ exit; } $PRE = getpgrp(0); $Filename = "$PRE.$Filename"; if (!open(OUTFILE, ">$SAVE_DIRECTORY\/$Filename")) { print "Content-type: text/plain\n\n"; print "-------------------------\n"; print "Error:\n"; print "-------------------------\n"; print "File: $SAVE_DIRECTORY\/$Filename\n"; print "-------------------------\n"; print "There was an error opening the Output File\n"; print "for Writing.\n\n"; print "Make sure that the directory:\n"; print "$SAVE_DIRECTORY\n"; print "has been chmodded with the permissions '777'.\n\n"; print "Also, make sure that if your attempting\n"; print "to overwrite an existing file, that the\n"; print "existing file is chmodded '666' or better.\n\n"; print "The Error message below should help you diagnose\n"; print "the problem.\n\n"; print "Error: $!\n"; exit; } undef $BytesRead; undef $Buffer; while ($Bytes = read($File_Handle,$Buffer,1024)) { $BytesRead += $Bytes; print OUTFILE $Buffer; } push(@Files_Written, "$SAVE_DIRECTORY\/$Filename"); $TOTAL_BYTES += $BytesRead; $Confirmation{$File_Handle} = $BytesRead; close($File_Handle); close(OUTFILE); chmod (0666, "$SAVE_DIRECTORY\/$Filename"); } $FILES_UPLOADED = scalar(keys(%Confirmation)); if ($TOTAL_BYTES > $MAXIMUM_UPLOAD && $MAXIMUM_UPLOAD > 0) { foreach $File (@Files_Written) { unlink $File; } print header; print <<__END_OF_HTML_CODE__; Error: Limit Reached

Limit Reached

You have reached your upload limit. You attempted to upload $FILES_UPLOADED files, totalling $TOTAL_BYTES. This exceeds the maximum limit of $MAXIMUM_UPLOAD bytes, set by the system administrator. None of your files were successfully saved. Please try again.


__END_OF_HTML_CODE__ exit; } if ($SUCCESS_LOCATION !~ /^\s*$/) { print $query->redirect($SUCCESS_LOCATION); } else { print header; $command = join(' ',"/usr/local/bin/wvHtml --dir ../temp/ --config wvOnline.xml","\"$SAVE_DIRECTORY\/$Filename\""); if (system($command) != 0) { print <<__END_OF_HTML_CODE__; Error: File Did Not Convert The File did not convert, it probably was not actually a word file at all, if it was then wvHtml crashed, (which is pretty unlikely with this version). You can submit a bugreport here if necessary

This table does not exist in the ordinary output of wvHtml, just in the online version to get any necessary bug reports, so if this file did not convert as you expected please submit a bugreport here

__END_OF_HTML_CODE__ exit; } exit; } # --------------------------------------------------------------------- # EOF