#! /usr/bin/perl # addchat.cgi # ----------------------------------- # Copyright (C) 2000, Michael Stewart # All Rights Reserved # based on S8 Chat http://www.s8.org # load the chat.setup file require "chat.setup"; # If the offline.txt file exists, then the chat is in # maintenance mode, and is closed. Output the message # in the offline.txt and end. if (-e "$path/offline.txt") { open (OFFLINE, "$path/offline.txt"); @offline = ; close OFFLINE; print "Content-Type: text/html\n\n"; print "Fatal Chatroom Error 0 - Maintenance\n"; print "

The chatroom is closed right now for maintenance.
\n"; print "The chatroom administrator left the following message:

\n"; print "
\n";
  foreach $offlineLine (@offline) {
    print "$offlineLine";
  }
  print "
"; print "
\n"; print "Chatroom version $ver Error Code 0 - Maintenance"; exit; } # Check for the cgi-lib, make sure it's readable and require it if (-e "$path/cgi-lib.cgi") { if (-r "$path/cgi-lib.cgi") { require "$path/cgi-lib.cgi"; } else { print "Content-Type: text/html\n\n"; print "Fatal Chatroom Error 2 - cgi-lib Unreadable\n"; print "

The chatroom cannot load the required module cgi-lib.cgi.
\n"; print "This module is required for the chatroom to work correctly.
\n"; print "Please contact the chatroom administrator.

\n"; print "
\n"; print "Chatroom version $ver Error Code 2 - cgi-lib Unreadable"; exit; } } else { print "Content-Type: text/html\n\n"; print "Fatal Chatroom Error 1 - Missing cgi-lib\n"; print "

The chatroom cannot find the required module cgi-lib.cgi.
\n"; print "This module is required for the chatroom to work correctly.
\n"; print "Please contact the chatroom administrator.

