$&<\/a>/g;
$message =~ s/\n\n/ /g;
$message =~ s/\n/
/g;
}
$message =~ s/"/"/g;
if($filter_plugin) {
require("$plugin_dir/filter.pl");
&lang_filter;
}
}
if ($FORM{'ignored'}) {
@ignored = split(/\(\)/,$FORM{'ignored'});
}
if($profile_plugin && -e "$profile_dir/$vname") {
$profile_link = "$profile_link_text";
$maillink = "$maillink $profile_link";
}
if($FORM{'admin'}) {
$adminyes = 1;
}
}
###########
# Read files
sub read_files {
if($where || $solo || $ENV{'PATH_INFO'}){
$origroom = $room;
open(MAIN,"$file_dir/chat$room");
@main = ;
close(MAIN);
@main = @main[(0 .. $max_mes)];
open(VISITORS,"$file_dir/vis$room");
@visitors = ;
close(VISITORS);
$vname = $name;
$vname =~ s/ /_/g;
$vname =~ s/\//_/g;
open(VFILE,"$vis_dir/$vname");
@vfile = ;
close(VFILE);
@vfile = @vfile[(0 .. $max_mes)];
}
}
############
# Check Referer
sub check_referer {
if ($ENV{'HTTP_REFERER'} =~ /^http:\/\/([^\/]+)/) {
foreach$referer(@valid_referers) {
if ($ENV{'HTTP_REFERER'} =~ /$referer/) {
$okay_referer = 1;
}
}
}
if(!$ENV{'HTTP_REFERER'}) {
$okay_referer = 1;
}
if(!$okay_referer) {
&unlock;
&login;
exit;
}
}
##########
# Prepare for sending them places
sub prelocation {
if($where eq "$ignore_text" && $ignore_plugin) {
require("$plugin_dir/ignore.pl");
&ignore;
}
if($where eq "$go_there") {
$oldroom = $room;
if ($priroom) {
$room = $priroom;
}
elsif($pubroom) {
$room = $pubroom;
}
else {
$where = $reload_text;
}
if ($room eq "$oldroom") {
$where = "$reload_text";
}
}
if($message_plugin) {
require("$plugin_dir/message.pl");
&message_prep;
}
}
##########
# Where are they coming from?
sub location {
if ($solo && $where eq "$post_text" && $solo ne $entire_room) {
&verify_password;
&main_page_lang;
&privmsg;
&update;
&write;
&unlock;
&reload;
}
elsif ($where eq "register") {
if($frames eq "yes" && !$ENV{'QUERY_STRING'}) {
&unlock;
&check_name;
if($access_control_plugin) {
require("$plugin_dir/access_control.pl");
&admit_style;
}
if($admin_plugin) {
require("$plugin_dir/admin.pl");
&check_admin;
}
require("$plugin_dir/frames.pl") || die "Couldn't find frames part";
&frames;
}
else {
&main_page_lang;
&check_name;
if($access_control_plugin) {
require("$plugin_dir/access_control.pl");
&admit_style;
}
if($admin_plugin) {
require("$plugin_dir/admin.pl");
&check_admin;
}
&create;
®ister;
&write;
&unlock;
&reload;
}
}
elsif ($where eq "$post_text") {
&verify_password;
&main_page_lang;
&create;
&post;
&update;
&write;
&unlock;
&reload;
}
elsif ($where eq "$reload_text") {
&verify_password;
&main_page_lang;
&snag;
&create;
&update;
&write;
&unlock;
&reload;
}
elsif ($where eq "$go_there") {
&verify_password;
if($pubroom || $priroom) {
$lang_file = $default_lang_file;
if($custom_room_plugin) {
require("$plugin_dir/custom_room.pl");
&custom_room;
if($message_plugin) {
require("$plugin_dir/message.pl");
&message_prep;
}
}
require("$lang_file") || die "Could not find language file";
&misc_lang;
&main_page_lang;
&create;
&change;
&write;
&unlock;
&reload;
}
else {
&main_page_lang;
&snag;
&create;
&update;
&write;
&unlock;
&reload;
}
}
elsif ($where eq "$leave_text") {
&verify_password;
&leave;
&write;
&unlock;
}
elsif ($profile_plugin && $where eq "$edit_profile") {
&check_name;
if($access_control_plugin) {
require("$plugin_dir/access_control.pl");
&admit_style;
}
if($passlistok) {
&edit_profile;
}
else {
&name_taken
}
}
elsif($profile_plugin && $where eq "$update_profile") {
&check_name;
if($access_control_plugin) {
require("$plugin_dir/access_control.pl");
&admit_style;
}
&update_profile;
}
elsif($profile_plugin && $where eq "$change_password") {
&check_name;
if($access_control_plugin) {
require("$plugin_dir/access_control.pl");
&admit_style;
}
&change_password;
}
elsif($who_is_where_plugin && $where eq "$who_is_where") {
&misc_lang;
if($where_locations =~ /A/ && !$load_time) {
&main_page_lang;
&check_name;
if($access_control_plugin) {
require("$plugin_dir/access_control.pl");
&admit_style;
}
if($admin_plugin) {
require("$plugin_dir/admin.pl");
&check_admin;
}
}
require("$plugin_dir/who_is_where.pl");
&who_is_where;
}
else {
&deletevfiles;
&unlock;
if(! -e "$file_dir/.htaccess") {
$access_dir = $file_dir;
&write_htaccess;
}
if(! -e "$vis_dir/.htaccess") {
$access_dir = $vis_dir;
&write_htaccess;
}
if(! -e "$plugin_dir/.htaccess" && -e $plugin_dir) {
$access_dir = $plugin_dir;
&write_htaccess;
}
&login;
}
}
############
# Login
sub login {
®_page_lang;
opendir(VFILES,$vis_dir);
@vfilelist = grep(!/^\.|^_/, readdir (VFILES));
closedir(VFILES);
$vtotal = @vfilelist - 1;
open(VISITORS,"$file_dir/vis$room");
@visitors = ;
close(VISITORS);
foreach $visitors_line (@visitors) {
($bogus,$load,$bogus2) = split(/:/,$visitors_line);
if ($time - $load < $visitors_time && $load) {
push (@visitors_new,"$visitors_line");
}
}
@visitors = @visitors_new;
undef @visitors_new;
$vnum = @visitors;
print "Content-type: text/html\n\n";
print "$page_title $reg_page\n";
print "\n";
if($font_face ne "") {
print "\n";
}
print "\n";
if($advertise_plugin && $ad_locations =~ /a/) {
&advertise;
}
if ($title_graphic eq "") {
print "$page_title
\n";
}
else {
print "
\n";
}
print "$reg_page
\n";
®ister_body;
}
###########
# Body of Registration Page
# used on initial login, and when their chosen name is taken
# or other problem requires them to login again
sub register_body {
print "$you_must
\n";
print "$instruct
\n";
if ($vnum < 1) {
print "$no_vis_a $room $no_vis_b
\n";
}
elsif ($vnum==1) {
print "$one_vis_a $room $one_vis_b
\n";
}
else {
print "$mult_vis_a $vnum $mult_vis_b $room $mult_vis_c
\n";
}
if ($vtotal < 1) {
print "$no_vis_tot
\n";
}
elsif ($vtotal==1) {
print "$one_vis_tot
\n";
}
else {
print "$mult_vis_tot_a $vtotal $mult_vis_tot_b
\n";
}
print "$enter_name
\n";
print "
\n";
if ($schedule_file) {
print "$sched_note_a ";
print "$sched_note_b $sched_note_c\n";
}
if ($help_file) {
print "$help_a $help_b $help_c
\n";
}
if($advertise_plugin && $ad_locations =~ /b/) {
&advertise;
}
print "
$our_image\n";
print " \n";
}
###########
# Name taken
sub name_taken {
®_page_lang;
print "Content-type: text/html\n\n";
print "$page_title $reg_page\n";
print "\n";
if($font_face ne "") {
print "\n";
}
print "\n";
if($advertise_plugin && $ad_locations =~ /a/) {
&advertise;
}
if ($title_graphic eq "") {
print "$page_title
\n";
}
else {
print "
\n";
}
print "$reg_page
\n";
print "$wrong_name\n";
®ister_body;
&unlock;
exit;
}
############
# Check Name
sub check_name {
if (!$passwd || !$name) {
&name_taken;
}
elsif (-e "$vis_dir/$vname"){
open (VSAME,"$vis_dir/$vname") || die $!;
$vsame = ;
close (VSAME);
($bogus,$test,$bogus2) = split(/:/,$vsame);
$password = crypt($passwd,MW);
if ($password ne $test) {
&name_taken;
}
}
elsif($user_limit_plugin) {
require("$plugin_dir/user_limit.pl");
&overflow;
}
}
########################
# Maintain files
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);
if($message_plugin) {
require("$plugin_dir/message.pl");
&message_prep;
}
opendir(FILES,"$file_dir");
@filelist = grep(!/^\./, readdir (FILES));
closedir(FILES);
foreach $file (@filelist) {
$tfile = $file;
$tfile =~ s/^chat//g;
if (-M "$file_dir/$file" > $chat_time / 86400 && ! $MESGROOMS{$tfile}) {
if ($file =~ /^chat/ || $file =~ /^vis/) {
unlink("$file_dir/$file");
}
}
}
&deletev;
}
sub deletev {
if (-e "$file_dir/vis$room") {
foreach $visitors_line (@visitors) {
($bogus,$load,$bogus2) = split(/:/,$visitors_line);
if ($time - $load < $visitors_time) {
push (@visitors_new,"$visitors_line");
}
}
}
@visitors = @visitors_new;
undef @visitors_new;
&deletevfiles;
}
sub deletevfiles {
opendir(VFILES,$vis_dir);
@vfilelist = grep(!/^\.|^_/, readdir (VFILES));
closedir(VFILES);
foreach $vfilelist (@vfilelist) {
if (-M "$vis_dir/$vfilelist" > ($visitors_time / 86400)) {
unlink("$vis_dir/$vfilelist");
}
}
if(!$where) {
opendir(VFILES,$vis_dir);
@ffilelist = grep(/^_/, readdir (VFILES));
closedir(VFILES);
foreach $ffilelist (@ffilelist) {
open(FFILE,"$vis_dir/$ffilelist");
$ffile = ;
close(FFILE);
$ffile =~ s/\n//g;
$ffile =~ s/ /_/g;
if(! -e "$vis_dir/$ffile") {
unlink("$vis_dir/$ffilelist");
}
}
}
}
###########
# Register
sub register {
$login = $date;
foreach $visitors_line (@visitors) {
if ($visitors_line !~ /^$name($| \d+:\d\d:\d\d$)/) {
push (@visitors_new,"$visitors_line");
}
}
@visitors = @visitors_new;
undef @visitors_new;
$temp = "$name\n";
unshift (@visitors,$temp);
shift(@vfile);
if($frame_remind && $frames eq "yes") {
if ($initial_message_plugin) {
require("$plugin_dir/initial_message.pl");
$temp = "$name, $frame_remind$countdown
$random_line
";
}
else {
$temp = "$name, $frame_remind
";
}
}
else {
if ($initial_message_plugin) {
require("$plugin_dir/initial_message.pl");
$temp = "$name, $reload_remind$countdown
$random_line
";
}
else {
$temp = "$name, $reload_remind
";
}
}
unshift (@vfile,"$temp\n");
$password = crypt($passwd,MW);
$temp = "\n";
unshift(@vfile,$temp);
$vmodified = 1;
if($show_status) {
$temp = "$name $maillink $joined_chat $date
\n";
unshift(@main,$temp);
$cmodified = 1;
}
}
##########
# Modify chat page
sub post {
if ($tempmessage) {
if($emoticon_plugin) {
require("$plugin_dir/emoticon.pl");
if ($FORM{'emoticon'} && $FORM{'emoticon'} ne $blank_emoticon) {
&post_emoticon;
}
else {
$temp = "$name $maillink $date
$message
\n";
}
}
else {
$temp = "$name $maillink $date
$message
\n";
}
unshift(@main,$temp);
$cmodified = 1;
}
}
#########
# Snag information when person hits reload
sub snag {
$mess = $message;
}
sub verify_password {
($bogus,$fpassword) = split(/:/,$vfile[0]);
if($where eq "$leave_text" && !$password) {
$password = $fpassword;
}
if($password ne $fpassword) {
&unlock;
&login;
exit;
}
}
##########
# Update Visitor's log
sub update {
foreach $visitors_line (@visitors) {
if ($visitors_line !~ /^$name$/ &&
$visitors_line !~ /^$name \d+:\d\d:\d\d$/ &&
$visitors_line !~ /^$name \d\d\/\d\d\/\d\d \d+:\d\d:\d\d$/) {
push (@visitors_new,"$visitors_line");
}
}
@visitors = @visitors_new;
undef @visitors_new;
$temp ="$name $date\n";
unshift (@visitors,$temp);
$vmodified = 1;
if ($admonish) {
&admonish;
}
}
############
# Reload
sub reload {
$public_count = @public_rooms;
if($password_style == 2 && $access_control_plugin) {
require("$plugin_dir/access_control.pl");
&admit_style;
}
elsif($frames eq "lite") {
require("$plugin_dir/lite.pl");
&lite_layout;
}
elsif($frames eq "yes") {
require("$plugin_dir/frames.pl");
&topframe_reload;
}
elsif($bottomframe) {
require("$plugin_dir/frames.pl");
&bottomframe_reload;
}
else {
$ignoredlist = join("()",@ignored);
if(!$nummes) {
$nummes = $def_mes;
}
if(!$refreq) {
$refreq = $def_reload;
}
if($nummes =~ /\D/ && $nummes !~ /^($new_nummes||$all_nummes)$/i) {
$nummes = $def_mes ;
}
if($nummes > $max_mes && $nummes !~ /^($new_nummes||$all_nummes)$/i) {
$nummes = $max_mes;
}
print "Content-type: text/html\n\n";
print "$page_title\n";
print "\n";
if($font_face ne "") {
print "\n";
}
print "\n";
if($advertise_plugin && $ad_locations =~ /e/) {
&advertise;
print "
";
}
print "\n";
if($bottomframe) {
print "
\n";
}
&nummes;
if($advertise_plugin && $ad_locations =~ /f/) {
&advertise;
}
print "$our_image\n";
print " \n";
}
}
sub nummes {
if($nummes =~ /^$all_nummes$/i) {
$clinecount = 0;
$vlinecount = 1;
while($clinecount < @main || $vlinecount < @vfile) {
&print_chat;
}
}
elsif($nummes =~ /^$new_nummes$/i) {
$clinecount = 0;
$vlinecount = 1;
$clinetime = $time;
while(($vlinetime > $load_time - $new_time || $clinetime > $load_time - $new_time) && ($clinecount < @main || $vlinecount < @vfile)) {
&print_chat;
}
}
else {
$clinecount = 0;
$vlinecount = 1;
while($mlinecount < $nummes && ($clinecount < @main || $vlinecount < @vfile)) {
&print_chat;
}
}
}
sub print_chat {
foreach$ignoree(@ignored) {
while($main[$clinecount] =~ /$ignoree<\/b>/) {
$clinecount++;
undef($clinetime);
}
while($vfile[$vlinecount] =~ /$ignoree<\/b>/) {
$vlinecount++;
undef($vlinetime);
}
}
if(!$clinetime || $nummes =~ /$new_nummes/i) {
($bogus,$clinetime) = split(/:/,$main[$clinecount]);
}
if(!$vlinetime || $nummes =~ /$new_nummes/i) {
($bogus,$vlinetime) = split(/:/,$vfile[$vlinecount]);
}
if(!$clinetime && !$vlinetime) {
$clinecount++;
$vlinecount++;
}
elsif($clinetime > $vlinetime) {
$tcline = $main[$clinecount];
$tcline =~ s/^//g;
if($adminyes && $show_ip == 1) {
$messtime = substr($clinetime, -5, 5);
$tcline =~ s// $messtime/g;
}
else {
$tcline =~ s///g;
}
if($clinetime > $load_time) {
if($tcline =~ /$joined_chat/ && $alert_sound_plugin) {
require("$plugin_dir/alert_sound.pl");
&alert_sound;
}
print "$new_message $tcline";
}
elsif(!$old_timer) {
$old_timer = 1;
print "\n";
print $tcline;
}
else {
print $tcline;
}
$clinecount++;
if($nummes !~ /$new_nummes/i) {
undef($clinetime);
}
}
else {
$tvline = $vfile[$vlinecount];
$tvline =~ s///g;
$tvline =~ s/^//g;
if($adminyes && $show_ip == 1) {
$tvline =~ s///g;
}
else {
$tvline =~ s///g;
}
if($vlinetime > $load_time) {
print "$new_message $tvline";
}
else {
print $tvline;
}
$vlinecount++;
if($nummes ne "$new_nummes") {
undef($vlinetime);
}
}
$mlinecount++;
}
##############
# Change rooms
sub change {
$load_time = 0;
if($oshow_status) {
open(OLDMAIN,"$file_dir/chat$oldroom");
@oldmain = ;
close(OLDMAIN);
$temp = "$name $maillink $left_room $date
\n";
unshift(@oldmain,$temp);
open(OLDMAIN,">$file_dir/tempc$oldroom");
foreach$oldmainline(@oldmain){
print OLDMAIN "$oldmainline";
}
close(OLDMAIN);
rename("$file_dir/tempc$oldroom","$file_dir/chat$oldroom");
open(OLDVIS,"$file_dir/vis$oldroom");
@oldvis = ;
close(OLDVIS);
}
foreach $visitors_line (@oldvis) {
if ($visitors_line !~ /^$name($| \d+:\d\d:\d\d$)/) {
push (@visitors_old,"$visitors_line");
}
}
@oldvis = @visitors_old;
undef @visitors_old;
open(OLDVIS,">$file_dir/tempv$oldroom");
foreach$oldvisline(@oldvis) {
print OLDVIS "$oldvisline";
}
close(OLDVIS);
rename("$file_dir/tempv$oldroom","$file_dir/vis$oldroom");
undef(@oldmain);
undef(@oldvis);
open(MAIN,"$file_dir/chat$room");
@main = ;
close(MAIN);
@main = @main[(0 .. $max_mes)];
if($show_status) {
$temp = "$name $maillink $joined_chat $date
\n";
unshift(@main,$temp);
$cmodified = 1;
}
open(VISITORS,"$file_dir/vis$room");
@visitors = ;
close(VISITORS);
$login = "$date";
foreach $visitors_line (@visitors) {
if ($visitors_line !~ /^$name($| \d+:\d\d:\d\d$)/) {
push (@visitors_new,"$visitors_line");
}
}
@visitors = @visitors_new;
undef @visitors_new;
$temp = "$name\n";
unshift (@visitors,$temp);
$vmodified = 1;
}
##############
# Send the private message
sub privmsg {
if ($tempmessage) {
$solo =~ s/ /_/g;
if(-e "$vis_dir/$solo"){
open (VFILES,"$vis_dir/$solo") || die $!;
@vfiles = ;
close (VFILES);
$vfilestemp = $vfiles[0];
shift(@vfiles);
if($emoticon_plugin) {
require("$plugin_dir/emoticon.pl");
if ($FORM{'emoticon'} && $FORM{'emoticon'} ne $blank_emoticon) {
&one_on_one_emoticon;
}
else {
$tempa ="$one_on_one_text:";
$tempb = " $name $date
$message
\n";
$temp = "$tempa$tempb";
}
}
else {
$tempa ="$one_on_one_text:";
$tempb = " $name $maillink $date
$message
\n";
$temp = "$tempa$tempb";
}
unshift(@vfiles,$temp);
unshift(@vfiles,"$vfilestemp");
open(VFILES,">$vis_dir/$solo") || die $!;
foreach $vfiles_line(@vfiles) {
print VFILES "$vfiles_line";
}
close(VFILES);
$primessage = $message;
}
else {
$primessage = "$person_gone
$message";
}
$solo =~ s/_/ /g;
$vfiletemp = $vfile[0];
shift(@vfile);
if($emoticon_plugin) {
require("$plugin_dir/emoticon.pl");
if ($FORM{'emoticon'} && $FORM{'emoticon'} ne $blank_emoticon) {
&send_one_on_one_emoticon;
}
else {
$tempa ="$one_on_one_text:";
$tempb = " To: $solo $date
$primessage
\n";
$temp = "$tempa$tempb";
}
}
else {
$tempa ="$one_on_one_text:";
$tempb = " To: $solo $date
$primessage
\n";
$temp = "$tempa$tempb";
}
unshift (@vfile,$temp);
unshift (@vfile,"$vfiletemp");
}
}
###############
# Leave
sub leave {
unlink("$vis_dir/$vname");
if($emoticon_plugin) {
require("$plugin_dir/emoticon.pl");
if ($FORM{'emoticon'} && $FORM{'emoticon'} ne $blank_emoticon) {
&leave_emoticon;
}
else {
$temp = "$name $maillink $left_chat $date
\n";
}
}
else {
$temp = "$name $maillink $left_chat $date
\n";
}
if($show_status) {
unshift(@main,$temp);
$cmodified = 1;
}
foreach $visitors_line (@visitors) {
if ($visitors_line !~ /^$name($| \d+:\d\d:\d\d$)/) {
push (@visitors_new,"$visitors_line");
}
}
@visitors = @visitors_new;
undef @visitors_new;
print "Location: $link\n\n";
$vmodified = 1;
}
###########
# Write Files
sub write {
if($cmodified) {
open(MAIN,">$file_dir/tempc$room");
print MAIN @main;
close(MAIN);
rename("$file_dir/tempc$room","$file_dir/chat$room")
}
if($vmodified) {
open(VISITORS,">$file_dir/tempv$room");
print VISITORS @visitors;
close(VISITORS);
rename("$file_dir/tempv$room","$file_dir/vis$room")
}
$vfile[0] = "\n";
if(!$vname) {
$vname = $name;
$vname =~ s/ /_/g;
}
if($where ne "$leave_text" && $vname){
open(VFILE,">$vis_dir/temp$vname");
print VFILE @vfile;
close(VFILE);
rename("$vis_dir/temp$vname","$vis_dir/$vname");
}
}
#############
# Write .htaccess file for security
sub write_htaccess {
open(HTACCESS,">$access_dir/.htaccess");
print HTACCESS "AuthUserFile /etc/.htpasswd\nAuthGroupFile /dev/null\n";
print HTACCESS "AuthName ChatPro Restricted Area\nAuthType Basic\n\n";
print HTACCESS "require user ChatPro\n\n";
close(HTACCESS);
}
#############
# Unlock
sub unlock {
unlink("$file_dir/$lock_file");
}