Gossamer Forum
Home : Products : DBMan : Customization :

Log File Viewer/Editor

(Page 1 of 3)
> >
Quote Reply
Log File Viewer/Editor
I'm wanting to have a little more complicated version of the "Log" mod (http://www.gossamer-threads.com/...ces/jump.cgi?ID=1179). Instead of it
displaying data like this:

Admin logged on at 10:27:22 on 01-Jan-1970 from
Admin added record: Admin at 10:27:49 on 01-Jan-1970 from
Testing logged on at 10:28:06 on 01-Jan-1970 from
Testing added record: Testing at 10:28:32 on 01-Jan-1970 from
Testing added record: 1 at 10:29:24 on 01-Jan-1970 from
Testing1 logged on at 10:32:40 on 01-Jan-1970 from
Testing1 added record: Testing1 at 10:32:53 on 01-Jan-1970 from

in a text area. Can it be more like this in summary format?:

http://server5.hypermart.net/philipclark/log1.jpg

I still want to have the textarea but I want this as well.

It shows that the user "Philip" has added 60 records this month, edited 11, deleted 9, and visited the news page 2 times. At the end of the month all values would reset themselves to 0.

Can this be done? I'm sure this would be so useful for so many people if it was created.

Quote Reply
Re: Log File Viewer/Editor In reply to
Interesting...

I hadn't thought of that, but it sounds like a cool idea. Let me see what I can come up with.

- Mark


Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Log File Viewer/Editor In reply to
Smile

Cool. Cool That would be great if you get something like that going... It would be so useful...

Any idea on how long this will take you to put together Mark?


Quote Reply
Re: Log File Viewer/Editor In reply to
Not sure... I put together the basic Viewer/Editor in about half an hour... but it doesn't do anything super special...

I'll keep you posted.

One thing though... what's "News Count"?

- Mark


Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Log File Viewer/Editor In reply to
Ok then.

That would be great. Thanks!!! Smile.

News count is a new procedure that I created where I put news that only users of the database can read.

Quote Reply
Re: Log File Viewer/Editor In reply to
Ok, here'e something I threw together... It seems to work, give it a go and let me know what you think.

(apologies for the horizontal scrolling Smile)

I haven't documented it terribly well... but if it works out, I'll add some proper installation help. If you get stuck, let me know.

Also, I haven't added that "News Count" field... so far it's just a generic summary page that any database can use. We can customise it later. Smile

new subroutine (html.pl)
Code:

sub html_admin_log_summary {
# --------------------------------------------------------
# Displays a summary of the LOG file
#

&html_print_headers;

print qq|
<html>
<head>
<title>Log Summary</title>
</head>
<body bgcolor="#ffffff" text="#000000">

<table width="100%" cellpadding="1" cellspacing="0" border="0" bgcolor="#000000"><tr><td>
<table width="100%" cellpadding="2" cellspacing="1" border="0"><tr bgcolor="#ffffff">
<td colspan="4"><h3>Log Summary</h3></td>
</tr><tr bgcolor="#ffffff">
<th>User</th>
<th>Records Added</th>
<th>Records Edited</th>
<th>Records Deleted</th>
</tr>
|;

my (@passdata);
open (PASS, "< $auth_pw_file") or &cgierr("error in view_log. unable to open pass file: $auth_pw_file.\nReason: $!");
if ($db_use_flock) { flock(PASS, 1); }
while (<PASS>) {
next if ($_ =~ /^#/);
($sum_username) = split(/:/, $_);
push(@passdata, $sum_username);
}
close (PASS);

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); }
my @logdata = <LOG>;
close (LOG);

my ($sum_add, $sum_mod, $sum_del);
foreach $sum_userid (sort(@passdata)) {
$sum_add = 0; $sum_mod = 0; $sum_del = 0;
for ($i = 0; $i <= $#logdata; $i++) {
($sum_id, $sum_action) = split(/ /, $logdata[$i]);
if ($sum_userid eq $sum_id) {
$sum_add++ if ($sum_action eq 'added');
$sum_mod++ if ($sum_action eq 'modified');
$sum_del++ if ($sum_action eq 'deleted');
}
}
print qq|
<tr bgcolor="#ffffff">
<td>$sum_userid &nbsp;</td>
<td>$sum_add &nbsp;</td>
<td>$sum_mod &nbsp;</td>
<td>$sum_del &nbsp;</td>
</tr>
|;
}

