#!/usr/bin/perl ### wwwboard-rescue.pl ################################################################# # Example code that reads in all message html files from a # wwwboard and tries to recreate the main html message list. # # If your main message list page got trashed or "cleared" this # should regenerate all the links for you. It only generates # the link area, you will have to add in the posting stuff # at the bottom and any custom html you had originally. # # If your wwwboard has been operating for years it's main # page may have some formatting problems here and there. Using # this script may generate a better file for you. # # If you have problems with your wwwadmin, it may be caused # by a messed up main message list page. wwwboard uses this # page as a database for the admin script. This script may # generate a better page and fix those problems. # # You should update your wwwboard to one that uses proper file # locking so your main message list doesn't get trashed all # the time. # # This program depends on your html message pages for data # so if your html pages got trashed, the output of this # program may get messed up. You may want to move those # trouble files to another directory 'till you can fix them. # # WARNING: BACK UP ALL YOUR MESSAGES FIRST!!!! Just in case. # # This program is READ ONLY on your messages, and writes # only the "rescue.html" file, but don't under estimate # a computers ability to screw up your data. # # If you have the space, make a copy of all your messsages # and place them into a new directory and change the settings # below accordingly. If your board is busy this is a better # way to do this because we take a lot of time opening # messages and reading them. # # Expect to lose a few link references and check # the output file carefully to make sure all data is # processed correctly. It's better than trying to recover # this by hand! # # This program is not perfect, so you may have to change a # few lines, but if your board is standard and not modified # very much, it should work as - is. All normal disclaimers # apply, if you use this you do so at your own risk. # # For more examples and free sources, visit www.nocrash.com # # V1.1 12/12/2002 # ################################################################# ################################################################# # The following variables are the SAME as the ones in the # start of all your other .pl files for the BBS, just # copy and paste from the other BBS .pl file ################################################################# # Define Variables $basedir = $ENV{'DOCUMENT_ROOT'} . "/bbs"; $mesgdir = "messages"; $ext = "html"; ################################################################# # The following variables are specific to this program and # should be changed as needed. ################################################################# #### This is the output filename, it's stored in the same place as #### the main board html page, make sure this program can write #### or create this file. It's just a text file really. $outputfile = "rescue.html"; ################################################################# # NOTE: We look for certian "keywords" to figure out which # messages are a reply message. # if you are having problems with strange text # then look in your message files and find something # that will identify a reply. ################################################################# $reply_keyword = "In Reply to: Making Rescue Html File\n"; print "
\n";

print "\nReading directory listing: $basedir/$mesgdir/*.$ext\n";

chdir("$basedir/$mesgdir");            # let's switch to the messages dir to make it simple
chomp( @files = `ls *.$ext` );         # do a shell "ls" command, else you write this yourself
$count = scalar @files;

print "Found $count files to process....\n";

foreach $file (@files) {
	 $STARTPAGE{$file} = 1;             ## make flag entries for each file
	 ## print "$file\n"; # debug print
	 }

print "processing....\n";

# we are going to need a list of the start pages, the ones that are
# not replies, so go through every message and flag any
# replies and all we have left is start pages!

foreach $file (@files) {

	 ## get this messages' text
	 if ( !open( MSGS2, "$file" ) ) {
		  print "\nERROR - Can't find/open '$file'\n";
		  next;
		  }
	 @lines = ;
	 close(MSGS2);

	 $msg        = "";
	 $gonextline = "0";

	 foreach ( $j = 0 ; $j <= @lines ; $j++ ) {
		  if ( $lines[$j] =~ $reply_keyword ) {
				$STARTPAGE{$file} = 0;    # this is NOT a start page
				## print "$file\n"; # debug print
				}
		  } ## end foreach ( $j = 0 ; $j <= @lines...
	 } ## end foreach $file (@files)

# now it's easy, just read all the start pages in backwards number
# order and recreate the main html file including any followup links
# we find inside the start message

# yea, yea. I know you could have written this in 3 lines but it works
# and I am happy. So it uses 2000 more CPU cycles, who cares?

$j = 0;
foreach $file (@files) {    # create a list that "sort" can use easily to reverse list
	 if ( $STARTPAGE{$file} == 1 ) {    # only save the start page file names
		  $file =~ /(.*)\.$ext/;
		  $num = int $1;                 # now we have the file number as a number
		  $reverse[$j] = sprintf( "%08d", $num );
		  $tmp = $reverse[$j];
		  ## print "$1 $file $num REVERSE= $tmp\n"; # debug print
		  $j++;
		  } ## end if ( $STARTPAGE{$file}...
	 } ## end foreach $file (@files)

@tmpfiles = sort { $b <=> $a } @reverse;    # and sort it properly, in reverse order

$j = 0;
foreach $file (@tmpfiles) {                 # make the list into proper file names again
	 $num = int $file;
	 $workfiles[$j] = "$num.$ext";
	 $j++;
	 ## print "PROPER= $file $num\n"; # debug print
	 } ## end foreach $file (@tmpfiles)

print "Creating: $basedir/$outputfile\n";

open( OUTFILE, ">$basedir/$outputfile" ) || die $!;

print OUTFILE "\n\nRescued Message List File\n\n";
print OUTFILE "\n
\n

Rescued Message List File



\n\n"; print OUTFILE "\n
    \n"; # my little kicker for some space print OUTFILE "\n\n\n"; print OUTFILE "\n\n"; foreach $file (@workfiles) { # read in each file and process it ## print "PROCESS= $file\n"; # debug print ## get this messages' text if ( !open( MSGS2, "$file" ) ) { print "\nERROR - Can't find/open '$file'\n"; next; } @lines = ; close(MSGS2); $file =~ /(.*)\.$ext/; # we need a number for the file $filenum = $1; $followups = ""; $flag = 0; $count = 0; $subject = $name = $date = ""; foreach ( $j = 0 ; $j <= @lines ; $j++ ) { # find any followup links and needed data and save them if ( $lines[$j] =~ /name="origsubject" value="(.*)">/ ) { $subject = $1; } if ( $lines[$j] =~ /name="origname" value="(.*)">/ ) { $name = $1; } if ( $lines[$j] =~ /name="origdate" value="(.*)">/ ) { $date = $1; } if ( $lines[$j] =~ // ) { $flag = 1; } if ( $lines[$j] =~ // ) { $flag = 0; $followups .= $lines[$j]; # write the last "!--end:" line } if ( $flag == 1 ) { if ( $lines[$j] =~ /
  • $subject - $name $date\n"; if ( $count == 0 ) { print OUTFILE "(0)\n"; print OUTFILE "
      \n"; print OUTFILE "
    \n"; } else { print OUTFILE "($count)\n"; print OUTFILE "$followups"; } } ## end foreach $file (@workfiles) print OUTFILE "\n\n\n"; print OUTFILE "\n\n\n"; print OUTFILE "\n
\n\n\n"; # end it all close OUTFILE; print "All done, data recovered. Aren't you happy now!!\n\n
\n"; exit 0;