#!/usr/local/bin/perl
# Define Variables
$basedir = "";
$baseurl = "";
$cgi_url = "";
$HOST = $ENV{"REMOTE_HOST"};
$ADDR = $ENV{"REMOTE_ADDR"};
$AGENT = $ENV{"HTTP_USER_AGENT"};
$mesgdir = "messages";
$datafile = "data.txt";
$mesgfile = "index.html";
$faqfile = "faq.html";
$ext = "html";
$date_command = "/bin/date";
$title = "";
# Done
###########################################################################
###########################################################################
# Configure Options
$show_faq = 0; # 1 - YES; 0 = NO
$allow_html = 1; # 1 = YES; 0 = NO
$quote_text = 1; # 1 = YES; 0 = NO
$subject_line = 0; # 0 = Quote Subject Editable; 1 = Quote Subject
# UnEditable; 2 = Don't Quote Subject, Editable.
$use_time = 1; # 1 = YES; 0 = NO
# Done
###########################################################################
# Get the Data Number
&get_number;
# Get Form Information
&parse_form;
# Put items into nice variables
&get_variables;
# Open the new file and write information to it.
&new_file;
# Open the Main WWWBoard File to add link
&main_page;
# Now Add Thread to Individual Pages
if ($num_followups >= 1) {
&thread_pages;
}
# Return the user HTML
&return_html;
# Increment Number
&increment_num;
############################
# 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 {
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;
$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/</
$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;
$hidden_body =~ s/"/"/g;
}
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
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","Septembe
r","October","November","December");
if ($use_time == 1) {
$date = "$hour\:$min\:$sec $month/$mday/$year";
}
else {
$date = "$month/$mday/$year";
}
chop($date) if ($date =~ /\n$/);
$long_date = "$months[$mon] $mday, 19$year at $hour\:$min\:$sec";
}
#####################
# New File Subroutine
sub new_file {
open(NEWFILE,">$basedir/$mesgdir/$num\.$ext") || die $!;
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 "[ $title
]\n";
}
else {
print NEWFILE "[ $title
]\n";
}
print NEWFILE "
\n";
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:
href=\"$last_message\.$ext\">$origsubject posted by ";
if ($origemail) {
print NEWFILE "$origname on
$origdate: \n";
}
else {
print NEWFILE "$origname on $origdate: \n";
}
}
if ($message_img) {
print NEWFILE " \n";
}
print NEWFILE "$body\n";
print NEWFILE " \n";
if ($message_url) {
print NEWFILE " \n";
}
print NEWFILE " \n";
if ($show_faq == 1) {
print NEWFILE "[ $title
]\n";
}
else {
print NEWFILE "[ $title
]\n";
}
print NEWFILE "
\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 "
href=\"$mesgdir/$num\.$ext\">$subject - $name $date\n";
print MAIN "(0)\n";
print MAIN "\n";
}
else {
print MAIN "$main_line";
}
}
}
else {
foreach $main_line (@main) {
$work = 0;
if ($main_line =~ //) {
print MAIN "\n";
print MAIN "-
href=\"$mesgdir/$num\.$ext\">$subject - $name $date\n";
print MAIN "(0)\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 "-
href=\"$num\.$ext\">$subject $name $date\n";
print FOLLOWUP "(0)\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";
print "
Message Added: $subject\n";
print "The following information was added to the message board:
size=7 width=75%>\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:
href=\"$message_url\">$message_url_title \n";
}
if ($message_img) {
print "Image: \n";
}
print "Added on Date: $date \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";
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";
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";
print "
ERROR: No Message\n";
print "You forgot to fill in the 'Message' fieldin 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";
print "
\n";
if ($show_faq == 1) {
print "[ Follow Ups ] [
href=\"#postfp\">Post Followup ] [
href=\"$baseurl/$mesgfile\">$title ] [
href=\"$baseurl/$faqfile\">FAQ ]\n";
}
else {
print "[ Follow Ups ] [
href=\"#postfp\">Post Followup ] [
href=\"$baseurl/$mesgfile\">$title ]\n";
}
print "
\n";
}
|
|
Favourite links
|
|