#!/usr/local/bin/perl ############################################################################## # WWWBoard Version 2.0 ALPHA 2 # # Copyright 1996 Matt Wright mattw@worldwidemart.com # # Created 10/21/95 Last Modified 11/25/95 # # Scripts Archive at: http://www.worldwidemart.com/scripts/ # ############################################################################## # COPYRIGHT NOTICE # # Copyright 1996 Matthew M. Wright All Rights Reserved. # # # # WWWBoard may be used and modified free of charge by anyone so long as # # this copyright notice and the comments above remain intact. By using this # # code you agree to indemnify Matthew M. Wright from any liability that # # might arise from it's use. # # # # Selling the code for this program without prior written consent is # # expressly forbidden. In other words, please ask first before you try and # # make money off of my program. # # # # Obtain permission before redistributing this software over the Internet or # # in any other medium. In all cases copyright and header must remain intact.# ############################################################################## # January 2000 face@centosprime.com fix date stuff # May 1996 trumbo@opus1.com modify for multiple boards under VMS # # For testing, this script is run from perl with a DCL command line like: #$ perl sys$login:wwwboard.PL "POST" "/htbin/perl/wwwboard" "HTTP/1.0" # >net_link: = 1) { &thread_pages; } # Return the user HTML &return_html; # Increment Number &increment_num; ####################### # Get Options Subroutine # For multiple boards running under the same server, each board # has a unique name, kept in a file in sys$login for the server; # the filename is a script option, $boarddat. # Use the boardname, a hidden form variable, to look up the path # to the particular board directory. sub get_options { $boarddatfile = "sys\$login:$boarddat"; # Find the board directory path from the server's config file open(BOARDDAT,$boarddatfile) || die $!; # open and read whole file into an array, separating name-value pairs @pairs = ; chop(@pairs); # trim newline char foreach $pair (@pairs) { ($name, $value) = split(/\s+/,$pair,2); $BOARDDAT{$name} = $value; } $boardname = $FORM{'boardname'}; die "Board name not found in server dat file" unless defined($BOARDDAT{$boardname}); $board_path = $BOARDDAT{$boardname}; $optfile = "$board_path$optfilename"; # open and read whole file into an array, separating name-value pairs open(OPTIONS,$optfile) || die $!; @pairs = ; chop(@pairs); # trim newline char foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair, 2); $OPTIONS{$name} = $value; } } ############################ # Get Data Number Subroutine sub get_number { open(NUMBER,"$basedir]$datafile"); $num = ; close(NUMBER); if ($num == 99999) { $num = "1"; } else { $num++; } } ####################### # Parse Form Subroutine sub parse_form { # Get the input read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # Split the name-value pairs @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); # Un-Webify plus signs and %-encoding $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s///g; if ($allow_html != 1) { $value =~ s/<([^>]|\n)*>//g; } else { unless ($name eq 'body') { $value =~ s/<([^>]|\n)*>//g; } } $FORM{$name} = $value; } } ############### # Get Variables sub get_variables { # stick all these options into less cumbersome variables that the script uses $cgi_url = $OPTIONS{'$cgi_url'}; $basedir = $OPTIONS{'$basedir'}; $baseurl = $OPTIONS{'$baseurl'}; $bgcolor = $OPTIONS{'$bgcolor'}; $mesgdir = $OPTIONS{'$mesgdir'}; $datafile = $OPTIONS{'$datafile'}; $mesgfile = $OPTIONS{'$mesgfile'}; $faqfile = $OPTIONS{'$faqfile'}; $headfile = $OPTIONS{'$headfile'}; $ext = $OPTIONS{'$ext'}; $title = $OPTIONS{'$title'}; $show_faq = $OPTIONS{'$show_faq'}; $allow_html = $OPTIONS{'$allow_html'}; $quote_text = $OPTIONS{'$quote_text'}; $subject_line = $OPTIONS{'$subject_line'}; $use_time = $OPTIONS{'$use_time'}; if ($FORM{'followup'}) { $followup = "1"; @followup_num = split(/,/,$FORM{'followup'}); $num_followups = @followups = @followup_num; $last_message = pop(@followups); $origdate = "$FORM{'origdate'}"; $origname = "$FORM{'origname'}"; $origsubject = "$FORM{'origsubject'}"; } else { $followup = "0"; } if ($FORM{'name'}) { $name = "$FORM{'name'}"; $name =~ s/"//g; $name =~ s///g; $name =~ s/\&//g; } else { &error(no_name); } if ($FORM{'email'} =~ /.*\@.*\..*/) { $email = "$FORM{'email'}"; } if ($FORM{'subject'}) { $subject = "$FORM{'subject'}"; $subject =~ s/\&/\&\;/g; $subject =~ s/"/\"\;/g; } else { &error(no_subject); } if ($FORM{'url'} =~ /.*\:.*\..*/ && $FORM{'url_title'}) { $message_url = "$FORM{'url'}"; $message_url_title = "$FORM{'url_title'}"; } if ($FORM{'img'} =~ /.*tp:\/\/.*\..*/) { $message_img = "$FORM{'img'}"; } if ($FORM{'body'}) { $body = "$FORM{'body'}"; $body =~ s/\cM//g; $body =~ s/\n\n/

