home *** CD-ROM | disk | FTP | other *** search
/ ftp.sunet.sepub/pictures / 2014.11.ftp.sunet.se-pictures.tar / ftp.sunet.se / pub / pictures / ACiD-artpacks / www / mirrors / acheron / cgi-bin / discus / board-image.cgi < prev    next >
Text File  |  1999-01-26  |  12KB  |  300 lines

  1. #!/usr/bin/perl
  2. $discus_conf = '/usr/local/www/www.acheron.org/discus_admin_245059122/discus.conf';
  3. #Discus board image upload script
  4. #-------------------------------------------------------------------------------
  5. # This script is copyright (c) 1998 by DiscusWare, LLC, all rights reserved.
  6. # Its use is subject to the license agreement that can be found at the following
  7. # URL:  http://www.chem.hope.edu/discus/license
  8. #-------------------------------------------------------------------------------
  9. if (open (FILE, "$discus_conf")) {
  10.     @file = <FILE>;
  11.     close (FILE);
  12.     $evals = "";
  13.     foreach $line (@file) {
  14.         if ($line =~ /^(\w+)=(.*)/) {
  15.             $varname = $1;
  16.             $value = $2;
  17.             $value =~ s/'/\\'/g; $value =~ s/\r//g;
  18.             $evals .= "\$$varname='$value'; ";
  19.         }
  20.     }
  21.     eval($evals);
  22.     require "$admin_dir/source/src-board-subs-common";
  23. } else {
  24.     print "Content-type: text/html\n\n";
  25.     print "<HTML><HEAD><TITLE>Script Execution Error</TITLE></HEAD>\n";
  26.     print "<BODY BGCOLOR=#ffffff TEXT=#000000>\n";
  27.     print "<H1>Script Execution Error</H1>\n";
  28.     print "Discus scripts could not execute because the discus.conf file\n";
  29.     print "could not be opened.";
  30.     print "<P>Reason: <FONT COLOR=#ff0000><B>$!</B></FONT>" if $!;
  31.     print "<P>This generally indicates a setup error of some kind.\n";
  32.     print "Consult the <A HREF=\"http://www.chem.hope.edu/discus/rc\">Discus ";
  33.     print "Resource Center</A> for troubleshooting information.</BODY></HTML>\n";
  34.     exit(0);
  35. }
  36. require "$admin_dir/source/src-board-subs-admin";
  37. ###################### MIME TYPES FOR ACCEPTABLE IMAGES ######################
  38. $extension{"image/gif"} = "gif"; $tag{"image/gif"} = "image_alreadyuploaded";
  39. $extension{"image/jpeg"} = "jpg"; $tag{"image/jpeg"} = "jpeg_alreadyuploaded";
  40. $extension{"image/pjpeg"} = "jpg"; $tag{"image/pjpeg"} = "jpeg_alreadyuploaded";
  41. ################################################
  42. #    Script Starts Here
  43. ################################################
  44. &parse_multipart;
  45. &read_cookie;
  46. if ($FORM{'action'} =~ /profile/) {
  47.     &ex('image_handler_PRO', 1);
  48.     exit(0);
  49. }
  50. &extract($FORM{'HTTP_REFERER'});
  51. $FORM{'name'} = $FORM{'username'} if $FORM{'username'} ne "";
  52. $FORM{'number'} = $FORM{'passwd'} if $FORM{'passwd'} ne "";
  53. $name2 = $FORM{'name'}; $name2 =~ tr/A-Z/a-z/;
  54. $number2 = $FORM{'number'}; $number2 =~ tr/A-Z/a-z/;
  55. ($auth, $passwordline, $poster_type) = &ex('verify_postread_privileges', $topic_number, $name2, $password_input, $number2, "posting");
  56. if ($ENV{'HTTP_REFERER'} ne "$script_url/board-post.$cgi_extension" && $ENV{'HTTP_REFERER'} ne "$script_url/board-image.$cgi_extension") {
  57.     &error_message("Invalid Referer", "You are not accessing this page from an acceptable referring page.  What are you trying to do?");
  58. }
  59. if ($FORM{'queue'}) {
  60.     $FORM{'queue'} =~ s/\D//g;
  61.     if (!-e "$admin_dir/queue/$FORM{'queue'}.txt") {
  62.         &error_message("Message Queue Error", "The message you are attempting to access is no longer in the queue.");
  63.     }
  64. }
  65. $formpostindex = $FORM{'postindex'}; $formpostindex =~ s/\D//g;
  66. if (!$FORM{'queue'} ) {
  67.     &lock("$message_dir/$topic_number/$me_number.$ext");
  68.     $filename = "$topic_number/$me_number.$ext";
  69.     ($head, $color, $lm, $ann, $ann_src, $sublist, $about, $about_src, $message_in, $message_src) = &get_page($topic_number,$me_number);
  70.     if (-e "$message_dir/$filename") {
  71.         $secure = 0;
  72.     } else {
  73.         $secure = 1;
  74.     }
  75.     @src = split(/\n/,$message_src); $flag = 0;
  76.     foreach $line (@src) {
  77.         if ($line =~ m|<!-Source: $formpostindex-|) {
  78.             $flag = 1;
  79.         } elsif ($line =~ m|<!-/Source: $formpostindex-|) {
  80.             $flag = 0;
  81.         } elsif ($flag == 1) {
  82.             $srcline = $line;
  83.         }
  84.     }
  85. } else {
  86.     $filename = "$admin_dir/queue/$FORM{'queue'}.txt";
  87.     &lock($filename);
  88.     open (QUEUE, $filename); @queue = <QUEUE>; close (QUEUE);
  89.     ($message_src) = grep(/^SOURCE: /, @queue); $message_src =~ s/^(\w+): (.*)/$2/;
  90.     $srcline = $message_src;
  91.     $queue = 1;
  92.     &unlock($filename);
  93. }
  94. $adminappend = "?username=$FORM{'name'}";
  95. $adminappend .= "&HTTP_REFERER=$FORM{'HTTP_REFERER'}&action=page_editor";
  96. ($bgcolor, $text, $link, $vlink, $alink, $face, $size, $image) = &ex('extract_colorsonly', 1);
  97. undef %status; undef %statuscode; undef @statusorder; undef %descr;
  98. $srcline = &unescape($srcline);
  99. while ($srcline =~ m|\\image_notuploaded\{(\d+),([^\}]*)\}|) {
  100.     ($counter, $description, $before, $after) = ($1, $2, $`, $');
  101.     $descr{$counter} = $description;
  102.     $FORMNAME{$counter} = "Image$counter";
  103.     push (@statusorder, $counter);
  104.     $formname = "Image$counter"; $content = $CONTENT{$formname};
  105.     if ($content =~ m|mac/unknown|) {
  106.         $content = "image/gif" if $FILE{$formname} =~ m|^GIF|i;
  107.         $content = "image/jpeg" if $FILE{$formname} !~ m|^GIF|i;
  108.     }    
  109.     if ($FILE{$formname} eq "") {
  110.         $status{$counter} = $FILENAME{$formname};
  111.         $statuscode{$counter} = 2;
  112.         $srcline = join("", $before, "\\image_notuploaded*{$counter,$description}", $after);
  113.     } elsif (!grep(/^$content$/, keys(%tag))) {
  114.         $status{$counter} = $content;
  115.         $statuscode{$counter} = 1;
  116.         $srcline = join("", $before, "\\image_notuploaded*{$counter,$description}", $after);
  117.     } elsif ($poster_type == 8 && length($FILE{$formname}) > ($GLOBAL_OPTIONS{'public_maxsize'} * 1000) && $GLOBAL_OPTIONS{'public_maxsize'} != 0) {
  118.         $statuscode{$counter} = 3;
  119.         $srcline = join("", $before, "\\image_notuploaded*{$counter,$description}", $after);
  120.     } elsif ($poster_type != 8 && length($FILE{$formname}) > ($GLOBAL_OPTIONS{'registered_maxsize'} * 1000) && $GLOBAL_OPTIONS{'registered_maxsize'} != 0) {
  121.         $statuscode{$counter} = 3;
  122.         $srcline = join("", $before, "\\image_notuploaded*{$counter,$description}", $after);
  123.     } else {
  124.         $newtag = $tag{$content}; $newext = $extension{$content};
  125.         ($num) = &ex('get_number', 1);
  126.         $srcline = join("", $before, "\\", $newtag, "{$num,$description}", $after);
  127.         $filename = "$message_dir/$topic_number/$num.$newext" if (!$queue && -e "$message_dir/$topic_number");
  128.         $filename = "$secdir/$topic_number/$num.$newext" if (!$queue && !-e "$message_dir/$topic_number");
  129.         $filename = "$admin_dir/queue/$num.$newext" if $queue;
  130.         open (FILE, ">$filename");
  131.         eval 'binmode(FILE);';
  132.         print FILE $FILE{$formname};
  133.         close (FILE);
  134.         chmod(0644, $filename);
  135.         $status{$counter} = length($FILE{$formname});
  136.         $statuscode{$counter} = 0;
  137.         $redoflag = 1;
  138.     }
  139. }
  140. while ($srcline =~ m|\\image_notuploaded\*\{(\d+),([^\}]*)\}|) {
  141.     ($counter, $description, $before, $after) = ($1, $2, $`, $');
  142.     $srcline = join("", $before, "\\image_notuploaded{$counter,$description}", $after);
  143. }
  144. if ($pro) {
  145.     ($srcline) = &ex('attachment_upload', $srcline, $topic_number, $queue, $poster_type);
  146. }
  147. $srcline =~ s/\"/"/g;
  148. $srcline =~ s/\</</g;
  149. $srcline =~ s/\>/>/g;
  150. $srcline =~ s/\&/&/g;
  151. $srcline_new = $srcline;
  152. $srcline = &escape($srcline_new);
  153. ($lint, $message_var_replace) = &ex('webtags', $srcline_new, 0, 1);
  154. if (!$queue) {
  155.     @msg = split(/\n/, $message_in); $flag = 0; $ctr = 0;
  156.     foreach $line (@msg) {
  157.         $ctr += 1;
  158.         if ($line =~ m|<!-/Post: $formpostindex-!>|) {
  159.             $flag = ($ctr-1);
  160.         }
  161.     }
  162.     if ($flag) {
  163.         $msg[$flag-1] = $message_var_replace;
  164.     }
  165.     @src = split(/\n/, $message_src); $flag = 0;
  166.     foreach $line (@src) {
  167.         if ($line =~ m|<!-Source: $formpostindex-|) {
  168.             $flag = 1;
  169.         } elsif ($line =~ m|<!-/Source: $formpostindex-|) {
  170.             $flag = 0;
  171.         } elsif ($flag == 1) {
  172.             $line = $srcline;
  173.         }
  174.     }
  175.     $message_var = join("\n", @msg);
  176.     $new_source = join("\n", @src);
  177.     &set_page($topic_number, $me_number, $head, $color, $lm, $ann, $ann_src, $sublist, $about, $about_src, $message_var, $new_source) if !$queue;
  178.     &unlock("$message_dir/$topic_number/$me_number.$ext");
  179. } else {
  180.     $filename = "$admin_dir/queue/$FORM{'queue'}.txt";
  181.     &lock($filename);
  182.     open (QUEUE, "$filename"); @queue = <QUEUE>; close (QUEUE);
  183.     @queue = grep(!/^TEXT:/, @queue);
  184.     @queue = grep(!/^SOURCE:/, @queue);
  185.     push (@queue, "TEXT: " . &escape($message_var_replace) . "\n");
  186.     push (@queue, "SOURCE: " . $srcline . "\n");
  187.     open (QUEUE, ">$filename"); print QUEUE @queue; close (QUEUE);
  188.     &unlock($filename);
  189. }
  190. $error = 0;
  191. foreach $key (keys(%statuscode)) {
  192.     $error = 1 if $statuscode{$key} != 0;
  193. }
  194. if ($error == 0) {
  195.     if ($queue) {
  196.         &ex('queue_submitted', $topic_number, $me_number, $adminappend, $FORM{'isitok'});
  197.     } elsif ($FORM{'isitok'} eq "okiedokie") {
  198.         &seturl("$cgiurlm$adminappend");
  199.     } else {
  200.         if (-e "$message_dir/$topic_number/$me_number.$ext") {
  201.             $lmstuff = "?$lm" if !$noqm;
  202.             &seturl("$message_url/$topic_number/$me_number.$ext$lmstuff");
  203.         } else {
  204.             &seturl("$script_url/board-auth.$cgi_extension?file=/$topic_number/$me_number.$ext&lm=$lm");
  205.         }
  206.     }
  207. }
  208. &header;
  209. &ex('printuntil', 1, 1, 0, $L{BI_UPLOAD_ERROR_TITLE});
  210. print "<CENTER><FONT SIZE=+1><B>$L{BI_UPLOAD_ERROR_TITLE}</B></FONT></CENTER><HR>\n";
  211. print $L{BI_UPLOAD_ERROR_MESSAGE};
  212. print "<P><HR>\n";
  213. &ex('printuntil', 3, 11, 0, "", 0, 1);
  214. print "<FORM ACTION=\"$script_url/board-image.$cgi_extension\" METHOD=POST ENCTYPE=\"multipart/form-data\">\n";
  215. foreach $num (@statusorder) {
  216.     next if $statuscode{$num} == 0;
  217.     print "$L{BPPROVIDEFILE} <B>$descr{$num}</B>:<P>\n";
  218.     $formname = $FORMNAME{$num};
  219.     if ($statuscode{$num} == 1) {
  220.         $fmt = $CONTENT{"Image$num"};
  221.         $fmtstr = $L{BI_UPLOAD_ERROR_BADFORMAT};
  222.         $fmtstr =~ s/\%format/$fmt/g;
  223.         print "<UL>$fmtstr</UL>\n";
  224.         print "<P>\n";
  225.     } elsif ($statuscode{$num} == 2) {
  226.         print "<UL>$L{BI_UPLOAD_ERROR_NODATA}</UL>\n";
  227.         print "<P>\n";
  228.     } elsif ($statuscode{$num} == 3) {
  229.         $fmtstr = $L{BI_UPLOAD_EXCEEDED_MAXLENGTH};
  230.         $maxsize = $GLOBAL_OPTIONS{'public_maxsize'} if $poster_type == 8;
  231.         $maxsize = $GLOBAL_OPTIONS{'registered_maxsize'} if $poster_type != 8;
  232.         $yoursize = length($FILE{$formname}); $yoursize = ($yoursize / 1000);
  233.         if ($yoursize =~ m|\.|) { $yoursize = $`; }
  234.         $fmtstr =~ s/\%maxsize/$maxsize/g;
  235.         $fmtstr =~ s/\%yoursize/$yoursize/g;
  236.         print "<UL>$fmtstr</UL>\n";
  237.         print "<P>\n";
  238.     }
  239.     $ctr++;
  240.     print "<TABLE><TR><TD><INPUT TYPE=FILE NAME=\"Attachment$num\" SIZE=40></TD></TR></TABLE>\n" if $formname =~ m|Attachment|;
  241.     print "<TABLE><TR><TD><INPUT TYPE=FILE NAME=\"Image$num\" SIZE=40></TD></TR></TABLE>\n" if $formname =~ m|Image|;
  242.     print "<HR>\n";
  243. }
  244. print "<INPUT TYPE=SUBMIT VALUE=\"$L{BPIMGUPLOADBUTTON}\">\n";
  245. print "<INPUT TYPE=HIDDEN NAME=name VALUE=\"$FORM{'name'}\">\n";
  246. print "<INPUT TYPE=HIDDEN NAME=number VALUE=\"$FORM{'number'}\">\n";
  247. print "<INPUT TYPE=HIDDEN NAME=HTTP_REFERER VALUE=\"$FORM{'HTTP_REFERER'}\">\n";
  248. print "<INPUT TYPE=HIDDEN NAME=postindex VALUE=\"$FORM{'postindex'}\">\n";
  249. print "<INPUT Type=hidden name=\"isitok\" value=\"okiedokie\">\n" if $FORM{'isitok'} eq "okiedokie";
  250. print "<INPUT TYPE=HIDDEN NAME=queue VALUE=\"$FORM{'queue'}\">\n";
  251. print "<HR></FORM>\n";
  252. &extract($FORM{'HTTP_REFERER'});
  253. $secure = 0;
  254. $secure = 1 if !-e "$message_dir/$topic_number";
  255. $url = "$message_url/$topic_number/$me_number.$ext" if !$secure;
  256. $url = "$script_url/board-auth.$cgi_extension?file=/$topic_number/$me_number.$ext&lm=$ts" if $secure;
  257. if ($FORM{'isitok'} ne "okiedokie") {
  258.     print "$L{BPIMGUPLOADCANCEL13_00} <A HREF=\"$url\">\n";
  259. } else {
  260.     print "$L{BPIMGUPLOADCANCEL13_00} <A HREF=\"$cgiurlm$adminappend\">\n";
  261. }
  262. print "$L{BPIMGUPLOADCANCEL2}</A>. ";
  263. print "$L{BPIMGUPLOADCANCEL33_00}\n";
  264. &ex('printuntil', 13, 17, 0, "", 0, 1);
  265. exit(0);
  266. sub parse_multipart {
  267.     &ex('default_mime_types', 1) if $pro;
  268.     $type = $ENV{'CONTENT_TYPE'};
  269.     ($boundary) = ($type =~ /boundary=(.*)/);
  270.     $boundary = "--" . $boundary;
  271.     $length = $ENV{'CONTENT_LENGTH'}; $len = 0; $input = "";
  272.     eval 'binmode(STDIN);';
  273.     while ($len < $length) {
  274.         $buf = ""; $len += sysread(STDIN, $buf, $length); $input .= $buf;
  275.     }
  276.     @input_pairs = split(/$boundary/, $input);
  277.     foreach $line (@input_pairs) {
  278.         ($header, $body) = split(/\r\n\r\n|\n\n/, $line, 2);
  279.         $body =~ s/\r\n$//;
  280.         $header =~ /name="([^"]+)"/;
  281.         $formname = $1;
  282.         $header =~ /filename="([^"]+)"/;
  283.         $filename = $1;
  284.         if ($header =~ /Type: (.*)/) {
  285.             $content = $1;
  286.             $FILE{$formname} = $body;
  287.             $CONTENT{$formname} = $content;
  288.             ($FILENAME{$formname}) = &ex('parse_filename', $filename);
  289.         } elsif ($header =~ m|filename="|) {
  290.             $content = "mac/unknown";
  291.             $FILE{$formname} = $body;
  292.             $CONTENT{$formname} = $content;
  293.             ($FILENAME{$formname}) = &ex('parse_filename', $filename);
  294.         } elsif ($formname =~ /^(\w+)$/) {
  295.             $FORM{$formname} = $body if $FORM{$formname} eq "";
  296.             $FORM{$formname} =~ s/\r//g;
  297.         }
  298.     }
  299. }
  300.