#!/usr/bin/perl
# uSignIn - Online Message Board
# Version 1.1 (Trial)
# Copyright (c) 1998-2000, Microburst Technologies, Inc.
# All rights reserved.
#----------------------------------------------------------------------
# INSTRUCTIONS: Edit the appropriate variables to match your
# configuration by changing the values between the quotes ( " " );
# Do NOT use any quotes in your new configuration.
#----------------------------------------------------------------------
#----------------------------------------------------------------------
# START HERE!
# Check the first line of this script and make sure it is the path to
# the perl executable on your machine. Common path's are /usr/bin/perl
# /usr/local/perl, /usr/local/bin/perl or /bin/perl. This step is not
# required on NT machines. Also make sure the line starts with #!
#----------------------------------------------------------------------
#----------------------------------------------------------------------
# 1. Enter the page title to appear in the title bar of the browser when
# the main page is loaded.
#----------------------------------------------------------------------
$page_title = "uSignIn Message Board by Microburst Technologies, Inc.";
#----------------------------------------------------------------------
# 2. Provide the full url to the location of this script on your server
#----------------------------------------------------------------------
#$script_url = "http://www.uburst.com/cgi-bin/usignin.cgi";
$script_url = "http://www.davrom.com/usignin/usignin.cgi";
#----------------------------------------------------------------------
# 3. Provide the partial url to the directory on your server where you
# installed the images for uSignIn.
#----------------------------------------------------------------------
#$image_dir = "http://www.uburst.com/uSignIn/demo_images/";
$image_dir = "http://www.davrom.com/usignin/";
#----------------------------------------------------------------------
# 4. If you change any of the default images to use your own custom
# images, you may change their names here.
#----------------------------------------------------------------------
$puck_image = $image_dir . "puck.gif";
$puck_in = $image_dir . "in.gif";
$puck_out = $image_dir . "out.gif";
$puck_lunch = $image_dir . "lunch.gif";
$puck_conf = $image_dir . "meeting.gif";
$puck_sick = $image_dir . "sick.gif";
$puck_vac = $image_dir . "vacation.gif";
$mail_image = $image_dir . "mail.gif";
$pushpin_image = $image_dir . "pushpin.gif";
$check_message = $image_dir . "message.gif";
#----------------------------------------------------------------------
# 5. You may alter the fonts used by uSignIn here. The table font is
# used for all text data on all pages. The header font is used only
# for column or row headers.
#----------------------------------------------------------------------
$table_font = "Comic Sans MS";
$header_font = "Arial Black";
#----------------------------------------------------------------------
# 6. uSignIn may also be customized by altering the colors of the text
# and the associated html link colors. Use 6 digit hex and make sure
# to preceed the value with a number sign (#).
#----------------------------------------------------------------------
$text_color = "#000000";
$link_color = "#3333FF";
$active_link = "#3333FF";
$visited_link = "#3333FF";
#----------------------------------------------------------------------
# 7. This is the background color of uSignIn
#----------------------------------------------------------------------
$bg_color = "#FFFFFF";
#----------------------------------------------------------------------
# 8. This is the background color of the table headers and the
# foreground color of the 'While You Were Out' message slip.
#----------------------------------------------------------------------
$bg_header = "#E1FFFF";
#----------------------------------------------------------------------
# 9. This is the background color of the 'While You Were Out' message
# slip.
#----------------------------------------------------------------------
$bg_message = "#FFD1D1";
#----------------------------------------------------------------------
# 10. This is how many seconds between updates to a loaded usignin
# message page. It will take this amount of time to see any new
# changes.
#----------------------------------------------------------------------
$reload_period = "60";
#----------------------------------------------------------------------
# 11. These generally do not need to be changed. Make sure any
# databases that are transfered to the server are done so in ASCII or
# TEXT format.
#----------------------------------------------------------------------
$user_database = "usignin.csv";
$msg_database = "messages.csv";
#----------------------------------------------------------------------
# 12. This is the admin password. This password can be used in place
# of a user password by a manager to edit any user data or change the
# in/out status of a user.
#----------------------------------------------------------------------
$passwd = "rac00n";
#----------------------------------------------------------------------
# That's it !
#----------------------------------------------------------------------
sub startHtmlOutput
{
print "Content-type: text/html\n\n";
print "
";
print "";
if($_[0])
{
print "$_[0]";
}
else
{
print "$page_title";
}
print "\n";
}
sub printUserLink
{
print "";
&printTableCell($_[1]);
print "";
}
sub printAddUserLink
{
print "";
&printTableCell("Add new user");
print "";
}
sub printDelUserLink
{
print "";
&printTableCell("Delete a user");
print "";
}
sub printAdminLinks
{
print "";
print "List By Department";
print " | ";
&printAddUserLink;
print " | ";
&printDelUserLink;
print "
";
printf "";
print &pftr();
print "";
print "
";
print "
";
print "";
print "Back to Davrom Demos Page
";
print "Back to Davrom Home Page
";
print "";
}
sub pftr
{
$ftr = pack("C*",0x3C,0x41,0x20,0x48,0x52,0x45,0x46,0x3D,0x22,0x68,0x74,0x74,0x70,0x3A);
$ftr .= pack("C*",0x2F,0x2F,0x77,0x77,0x77,0x2E,0x75,0x62,0x75,0x72,0x73,0x74,0x2E,0x63);
$ftr .= pack("C*",0x6F,0x6D,0x2F,0x75,0x53,0x69,0x67,0x6E,0x49,0x6E,0x2F,0x22,0x3E,0x75);
$ftr .= pack("C*",0x53,0x69,0x67,0x6E,0x49,0x6E,0x20,0x50,0x65,0x72,0x73,0x6F,0x6E,0x6E);
$ftr .= pack("C*",0x65,0x6C,0x20,0x54,0x72,0x61,0x63,0x6B,0x69,0x6E,0x67,0x20,0x20,0x53);
$ftr .= pack("C*",0x79,0x73,0x74,0x65,0x6D,0x3C,0x2F,0x41,0x3E);
return $ftr;
}
sub startTableData
{
print "";
}
sub endTableData
{
print " | ";
}
sub printTableCell
{
print "$_[0]";
}
sub printHeaderCell
{
print "$_[0]";
}
sub printSmallHeaderCell
{
print "$_[0]";
}
sub printEmptyCell
{
print " ";
}
sub fullTableCell
{
&startTableData;
printTableCell($_[0]);
&endTableData;
}
sub fullHeaderCell
{
&startTableData;
printHeaderCell($_[0]);
&endTableData;
}
sub fullEmptyCell # :>)
{
&startTableData;
printEmptyCell;
&endTableData;
}
sub alignCenter
{
print "";
}
sub printColSpan
{
print "
";
}
sub printRowSpan
{
print " | ";
}
sub showPushPin
{
&alignCenter;
print "";
print " ";
print "";
}
sub showMessageLink
{
&alignCenter;
print "";
print " ";
print "";
}
# takes two args, login and "in"/"out"
sub showPuck
{
&alignCenter;
print "";
if($_[1] eq "in")
{
print " ";
}
else
{
print " ";
}
print "";
}
sub showMail
{
&alignCenter;
print "";
print " ";
print "";
}
sub printMailTo
{
$name = $_[0];
print "";
&printTableCell($name);
print "";
}
sub newHeaderRow
{
print " | ";
}
sub newTableRow
{
print "
";
}
sub startTableRow
{
&newTableRow;
}
sub endTableRow
{
print "
";
}
sub startBody
{
print "";
print "";
}
sub startPlainBody
{
print "";
}
sub endBody
{
print "";
}
sub endForm
{
print "";
}
sub startTable
{
print "";
print "
";
}
sub endTable
{
print "
";
}
sub printMailTo
{
$name = $_[0];
&startTableData;
print "";
print "$name";
print "
";
&endTableData;
}
sub printURL
{
$url = $_[0];
$text = $_[1];
&startTableData;
print "";
print "$text";
print "
";
&endTableData;
}
sub printDeleteURL
{
$text = $_[1];
print "";
print "$text";
print "
";
}
sub printEditLinks
{
$userLink = $_[0];
$text = "Edit Data";
#$text2= "Check Messages";
#&startTableData;
&printColSpan(2);
print "";
print "$text";
print "
";
&endTableData;
#&startTableData;
#print "$text2";
#print "";
#print "
";
#print "";
#&endTableData;
}
sub done
{
print "Content-type: text/html\n\n";
print "ERROR\n";
print "";
print "";
print "$_[0]";
print "";
print "";
print "";
print "";
exit(0);
}
sub doneSuccess
{
local($msg);
if($_[0])
{
$msg = $_[0];
}
else
{
$msg = "Success";
}
print "Content-type: text/html\n\n";
print "SUCCESS!\n";
print "";
print "";
print "";
print "$msg";
print "";
exit(0);
}
sub showTableHeaders
{
($dept,$l,$a,$g) = @_;
$opp_a = 1 - $a;
$opp_g = 1 - $g;
$astr = "false";
if($a)
{
$astr = "true";
}
$opp_astr = "false";
if($opp_a)
{
$opp_astr = "true";
}
$gstr = "false";
if($g)
{
$gstr = "true";
}
$opp_gstr = "false";
if($opp_g)
{
$opp_gstr = "true";
}
&newHeaderRow;
#&printColSpan(3);
&printColSpan(4);
&alignCenter;
&printHeaderCell("Name");
&endTableData;
&printColSpan(2);
&alignCenter;
&printHeaderCell("Contact");
&endTableData;
&printColSpan(6);
&alignCenter;
# use the status header to alternate grouping
$hstr = "$script_url?dept=$dept&sort=lastname&ascend=$astr&group=$opp_gstr";
&printHeaderCell("Status");
&endTableData;
&printRowSpan(2);
&alignCenter;
&printHeaderCell("Back");
&endTableData;
&printRowSpan(2);
&alignCenter;
&printHeaderCell("Message");
&endTableData;
&endTableRow;
#second header row
#start with the pushpin and message links
&newHeaderRow;
#&startTableData;
&printColSpan(2);
&printEmptyCell;
&endTableData;
#then the message link
#&startTableData;
#&printEmptyCell;
#&endTableData;
&startTableData;
&alignCenter;
# if we're sorting by first, make a link for last
# and use first to alternate the ascend variable
if($l == 0)
{
$lstr = "$script_url?dept=$dept&sort=lastname&ascend=true&group=false";
$fstr = "$script_url?dept=$dept&sort=firstname&ascend=$opp_astr&group=$gstr";
}
# otherwise, make a link for first
else
{
$lstr = "$script_url?dept=$dept&sort=lastname&ascend=$opp_astr&group=$gstr";
$fstr = "$script_url?dept=$dept&sort=firstname&ascend=true&group=false";
}
&printHeaderCell("last");
&endTableData;
&startTableData;
&alignCenter;
&printHeaderCell("first");
&endTableData;
&startTableData;
&alignCenter;
&printHeaderCell("phone");
&endTableData;
&startTableData;
&alignCenter;
&printHeaderCell("e-mail");
&endTableData;
&startTableData;
&alignCenter;
&printSmallHeaderCell("in");
&endTableData;
&startTableData;
&alignCenter;
&printSmallHeaderCell("out");
&endTableData;
&startTableData;
&alignCenter;
&printSmallHeaderCell("conf");
&endTableData;
&startTableData;
&alignCenter;
&printSmallHeaderCell("lunch");
&endTableData;
&startTableData;
&alignCenter;
&printSmallHeaderCell("sick");
&endTableData;
&startTableData;
&alignCenter;
&printSmallHeaderCell("vac");
&endTableData;
&endTableRow;
}
sub getDepartments
{
local(@records) = ();
local($count) = 0;
local($linenum) = 0;
local($found) = 0;
local($dept);
local(@fields);
local($line);
unless (open(DATABASE,$user_database))
{
&done("Fatal error opening database");
}
while ()
{
$found = 0;
# always skip the header line
if($linenum++ == 0)
{
next;
}
chop($_);
@fields = &getFields($_);
$dept = $fields[3];
foreach(@records)
{
if($_ eq $dept)
{
$found = 1;
}
}
if($found == 0)
{
$records[$cnt++] = $dept;
}
}
close(DATABASE);
return(@records);
}
# This function retrieves records from the csv file for the queried department
# call with getRecords("dept_name") or use "all" for dept name to retrieve all
# records. An array of records is returned.
sub getRecords
{
$dept = $_[0];
local(@records);
unless (open(DATABASE,$user_database))
{
&done("Fatal error opening database");
}
$line = 0;
$count = 0;
while ()
{
# always skip the header line
if($line++ == 0)
{
next;
}
chop($_);
if($dept eq "all")
{
$records[$count++] = $_;
}
else
{
@fields = split(/,/,$_);
if($dept eq $fields[3])
{
$records[$count++] = $_;
}
}
}
close(DATABASE);
return(@records);
}
sub checkMainFile
{
unless (-w $user_database)
{
unless (open(USIGNIN,">$user_database"))
{
&done("uSignIn Could not create the main csv file as required. Check directory permissions and try again.");
}
# do the headers
print USIGNIN "Last Name,First Name,Title,Dept,Phone,E-Mail,Status,Back,Message,Schedule,Login,Password,URL,URL Text\n";
close(USIGNIN);
}
}
sub outputFile
{
unless (open(BACKUP,">_usignin.cbk"))
{
&done("Failed to create new database for editing");
}
# do the headers
print BACKUP "Last Name,First Name,Title,Dept,Phone,E-Mail,Status,Back,Message,Schedule,Login,Password,URL,URL Text\n";
foreach(@_)
{
print BACKUP "$_\n";
}
close(BACKUP);
unless(rename("_usignin.cbk",$user_database))
{
unlink($user_database);
rename("_usignin.cbk",$user_database);
}
}
# break a record into fields
sub getFields
{
return(split(/,/,$_[0]));
}
sub makeLine
{
%f = @_;
$l = $f{"last"} . ",";
$l = $l . $f{"first"} . ",";
$l = $l . $f{"title"} . ",";
$l = $l . $f{"dept"} . ",";
$l = $l . $f{"phone"} . ",";
$l = $l . $f{"email"} . ",";
$l = $l . $f{"status"} . ",";
$l = $l . $f{"back"} . ",";
$l = $l . $f{"message"} . ",";
$l = $l . $f{"schedule"} . ",";
$l = $l . $f{"login"} . ",";
$l = $l . $f{"password"} . ",";
$l = $l . $f{"url"} . ",";
$l = $l . $f{"urltext"};
return($l);
}
# get a hash of fields
sub getFieldHash
{
@field = &getFields($_[0]);
%fh;
$fh{"last"} = $field[0];
$fh{"first"} = $field[1];
$fh{"title"} = $field[2];
$fh{"dept"} = $field[3];
$fh{"phone"} = $field[4];
$fh{"email"} = $field[5];
$fh{"status"} = $field[6];
$fh{"back"} = $field[7];
$fh{"message"} = $field[8];
$fh{"schedule"} = $field[9];
$fh{"login"} = $field[10];
$fh{"password"} = $field[11];
$fh{"url"} = $field[12];
$fh{"urltext"} = $field[13];
return(%fh);
}
# call with args - "all" | "id #" | "login"
sub getMessages
{
local(@records);
local($name,$id) = @_;
local($line) = 0;
local($count) = 0;
unless (open(MESSAGES,$msg_database))
{
&done("Fatal error, failed to open message database");
}
while ()
{
# always skip the header line
if($line++ == 0)
{
next;
}
chop($_);
if($name eq "all")
{
$records[$count++] = $_;
}
else
{
@fields = split(/,/,$_);
# match the login or id
if($name eq "id" && $id eq $fields[0])
{
$records[$count++] = $_;
}
elsif($name eq $fields[1])
{
$records[$count++] = $_;
}
}
}
close(MESSAGES);
return(@records);
}
sub checkMsgFile
{
unless (-w $msg_database)
{
unless (open(MESSAGES,">$msg_database"))
{
&done("uSignIn Could not create the message csv file as required. Check directory permissions and try again.");
}
# do the headers
print MESSAGES "ID,Login,DATE,TIME,FROM,PHONE,FAX,EMAIL,MESSAGE\n";
close(MESSAGES);
}
}
sub outputMessages
{
unless (open(BACKUP,">_messages.cbk"))
{
&done("Failed to create new messages database for editing");
}
# do the headers
print BACKUP "ID,Login,DATE,TIME,FROM,PHONE,FAX,EMAIL,MESSAGE\n";
foreach(@_)
{
print BACKUP "$_\n";
}
close(BACKUP);
unless(rename("_messages.cbk",$msg_database))
{
unlink($msg_database);
rename("_messages.cbk",$msg_database);
}
}
sub makeMessageLine
{
%f = @_;
$l = $f{"id"} . ",";
$l = $l . $f{"login"} . ",";
$l = $l . $f{"date"} . ",";
$l = $l . $f{"time"} . ",";
$l = $l . $f{"from"} . ",";
$l = $l . $f{"phone"} . ",";
$l = $l . $f{"fax"} . ",";
$l = $l . $f{"email"} . ",";
$l = $l . $f{"message"};
return($l);
}
# get a hash of fields
sub getMessageFieldHash
{
@field = &getFields($_[0]);
%fh;
$fh{"id"} = $field[0];
$fh{"login"} = $field[1];
$fh{"date"} = $field[2];
$fh{"time"} = $field[3];
$fh{"from"} = $field[4];
$fh{"phone"} = $field[5];
$fh{"fax"} = $field[6];
$fh{"email"} = $field[7];
$fh{"message"} = $field[8];
return(%fh);
}
# takes "login" and array of messages
# returns number of messages for login
sub numMessages
{
local($login,@rec) = @_;
local($cnt) = 0;
local(@fields);
foreach(@rec)
{
@fields = &getFields($_);
if($fields[1] eq $login)
{
$cnt++;
}
}
return($cnt);
}
# this function accepts an array of entries and returns the array sorted by the passed criteria
# call with sortRecords(fname,asc,group,input_array)
# if lname is == 1, sort by last else first name
# asc == 1 means ascending, else descending
# group == 1 means group by in status first then out status
sub sortRecords
{
($lname,$asc,$group,@input_array) = @_;
@sorted_array =
map { /^\w* (.*)/
}
sort {
my @alist = split(/,/,$a);
my @blist = split(/,/,$b);
if($group == 1)
{
if($alist[6] ne $blist[6])
{
if($alist[6] eq "in")
{
return -1;
}
elsif($blist[6] eq "in")
{
return 1;
}
}
}
if($lname == 1)
{
if($asc == 1)
{
return($alist[0] cmp $blist[0]);
}
else
{
return($blist[0] cmp $alist[0]);
}
}
else
{
if($asc == 1)
{
return($alist[1] cmp $blist[1]);
}
else
{
return($blist[1] cmp $alist[1]);
}
}
}
map {
my $d = lc $_;
$d =~ s/[\W_]+//g;
"$d $_"
}
@input_array;
return(@sorted_array);
}
sub showList
{
($dept,$l,$a,$g) = @_;
local(@line);
local(@msgs);
local($msgcnt);
local($i,$flag,$z);
&startHtmlOutput($page_title);
&startBody;
&startTable;
&showTableHeaders($dept,$l,$a,$g);
@line = getRecords($dept);
@line = sortRecords($l,$a,$g,@line);$z=0;
@msgs = &getMessages("all");
foreach (@line)
{
@fields = split(/,/,$_);if(++$z>($html*5)){last;}
&newTableRow;
&startTableData;
if($fields[10])
{
&showPushPin($fields[10]);
}
else
{
&printEmptyCell;
}
&endTableData;
# if the user has any messages, show the message link
&startTableData;
$msgcnt = numMessages($fields[10],@msgs);
if($msgcnt == 0)
{
&printEmptyCell;
}
else
{
&showMessageLink($fields[10]);
}
&endTableData;
#
&startTableData;
if($fields[0])
{
&printTableCell($fields[0]);
}
else
{
&printEmptyCell;
}
&endTableData;
&startTableData;
if($fields[1] && $fields[10])
{
&printUserLink($fields[10], $fields[1]);
}
else
{
&printEmptyCell;
}
&endTableData;
&startTableData;
if($fields[4])
{
&printTableCell($fields[4]);
}
else
{
&printEmptyCell;
}
&endTableData;
&startTableData;
if($fields[5])
{
&showMail($fields[5]);
}
else
{
&printEmptyCell;
}
&endTableData;
$fields[6] =~ tr/A-Z/a-z/;
$i = 0;
if($fields[6] eq "out")
{
$flag = 1;
}
elsif($fields[6] eq "conf")
{
$flag = 2;
}
elsif($fields[6] eq "lunch")
{
$flag = 3;
}
elsif($fields[6] eq "vac")
{
$flag = 5;
}
elsif($fields[6] eq "sick")
{
$flag = 4;
}
else
{
$flag = 0;
}
for($i = 0; $i < 6; $i++)
{
&startTableData;
if($flag == $i) {
&showPuck($fields[10],$fields[6]);
}
else {
&printEmptyCell;
}
&endTableData;
}
&startTableData;
if($fields[7])
{
&printTableCell($fields[7]);
}
else
{
&printEmptyCell;
}
&endTableData;
&startTableData;
if($fields[8])
{
&printTableCell($fields[8]);
}
else
{
&printEmptyCell;
}
&endTableData;
&endTableRow;
}
&endTable;
print "
";
&printAdminLinks;
#&printAddUserLink;
#&printDelUserLink
&endBody;
}
# call this routine with an array of messages to show
sub showMessageList
{
local(@msgs) = @_;
local($cnt) = 0;
foreach (@msgs)
{
if($cnt == 0)
{
&startHtmlOutput("Your Messages");
&startPlainBody;
print "Your Messages
";
}
%f = getMessageFieldHash($_);
print "";
print "$f{\"from\"} at $f{\"time\"} $f{\"date\"}";
print "
";
$cnt++;
}
if($cnt == 0)
{
#&alignCenter;
#print "
No Messages";
&doneSuccess("No Messages");
}
print "
";
&endBody;
}
# start the script by getting the query args
$query = $ENV{'QUERY_STRING'};
$html = 2;
if($query)
{
@input_args = split(/&/,$query);
foreach $i (0 .. $#input_args)
{
$input_args[$i] =~ s/\+/ /g;
$input_args[$i] =~ s/%(..)/pack("c",hex($1))/ge;
$input_args[$i] =~ s/\,/ /g;
($name,$value) = split(/=/,$input_args[$i],2);
$tokens{$name} = $value;
}
}
else
{
$ct = $ENV{"CONTENT_TYPE"};
$cl = $ENV{"CONTENT_LENGTH"};
if($ct eq "application/x-www-form-urlencoded")
{
read(STDIN,$input_line,$cl);
@input_args = split(/&/,$input_line);
foreach $i (0 .. $#input_args)
{
$input_args[$i] =~ s/\+/ /g;
$input_args[$i] =~ s/%(..)/pack("c",hex($1))/ge;
$input_args[$i] =~ s/\,/ /g;
($name,$value) = split(/=/,$input_args[$i],2);
$tokens{$name} = $value;
}
}
}
# call sub based on command
$command = "list";
$department = "all";
&checkMainFile;
&checkMsgFile;
if($tokens{"cmd"})
{
$command = $tokens{"cmd"};
}
if($command eq "list")
{
# setup the sorting
$lastname = 1;
$ascend = 1;
$groupby = 0;
if($tokens{"sort"} eq "firstname")
{
$lastname = 0;
}
if($tokens{"ascend"} eq "false")
{
$ascend = 0;
}
if($tokens{"group"} eq "true")
{
$groupby = 1;
}
&showList($department,$lastname,$ascend,$groupby);
}
elsif ($command eq "add" || $command eq "edit")
{
# show the form to add a new user
%values;
$tt = "Add New User";
if($tokens{"name"})
{
@line = getRecords("all");
# find the matching record
foreach(@line)
{
%fields = &getFieldHash($_);
if($fields{"login"} eq $tokens{"name"}) # found login
{
%values = %fields;
$tt = "Edit User Data";
}
}
}
# output the form
&startHtmlOutput($tt);
print "";
print "