print qq|
</td></tr></table>
</td></tr></table>

</body>
</html>
|;

} # End of SUB
add to sub html_admin_view_log

<a href="#" onclick="window.open('$db_script_link_url&log_summary=1', 'Summary', 'location=no,width=500,height=400,scrollbars=yes,screenX=5,screenY=5,top=5,left=5'); return false;">View Summary</a>

add to db.cgi (near all the other elif's)

elsif ($in{'log_summary'}) { if ($per_admin) { &html_admin_log_summary; } else { &html_unauth; } }



Cheers,

- Mark


Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Log File Viewer/Editor In reply to
Thanks a lot Mark. Smile

It doesn't scroll on my monitor (1024*768)

I'm just off to try it now... Back very soon...

Thanks again Smile

Quote Reply
Re: Log File Viewer/Editor In reply to
IT WORKS!!! Cool

but... there is one minor bug... It doesn't add one onto the count for the user until another user has added a record.

For example if PhilipClark logs in and adds a record and then the admin views the summary it hasn't increased the value of "add" by one for PhilipClark.

But if say Mark logs in and adds a record it then adds one onto PhilipClark's add count.

The code seems to be one behind itself as that another record must be added for the previous record to be added onto the summary list.

Do you understand what I'm saying? Do I need to explain more?

Thanks so so so much for doing this so quickly!! Smile

Quote Reply
Re: Log File Viewer/Editor In reply to
In regard to the "news online" count. I have a procedure called:

elsif ($in{'dealernews'}){ if ($per_add) { &html_dealer_news; } else { &html_unauth; } }

and everytime a user clicks on the link for that procedure it adds one to a count and displays the number in the "log summary". I just need it to work exactly the same as the "add", "edit", "delete" counts.

Is it also possible to record in the summary a count of how many times a user has logged on? If it's too hard then don't bother.

Also since I want the count to go back to 0 at the start of every month can't I just empty
out "default.log" and it will do it automatically since you are reading the values from
"default.log".

Thanks for much for this help. Smile It's just so much appreciated.

Quote Reply
Re: Log File Viewer/Editor In reply to
Also, sorry to be a pain but can the usernames be in alphabetical order in the summary?

Quote Reply
Re: Log File Viewer/Editor In reply to
In Reply To:
The code seems to be one behind itself as that another record must be added for the previous record to be added onto the summary list.
Woops, just made a maths error... It was skipping the last line in the logfile, should be fixed now.

In Reply To:
Also, sorry to be a pain but can the usernames be in alphabetical order in the summary?
I saw that shortly after posting it, I agree it's nicer to have them sorted. The codes been updated for that too.

In Reply To:
Is it also possible to record in the summary a count of how many times a user has logged on? If it's too hard then don't bother.
It's not exactly hard... I figured it wasn't terribly important, but I'll check it out...

In Reply To:
Also since I want the count to go back to 0 at the start of every month can't I just empty out "default.log" and it will do it automatically since you are reading the values from "default.log".
Absolutely... you could even run a backup script to restart the log each month automatically...

In Reply To:
In regard to the "news online" count....
Could you give me an example of a typical entry in the log file for "News Online"?


I think that covers everything... the updates only affect sub html_admin_log_summary

Cheers,

- Mark


Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Log File Viewer/Editor In reply to
In Reply To:
Woops, just made a maths error... It was skipping the last line in the logfile, should be fixed now.
Cool!! Cool

In Reply To:
I saw that shortly after posting it, I agree it's nicer to have them sorted. The codes been updated for that too.
Yeah I think so too. Thanks a lot!!!! Smile

In Reply To:
It's not exactly hard... I figured it wasn't terribly important, but I'll check it out...
If its going to be a problem then don't worry about it.

In Reply To:
Absolutely... you could even run a backup script to restart the log each month automatically...
OH OK!!! Shocked... How can I go about doing that?

In Reply To:
Could you give me an example of a typical entry in the log file for "News Online"?
The "News Online" page is just like a normal news html file except it's a procedure in the database so that no one can read the news without having a username and password. An exmaple is:

19th November
Tournament planned for the 27th of November

-----

I don't have access to my database until tommorow morning now so I'll test the changes out then. I'll let you know.

Thanks so much for this!!! Smile






Quote Reply
Re: Log File Viewer/Editor In reply to
Log backer-upperer: http://www.gossamer-threads.com/...ces/jump.cgi?ID=1352

I'm still a little unsure as to how this "News Count" thing works... Is it just counting up how many times a user reads the news?

Basically, the script works by reading the log file and adding up each occurance of username added record(for example). So are there similar lines in the log that read username read news or something?

- Mark


Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Log File Viewer/Editor In reply to
Thanks.

Yes I want it to count the number of times a user clicks on the news link.

No there isn't anything in the logfile. Is there some other way we can do it?

Quote Reply
Re: Log File Viewer/Editor In reply to
It works perfectly now!!! Smile

The last thing I need now is a another column in the summary showing how many times each user has gone to the news page.
If it has to be done by reading data from the log file couldn't we create a new sentence to be added everytime a user
accesses the news, e.g. "PhilipClark has read the news" or something like that?

You're probably have a much better suggestion than that for how we could get this working so...

Thanks Mark. Smile

Quote Reply
Re: Log File Viewer/Editor In reply to
Don't worry about the news count anymore thanks Mark. However I would really like a count on how many times a user has logged on.

Another thing which I hope isn't that hard is that is it possible to reset the log every month but it doesn't lose the values?
It puts all the values into another logfile and a link is made, i.e. At the end of November it would create a new log
file named november.log and would empty out default.log ready for December. You would then be able to view the log details
monthly or if its too hard to do it monthly what about weekly?

So you would have links like this:

View September 99 Log
View October 99 Log
View Current Log

Quote Reply
Re: Log File Viewer/Editor In reply to
I've just installed your Log File Backup Mod (http://www.zip.com.au/...n/log_backup.htm#sub) which does half the job but what can we do so it automatically creates a link in the log screen (http://server5.hypermart.net/...clark/log_screen.jpg of say the name of the file.

I noticed that when you backup the log file it gives it the name of "log_22-Nov-2000" for example. I want to be able to see a summary on that backup that was created so everytime you run a backup it automatically creates a link.

This can't be that hard can it?

Quote Reply
Re: Log File Viewer/Editor In reply to
In my database for the log file it doesn't seem to be writing the
"USER logged on at ..... to the log file. An example of this is shown
at http://server5.hypermart.net/...lark/log_screen1.jpg where I logged on
as "Admin" and modified a record except it didn't say "Admin logged on at 11:04". Any idea why?

It used to write it to the log file but it doesn't anymore.
Here is the auth.pl file: http://server5.hypermart.net/philipclark/authpl.txt.

I think I've got it calculating the number of logon's pre user now though. Of course
we won't know for certain until it actaully starts writing it to the log file but...

Code shown below:


sub html_admin_log_summary {
# --------------------------------------------------------
# Displays a summary of the LOG file
#

&html_print_headers;

print qq|
<html>
<head>
<title>Log Summary</title>
</head>
<body bgcolor="#ffffff" text="#000000">

<table width="100%" cellpadding="1" cellspacing="0" border="0" bgcolor="#000000"><tr><td>
<table width="100%" cellpadding="2" cellspacing="1" border="0"><tr bgcolor="#ffffff">
<td colspan="4"><h3>Log Summary</h3></td>
</tr><tr bgcolor="#ffffff">
<th>User</th>
<th>Records Added</th>
<th>Records Edited</th>
<th>Records Deleted</th>
<th>Log On</th>
</tr>
|;

my (@passdata);
open (PASS, "< $auth_pw_file") or &cgierr("error in view_log. unable to open pass file: $auth_pw_file.\nReason: $!");
if ($db_use_flock) { flock(PASS, 1); }
while (<PASS>) {
next if ($_ =~ /^#/);
($sum_username) = split(/:/, $_);
push(@passdata, $sum_username);
}
close (PASS);

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); }
my @logdata = <LOG>;
close (LOG);

my ($sum_add, $sum_mod, $sum_del, $sum_log);
foreach $sum_userid (sort(@passdata)) {
$sum_add = 0; $sum_mod = 0; $sum_del = 0; $sum_log = 0;
for ($i = 0; $i <= $#logdata; $i++) {
($sum_id, $sum_action) = split(/ /, $logdata[$i]);
if ($sum_userid eq $sum_id) {
$sum_add++ if ($sum_action eq 'added');
$sum_mod++ if ($sum_action eq 'modified');
$sum_del++ if ($sum_action eq 'deleted');
$sum_log++ if ($sum_action eq 'logged');
}
}
print qq|
<tr bgcolor="#ffffff">
<td>$sum_userid  </td>
<td>$sum_add  </td>
<td>$sum_mod  </td>
<td>$sum_del  </td>
<td>$sum_log  </td>
</tr>
|;
}

print qq|
</td></tr></table>
</td></tr></table>

</body>
</html>
|;

} # End of SUB


