#!/usr/bin/perl ############################################################################## # Cliff's Message Board Script Version 1.51 # # Copyright 1998 Shaven Ferret Productions # # Created 6/4/98 Last Modified 1/6/2000 # # Available at http://www.shavenferret.com/scripts # ############################################################################## # COPYRIGHT NOTICE # # Copyright 1998 Shaven Ferret Productions All Rights Reserved. # # # # This script can be used\modified free of charge as long as you don't # # change this header, the parts that generate the return link, or the parts # # that mention me in the e-mail. If you really need to change these parts, # # go to http://www.shaveneferret.com/scripts/register.shtml . By using this # # script you agree to indemnify me from any liability that might arise from # # its use. In simple English, if this script somehow makes your computer # # run amuck and kill the pope, it's not my fault. # # # # Redistributing\selling the code for this program without prior written # # consent is expressly forbidden. # ############################################################################## # Paths ############################################################################## # Set this to the path of the directory where the forums will be kept. Do not # include a trailing slash. $path = "/server/path/to/message"; # Set this to the path of the directory where all the messages will be kept. # Do not include a trailing slash. Do not make this the same directory # as the forums directory. $post = "/server/path/to/message/posts"; # Set this to the path of the admin.html file. You should put this where # no one will find it. $adminpath = "/server/path/to/admin.html"; ############################################################################## # URLs ############################################################################## # Set this to the URL of the message board directory. Do not include a # trailing slash $mainurl = "http://www.yourdomain.com/message"; # Set this to the URL of the directory where all the messages will be kept. # Do not include a trailing slash. $posturl = "http://www.yourdomain.com/message/posts"; # Set this to the file name of the main message page $mainpage = "index.html"; # Set this to the URL of the message.cgi file once uploaded $script_url = "/cgi-bin/message.cgi"; ############################################################################## # Mail Stuff ############################################################################## # Enter the location of your mail program. $mailprogram = "/usr/lib/sendmail"; # Enter your e-mail address. Be sure to put a \ in front of the @. # (user@domain.com becomes user\@domain.com) $youremail = "you\@yourdomain.com"; # If you don't want to be notified every time someone posts a message, put a # # in front of the next line. $notifyme = -1; ############################################################################## # Other Stuff ############################################################################## # Set the next variable to whatever you want your password to be. You will # need the password to create\delete forums and message. $password = "shavenferret.com"; # Enter the name of your message board $title = "My Message Board"; # If you'd like to lock out HTML, leave this next variable as 1. If you'd # like to allow HTML, change it to 0. If you leave it as 1, anything in # a message between < and > will be removed. $nohtml = 1; ############################################################################## # Congratulations! You've finished defining the variables. If you want to, # # you can continue screwing with the script, but it isn't necessary. # ############################################################################## # Put the posted data into variables read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; if ($nohtml == 1) { $value =~ s/<([^>]|\n)*>//g; $value =~ s///g; } $value =~ s/"/'/g; $FORM{$name} = $value; } # Define $date and $time @months = ('January','February','March','April','May','June','July','August','September','October','November','December'); @days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); ($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime(time))[0,1,2,3,4,5,6]; if ($sec < 10) { $sec = "0$sec"; } if ($min < 10) { $min = "0$min"; } if ($hour < 10) { $hour = "0$hour"; } if ($mday < 10) { $mday = "0$mday"; } $year += 1900; $date = "$days[$wday], $months[$mon] $mday, $year"; $time = "$hour:$min:$sec"; # This script runs every part of the message board. To find out what it is # doing, it looks at $FORM{'action'}, which is a hidden input thing in all # the files it creates. The next line examines $FORM{'action'} to find out # what to do. print "Content-type: text/html\n\n"; if ($FORM{'action'} eq "new_forum") { &new_forum; } if ($FORM{'action'} eq "add_music") { &new_songicon("song"); } if ($FORM{'action'} eq "add_icon") { &new_songicon("icon"); } if ($FORM{'action'} eq "new_message") { &new_message; } if ($FORM{'action'} eq "preview_message") { &preview_message; } if ($FORM{'action'} eq "del_songicon") { &delmi; } if ($FORM{'action'} eq "remove_message") { &delmessage; } # If nothing has been done, then the action thing has been removed, # implying that the file has been corrupted. The next few lines print a # message that lets the user know this. print "This could be a problem \n"; print "

D'oh!

It would appear that the variable that lets this\n"; print "script know what to do has mysteriously disappeared or been altered. This could\n"; print "mean that the page you were just at has become corrupted."; sub new_forum { &checkpassword; # Make sure you've picked a name for the forum unless ($FORM{'forum_name'}) { print "You forgot the forum name\n"; print "

