#!/usr/bin/perl



#  _       ____  ______                      
# | |     / / / / / __ \            v1.1
# | | /| / / /_/ / / / /                     
# | |/ |/ / __  / /_/ /         ___          
# |__/|__/_(_)_/\____/_  ____  / (_)___  ___ 
#         / / ___// __ \/ __ \/ / / __ \/ _ \
#        / (__  )/ /_/ / / / / / / / / /  __/
#       /_/____/ \____/_/ /_/_/_/_/ /_/\___/ 
#
# COPYRIGHT (C) 2002 BROCAAR.COM 
#       E-MAIL: INFO@BROCAAR.COM

######################################
#// CONFIGURATION ////////////////////
######################################

# REFRESH TIME (in seconds)
$refresh = 300;

# PATH TO DATA FILE
$data_file = './who_users.dat';

# FONT
$font = 'arial';

# FONT SIZE
$font_size = 2;

#######################################
#// END CONFIGURATION /////////////////
#######################################

use CGI;
$q = new CGI;

$usr_id = $ENV{REMOTE_ADDR};

$bgcolor = $q->param('bgcolor') || 'EFFFFF';
$txtcolor = $q->param('txtcolor') || '000000';
$found = 0;
$marge = $refresh + 10;
$time = time;
$users = 0;


open(DATA,"$data_file");
flock(DATA, 2);
@lines = <DATA>;
close(DATA);

open(DATA,">$data_file");
flock(DATA, 2);
foreach $line (@lines)
	{
	($data_id, $data_time, $tmp) = split(/\|/,$line, 3);
	if ($data_id eq $usr_id)
		{
		print DATA ("$usr_id|$time|\n");
		$users++;
		$found = 1;
		}
	else
		{
		$timeoff = $time - $data_time;
		if ($timeoff > 0 && $timeoff < $marge)
			{
			print DATA $line;
			$users++;
			}
		}
	}
if ($found == 0)
	{
	print DATA ("$usr_id|$time|\n");
	$users++;
	}
close(DATA);

if ($users == 1)
	{
	$text = 'dreamer';
	$are = 'is';
	}
else
	{
	$text = 'dreamers';
	$are = 'are';
	}

print $q->header(-type => "text/html", -expires => "now");
print <<HTML;
<html>
<head>
<title>Who (is online) by Brocaar.com</title>
<meta http-equiv="REFRESH" content="$refresh;URL=who.pl?bgcolor=$bgcolor&txtcolor=$txtcolor">
</head>
<body bgcolor="#$bgcolor" topmargin="0" leftmargin="0">
<font color="#$txtcolor" size="$font_size" face="$font"><i>There $are currently $users $text on the Dream Moods site.</i></font>
</body>
</html>
HTML

exit;