/g; $body =~ s/\n/
/g; $body =~ s/<//g; $body =~ s/"/"/g; } else { &error(no_body); } if ($quote_text == 1) { $hidden_body = "$body"; $hidden_body =~ s//>/g; $hidden_body =~ s/"/"/g; } ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $year = ($year + 1900); # face if ($sec < 10) { $sec = "0$sec"; } if ($min < 10) { $min = "0$min"; } if ($hour < 10) { $hour = "0$hour"; } if ($mon < 10) { $mon = "0$mon"; } if ($mday < 10) { $mday = "0$mday"; } $month = ($mon + 1); @months = ("January","February","March","April","May","June","July","August","September","October","November","December"); if ($use_time == 1) { $date = "$month/$mday/$year $hour\:$min\:$sec"; } else { $date = "$month/$mday/$year"; } chop($date) if ($date =~ /\n$/); #face $long_date = "$months[$mon] $mday, 19$year at $hour\:$min\:$sec"; $long_date = "$months[$mon] $mday, $year at $hour\:$min\:$sec"; } ##################### # New File Subroutine sub new_file { # put an individual post into an individual file # read in some locally customized stuff from a file $newfile = "<$basedir]$headfile"; open(HEADER,$newfile) || die $!; @header =

; $newfile = ">$basedir.$mesgdir]$num\.$ext"; open(NEWFILE,$newfile) || die $!; foreach $header_line (@header) { print NEWFILE $header_line; } # this stuff should be in the HEADER file now # print NEWFILE "\n"; # print NEWFILE " \n"; # print NEWFILE " $subject\n"; # print NEWFILE " \n"; # print NEWFILE " \n"; # print NEWFILE "
\n"; # print NEWFILE "

$subject

\n"; # print NEWFILE "
\n"; print NEWFILE "
\n"; if ($show_faq == 1) { print NEWFILE "
[ Follow Ups ] [ Post Followup ] [ $title] [ FAQ ]
\n"; } else { print NEWFILE "
[ Follow Ups ] [ Post Followup ] [ $title ]
\n"; } print NEWFILE "

\n"; print NEWFILE "
$FORM{'subject'}
"; print NEWFILE "Posted by "; if ($email) { print NEWFILE "$name on $long_date:

\n"; } else { print NEWFILE "$name on $long_date:

\n"; } if ($followup == 1) { print NEWFILE "In Reply to: $origsubject posted by "; if ($origemail) { print NEWFILE "$origname on $origdate:

\n"; } else { print NEWFILE "$origname on $origdate:

\n"; } } print NEWFILE "$body\n"; print NEWFILE "
\n"; if ($message_url) { print NEWFILE "

\n"; } if ($message_img) { print NEWFILE "

\n"; } print NEWFILE "


\n"; print NEWFILE "Follow Ups:
\n"; print NEWFILE "

    \n"; print NEWFILE "
\n"; print NEWFILE "

\n"; print NEWFILE "Post a Followup

\n"; print NEWFILE "

\n"; print NEWFILE "\n"; print NEWFILE "\n"; if ($email) { print NEWFILE "\n"; } print NEWFILE "\n"; print NEWFILE "\n"; print NEWFILE ""; print NEWFILE "Name:
\n"; print NEWFILE "E-Mail:

\n"; if ($subject_line == 1) { if ($subject_line =~ /^Re:/) { print NEWFILE "\n"; print NEWFILE "Subject: $subject

\n"; } else { print NEWFILE "\n"; print NEWFILE "Subject: Re: $subject

\n"; } } elsif ($subject_line == 2) { print NEWFILE "Subject:

\n"; } else { if ($subject =~ /^Re:/) { print NEWFILE "Subject:

\n"; } else { print NEWFILE "Subject:

\n"; } } print NEWFILE "Comments:
\n"; print NEWFILE "\n"; print NEWFILE "

\n"; print NEWFILE "Optional Link URL:
\n"; print NEWFILE "Link Title:
\n"; print NEWFILE "Optional Image URL:

\n"; print NEWFILE " \n"; print NEWFILE "


