##################################################################### # W H O ' S O N L I N E # by JPDeni # Written: 30 Jun 2000 ##################################################################### # This mod will allow you to add a link to the footer which will # display the userids of those who are currently logged in to the # database. # # Included is a "true logoff," which removes the session file for the # user when he logs off the database. Also, since many users do not # log off when they leave the database, their session ids will be # after 10 or 20 minutes of inactivity. ##################################################################### # # In auth.pl, sub auth_check_permissions, after ($userid =~ /^([A-Za-z0-9]+)\.\d+$/) ? ($username = $1) : return (0,0,0,0,0); # add unlink "$auth_dir/$userid"; open(AUTH, ">$auth_dir/$userid") or &cgierr("unable to open auth file: $auth_dir/$userid. Reason: $!\n"); print AUTH "$userid: $ENV{'REMOTE_HOST'}\n"; close AUTH; ##################################################################### # # In *.cfg, set $auth_time = 600; # (10 minutes) # or $auth_time = 1200; # (20 minutes) ##################################################################### # # In db.cgi, sub main, change elsif ($in{'logoff'}) { &auth_logging('logged off') if ($auth_logging); $auth_logoff ? (print "Location: $auth_logoff\n\n") : (print "Location: $db_script_url\n\n"); } # to elsif ($in{'logoff'}) { &auth_logging('logged off') if ($auth_logging); unlink "$auth_dir/$db_uid"; $auth_logoff ? (print "Location: $auth_logoff\n\n") : (print "Location: $db_script_url\n\n"); } ##################################################################### # # In db.cgi, sub main after if ($in{'add_form'}) { if ($per_add) { &html_add_form; } else { &html_unauth; } } # add elsif ($in{'whos_online'}) { if ($per_view) { &html_whos_online; } else { &html_unauth; } } ##################################################################### # # In html.pl, sub html_footer, add print qq!| Who's Online ! if ($per_view); ##################################################################### # # In html.pl, add a new subroutine # (For those using the default html.pl file. The one for the "user-friendly" html.pl file follows.) sub html_whos_online { # -------------------------------------------------------- my (@files,$file); &html_print_headers; print qq| $html_title: Who's Online.
$html_title: Who's Online

<$font_title>Who's Online

<$font>The following users are currently logged in to the database:

|; opendir (AUTHDIR, "$auth_dir") || &cgierr("unable to open directory in html_whos_online: $auth_dir. Reason: $!"); @files = readdir(AUTHDIR); # Read in list of files in directory.. closedir (AUTHDIR); FILE: foreach $file (@files) { next if ($file =~ /^\./); # Skip "." and ".." entries.. next if ($file =~ /^index/); # Skip index.htm type files.. ($file =~ /^([A-Za-z0-9]+)\.\d+$/) ? ($username = $1) : next; # At this point, you can decide what you want to print out. If you have a database that # has the userid as the key value, you can get the information from the database, using # %rec = &get_record($username); # and then print out whatever fields you want to appear on the page. You can have a link # to the user's record, if you wish. # Or you can just use the line below to print out the usernames. print "$username
"; } print qq|

|; &html_footer; print qq|
|; } ##################################################################### # # For those using the "user-friendly" html.pl file sub html_whos_online { # -------------------------------------------------------- my (@files,$file); $page_title = "Who's Online"; &html_page_top; # < -- Start page text -- > print qq|

<$font>The following users are currently logged in to the database:

|; opendir (AUTHDIR, "$auth_dir") || &cgierr("unable to open directory in html_whos_online: $auth_dir. Reason: $!"); @files = readdir(AUTHDIR); # Read in list of files in directory.. closedir (AUTHDIR); FILE: foreach $file (@files) { next if ($file =~ /^\./); # Skip "." and ".." entries.. next if ($file =~ /^index/); # Skip index.htm type files.. ($file =~ /^([A-Za-z0-9]+)\.\d+$/) ? ($username = $1) : next; # At this point, you can decide what you want to print out. If you have a database that # has the userid as the key value, you can get the information from the database, using # %rec = &get_record($username); # and then print out whatever fields you want to appear on the page. You can have a link # to the user's record, if you wish. # Or you can just use the line below to print out the usernames. print "$username
"; } print qq|

|; &html_footer; &html_page_bottom; }