#!/usr/ucb/perl $admin = "no"; require "config.cgi"; require "cgi-lib.sol"; $script_name = $ENV{'SCRIPT_NAME'}; $lock_file = "lock2"; &lock; ############### # Lock File sub lock { $time = time(); $quit = 0; while ($quit != 1) { if (-e "$file_dir/$lock_file") { if ($time + $lock_time < time()) { &parse_form; } else { sleep(1); } } else { open(LOCK,">$file_dir/$lock_file"); close LOCK; &parse_form; } } } ######################## # Parse Form # This subroutine is taken from Matt Wright's WWWBoard script # with a few minor modifications. 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; $value =~ s/<([^>]|\n)*>//g; $FORM{$name} = $value; } &get_variables; } ########### # Get variables from form sub get_variables { if ($FORM{'where'}) { $where = "$FORM{'where'}"; } if ($FORM{'room'}) { $room = "$FORM{'room'}"; $room =~ s/ /_/g; $room =~ s/\//_/g; $oldroom = $room; } if ($FORM{'pubroom'}) { $pubroom = "$FORM{'pubroom'}"; $pubroom =~ s/ /_/g; $pubroom =~ s/\//_/g; } if ($FORM{'priroom'}) { $priroom = "$FORM{'priroom'}"; $priroom =~ s/ /_/g; $priroom =~ s/\//_/g; } if ($FORM{'solo'}) { $solo = "$FORM{'solo'}"; } if ($FORM{'link'}) { $link = "$FORM{'link'}"; if ($link ne "") { $leave_link = $link; } } if ($FORM{'name'}) { $name = "$FORM{'name'}"; $name =~ s/"//g; $name =~ s///g; $name =~ s/\&//g; $name =~ s/\(//g; $name =~ s/\)//g; $name =~ s/\$/S/g; $name =~ s/\*//g; $name =~ s/\?//g; } if ($FORM{'load_time'}) { $load_time = "$FORM{'load_time'}"; } if ($FORM{'mail'} =~ /.*\@.*\..*/) { $mail = "$FORM{'mail'}"; } if ($FORM{'passwd'}) { $passwd = "$FORM{'passwd'}"; } if ($FORM{'nummes'}) { $nummes = $FORM{'nummes'}; } if ($FORM{'message'}) { $message = $FORM{'message'}; $message =~ s/\cM//g; $message =~ s/\n\n/

