home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 October / INTERNET108.ISO / pc / software / windows / messages / greymatter / gm-upload.cgi < prev    next >
Encoding:
Text File  |  2001-12-03  |  9.1 KB  |  188 lines

  1. #!/usr/bin/perl
  2.  
  3. # =============================
  4. # GREYMATTER - Uploading Module
  5. # Weblog/Journal Software
  6. # version one point two
  7. # Copyright (c)2000 Noah Grey
  8. # http://noahgrey.com/greysoft/
  9. # =============================
  10.  
  11. # ***  Your possession of this software indicates that you agree to the terms   ***
  12. # *** specified under the "Copyright & Usage" heading in the "manual.txt" file. ***
  13.  
  14. eval {
  15.     ($0 =~ m,(.*)/[^/]+,) && unshift (@INC, "$1");
  16.     ($0 =~ m,(.*)\\[^\\]+,) && unshift (@INC, "$1");
  17. };
  18.  
  19. use CGI::Carp qw(fatalsToBrowser);
  20. use CGI qw(:standard);
  21.  
  22. require "gm-library.cgi";
  23.  
  24. print "Content-type: text/html\n\n";
  25.  
  26. $authorIP = $ENV{'REMOTE_ADDR'};
  27.  
  28. $| = 1;
  29. use CGI qw(:standard);
  30. $cgiquery = new CGI;
  31.  
  32. $otherkeys = "";
  33.  
  34. foreach $key (sort {$a <=> $b} $cgiquery->param()) {
  35.     $otherparams = param($key);
  36.     $otherkeys .= "$otherparams|";
  37. }
  38.  
  39. chop ($otherkeys);
  40. @otherkeyvalues = split (/\|/, $otherkeys);
  41. $IN{'authorname'} = $otherkeyvalues[0];
  42. $IN{'authorpassword'} = $otherkeyvalues[1];
  43.  
  44. if (($IN{'authorname'} eq "") || ($IN{'authorpassword'} eq "")) {
  45.     &gm_dangermouse("The author name or password is blank.  This file is only to be used by logging into Greymatter.");
  46. }
  47.  
  48. &gm_validate;
  49.  
  50. if ($gmuploadaccess ne "yes") {
  51.     &gm_writetocplog("$IN{'authorname'} attempted to upload a file without authorization");
  52.     &gm_dangermouse("You don't have access to upload files.");
  53. }
  54.  
  55. foreach $key (sort {$a <=> $b} $cgiquery->param()) {
  56.  
  57.     next if ($key =~ /^\s*$/);
  58.     next if ($cgiquery->param($key) =~ /^\s*$/);
  59.     next if ($key !~ /^uploadfile-(\d+)$/);
  60.  
  61.     if ($cgiquery->param($key) =~ /([^\/\\]+)$/) {
  62.         $uploadfilename = $1;
  63.         $uploadfilename =~ s/^\.+//;
  64.         $uploadfilenamehandle = $cgiquery->param($key);
  65.         if ($uploadfilename =~ m/\ /) { &gm_dangermouse("Your filename cannot contain spaces.  Please rename your file, go back, and try again."); }
  66.     } else {
  67.         &gm_dangermouse("Your filename cannot contain backslashes, or have a period at the beginning of its name.  Please rename your file, go back, and try again.");
  68.     }
  69.  
  70.     if ($uploadfilename =~ /'/) { &gm_dangermouse("Your filename cannot contain apostrophes.  Please rename your file, go back, and try again."); }
  71.  
  72.     if ($uploadfilesallowed ne "") {
  73.         $thisfileisokay = "no";
  74.         @uploadfiletypecheck = split (/;/, $uploadfilesallowed);
  75.         foreach $checkagainstthis (@uploadfiletypecheck) {
  76.             if ($uploadfilename =~ /\.$checkagainstthis$/i) { $thisfileisokay = "yes"; }
  77.         }
  78.         if ($thisfileisokay eq "no") {
  79.             &gm_dangermouse("Uploading files of that type is currently not permitted.  Please go back and try a different file.");
  80.         }
  81.     }
  82.  
  83.     if (-e "$EntriesPath/$uploadfilename") { &gm_dangermouse("A file with that name already exists in your entries/archives directory.  Please go back and try a file with a different name."); }
  84.  
  85.     undef $bytesread;
  86.     undef $buffer;
  87.  
  88.     open(OUTFILE, ">$EntriesPath/$uploadfilename") || &gm_dangermouse("Can't write to $EntriesPath/$uploadfilename.  Make sure that $EntriesPath is your correct entries/archives directory, and that this directory is CHMODed to 777.");
  89.     while ($bytes = read($uploadfilenamehandle, $buffer, 2096)) {
  90.         $bytesread += $bytes;
  91.         binmode OUTFILE;
  92.         print OUTFILE $buffer;
  93.     }
  94.  
  95.     push (@fileswritten, "$EntriesPath\/$uploadfilename");
  96.     $totalbytes += $bytesread;
  97.     $uploadconfirm{$uploadfilenamehandle} = $bytesread;
  98.     close($uploadfilenamehandle);
  99.     close(OUTFILE);
  100.  
  101. }
  102.  
  103. $filesuploaded = scalar(keys(%uploadconfirm));
  104.  
  105. if (($totalbytes eq $null) || ($totalbytes == 0)) { &gm_dangermouse("You didn't enter a filename, or you attempted to upload an empty file.  Please go back and try again."); }
  106.  
  107. $totalkbytes = $totalbytes / 1024;
  108. $totalkbytes = sprintf("%.0f", $totalkbytes);
  109.  
  110. if (($uploadfilesizelimit ne "0") && ($totalkbytes > $uploadfilesizelimit)) {
  111.     foreach $filetemp (@fileswritten) { unlink $filetemp; }
  112.     $overthelimitby = $totalkbytes - $uploadfilesizelimit;
  113.     &gm_dangermouse("The file you attempted to upload was too large ($overthelimitby\k over the $uploadfilesizelimit\k filesize limit).  Please go back and try a smaller file.");
  114. }
  115.  
  116. &gm_writetocplog("$IN{'authorname'} uploaded a file ($uploadfilename, $totalkbytes\k)");
  117.  
  118. if (($uploadfilename =~ /\.jpg$/i) || ($uploadfilename =~ /\.gif$/i) || ($uploadfilename =~ /\.png$/i)) {
  119.  
  120. $usethisauthorname = $IN{'authorname'};
  121. $usethisauthorpassword = $IN{'authorpassword'};
  122. $filenameprefix = $uploadfilename;
  123. $filenameprefix =~ s/\.(...)$//;
  124.  
  125. print<<UPLOADEDIMAGE;
  126.  
  127. <HTML>
  128. <HEAD>
  129. <TITLE>Measuring Image...</TITLE>
  130.  
  131. <SCRIPT TYPE="text/javascript" LANGUAGE="Javascript1.2">
  132. <!--//
  133. function writesize() {
  134.     thisheight = document.thisimage.height;
  135.     thiswidth = document.thisimage.width;
  136.     document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><TITLE>Greymatter</TITLE><META NAME="Generator" CONTENT="Greymatter 1.2"></HEAD><BODY BGCOLOR="#8080B0" TEXT="#000000" LINK="#000000" VLINK="#000000" ALINK="#000000" MARGIN=10 TOPMARGIN=10 LEFTMARGIN=10 RIGHTMARGIN=10 BOTTOMMARGIN=10 MARGINHEIGHT=10 MARGINWIDTH=10 STYLE="scrollbar-face-color: #A0C0E0; scrollbar-shadow-color: #000000; scrollbar-highlight-color: #000000; scrollbar-3dlight-color: #000000; scrollbar-darkshadow-color: #000000; scrollbar-track-color: #000000; scrollbar-arrow-color: #000000"><BASE TARGET="_top"><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100% HEIGHT=100%><TR><TD VALIGN=MIDDLE ALIGN=CENTER><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD><P ALIGN=LEFT><FONT FACE="VERDANA, ARIAL, HELVETICA" SIZE=2><FONT COLOR="#C0C0E0" SIZE=4><B>Greymatter</B></FONT></FONT></P><TABLE BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR="#000000"><TR><TD><TABLE BORDER=0 CELLPADDING=10 CELLSPACING=0 BGCOLOR="#FFFFFF"><TR><TD VALIGN=MIDDLE ALIGN=CENTER><FONT FACE="VERDANA, ARIAL, HELVETICA" SIZE=2><B><FONT COLOR="#0000FF">Upload Complete</FONT></B><P>Your image (' + thiswidth + 'x' + thisheight + ', $totalkbytes\k) was successfully uploaded.<P><IMG BORDER=0 SRC="$EntriesWebPath/$uploadfilename" ALT="$filenameprefix ($totalkbytes\k image)" HEIGHT=' + thisheight + ' WIDTH=' + thiswidth + '><P><FONT SIZE=1><IMG BORDER=0 SRC="$EntriesWebPath/$uploadfilename" ALT="$filenameprefix ($totalkbytes\k image)" HEIGHT=' + thisheight + ' WIDTH=' + thiswidth + '><BR>{{popup $uploadfilename $filenameprefix ' + thiswidth + 'x' + thisheight + '}}$filenameprefix</A></FONT><P><FORM ACTION="gm.cgi" METHOD=POST><INPUT TYPE=HIDDEN NAME="authorname" VALUE="$usethisauthorname"><INPUT TYPE=HIDDEN NAME="authorpassword" VALUE="$usethisauthorpassword"><INPUT TYPE=HIDDEN NAME="newentrymaintext" VALUE="<IMG BORDER=0 SRC="$EntriesWebPath/$uploadfilename" ALT="$filenameprefix ($totalkbytes\k image)" HEIGHT=' + thisheight + ' WIDTH=' + thiswidth + '>"><INPUT TYPE=HIDDEN NAME="newentrypopuptext" VALUE="{{popup $uploadfilename $filenameprefix ' + thiswidth + 'x' + thisheight + '}}$filenameprefix</A>"><P><INPUT TYPE=SUBMIT CLASS="button" NAME="thomas" VALUE="Include This Image In A New Entry" STYLE="background: #D0FFD0; font-family: verdana, arial, helvetica; font-size: 13px; border-color: #000000; width: 300; height: 26"><P><INPUT TYPE=SUBMIT CLASS="button" NAME="thomas" VALUE="Include In Entry As A Popup Window" STYLE="background: #D0FFD0; font-family: verdana, arial, helvetica; font-size: 13px; border-color: #000000; width: 300; height: 26"><P><INPUT TYPE=SUBMIT CLASS="button" NAME="thomas" VALUE="Return To Main Menu" STYLE="background: #D0D0FF; font-family: verdana, arial, helvetica; font-size: 13px; border-color: #000000; width: 240; height: 26"></FORM><P><FONT SIZE=1>"If God created us in his own image, we have more than reciprocated."—Voltaire</FONT></FONT></TD></TR></TABLE></TD></TR></TABLE><P ALIGN=RIGHT><FONT FACE="VERDANA, ARIAL, HELVETICA" SIZE=1><A HREF="http://noahgrey.com/greysoft/" STYLE="text-decoration: none" TARGET="NEW">v$gmversion · ©2000-2001 Noah Grey</A></FONT></P></TD></TR></TABLE></TD></TR></TABLE></TD></TR></TABLE></BODY></HTML>');
  137. }
  138. //-->
  139. </SCRIPT>
  140.  
  141. </HEAD>
  142.  
  143. <BODY onLoad="writesize();">
  144.  
  145. <IMG NAME="thisimage" SRC="$EntriesWebPath/$uploadfilename">
  146.  
  147. </BODY>
  148. </HTML>
  149.  
  150. UPLOADEDIMAGE
  151.  
  152. exit;
  153.  
  154. }
  155.  
  156. if ($statusnote eq "") { $statusnote = qq(<B><FONT COLOR="#0000FF">Upload Complete</FONT></B><P>); }
  157.  
  158. $uploadfilenamelink = qq(<A HREF="$EntriesWebPath/$uploadfilename">$uploadfilename ($totalkbytes\k file)</A>);
  159.  
  160. print<<UPLOADCOMPLETE;
  161.  
  162. $gmheadtag
  163.  
  164. $gmframetop
  165. $statusnote
  166. Your file ($totalkbytes\k) was successfully uploaded.
  167. <P>
  168. <FONT SIZE=1>$uploadfilenamelink</FONT>
  169. <P>
  170. <FORM ACTION="gm.cgi" METHOD=POST>
  171. <INPUT TYPE=HIDDEN NAME="authorname" VALUE="$IN{'authorname'}">
  172. <INPUT TYPE=HIDDEN NAME="authorpassword" VALUE="$IN{'authorpassword'}">
  173. <INPUT TYPE=HIDDEN NAME="newentrymaintext" VALUE="$uploadfilenamelink">
  174. <INPUT TYPE=SUBMIT CLASS="button" NAME="thomas" VALUE="Include This Link In A New Entry" STYLE="background: #D0FFD0">
  175. <P>
  176. <INPUT TYPE=SUBMIT CLASS="button" NAME="thomas" VALUE="Return To Main Menu" STYLE="background: #D0D0FF">
  177. </FORM>
  178. <P>
  179. <FONT SIZE=1>"We can never tell what is in store for us."—Harry S. Truman</FONT>
  180. $gmframebottom
  181.  
  182. </BODY>
  183. </HTML>
  184.  
  185. UPLOADCOMPLETE
  186.  
  187. exit;
  188.