radical hacks WebBBS File Attachment Enhancements sent in this hack which makes file attachments in webBBS work a bit better. He modified the section of code in "CreatePosting" that deals with saving the attachment and has included some of the original code so you should be able to spot where to make the modifications. This change will allow the web server to send the correct MIME type based on the file extension.

Patching with a diff File

You can get a diff file from here. This diff file was generated from modifications to BBS v. 5.0 and is not necessarily sanctioned by eXtropia: Any complaints should be directed to . You should run 'patch <extropia-bbs.diff' in the bbs directory to apply this patch.

Please note that this changes the path to perl from /usr/local/bin/perl to /usr/bin/perl in both of the '.cgi' programs so be sure the executable path in said files is set to the correct location. Also, you will need to create an Attach directory as configured in bbs.setup.

 

Patching by Hand

At about line 150 in bbs.setup, add the seven lines:

#Hack for images -- Bill Adams (bill@evil.inetarena.com)
#What extensions are allowed?  Be careful that you do not include
#  anything executable (i.e. bat, pl, cgi, exe, sh, dll, etc.).  If
#  it is not listed here it will get the extension 'bin'.
@allowed_exts = qw(jpg jpeg tif tiff png gif html htm);

#And what extension is an image extension?
@image_exts = qw( jpg tif png gif );

If you want images to appear automatically, then add/change the code in bbs_forum.cgi at line 293 to:
    #Hack -- Bill Adams
    my $regexp = join('|', @image_exts);
    if ($post_attachment =~ /\.($regexp)$/) {
      $post_message .= "<BR>
      <IMG SRC=\"$attach_url/$post_attachment\"
           ALT=\"Image\"><BR>";
    } else {
      $post_attach_html = 
        qq!<BR><B>Attached File:</B> ! . 
          qq!<A HREF="$attach_url/$post_attachment">
            $post_attachment_filename</A><BR>!;
    }

To enable the correct extension to be placed on the attached file -- at the now line 731 if you made the above change -- add/change the following lines:
    # Hack -- Bill Adams for attaching images...
    if ($post_attachment_filename ne "") {
      my $ext;
      if ($post_attachment_filename =~ /\.([\d\w]{1,4})$/i) {
        $ext = $1;
        $ext =~ tr/[A-Z]/[a-z]/; #Lower case only!
        #Fix the extension for a couple of special cases
        if ($ext eq 'jpeg') {$ext = 'jpg'}
        elsif ($ext eq 'htm') {$ext = 'html'}
        elsif ($ext =~ /\.(cgi|pl|exe)/) {$ext = 'bix'} #Security!
        
      } else {
        #Default is unknown.
        $ext = 'bin';
      }
        rename($post_attachment, 
               "$attach_dir/$forum-$message_name.$ext");
        open(WRITEATTACH, 
             ">$forum_dir/$message_name.attach") ||
                 &CgiDie("Could Not Open Attachment\n");
        print WRITEATTACH 
            "$forum-$message_name.$ext" . 
                "|$post_attachment_filename\n";
        close(WRITEATTACH);
    } else {
        unlink("$post_attachment");
    }