\n"; print "
\n"; print "Chatroom version $ver Error Code 1 - Missing cgi-lib"; exit; } # Load the User Input into %in &ReadParse(); # set defaults if varibles don't exist unless ($in{'room'}) { $room = "chat"; } else { $room = $in{'room'}; } if ($room eq "none") { $room = "chat"; } # load the chat.config file open (CONFIG, "$path/chat.config"); @config = ; close CONFIG; # make sure this isn't a private room # if it is, then check for correct password foreach $configLine (@config) { $configLine =~ s/\n//; ($chatroom, $name, $description, $pass) = split(/\|/, $configLine); if ($chatroom eq $in{'room'}) { $foundroom = "1"; if ($pass ne "") { if ($pass ne $in{'pass'}) { print "Content-Type: text/html\n\n"; print "A password is required to post to this room.
\n"; print "Please enter the correct password in the pw box."; print "
Chat Version: $ver - $copyinfo"; exit; } } } } # if the room wasn't found, then it's been deleted unless ($foundroom) { print "Content-Type: text/html\n\n"; print "$bodytag\n"; print "I'm sorry, but the administrator has left this room, and it has been deleted.\n"; print "Click Here to goto a diffrent chat.\n"; print "You will be redirected there automaticly.\n"; print "\n"; print "
Chat Version: $ver - $copyinfo"; exit; } # see if it's a user-defined room, and process... ($roomleft, $roomright) = split(/\//, $room); if ($roomleft eq "user") { # make sure the user who created this has reloaded in the last 10 mins $tt = localtime; ($d1, $d2, $d3, $d4, $d5, $d6) = split(/\s/, $tt); if ($d3 ne "") { $dday = "$d1"; $dmonth = "$d2"; $ddate = "$d3"; $dtime = "$d4"; $dyear = "$d5"; } else { $dday = "$d1"; $dmonth = "$d2"; $ddate = "$d4"; $dtime = "$d5"; $dyear = "$d6"; } ($dhh, $dmm, $dss) = split(/:/, $dtime); open (ADMIN, "$path/$room.admin"); @admin = ; close ADMIN; $cnt = 0; foreach $adminLine (@admin) { $cnt++; if ($cnt = 1) { $adminLine =~ s/\n//; ($att, $adminUser) = split(/\|/, $adminLine); } } ($a1, $a2, $a3, $a4, $a5, $a6) = split(/\s/, $att); if ($a3 ne "") { $aday = "$a1"; $amonth = "$a2"; $adate = "$a3"; $atime = "$a4"; $ayear = "$a5"; } else { $aday = "$a1"; $amonth = "$a2"; $adate = "$a4"; $atime = "$a5"; $ayear = "$a6"; } ($ahh, $amm, $ass) = split(/:/, $atime); # this would be where to change the time limit $amm = $amm + 10; if ($amm > 59) { $amm = $amm - 60; $ahh = $ahh + 1; if ($ahh > 23) { $ahh = $ahh - 24; } } if ($tmm > $amm) { if ($thh = $ahh) { print "Content-Type: text/html\n"; print "$bodytag\n"; print "I'm sorry, but the administrator has left this room, and it will be deleted.\n"; print "Click Here to goto a diffrent chat.\n"; print "You will be redirected there automaticly.\n"; open (CONFIG, "$path/chat.config"); @config = ; close CONFIG; open (CONFIG, ">$path/chat.config"); foreach $configLine (@config) { $configLine =~ s/\n//; ($chatroom, $name, $description, $pass) = split(/\|/, $configLine); if ($chatroom ne $room) { print CONFIG "$configLine\n"; } } close CONFIG; unlink ("$path/$room.header"); unlink ("$path/$room.chat"); unlink ("$path/$room.footer"); unlink ("$path/$room.ban"); unlink ("$path/$room.banpass"); unlink ("$path/$room.lock"); unlink ("$path/$room.admin"); print "\n"; print "
Chat Version: $ver - $copyinfo"; exit; } } if ($in{'admin'} eq $adminUser) { open (ADMIN, ">$path/$room.admin"); print ADMIN "$tt\|$adminUser"; close ADMIN; } } # load the text into $text variable unless ($in{'text'}) { $text = "..."; } else { $text = $in{'text'}; } # try to split text into a command ($cmdA, $cmdB, $cmdC, $cmdD) = split(/:/, $text); # ban command if ($cmdA eq "-ban") { print "Content-Type: text/html\n"; print "Location: $url/command.cgi?room=$room&pass=$in{'pass'}&cmdA=$cmdA&cmdB=$cmdB&cmdC=$cmdC&cmdD=$cmdD\n\n"; exit; } # unban command if ($cmdA eq "-unban") { print "Content-Type: text/html\n"; print "Location: $url/command.cgi?room=$room&pass=$in{'pass'}&cmdA=$cmdA&cmdB=$cmdB&cmdC=$cmdC&cmdD=$cmdD\n\n"; exit; } # clear command if ($cmdA eq "-clear") { print "Content-Type: text/html\n"; print "Location: $url/command.cgi?room=$room&pass=$in{'pass'}&cmdA=$cmdA&cmdB=$cmdB&cmdC=$cmdC&cmdD=$cmdD\n\n"; exit; } # change room password if ($cmdA eq "-pass") { print "Content-Type: text/html\n"; print "Location: $url/command.cgi?room=$room&pass=$in{'pass'}&cmdA=$cmdA&cmdB=$cmdB&cmdC=$cmdC&cmdD=$cmdD\n\n"; exit; } # change the banpass if ($cmdA eq "-banpass") { print "Content-Type: text/html\n"; print "Location: $url/command.cgi?room=$room&pass=$in{'pass'}&cmdA=$cmdA&cmdB=$cmdB&cmdC=$cmdC&cmdD=$cmdD\n\n"; exit; } # edit the header and footer if ($cmdA eq "-edit") { print "Content-Type: text/html\n"; print "Location: $url/command.cgi?room=$room&pass=$in{'pass'}&cmdA=$cmdA&cmdB=$cmdB&cmdC=$cmdC&cmdD=$cmdD\n\n"; exit; } # make sure the user isn't banned # banning matches by first three parts of IP # the last part changes often, or I would use that too # load the ban list open (BAN, "$path/$room.ban"); @ban = ; close BAN; # get the user's IP $userIP = $ENV{'REMOTE_ADDR'}; ($userIPa, $userIPb, $userIPc, $userIPd) = split(/\./, $userIP); # compare IP's to the ban list foreach $banLine (@ban) { $banline =~ s/\n//; ($banIPa, $banIPb, $banIPc, $banIPd) = split(/\./, $banLine); if ($banIPa eq $userIPa) { if ($banIPb eq $userIPb) { if ($banIPc eq $userIPc) { # found the user on the ban list $userIsBanned = "IP"; } } } } if ($userIsBanned) { # if the user is banned, then print a message at the top of the # chat using the message varible with the view action print "Content-Type: text/html\n"; print "Location: $url/reload.cgi?room=$room&showban=true&pass=$in{'pass'}\n\n"; exit; } # get user input, set defaults if it's not there # need to write something to disable HTML unless ($in{'name'}) { $userName = "Anonymous"; } else { $userName = $in{'name'}; } if ($in{'mail'}) { $mail = $in{'mail'}; } else { $mail = ""; } if ($in{'url'}) { $userUrl = $in{'url'}; } else { $userUrl = ""; } unless ($in{'color'}) { $color = ""; } else { $color = $in{'color'}; } # prepare the time $tt = localtime; ($d1, $d2, $d3, $d4, $d5, $d6) = split(/\s/, $tt); if ($d3 ne "") { $dday = "$d1"; $dmonth = "$d2"; $ddate = "$d3"; $dtime = "$d4"; $dyear = "$d5"; } else { $dday = "$d1"; $dmonth = "$d2"; $ddate = "$d4"; $dtime = "$d5"; $dyear = "$d6"; } ($dhh, $dmm, $dss) = split(/:/, $dtime); if ($dhh > 12) { $dhh = $dhh - 12; $dampm = "PM"; } else { $dampm = "AM"; } # disable this to enable images $text =~ s//Images not allowed/gio; # basic safety - add more if you wish $text =~ s//Applets not allowed/gio; $text =~ s//Scripts not allowed/gio; $text =~ s//Scripts not allowed/gio; $text =~ s//Scripts not allowed/gio; # removes comments $text =~ s///go; # enable this to remove HTML # $text =~ s//>\;/go; # format carriage returns, line feeds,
,