I think we're nearly there Mark Smile

It would be really great if we could get this sorted out today.
Quote Reply
Re: Log File Viewer/Editor In reply to
I've got it writing "logged on" to the log file correctly now with this code:


sub auth_check_password {
# --------------------------------------------------------
# This routine checks to see if the password and userid found
# in %in (must be 'pw' and 'userid') match a valid password and
# userid in the password file.
# It returns a status message and a userid which is built by a
# "user name" + "random number"
# which get's stored in the query string.

my ($pass, @passwd, $userid, $pw, @permissions, $file, $uid);
my ($server_auth) = $ENV{'REMOTE_USER'} || $ENV{'AUTH_USER'};

if ($auth_no_authentication || (($db_uid eq 'default') && $auth_allow_default)) {
return ('ok', 'default', @auth_default_permissions);
}
elsif ($server_auth) { # The user has logged in via server authentication.
return ('ok', $server_auth, &auth_check_permissions($server_auth));
}
elsif ($in{'login'}) { # The user is trying to login.
open (PASSWD, "<$auth_pw_file") || &cgierr("unable to open password file. Reason: $!\n");
@passwds = <PASSWD>; # Let's get the user id and passwords..
close PASSWD;
#&auth_logging('logged on1', $userid) if ($auth_logging);
my ($view, $add, $mod, $del, $admin);
PASS: foreach $pass (@passwds) { # Go through each pass and see if we match..
next PASS if ($pass =~ /^$/); # Skip blank lines.
next PASS if ($pass =~ /^#/); # Skip Comment lines.
chomp ($pass);
($userid, $pw, $view, $add, $del, $mod, $admin) = split (/:/, $pass);
if (($in{'userid'} eq $userid) && ($in{'pw'} eq $pw)) {
srand( time() ^ ($$ + ($$ << 15)) ); # Seed Random Number
$db_uid = "$userid." . time() . (int(rand(100000)) + 1);# Build User Id
open(AUTH, ">$auth_dir/$db_uid") or &cgierr("unable to open auth file: $auth_dir/$uid. Reason: $!\n");
print AUTH "$uid: $ENV{'REMOTE_HOST'}\n";
close AUTH;
&auth_logging('logged on', $userid) if ($auth_logging);
foreach (0 .. 3) { $permissions[$_] = int($permissions[$_]); }
&auth_logging('logged on3', $userid) if ($auth_logging);
return ('ok', $db_uid, $view, $add, $del, $mod, $admin);
}
}
return ("invalid username/password");
}
elsif ($db_uid) { # The user already has a user id given by the program.
(-e "$auth_dir/$db_uid") ?
return ('ok', $db_uid, &auth_check_permissions($db_uid)) :
return ('invalid/expired user session');
}
else { # User has not logged on yet.
return 'no login';
}
}


The purple text shows where the statement was before and the red text showed where I moved it to in order for it to correctly write to default.log

I've also got the summary working in terms of it telling you how many times each user has logged on.

Sorry about all these messages Mark but I thought it would probably be best to keep you up to date on what I'm doing Smile.

Now the only thing left to do is to get it displaying the summary weekly or monthly as I explained a few messages ago Smile.

Quote Reply
Re: Log File Viewer/Editor In reply to
or really how it should work is that as soon as you click the "backup log" button it then creates the link in the log page and writes the data to another logfile and clears default.log. Just how your backup log mod script works at the moment really except it creates a link in the log page allowing you to do a "summary" on the data that you backed up...

Quote Reply
Re: Log File Viewer/Editor In reply to
In Reply To:
I think I've got it calculating the number of logon's pre user now though. Of course we won't know for certain until it actaully starts writing it to the log file but...
What you've done looks good, but there is one slight hitch. DBMan also logs the "Logged off" action (although not everyone clicks 'log off', most will just close the window or go somewhere else).

So the count may include the odd username logged off. You could easily turn off "logged off" logging in db.cgi:
Code:

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"; }
Just comment out or delete the red line. Or change the message to 'logged_off' (for example, just as long as it isnt "logged something") if you wanted to keep it.

- Mark

PS: Working on the viewing of backed-up logs now. I may even combine the Viewer and Backup log into one big "Log Tools" MOD, might make things a little easier to keep track of... Smile


Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Log File Viewer/Editor In reply to
In Reply To:
Just comment out or delete the red line. Or change the message to 'logged_off' (for example, just as long as it isnt "logged something") if you wanted to keep it.
Ah yes good point. Thanks for that. I've just changed the code to:


elsif ($in{'logoff'}){ &auth_logging('logged_off') if ($auth_logging);


as you suggested.

In Reply To:
PS: Working on the viewing of backed-up logs now. I may even combine the Viewer and Backup log into one big "Log Tools" MOD, might make things a little easier to keep track of...
Cool. Cool That's a good idea. Like I said orginally I'm sure a lot of people will find this mod extremely useful so its probably best to have it all together.

Any idea of when you'll have it done?




Quote Reply
Re: Log File Viewer/Editor In reply to
As you probably noticed in my first post it's saying the date is 01-Jan-1970 on every occurance in the log file.

I've tried putting this code into "auth.pl" but it doesn't work:


Hypermart fix for auth.pl file.

It seems that Hypermart servers does not use the remote host command as needed by DBMan. This solution will let you log remote hosts:

In auth.pl file make the following changes:

Add the sub GetHost to your auth.pl file. In sub auth_logging,

After: my ($date) = &get_date(time);

Add: my($host) = &GetHost; #### change for Hypermart servers

and then change:

print LOG "$uid $action at $time on $date from $ENV{'REMOTE_HOST'}\n";

To:

print LOG "$uid $action at $time on $date from $host\n";

#### added for Hypermart ###########

sub GetHost {
# --------------------------------------------------------------
if (($ENV{'REMOTE_HOST'} eq $ENV{'REMOTE_ADDR'}) && ($ENV{'REMOTE_ADDR'} =~/(\d+)\.(\d+)\.(\d+)\.(\d+)/)) {
$ip = pack('C4', $1, $2, $3, $4);
$DNS_Address = (gethostbyaddr($ip, 2))[0];
$ENV{'REMOTE_HOST'} = $DNS_Address if $DNS_Address; }
$ENV{'REMOTE_HOST'} =~ tr/[A-Z]/[a-z]/;
$hostname = gethostbyaddr pack ( 'C4' , split /\./, $ENV {REMOTE_ADDR} ) ,2;
}

### end add for Hypermart servers ###
This is tested and works great!


Any ideas on what else I could try?


Quote Reply
Re: Log File Viewer/Editor In reply to
I've just solved it by having a look at this page:

http://webmagic.hypermart.net/dbman/admin102.txt

Correct Code:


sub auth_logging {
# --------------------------------------------------------
# Logs an action to the database. Takes as input an action, and
# optionally a user id. If no user id is passed in, it get's one from
# the global $db_userid.

my ($action, $uid) = @_;
my ($time) = &get_time; # Change time/date format globally
my ($date) = &get_date(time()); # in get_time and get_date.
my ($host) = &GetHost;
if (!$uid) {
$db_userid ?
($uid = $db_userid) :
($uid = "UNKNOWN"); # Hopefully we shouldn't see this..
}
open (LOG, ">>$auth_log_file") || &cgierr("unable to open log file: $auth_log_file. Reason: $!\n");
flock (LOG, 2) unless (!$db_use_flock);
print LOG "$uid $action at $time on $date from $host\n";
close AUTH; # releases file lock.
}


The text in purple is the code that was needed to fix the problem.

Quote Reply
Re: Log File Viewer/Editor In reply to
Another thing that would probably be useful is instead of it just saying "Log Summary" as the title it should say something like "Log Summary from 'start of current log' to 'todays date'"

so it would be something like:

Log Summary from 12th November (when log was created) to 22th November (todays date)

> >