\n"; if ($show_faq == 1) { print NEWFILE "
[ Follow Ups ] [ Post Followup ] [ $title ] [ FAQ ]
\n"; } else { print NEWFILE "
[ Follow Ups ] [ Post Followup ] [ $title ]
\n"; } print NEWFILE "\n"; close(NEWFILE); } ############################### # Main WWWBoard Page Subroutine sub main_page { open(MAIN,"$basedir]$mesgfile") || die $!; @main =
; close(MAIN); open(MAIN,">$basedir]$mesgfile") || die $!; if ($followup == 0) { foreach $main_line (@main) { if ($main_line =~ //) { print MAIN "\n"; print MAIN "
  • $subject - $name $date\n"; print MAIN "(0)\n"; print MAIN "
      \n"; print MAIN "
    \n"; } else { print MAIN "$main_line"; } } } else { foreach $main_line (@main) { $work = 0; if ($main_line =~ /
      /) { print MAIN "
        \n"; print MAIN "
      • $subject - $name $date\n"; print MAIN "(0)\n"; print MAIN "
          \n"; print MAIN "
        \n"; } elsif ($main_line =~ /\((.*)\)/) { $response_num = $1; $num_responses = $2; $num_responses++; foreach $followup_num (@followup_num) { if ($followup_num == $response_num) { print MAIN "($num_responses)\n"; $work = 1; } } if ($work != 1) { print MAIN "$main_line"; } } else { print MAIN "$main_line"; } } } close(MAIN); } ############################################ # Add Followup Threading to Individual Pages sub thread_pages { foreach $followup_num (@followup_num) { open(FOLLOWUP,"$basedir.$mesgdir]$followup_num\.$ext"); @followup_lines = ; close(FOLLOWUP); open(FOLLOWUP,">$basedir.$mesgdir]$followup_num\.$ext"); foreach $followup_line (@followup_lines) { $work = 0; if ($followup_line =~ /
          /) { print FOLLOWUP "
            \n"; print FOLLOWUP "
          • $subject $name $date\n"; print FOLLOWUP "(0)\n"; print FOLLOWUP "
              \n"; print FOLLOWUP "
            \n"; } elsif ($followup_line =~ /\((.*)\)/) { $response_num = $1; $num_responses = $2; $num_responses++; foreach $followup_num (@followup_num) { if ($followup_num == $response_num) { print FOLLOWUP "($num_responses)\n"; $work = 1; } } if ($work != 1) { print FOLLOWUP "$followup_line"; } } else { print FOLLOWUP "$followup_line"; } } close(FOLLOWUP); } } sub return_html { print "Content-type: text/html\n\n"; print "Message Added: $subject\n"; if ($bgcolor) { print "$bgcolor\n"; } print "

            Message Added: $subject

            \n"; print "The following information was added to the message board:


            \n"; print "Name: $name
            \n"; print "E-Mail: $email
            \n"; print "Subject: $subject
            \n"; print "Body of Message:

            \n"; print "$body

            \n"; if ($message_url) { print "Link: $message_url_title
            \n"; } if ($message_img) { print "Image:
            \n"; } print "Added on Date: $date $time

            \n"; print "


            \n"; print "
            [ Go to Your Message ] [ $title ]
            \n"; print "\n"; } sub increment_num { open(NUM,">$basedir]$datafile") || die $!; print NUM "$num"; close(NUM); } sub error { $error = $_[0]; print "Content-type: text/html\n\n"; if ($error eq 'no_name') { print "$title ERROR: No Name\n"; if ($bgcolor) { print "$bgcolor\n"; } print "

            ERROR: No Name

            \n"; print "You forgot to fill in the 'Name' field in your posting. Correct it below and re-submit. The necessary fields are: Name, Subject and Message.


            \n"; &rest_of_form; } elsif ($error eq 'no_subject') { print "$title ERROR: No Subject\n"; if ($bgcolor) { print "$bgcolor\n"; } print "

            ERROR: No Subject

            \n"; print "You forgot to fill in the 'Subject' field in your posting. Correct it below and re-submit. The necessary fields are: Name, Subject and Message.


            \n"; &rest_of_form; } elsif ($error eq 'no_body') { print "$title ERROR: No Message\n"; if ($bgcolor) { print "$bgcolor\n"; } print "

            ERROR: No Message

            \n"; print "You forgot to fill in the 'Message' field in your posting. Correct it below and re-submit. The necessary fields are: Name, Subjectand Message.


            \n"; &rest_of_form; } else { print "ERROR! Undefined.\n"; } exit; } sub rest_of_form { print "\n"; if ($followup == 1) { print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print ""; } print "Name:
            \n"; print "E-Mail:

            \n"; if ($subject_line == 1) { print "\n"; print "Subject: $FORM{'subject'}

            \n"; } else { print "Subject:

            \n"; } print "Message:
            \n"; print "

            \n"; print "Optional Link URL:
            \n"; print "Link Title:
            \n"; print "Optional Image URL:

            \n"; print " \n"; print ""; print "

          • \n"; print "

            \n"; if ($show_faq == 1) { print "
            [ Follow Ups ] [ Post Followup ] [ $title ] [ FAQ ]
            \n"; } else { print "
            [ Follow Ups ] [ Post Followup ] [ $title ]
            \n"; } print "\n"; } ;