$text =~ s/\r//go; $text =~ s/

\n/

/gio; $text =~ s/\n

/

/gio; $text =~ s/
\n/
/gio; $text =~ s/\n
/
/gio; $text =~ s/\n/
/gio; # change pipe (|) to colon (:) $text =~ s/\|/:/go; # formats Name, E-Mail, and URL to be HTML safe $userName =~ s//>\;/go; $userName =~ s/\r//go; $userName =~ s/\n//go; $userName =~ s/\|/:/go; $mail =~ s//>\;/go; $mail =~ s/\r//go; $mail =~ s/\n//go; $mail =~ s/\|/:/go; $userUrl =~ s//>\;/go; $userUrl =~ s/\r//go; $userUrl =~ s/\n//go; $userUrl =~ s/\|/:/go; # file locking routine # chat status codes: # 0 - free # 1 - used # file locking rountine is too slow... find a faster one # # check to see if the chat file can be written to # $chatstat = "3"; # while ($chatstat ne "0") { # open (STATUS, "$path/$room.lock"); # @status = ; # close STATUS; # # extract the first line # ($chatstat) = split(s/\n/, @status, 1); # } # the chat file is not being used, lock it open (STATUS, ">$path/$room.lock"); print STATUS "1\n"; close STATUS; # load the chat file open (CHAT, "$path/$room.chat"); @chat = ; close CHAT; # open the chat file open (CHAT, ">$path/$room.chat"); # write the post to the chat file print CHAT "$userName\|$mail\|$userUrl\|$color\|$text\|$dday $dmonth $ddate $dyear $dhh:$dmm:$dss $dampm MST\|$userIP\n"; $cnt = "1"; # write the rest of the posts to the chat... counting to 30 posts foreach $chatLine (@chat) { unless ($donePosting) { $cnt++; if ($cnt eq "31") { $donePosting = "1"; } else { print CHAT "$chatLine"; } } } # close the file close CHAT; # unlock the chat file open (STATUS, ">$path/$room.lock"); print STATUS "0\n"; close STATUS; # we're done... redirect user to chat file and exit print "Content-Type: text/html\n"; print "Location: $url/reload.cgi?room=$room&pass=$in{'pass'}\n\n";