/g; $message =~ s/\n/
/g; $message =~ s/<//g; $message =~ s/"/"/g; } ($sec,$min,$hour,$day,$month,$year) = localtime(time); if ($sec < 10) { $sec = "0$sec"; } if ($min < 10) { $min = "0$min"; } if ($hour < 10) { $hour = "0$hour"; } $date = "$hour\:$min\:$sec"; $recorddate = "$date $month/$day/$year";; chop($date) if ($date =~ /\n$/); $time = time(); $entry =~ s/ /_/g; $entry =~ s/\//_/g; &location; } ########## # Where are they coming from? sub location { if ($ENV{'HTTP_REFERER'} =~ /http:\/\/([^\/]+)/) { if (!($1 =~ /$valid_referer/)) { &login; &unlock; exit; } } if ($name eq "link") { &name_taken; # Tell them the name was taken and to try again } elsif ($solo ne "") { if ($solo eq "$return_to_chat") { &update; # Update the reload time in the visitors file &reload; # Reload the chat page with the latest information &unlock; # Unlock the script } else { &privmsg; # Send the 1 on 1 message &update; # Update the reload time in the visitors file &reload; # Reload the chat page with the latest information &unlock; # Unlock the script } } elsif ($where eq "register") { &check_name; &create; # Maintain files (create, delete, and shorten) ®ister; # Add their information to the visitors file &reload; # Reload the chat page with the latest information &unlock; # Unlock the script } elsif ($where eq "$one_on_one_text") { &create; # Maintain files (create, delete, and shorten) &one_on_one; # Print the one on one page &unlock; # Unlock the script } elsif ($where eq "$post_text") { &create; # Maintain files (create, delete, and shorten) &post; # Add their message to the chat file &update; # Update the reload time in the visitors file &reload; # Reload the chat page with the latest information &unlock; # Unlock the script } elsif ($where eq "$reload_text") { &snag; # Get the information in the message field &create; # Maintain files (create, delete, and shorten) &update; # Update the reload time in the visitors file &reload; # Reload the chat page with the latest information &unlock; # Unlock the script } elsif ($where eq "$go_there") { if ($priroom ne "") { $room = "$priroom"; &create; # Maintain files (create, delete, and shorten) &change; # Remove the person from the old room ®ister; # Add their information to the visitors file &reload; # Reload the chat page with the latest information &unlock; # Unlock the script } elsif ($pubroom ne "") { $room = "$pubroom"; &create; # Maintain files (create, delete, and shorten) &change; # Remove the person from the old room ®ister; # Add their information to the visitors file &reload; # Reload the chat page with the latest information &unlock; # Unlock the script } else { &create; # Maintain files (create, delete, and shorten) &update; # Update the reload time in the visitors file &reload; # Reload the chat page with the latest information &unlock; # Unlock the script } } elsif ($where eq "$leave_text") { &leave; # Remove person's name from visitors file and send them away &unlock; # Unlock the script } else { &countv; # Count the number of visitors &login; # Print the login page &unlock; # Unlock the script } exit; } ######################## # Create files if they don't exist sub create { open(INDEX,">$file_dir/index.html"); print INDEX "$index_html\n"; close(INDEX); open(INDEXB,">$vis_dir/index.html"); print INDEXB "$index_html\n"; close(INDEXB); &createv; } sub createv { if (-e "$file_dir/vis$room") { open (VISITORS,"$file_dir/vis$room"); @visitors = ; close (VISITORS); if ($visitors[0] =~ /\\n"); } elsif ($time - $load > $visitors_time) { } else { push (@visitors_new,"$visitors_line"); } } open(VISITORS,">$file_dir/vis$room"); foreach $visitors_line(@visitors_new) { print VISITORS "$visitors_line"; } close (VISITORS); undef @visitors_new; } else { open (VISITORS,">$file_dir/vis$room"); print VISITORS ""; close (VISITORS); } } else { open (VISITORS,">$file_dir/vis$room"); print VISITORS ""; close (VISITORS); } opendir(FILES,$file_dir); @filelist = grep(!/^\.\.?$/, readdir (FILES)); closedir(FILES); foreach $filelist (@filelist) { if (-A "$file_dir/$filelist" > $chat_time / 86400) { unlink("$file_dir/$filelist"); } } &createc; } sub createc { if (-e "$file_dir/chat$room") { open(MAIN,"$file_dir/chat$room"); @main =

; close(MAIN); if ($main[0] =~ /\\n"); } elsif ($time - $entry > $chat_time) { } else { push (@main_new,"$main_line") } } open(MAIN,">$file_dir/chat$room"); foreach $main_line(@main_new) { print MAIN "$main_line"; } close (MAIN); undef @main_new; } else { open (MAIN,">$file_dir/chat$room"); print MAIN "\n"; print MAIN "The chat file somehow became corrupted, but it has been fixed and all is fine now.
\n"; close (MAIN); } } else { open (CHAT,">$file_dir/chat$room"); print CHAT ""; close (CHAT); } &createone; } sub createone { $vname = $name; $vname =~ s/ /_/g; $vname =~ s/\//_/g; if (-e "$vis_dir/$vname") { } else { $password = crypt($passwd,MW); open (VFILE,">$vis_dir/$vname"); print VFILE "\n"; close (VFILE) } &countv; } sub countv { opendir(VFILES,$vis_dir); @vfilelist = grep(!/^\.\.?$/, readdir (VFILES)); closedir(VFILES); foreach $vfilelist (@vfilelist) { if (-A "$vis_dir/$vfilelist" > $visitors_time / 86400) { unlink("$vis_dir/$vfilelist"); } } } ############ # Login sub login { opendir(VFILES,$vis_dir); @vfilelist = grep(!/^\.\.?$/, readdir (VFILES)); closedir(VFILES); $vtotal = @vfilelist; $vtotal = $vtotal - 1; $entry =~ s/ /_/g; $entry =~ s/\//_/g; open (VISITORS,"$file_dir/vis$entry"); @visitors = ; close (VISITORS); foreach $visitors_line (@visitors) { ($bogus,$load,$bogus2) = split(/:/,$visitors_line); if ($visitors_line =~ /\\n"); } elsif ($time - $load > $visitors_time) { } else { push (@visitors_new,"$visitors_line"); } } open(VISITORS,">$file_dir/vis$entry"); foreach $visitors_line(@visitors_new) { print VISITORS "$visitors_line"; } close (VISITORS); $vnum=@visitors_new; $vnum=$vnum - 1; undef @visitors_new; print "Content-type: text/html\n\n"; print " $page_title Login\n"; print "