You forgot the forum name

Please enter the name of\n"; print "the forum you wish to create...\n"; &missing('forum_name'); } # Get the name of the forum and update the data open (DATA, "$path/nums.txt"); $data = ; ($forum_num,$message_num) = split(/\|/,$data); close(DATA); $forum_num++; open (DATA, ">$path/nums.txt"); print DATA "$forum_num|$message_num"; close(DATA); # Create the html file that will be used as the forum. open (FILE, ">$path/$forum_num.html"); print FILE "$title :: $FORM{'forum_name'} Forum\n"; print FILE "

$title :: "; print FILE "$FORM{'forum_name'} Forum

\n"; &sig; print FILE "$FORM{'desc'}
\n"; if ($FORM{'require'} == 0) { print FILE "You can post here anonymously\n"; } if ($FORM{'require'} == 1) { print FILE "You need to enter your name to post here\n"; } if ($FORM{'require'} == 2) { print FILE "You need to enter your e-mail address to post here\n"; } if ($FORM{'require'} == 3) { print FILE "You need to enter your name and e-mail address to post here\n"; } print FILE "

\n"; print FILE "Messages: (click here to post a message.)\n"; print FILE "

\n

\n"; &posthtml; print FILE "\n"; print FILE "\n"; print FILE "\n"; print FILE "\n"; &sig; print FILE "\n"; # Add the forum to the administrative file. open (FILE, "$adminpath"); @lines = ; close(FILE); open (FILE, ">$adminpath"); foreach $line(@lines) { if (substr($line,0,14) eq "") { print FILE "\n"; print FILE "
  • $FORM{'forum_name'} -- Forum"; print FILE "
      \n
    \n"; } elsif (substr($line,0,6) eq "
    ") { print FILE "\n"; } else { print FILE "$line"; } } close(FILE); # Add the forum to the main page open (FILE, "$path/$mainpage"); @lines = ; close(FILE); open (FILE, ">$path/$mainpage"); foreach $line(@lines) { if (substr($line,0,14) eq "") { print FILE "\n
    $FORM{'forum_name'}"; print FILE "\nNA\n"; } elsif (substr($line,0,7) eq "") { print FILE "<title>$title\n"; } elsif (substr($line,0,14) eq "") { print FILE "$title\n"; } else { print FILE "$line"; } } close(FILE); # If everything went ok, display the following and exit. print "Forum Added\n"; print "

    Forum Added

    The $FORM{'forum_name'} forum has been\n"; print "added. Your description of it reads: $FORM{'desc'}. It is\n"; print "located at "; print "$mainurl/$forum_num.html\n"; exit; } sub checkpassword { unless ($FORM{'password'} eq $password) { print "Bad password\n"; print "

    Bad Password


    \n"; print "The password you entered, $FORM{'password'}, is incorrect.\n"; print "The following information has been mailed to the owner of\n"; print "the message board...
      \n"; print "
    • Date/Time: $date $time\n"; print "
    • Domain: $ENV{'REMOTE_HOST'}\n"; print "
    • IP Address: $ENV{'REMOTE_ADDR'}\n"; print "
    • Password: $FORM{'password'}\n"; print "
    \n"; open (MAIL,"|$mailprogram -t"); print MAIL "To: $youremail\n"; print MAIL "From: bad\@password.xxx\n"; print MAIL "Subject: bad password\n"; print MAIL "Just a quick note to let you know that someone\n"; print MAIL "has entered the wrong password for your message\n"; print MAIL "board. Here's the\n"; print MAIL "information...\n\n"; print MAIL " Date/Time: $date $time\n"; print MAIL " Domain: $ENV{'REMOTE_HOST'}\n"; print MAIL " IP Address: $ENV{'REMOTE_ADDR'}\n"; print MAIL " Password: $FORM{'password'}\n"; close(MAIL); exit; } } sub sig { # Please do NOT change this sub or any place in this script where this sub # is called print FILE "

    Message Board Script by Cli"; print FILE "ff(tm), Shaven Ferret Productions, and availab"; print FILE "le at http://www.shavenferret.com/scripts
    \n"; } sub posthtml { print FILE "\n"; print FILE "

    Post\n"; print FILE "a Message

    \n"; print FILE "\n"; print FILE "\n"; &musicicon("song"); &musicicon("icon"); if ($FORM{'email'}) { print FILE "\n"; } print FILE "\n"; print FILE "
    \n"; print FILE "Your name:
    Your e-mail address:
    Subject
    \n"; print FILE "Message:
    E-mail response to\n"; print FILE "original poster?\n"; print FILE "Yes
    \n"; print FILE "No
    \n"; print FILE "\n"; unless ($FORM{'email'}) { print FILE "\n"; } } sub new_songicon { $which = shift(@_); &checkpassword; # make sure everything's filled out if ($FORM{'url'} eq "http://" || $FORM{'url'} eq "" || substr($FORM{'url'},0,7) ne "http://") { print "Please enter the full URL of the $which\n"; print "

    Please enter the full URL of the $which

    "; &missing("url"); } unless ($FORM{'title'}) { print "Please enter the title of the $which\n"; print "

    Please enter the title of the $which

    "; &missing("title"); } # Add the song or icon to the data &update($which); # add it to the admin file open (FILE, "$adminpath"); @lines = ; close(FILE); open (FILE, ">$adminpath"); foreach $line(@lines) { if (substr($line,0,13) eq "") { print FILE "\n"; print FILE "
  • $FORM{'title'}"; if ($which eq "song") { print FILE "(song)\n"; } if ($which eq "icon") { print FILE "()\n"; } } else { print FILE "$line"; } } print "$which added\n"; print "The $which has been added. Please click back\n"; print "\n"; exit; } sub missing { $dontprint = shift(@_); print "\n"; foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; if ($nohtml == 1) { $value =~ s/<([^>]|\n)*>//g; $value =~ s///g; } unless ($name eq $dontprint) { print "\n"; } } print "\n"; print "
  • \n"; exit; } sub musicicon { $which = shift(@_); print FILE "\n"; open (DATA, "$path/$which.txt"); @bgmusic = ; close(DATA); if ($#bgmusic >= 0) { if ($which eq "song") { print FILE "Background Music:\n\n"; print FILE "\n"; } foreach $music(@bgmusic) { print FILE "$music\n"; } print FILE "\n"; print FILE "\n\n"; } print FILE "\n"; } sub preview_message { # Make sure required fields are filled out if ($FORM{'required'} == 1 || $FORM{'required'} == 3) { unless($FORM{'name'}) { print "You must give your name to post here\n"; print "

    Please enter your name

    \n"; &missing("name"); } } if ($FORM{'required'} > 1 && $FORM{'email'} eq "") { print "E-mail address required\n"; print "

    I'm sorry, but you must enter an\n"; print "e-mail address to post here

    \n"; &missing("email"); } if ($FORM{'email'} && ($FORM{'email'}) !~ /.+@.+\.\w\w+/) { print "Bad e-mail address\n"; print "

    Bad E-mail

    I'm sorry, but the e-mail\n"; print "address you've entered, $FORM{'email'}, is invalid. Please\n"; print "try again.\n"; &missing("email"); } unless ($FORM{'body'}) { print "Please write something\n"; print "

    You didn't write anything!

    Please click back and\n"; print "try again.\n"; exit; } if ($FORM{'subject'} eq "") { $FORM{'subject'} = "[ No Subject ]"; } if ($FORM{'name'} eq "") { $FORM{'name'} = "anonymous"; } # show a preview of the message $message_preview = &message_html; print "Preview your message...\n"; print "

    Preview your message:

    \n"; print "This is what your message will look like when posted. If you want\n"; print "to change anything, please click back now. To post it, click the button\n"; print "below the message.

    \n"; print "$message_preview\n"; print "

    \n"; foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; if ($nohtml == 1) { $value =~ s/<([^>]|\n)*>//g; $value =~ s///g; } unless ($name eq "action") { print "\n"; } $FORM{$name} = $value; } print "\n"; print "
    \n"; print "\n"; exit; } sub new_message { # get the number for the message and update the data file open (DATA, "$path/nums.txt"); $data = ; ($forum_num,$message_num) = split(/\|/,$data); close(DATA); $message_num++; open (DATA, ">$path/nums.txt"); print DATA "$forum_num|$message_num"; close(DATA); # Create the message if ($FORM{'subject'} eq "") { $FORM{'subject'} = "[ No Subject ]"; } if ($FORM{'name'} eq "") { $FORM{'name'} = "anonymous"; } open (FILE, ">$post/$message_num.html"); print FILE "$FORM{'subject'}\n"; &sig; $message = &message_html; print FILE "$message\n"; print FILE "

    \n"; print FILE "Replies:\n
      \n"; print FILE "
    \n"; print FILE "

    \n"; print FILE "Post a Reply:\n"; &posthtml; if ($FORM{'reply'} eq "yes") { $FORM{'history'} .= "x"; } $FORM{'history'} .= $message_num; print FILE "\n"; print FILE "\n"; print FILE "\n"; print FILE "\n"; print FILE "\n"; print FILE "\n"; print FILE "\n"; &sig; print FILE "\n"; close(FILE); # put a link on any message this is a reply to if ($FORM{'icon'}) { $icon = ""; } if ($FORM{'reply'} eq "yes") { @replies = split(/x/, $FORM{'history'}); $search = "$posturl/$replies[$#replies - 1].html"; foreach $reply(@replies) { open (FILE, "$post/$reply.html"); @lines = ; close(FILE); open (FILE, ">$post/$reply.html"); foreach $line(@lines) { if ($line =~ //) { print FILE "
  • $icon$FORM{'subject'}"; print FILE "$icon
      \n"; print FILE "
    \n"; print FILE "$line"; } else { print FILE "$line"; } } close(FILE); } } # Put a link on the forum page open (FILE, "$path/$FORM{'forum'}"); @lines = ; close(FILE); open (FILE, ">$path/$FORM{'forum'}"); foreach $line(@lines) { print FILE "$line"; if (($FORM{'reply'} eq "no" && substr($line,0,14) eq "") || ($FORM{'reply'} ne "no" && $line =~ /
  • .*/)) { print FILE "
  • $icon"; print FILE "$FORM{'subject'}"; print FILE "$icon
      \n"; print FILE "
    \n"; } } close(FILE); # Update the "last post" part of the main page open (FILE, "$path/$mainpage"); @lines = ; close(FILE); open (FILE, ">$path/$mainpage"); foreach $line(@lines) { if ($line =~ //) { print FILE "$date $time \n"; } else { print FILE "$line"; } } close(FILE); # Put the message on the administrative page open (FILE, "$adminpath"); @lines = ; close(FILE); open (FILE, ">$adminpath"); foreach $line(@lines) { print FILE "$line"; if ($FORM{'reply'} eq "yes") { $i = ""; } else { $i = ""; } if ($line =~ /$i/) { print FILE "
  • "; print FILE "$icon"; print FILE "$FORM{'subject'}"; print FILE "$icon
      \n"; print FILE "
    \n"; } } close(FILE); if ($FORM{'email_reply'} eq "yes") { &mailposter($message_num); } print "Thank you!

    Your\n"; print "message has been posted!

    You can find it here.\n"; if ($notifyme) { open(MAIL,"|$mailprogram -t"); print MAIL "To: $youremail\n"; print MAIL "From: \"$FORM{'name'}\" <$FORM{'email'}>\n"; print MAIL "Subject: $FORM{'subject'}\n"; print MAIL "Hello. This is to let you know that $FORM{'name'}\n"; print MAIL "has posted a message. You can find it at\n"; print MAIL "$posturl/$message_num.html\nThe message reads:\n\n"; print MAIL ""; print MAIL "$FORM{'body'}\n\n"; close(MAIL); } exit; } sub loopmusicicon { $k = shift(@_); $which = shift(@_); open (FILE, "$k"); @lines = ; close(FILE); open (FILE, ">$k"); $nowrite = 0; foreach $line(@lines) { if (substr($line,0,13) eq "") { &musicicon($which); $nowrite = 1; } elsif (substr($line,0,14) eq "") { $nowrite = 0; } else { if ($nowrite == 0) { print FILE "$line"; } } } } sub message_html { if ($FORM{'icon'}) { $icon = ""; } $message = "
    \n"; $message .= "\n"; if ($FORM{'email'}) { $poster = ""; $poster .= "$FORM{'name'}"; } else { $poster = "$FORM{'name'}"; } $message .= ""; $message .= "
    $icon"; $message .= "$FORM{'subject'}\n"; $message .= "$icon
    Posted by $poster on $date at $time
    \n"; if ($FORM{'reply'} eq "yes") { if ($FORM{'oemail'}) { $poster = ""; $poster .= "$FORM{'oname'}"; } else { $poster = "$FORM{'oname'}"; } $message .= "on $date at $time, $poster wrote:

    $FORM{'omessage'}\n"; $message .= "


    \n"; } $message .= "$FORM{'body'}
    \n"; if ($FORM{'song'}) { $message .= "; close(FILE); open (FILE, ">$path/$which.txt"); foreach $line(@lines) { if ($line !~ /"$FORM{'delete'}"/) { print FILE "$line"; } else { $i = 3; } } close(FILE); } # Remove song\icon from admin file open (FILE, "$adminpath"); @lines = ; close(FILE); open (FILE, ">$adminpath"); foreach $line(@lines) { $test = ""; if ($line !~ /$test/) { print FILE "$line"; } } close (FILE); # Loop through messages and forums updating songs or icons &update($which); # Display a message that says everything went ok print "$which deleted\n"; print "The $which has been deleted.  Please click back.\n"; print "\n"; exit; } sub update { $which = shift(@_); if ($FORM{'url'}) { open (DATA, ">>$path/$which.txt"); print DATA "