Okey-dokey. With all my usual caveats, here's the code.
In sub html_home, where you want to print out the last 5 logins, add
Code:
open (LOG, "<$auth_log_file") or &cgierr("error in view_log.
unable to open log file: $auth_log_file.\nReason: $!");
if ($db_use_flock) { flock(LOG, 1); }
@lines = <LOG>;
close LOG;
$log_number = $#lines;
print "Our last 5 visitors:<BR>\n";
while ($log_count < 5) {
$line = $lines[$log_number];
--$log_number;
chomp $line;
if ($line =~ /logged on at /) {
++$log_count;
$line =~ s/logged on at //;
$line =~ s/ on /\//;
$place = index $line, " from ";
$line = substr($line,0,$place);
print "$line<BR>\n";
}
}
In sub html_admin_display, add the following link:
Code:
print qq!| <A HREF="$db_script_link_url&view_log=1">View Log</A> !;
In sub html.pl add the following subroutine:
Code:
sub html_view_log {
# --------------------------------------------------------
&html_print_headers;
print qq|
<html>
<head>
<title>$html_title: View Log</title>
</head>
<body bgcolor="#DDDDDD">
<center>
<table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500 align=center valign=top>
<tr><td bgcolor="navy">
<FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF">
<b>$html_title: View Log</b>
</td></tr>
<tr><td><p><center><$font_title><b>View Log</b></font></center><br>
<$font>This is the current contents of the log file:<BR><BR>|;
open (LOG, "<$auth_log_file") or &cgierr("error in view_log.
unable to open log file: $auth_log_file.\nReason: $!");
if ($db_use_flock) { flock(LOG, 1); }
@lines = <LOG>;
close LOG;
foreach $line (@lines) {
print "$line<BR>";
}
print qq|</font></p>|;
&html_footer;
print qq|</td></tr></table></center></body></html>|;
}
In db.cgi, sub main, add
Code:
elsif ($in{'view_log'}) { if ($per_admin) { &html_view_log; } else { &html_unauth; } }
That should do it.
------------------
JPD