home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / wvhtm064.zip / gateway / wvHtml-upload.cgi < prev    next >
Text File  |  2001-02-04  |  15KB  |  433 lines

  1. #!/usr/bin/perl
  2. #
  3. # File Upload Script        Version 6.00
  4. # Created by Jeff Carnahan  jeffc@terminalp.com
  5. # Created on: 4/8/95        Last Modified on: 01/23/98 23:06
  6. # Scripts Archive:          http://www.terminalp.com/scripts/
  7. #
  8. # ---------------------------------------------------------------------
  9. #
  10. # Copyright (C) 1996 Jeffrey D. Carnahan
  11. #
  12. # This program is free software; you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation; either version 2 of the License, or (at
  15. # your option) any later version.
  16. #
  17. # This program is distributed in the hope that it will be useful, but
  18. # WITHOUT ANY WARRANTY; without even the implied warranty of
  19. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. # General Public License for more details.
  21. #
  22. # A full copy of the GNU General Public License can be retrieved from
  23. # http://www.terminalp.com/scripts/license.shtml
  24. #
  25. # - Jeff Carnahan <jeffc@terminalp.com
  26. #
  27. # ---------------------------------------------------------------------
  28. # Program Specific Quickie Notes:
  29. #   * Make Sure The First Line Is Pointing To The Correct Location Of Perl 5.
  30. #   * Make Sure This Program is chmodded with the permissions '755'.
  31. #
  32. #  Version:  Time Stamp:        History:
  33. #  ____________________________________________________________________
  34. #
  35. #     1.00  04/08/96 00:00     The script was created.
  36. #     1.10  04/23/96 00:00     Added User and Group ID to allow file
  37. #                              changing by the actual user, also updated
  38. #                              a security hole which allowed any user with
  39. #                              the UID of 1376 to own the uploaded files.
  40. #                              Also Updated the INSTALL program and README
  41. #                              files.
  42. #     3.00  05/07/96 00:00     New release with group and user id fixes, it
  43. #                              updates a previously unreleased version (2.0)
  44. #     3.10  05/10/96 00:00     Stupid Typo in script fixed, it was
  45. #                              causing problems for some users.
  46. #     4.00  08/04/96 23:16     Security hole regarding '../' paths
  47. #                              fixed.  Thanks to: Rus Berrett.  Mime
  48. #                              type error fixed.  Thanks to: Bob Stewart.
  49. #     4.01  08/07/96 11:20     Typo fixed in &NoOpen.  Thanks to Marco
  50. #                              Dings.
  51. #     5.00  10/06/96 21:42     Fully rewrote script around CGI.pm library.
  52. #                              As soon as I get the time, I'll write more
  53. #                              features into it, but for now, this version
  54. #                              is stable (to the best of my knowledge).
  55. #     5.01  02/09/97 12:41     Fixed some typo's, and added support for
  56. #                              Netscape Communicator.
  57. #     5.02  05/07/97 15:37     Fixed a possible binary file uploading,
  58. #                              added easier support for NT, and fixed
  59. #                              documentation problems. Added the FAQ.
  60. #     5.03  06/19/97 17:30     Fixed a bug which resulted in all files
  61. #                              appearing to be less than one byte in
  62. #                              size, thus uploads weren't saved.
  63. #     6.00  01/23/98 23:06     Added multiple-file uploading.  You can
  64. #                              now upload more than one file at a time.
  65. #                              Also added $MAXIMUM_UPLOAD variable to
  66. #                              restrict file upload sizes.  Script 
  67. #                              completely re-written.  Removed buggy
  68. #                              NT support, and simplified variables.
  69. #                              CGI.pm is no longer bundled with this 
  70. #                              script.  If you need it, download it 
  71. #                              from:
  72. #       http://www.genome.wi.mit.edu/ftp/pub/software/WWW/cgi_docs.html
  73. #                             
  74. # ---------------------------------------------------------------------
  75. # Configurable Options Follow:
  76. #
  77.  
  78. BEGIN {
  79.  
  80.     $SAVE_DIRECTORY = "f";
  81.                               #
  82.                               # --> Variable:
  83.                               #         $SAVE_DIRECTORY
  84.                               # --> Function:
  85.                               #         Defines the path to the directory
  86.                               #         on the server that should be used
  87.                               #         as the folder to save files into.
  88.                               # --> Directory Permissions:
  89.                               #         a+rwx
  90.                               # --> Additional Notes:
  91.                               #         This path should not have a
  92.                               #         trailing forward slash.  Also
  93.                               #         remember that this is a path, not
  94.                               #         a URL.  Use something similar to:
  95.                               #
  96.                               #         /home/myself/www/uploads
  97.                               #
  98.  
  99.     $MAXIMUM_UPLOAD = 0;
  100.                               #
  101.                               # --> Variable:
  102.                               #         $MAXIMUM_UPLOAD
  103.                               # --> Function:
  104.                               #         Defines the number of bytes that
  105.                               #         can be uploaded.  Files that exceed
  106.                               #         this limit will not be saved on the
  107.                               #         server.
  108.                               # --> Additional Notes:
  109.                               #         Set this to zero in order to 
  110.                               #         disable size checking.
  111.                               #
  112.                               
  113.     $ALLOW_INDEX = 0;
  114.                               #
  115.                               # --> Variable:
  116.                               #         $ALLOW_INDEX
  117.                               # --> Function:
  118.                               #         If set to zero, files whose
  119.                               #         names begin with the word 
  120.                               #         index will not be saved.
  121.                               # 
  122.                               #         Set to one to allow files
  123.                               #         named index* to be uploaded.
  124.                               # --> Additional Notes:
  125.                               #
  126.                               
  127.     $SUCCESS_LOCATION = ""
  128.                               #
  129.                               # --> Variable:
  130.                               #         $SUCCESS_LOCATION
  131.                               # --> Function:
  132.                               #         Defines the URL that users
  133.                               #         should be redirected to if 
  134.                               #         the script works properly.  If
  135.                               #         this is left blank, a default
  136.                               #         page will be returned to the
  137.                               #         user.
  138.                               # --> Additional Notes:
  139.                               #         This is a COMPLETE URL, not
  140.                               #         a path.
  141. }
  142. #
  143. # End of Configurable Options.
  144. # ---------------------------------------------------------------------
  145. # ---------------------------------------------------------------------
  146. # -->           Do Not Change Anything Below This Line.           <-- #
  147. # ---------------------------------------------------------------------
  148. # ---------------------------------------------------------------------
  149.  
  150.     $| = 1;
  151.     chop $SAVE_DIRECTORY if ($SAVE_DIRECTORY =~ /\/$/);
  152.     use CGI qw(:standard);
  153.     $query = new CGI;
  154.  
  155.     if ( (!(-e $SAVE_DIRECTORY)) ||
  156.          (!(-W $SAVE_DIRECTORY)) ||
  157.          (!(-d $SAVE_DIRECTORY)) ) {
  158.         print header;
  159.         print <<__END_OF_HTML_CODE__;
  160.         
  161.         <HTML>
  162.         <HEAD>
  163.             <TITLE>Error: Bad Directory</TITLE>
  164.         </HEAD>
  165.         <BODY link="#CC0000" alink="#FF3300" vlink="#330099" text="#000000" bgcolor="#ffffff" background="../pics/weave.jpg">
  166.         <table border=0 width=590>  <!-- begin table-->
  167.         <tr>
  168.         <tr>
  169.         <td valign="top" width="110">
  170.         <img src="../pics/sidebar.gif" usemap="#sidebar.gif" border="0">
  171.         <br>
  172.         </td>
  173.         <td width="480">      <!-- total = 590 -->
  174.  
  175.         
  176.         <H1>Bad Directory</H1>
  177.         <P>
  178.         The directory you specified:
  179.         <BR>
  180.         <BLOCKQUOTE>
  181.             <TT>\$SAVE_DIRECTORY = "<B>$SAVE_DIRECTORY</B>";</TT>
  182.         </BLOCKQUOTE>
  183.         <BR>
  184.         is invalid.  This problem is caused by one of the three following reasons:
  185.         <OL>
  186.             <LI>The directory doesn't exist.  Make sure that this directory is a complete path name, not
  187.                 a URL or something similar.  It should look similar to <TT>/home/username/public_html/uploads</TT>
  188.             <P>
  189.             <LI>The directory isn't writable.  Make sure that this directory is writable by all users.  At
  190.                 your UNIX command prompt, type <TT>chmod 777 $SAVE_DIRECTORY</TT>
  191.             <P>
  192.             <LI>The directory you specified isn't really a directory.  Make sure that this is indeed a directory
  193.                 and not a file.
  194.         </OL>
  195.         <HR SIZE=1>
  196. <center>
  197. <A HREF="http://www.csn.ul.ie/"> <IMG Border="0" SRC="../pics/skynet-button.gif"></a>
  198. </center>
  199.         </td>
  200.         </tr>
  201.         </table>
  202.         </BODY>
  203.         </HTML>
  204.         
  205. __END_OF_HTML_CODE__
  206.         exit;
  207.     }
  208.     
  209.     foreach $key (sort {$a <=> $b} $query->param()) {
  210.         next if ($key =~ /^\s*$/);
  211.         next if ($query->param($key) =~ /^\s*$/);
  212.         next if ($key !~ /^file-to-upload-(\d+)$/);
  213.         $Number = $1;
  214.         
  215.         if ($query->param($key) =~ /([^\/\\]+)$/) {
  216.             $Filename = $1;
  217.             $Filename =~ s/^\.+//;
  218.             $File_Handle = $query->param($key);
  219.             
  220.             if (!$ALLOW_INDEX && $Filename =~ /^index/i) {
  221.                 print header;
  222.                 print <<__END_OF_HTML_CODE__;
  223.                 
  224.                 <HTML>
  225.                 <HEAD>
  226.                     <TITLE>Error: Filename Problem</TITLE>
  227.                 </HEAD>
  228.                 <BODY link="#CC0000" alink="#FF3300" vlink="#330099" text="#000000" bgcolor="#ffffff" background="../pics/weave.jpg">
  229.                 <table border=0 width=590>  <!-- begin table-->
  230.                 <tr>
  231.                 <tr>
  232.                 <td valign="top" width="110">
  233.                 <img src="../pics/sidebar.gif" usemap="#sidebar.gif" border="0">
  234.                 <br>
  235.                 </td>
  236.                 <td width="480">      <!-- total = 590 -->
  237.  
  238.                 <H1>Filename Problem</H1>
  239.                 <P>
  240.                 You attempted to upload a file that isn't properly formatted.  The system administrator
  241.                 has decided that you can't upload files that begin with the word '<B>index</B>'. Please
  242.                 rename the file on your computer, and try uploading it again.
  243.                 <P>
  244.                 <HR SIZE=1>
  245. <center>
  246. <A HREF="http://www.csn.ul.ie/"> <IMG Border="0" SRC="../pics/skynet-button.gif"></a>
  247. </center>
  248.  
  249.         </td>
  250.         </tr>
  251.         </table>
  252.                 </BODY>
  253.                 </HTML>
  254.     
  255. __END_OF_HTML_CODE__
  256.                 exit;
  257.             }
  258.         } else {
  259.             $FILENAME_IN_QUESTION = $query->param($key);
  260.             
  261.             print header;
  262.             print <<__END_OF_HTML_CODE__;
  263.             
  264.             <HTML>
  265.             <HEAD>
  266.                 <TITLE>Error: Filename Problem</TITLE>
  267.             </HEAD>
  268.             <BODY link="#CC0000" alink="#FF3300" vlink="#330099" text="#000000" bgcolor="#ffffff" background="../pics/weave.jpg">
  269.             <table border=0 width=590>  <!-- begin table-->
  270.             <tr>
  271.             <tr>
  272.             <td valign="top" width="110">
  273.             <img src="../pics/sidebar.gif" usemap="#sidebar.gif" border="0">
  274.             <br>
  275.             </td>
  276.             <td width="480">      <!-- total = 590 -->
  277.  
  278.  
  279.             <H1>Filename Problem</H1>
  280.             <P>
  281.             You attempted to upload a file that isn't properly formatted.  The file in question 
  282.             is <TT><B>$FILENAME_IN_QUESTION</B></TT>  Please rename the file on your computer, and
  283.             attempt to upload it again.  Files may not have forward or backward slashes in their 
  284.             names.  Also, they may not be prefixed with one (or more) periods.
  285.             <P>
  286.             <HR SIZE=1>
  287. <center>
  288. <A HREF="http://www.csn.ul.ie/"> <IMG Border="0" SRC="../pics/skynet-button.gif"></a>
  289. </center>
  290.  
  291.         </td>
  292.         </tr>
  293.         </table>
  294.             </BODY>
  295.             </HTML>
  296.  
  297. __END_OF_HTML_CODE__
  298.             exit;
  299.         }
  300.  
  301.         $PRE = getpgrp(0);
  302.         $Filename = "$PRE.$Filename";
  303.  
  304.         if (!open(OUTFILE, ">$SAVE_DIRECTORY\/$Filename")) {
  305.             print "Content-type: text/plain\n\n";
  306.             print "-------------------------\n";
  307.             print "Error:\n";
  308.             print "-------------------------\n";
  309.             print "File: $SAVE_DIRECTORY\/$Filename\n";
  310.             print "-------------------------\n";
  311.             print "There was an error opening the Output File\n";
  312.             print "for Writing.\n\n";
  313.             print "Make sure that the directory:\n";
  314.             print "$SAVE_DIRECTORY\n";
  315.             print "has been chmodded with the permissions '777'.\n\n";
  316.             print "Also, make sure that if your attempting\n";
  317.             print "to overwrite an existing file, that the\n";
  318.             print "existing file is chmodded '666' or better.\n\n";
  319.             print "The Error message below should help you diagnose\n";
  320.             print "the problem.\n\n";
  321.             print "Error: $!\n";
  322.             exit;
  323.         }
  324.  
  325.         undef $BytesRead;
  326.         undef $Buffer;
  327.         
  328.         while ($Bytes = read($File_Handle,$Buffer,1024)) {
  329.             $BytesRead += $Bytes;
  330.             print OUTFILE $Buffer;
  331.         }
  332.         
  333.         push(@Files_Written, "$SAVE_DIRECTORY\/$Filename");
  334.         $TOTAL_BYTES += $BytesRead;
  335.         $Confirmation{$File_Handle} = $BytesRead;
  336.  
  337.         close($File_Handle);
  338.         close(OUTFILE);
  339.  
  340.         chmod (0666, "$SAVE_DIRECTORY\/$Filename");
  341.     }
  342.  
  343.     $FILES_UPLOADED = scalar(keys(%Confirmation));
  344.  
  345.     
  346.     if ($TOTAL_BYTES > $MAXIMUM_UPLOAD && $MAXIMUM_UPLOAD > 0) {
  347.         foreach $File (@Files_Written) {
  348.             unlink $File;
  349.         }
  350.         
  351.         print header;
  352.         print <<__END_OF_HTML_CODE__;
  353.         
  354.         <HTML>
  355.         <HEAD>
  356.             <TITLE>Error: Limit Reached</TITLE>
  357.         </HEAD>
  358.         <BODY link="#CC0000" alink="#FF3300" vlink="#330099" text="#000000" bgcolor="#ffffff" background="../pics/weave.jpg">
  359.         <table border=0 width=590>  <!-- begin table-->
  360.         <tr>
  361.         <tr>
  362.         <td valign="top" width="110">
  363.         <img src="../pics/sidebar.gif" usemap="#sidebar.gif" border="0">
  364.         <br>
  365.         </td>
  366.         <td width="480">      <!-- total = 590 -->
  367.  
  368.         <H1>Limit Reached</H1>
  369.         <P>
  370.         You have reached your upload limit.  You attempted to upload <B>$FILES_UPLOADED</B> files, totalling 
  371.         <B>$TOTAL_BYTES</B>.  This exceeds the maximum limit of <B>$MAXIMUM_UPLOAD</B> bytes, set by the system 
  372.         administrator.  <B>None</B> of your files were successfully saved.  Please try again.
  373.         <P>
  374.         <HR SIZE=1>
  375. <center>
  376. <A HREF="http://www.csn.ul.ie/"> <IMG Border="0" SRC="../pics/skynet-button.gif"></a>
  377. </center>
  378.  
  379.         </td>
  380.         </tr>
  381.         </table>
  382.         </BODY>
  383.         </HTML>
  384.                 
  385. __END_OF_HTML_CODE__
  386.         exit;
  387.     }
  388.     
  389.     if ($SUCCESS_LOCATION !~ /^\s*$/) {
  390.         print $query->redirect($SUCCESS_LOCATION);
  391.     } else {
  392.     
  393.  
  394.         print header;
  395.         $command = join(' ',"/usr/local/bin/wvHtml --dir ../temp/ --config wvOnline.xml","\"$SAVE_DIRECTORY\/$Filename\"");
  396.         if (system($command) != 0)
  397.             {
  398.             print <<__END_OF_HTML_CODE__;
  399.  
  400.         <HTML>
  401.         <HEAD>
  402.             <TITLE>Error: File Did Not Convert</TITLE>
  403.         </HEAD>
  404.         <BODY link="#CC0000" alink="#FF3300" vlink="#330099" text="#000000" bgcolor="#ffffff" background="../pics/weave.jpg">
  405.         The File did not convert, it probably was not actually a word file at all, if it was
  406.         then wvHtml crashed, (which is pretty unlikely with this version). You can submit
  407.         a bugreport here if necessary<p>
  408.         <table border="1">
  409.         <tr>
  410.         <td>
  411.         This table does not exist in the ordinary output of wvHtml, just in the online version to get any
  412.         necessary bug reports, so if this file did not convert as you expected please submit a bugreport here<br>
  413.         <form method="post" action="wvHtmlBug.cgi">
  414.         <textarea name="comments" wrap=hard rows=6 cols=80>
  415.         </textarea>
  416.         <br>
  417.         <input type="hidden" name="name" value="$Filename">
  418.         <input type=submit value="Submit Bug Report">
  419.         </form>
  420.         </td>
  421.         </tr>
  422.         </table>
  423.         </BODY>
  424.         </HTML>
  425. __END_OF_HTML_CODE__
  426.         exit;
  427.             }
  428.         exit;    
  429.     }
  430.     
  431. # ---------------------------------------------------------------------
  432. # EOF
  433.