################################## ###CONFIGURATION################## ################################## ################################## ###FULL URL of BBS################ ################################## $BBS_HOME='::'; ################################## ###DISPLAY DIRECTORY############## ################################## $HTML_DIR='::html'; $ERROR='error.html'; $ERROR_CHAR='error-char.html'; $SUCCESS='success.html'; ################################### ###STORAGE DIRECTORY############### ################################### # This directory should be "server" readable/writeable/executable only. $STORAGE_DIR='::message'; # The files below should be world readable/writable only. $ERROR_COLLECT='error-collect.txt'; $SUCCESS_COLLECT='bbs-data.html'; $TOKEN_FILE ='counter'; $THREAD_TOKEN ='thread_counter'; # if your system does not support the flock() function, comment this out, or set it to 0. # the latest edition of NT Perl, as well as all unix perl should have flock build in. $flock_exists = 1; ################################## ### END OF CONFIGURATION ######### ################################## ### APPEND DIRECTORY with FILE ### ################################## $ERROR = $HTML_DIR.':'.$ERROR; $ERROR_CHAR = $HTML_DIR.':'.$ERROR_CHAR; $SUCCESS = $HTML_DIR.':'.$SUCCESS; $TMP = $STORAGE_DIR.':'.($$).".tmp"; $ERROR_COLLECT = $STORAGE_DIR.':'.$ERROR_COLLECT; $INDEX_FILE = $STORAGE_DIR.':'.$SUCCESS_COLLECT; $TOKEN_FILE = $STORAGE_DIR.':'.$TOKEN_FILE; $THREAD_TOKEN = $STORAGE_DIR.':'.$THREAD_TOKEN; ################################### print "Content-type: text/html\n\n"; # # This reads in the information sent when the user pressed Submit # if ($ENV{'REQUEST_METHOD'} eq "GET") { $buffer = $ENV{'QUERY_STRING'}; } else { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } # # Now, using a little loop, we'll split up the data into name/value # pairs, which makes them easier to work with. # @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; $FORM{$name} = $value; } # # Once the name/value pairs have been created, you can work with # them by referring to the variable names you set up in the # original HTML, using $FORM{"varname"}. # # # First, we make sure that they actually gave an email address # #check for error -- REQUIRE ALL ¬complete unless $FORM{'thread'} && $FORM{'time'} && $FORM{'RealTime'}; #$FORM{'name'} =~ s/([\(\)\>\<\"\'])/\\$1/g; $FORM{'name'} =~ tr/\n//d; #$FORM{'email'} =~ s/([\(\)\>\<\"\'])/\\$1/g; $FORM{'email'} =~ tr/\n//d; # $FORM{'subject'} =~ s/([\(\)\>\<\"\'])/\\$1/g; $FORM{'subject'} =~ tr/\n//d; #$FORM{'body'} =~ s/([\(\)\>\<\"\'])/\\$1/g; $body = $FORM{'body'}; $body =~ s/\r//g; $body =~ s/\n/
/g; $name = $FORM{'name'}; $name =~ s/\r//g; $name =~ s/\n/
/g; $email = $FORM{'email'}; $email =~ s/\r//g; $email =~ s/\n/
/g; $subject = $FORM{'subject'}; $subject =~ s/\r//g; $subject =~ s/\n/
/g; $subject2 = $subject; $subject2 =~ s/\"/\\\"/g; $name2 = $name; $name2 =~ s/\"/\\\"/g; ### The following 3 field is internal and self generating. user have no business ### to generate beyond the set allowed &invalidchar if $FORM{'RealTime'} =~ /([*\|\;\&\\\~\^\[\]\$\.\(\)\>\<\"\'\n\r])/; &invalidchar if $FORM{'thread'} =~ /([A-z*\|\;\&\\\~\^\[\]\$\.\(\)\>\<\"\'\,\n\r])/; &invalidchar if $FORM{'time'} =~ /([A-z*\|\;\&\\\~\^\[\]\$\.\(\)\>\<\"\'\,\n\r])/; &invalidchar if $FORM{'parent'} =~ /([A-z*\|\;\&\\\~\^\[\]\$\.\(\)\>\<\"\'\,\n\r])/; $realTime = $FORM{'RealTime'}; $realTime =~ s/_/ /g; &makeMessage; &addToIndex; &success; exit; ####################################################################### ############################ Add to data file ####################### ####################################################################### sub addToIndex { select(STDOUT); open(toINDEX,"$INDEX_FILE") || die "can't open $INDEX_FILE\n"; &lock(toINDEX); open(temp, "> $TMP") || die "can't open $TMP\n"; while(){ if(//){ print temp "parent.addpbbsArray(\"$subject2\",$FORM{'time'},\"$realTime\",\"$name2\",$FORM{'thread'},\"message/$file_handle.html\",\"$FORM{'parent'}\",\"$file_handle\")\n\n"; } else { print temp $_; } } &unlock(toINDEX); close(toINDEX); close(temp); rename($TMP, $INDEX_FILE); } ###################################################################### ############################ Make .dat file ###################### ###################################################################### sub makeMessage { select(STDOUT); $file_handle = getToken(); open(NEW,">> $STORAGE_DIR:$file_handle.html") || die "can't open $STORAGE_DIR:$file_handle.html\n"; select(NEW); print <<"DONE"; $subject
Name:    $name
Email:   $email  
Subject: $subject
Thread:  $FORM{'thread'}
Time:    $realTime

$body DONE close(NEW); } ############################################################################### ############################ Get Token ####################################### sub getToken{ ###### #lock ###### open(TOKEN,"$TOKEN_FILE") || die "can't open $STORDIR:$file_handle.html\n"; &lock(TOKEN); while () { $tokenReturn = "$_"; chop($tokenReturn); } close(TOKEN); open(TOKEN,"> $TOKEN_FILE") || die "can't open $STORDIR:$file_handle.html\n"; $tokenNext = $tokenReturn + 1; select(TOKEN); print <<"DONE"; $tokenNext DONE &unlock(TOKEN); close(TOKEN); select(STDOUT); return $tokenReturn; ####### #unlock ####### } sub lock{ } sub unlock{ } ############################################################################### ############################ Complete/Success ############################### ############################################################################### sub success{ select(STDOUT); open(EP,"$SUCCESS"); while(){ $tk = "$_"; $tk =~ s/\#\#\#\#HOME-LOCATION\#\#\#\#/$BBS_HOME/; print "$tk"; } close(EP); exit; } ############################################################################### ############################ Incomplete Error ############################### ############################################################################### sub notcomplete { select(STDOUT); open(EP,"$ERROR"); while(){ print "$_"; } close(EP); exit; } ############################################################################### ############################ Invalid char ############################### ############################################################################### sub invalidchar { select(STDOUT); open(EP,"$ERROR_CHAR"); while(){ print "$_"; } close(EP); exit; }