Gossamer Forum
Home : Products : DBMan : Customization :

Log File Viewer/Editor

(Page 2 of 3)
> > > >
Quote Reply
Re: Log File Viewer/Editor In reply to
Cool, glad you got it working Cool

Ok, I've put together the changes I've made and dumped it on a free host I created at VirtualAvenue...
Although I uploaded as .txt, VA took the liberty of formatting it as HTML when you view it, so it looks kinda screwy. Instead, either view the source code, or just save the page to your hard drive and open it in notepad.

http://mightyatom.virtualave.net/logfile.txt
(temporary location, I'll add it to resources section once complete)

There are 3 sub routines to replace: html_admin_view_log, sub html_admin_log_summary and edit_log. The 2 for HTML.PL have been written for the USER FRIENDLY version, I'll adapt them to the original version after testing.

If anyone else would like to try it out, you're welcome, but please back up your log file before you start! Just to be safe.

- Mark


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

Wow it certainly has messed with it Laugh

I'm just off to try it out know. Thanks Mark!! Smile

Quote Reply
Re: Log File Viewer/Editor In reply to
Seems to work perfectly Mark!!! Cool GREAT JOB Smile

However what do you think of my idea on instead of saying Summary of ./backups/log_22-Nov-2000.txt

it would say
Summary between 21st November and 22nd of November (./backups/log_22-Nov-2000.txt)

I suppose the logic would be to get the first date in the log and the last date in the log and put them in the title.

Can that be done?



Quote Reply
Re: Log File Viewer/Editor In reply to
Things have been shifted around slightly, but it seems to work:

[code deleted - 22/11/2000]

- Mark


Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Log File Viewer/Editor In reply to
Hmm... For me it brings up this:


Summary between at 10:27:22 - at 10:34:50 (./backups/log_22-Nov-2000.txt)


Quote Reply
Re: Log File Viewer/Editor In reply to
The code takes everything from " on " onwards, then deletes everything from " from" onwards.

Eg: In my case, the red text would be deleted from the green text:
username added record: 11 at 14:30:17 on 23-May-2000 from ipaddress

I had a feeling my methodology wouldn't quite work across all DBMans... dang Frown

I'm stuck for other ideas, there's just nothing really consistant about the Log file that you could use...

- Mark


Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Log File Viewer/Editor In reply to
Damn [] Thanks for trying though. Smile

I changed a bit of the code changing [1] to [2] and works a little better:


my $date_start = $start_date[2];
$date_start =~ s/from .+$//i;

my @end_date = split(/ on /, $logdata[$#logdata - 1]);
my $date_end = $end_date[2];


On the "*.log" file title is says:

Summary between 01-Jan-1970 from - 22-Nov-2000 from (./default.log)

while on the "*.txt" it says:

Summary between 01-Jan-1970 - 01-Jan-1970 (./backups/log_22-Nov-2000.txt)

when it should say

Summary between 01-Jan-1970 - 22-Nov-2000 (./backups/log_22-Nov-2000.txt)

so I'm not sure what it's doing with the *.txt" file.





Quote Reply
Re: Log File Viewer/Editor In reply to
Since we can't change the title can we automatically have the log backup itself every week. Wouldn't it then make it easier to change the title to be?:


Summary between 01-Jan-1970 from - 22-Nov-2000 from (./default.log)


Quote Reply
Re: Log File Viewer/Editor In reply to
I think I have the logic for a solution for changing the title to be the dates. Your code can get the first date in the log files but not the last but the name of an archived log file includes the date at when it was archived (last date) so is it possible to put the name of the log file in the second part of the title?

Quote Reply
Re: Log File Viewer/Editor In reply to
I've got the title like this now:

Summary between 01-Jan-1970 - ./backups/log_23-Nov-2000.txt

but how could I get rid of the ./backups/log_ part? It would be good to get rid of the .txt as well but that doesn't really
matter.

Any ideas now Mark?

Quote Reply
Re: Log File Viewer/Editor In reply to
Try:
my $last_date = $log_file;
$last_date =~ s~^\./backups/log_([^.]+)\.txt~$1~i;


Then use $last_date in the title.

Note: This won't work for "default.log" (obviously), you'll need to accomidate for that.

- Mark


Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Log File Viewer/Editor In reply to
You ROCK Mark!!! Cool. That's just what I wanted.

Thanks a lot Cool

If it possible to do something like this for "default.log".


If logfile = default.log
print todays date in title


Quote Reply
Re: Log File Viewer/Editor In reply to
my $last_date = $log_file;
if ($last_date =~ /default/) {
$last_date = &get_date;
} else {
$last_date =~ s~^\./backups/log_([^.]+)\.txt~$1~i;
}


- Mark


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

You've got a solution for everything don't you!!! Wink

Quote Reply
Re: Log File Viewer/Editor In reply to
Sorry Mark one last thing to do with the log section... At the moment I have "backup log" as a text link as when I put in this code on: http://www.zip.com.au/...dbman/log_backup.htm


<form action="$db_script_url" method="post">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
<input type=hidden name="backup_log" value="1">
<input type=submit value="Backup Log">
</form>


it doesn't work. It just refreshes the screen. Any ideas why?

I remember we had this problem before with image submit buttons but hopefully you can think of a way I can have the "backup log" text as a button instead of a normal text link.




Quote Reply
Re: Log File Viewer/Editor In reply to
I've got it working Mark with the following code: Smile


function archive(logfile) {
if (logfile != '- - - - - - - - - -') {
var url = '$db_script_link_url&backup_log=1=' + logfile;
top.location = url;
}
}

<form action="$db_script_url" method="post">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
<input type=hidden name="backup_log" value="1">
<input type=button name="backup_log" value="Backup Log" onclick="archive(document.editlog.log_file.options[document.editlog.log_file.selectedIndex].value); return false;">
</form>


Quote Reply
Re: Log File Viewer/Editor In reply to
First thing I'd check it that you don't have nested forms. Having a form inside a form will confuse DBMan.

If you can't avoid nested forms, what if you tried just having the button (minus the other code) like so:
<input type=submit name="backup_log" value="Backup Log">
(no guarantees)

- Mark


Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Log File Viewer/Editor In reply to
Yes I do have nested forms... Frown

I'll try that then... I don't have access to my script until the morning so I'll try it out then and let you know...

Quote Reply
Re: Log File Viewer/Editor In reply to
Hi Mark,

You know how you set up the "Summary" to sort by "username". Can we change it to sort by "Records Added" as I have 120-130 users and looking through a lot of zero's is really annoying especially since I have a lot of users.

Better still can a double sort be done where it lists all users in alphatical order by "Records Added" so you would have all the users who have added 0 records at the bottom.

Can one of those be done?

Quote Reply
Re: Log File Viewer/Editor In reply to
You'll have to forgive the awkwardness of the implementation, but I've lost track of what we were up to and what extra changes we made to the original code...

Basically, the red section has been re-written (the green code is to help you locate where it should go)

[code deleted 08/12/2000 - moved several posts down]

Let me know how it goes.

- Mark


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

I'll try the code out and let you know!!!

I'd like to send you something in appreciation of all the help you have given me over the last couple of months. If you'd like to send me your address in a "private message" I'll send you something for Christmas.

Quote Reply
Re: Log File Viewer/Editor In reply to
It worked perfectly thanks Mark but I changed a little bit to get it to display correctly which is shown below:


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

my $log_file = (($in{'log_file'}) ? $in{'log_file'} : $auth_log_file);

&html_print_headers;

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, "< $log_file") or &cgierr("error in view_log. unable to open log file: $log_file.\nReason: $!");
if ($db_use_flock) { flock(LOG, 1); }
my @logdata = <LOG>;
close (LOG);

my $count = 0;
my ($sum_add, $sum_mod, $sum_del, $sum_log, @summary);
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');
}
}

$summary[$count] = { userid => "$sum_userid",
added => "$sum_add",
modified => "$sum_mod",
deleted => "$sum_del",
logged => "$sum_log" };
$count++;
}

my @summary_sort = map { $_->[0] }
sort { $a->[1] <=> $b->[1] || $a->[2] <=> $b->[2] }
map { [ $_, $_->{'logged'}, $_->{'added'} ] } (sort(@summary));

print '<table>';
print '<tr bgcolor="#ffffff" align="center">';
print '<td></td>';
print '<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Logged On</td>';
print '<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Vehicles Added</td>';
print '<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Vehicles Edited</td>';
print '<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Vehicles Deleted</td>';
print '</tr>';

for ($i = $#summary_sort; $i >= 0; $i--) {
print '<tr bgcolor="#ffffff" align="center">';
print '<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">' . $summary_sort[$i]->{'userid'} . '</td>';
print '<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">' . $summary_sort[$i]->{'logged'} . ' </td>';
print '<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">' . $summary_sort[$i]->{'added'} . ' </td>';
print '<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">' . $summary_sort[$i]->{'modified'} . ' </td>';
print '<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">' . $summary_sort[$i]->{'deleted'} . ' </td>';
print '</tr>';
}

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

</body>
</html>
|;

} # End of SUB


One thing that would be nice is to have it also list the usernames in alphabetical order as well as by "records added".

Can that be done? It's not a huge big deal but it would be nice to have.

Thanks Smile

Quote Reply
Re: Log File Viewer/Editor In reply to
Ahh... I've just noticed one thing. You didn't account for the Summary between 06-Dec-2000 from - 08-Dec-2000 part.

Would you be able to add it into the code in my previous message please?

Quote Reply
Re: Log File Viewer/Editor In reply to
Changing the sort should be easy now actually.

map { [ $_, $_->{'logged'}, $_->{'added'} ] } (sort(@summary));

This line controls the sorting. Currently it is set to sort first by logged, then by added.

All you need to do is change them to suit your sort order. The 5 options are:
- userid
- logged
- added
- modified
- deleted

If you wanted to get really tricky, you could make the sort customizable on the log page by adding some drop-down menus and substituting $in{''}'s in place of the "tags". But I'll leave that one to you Wink

Cheers,

- Mark


Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Log File Viewer/Editor In reply to
In Reply To:
Ahh... I've just noticed one thing. You didn't account for the Summary between 06-Dec-2000 from - 08-Dec-2000 part.

Would you be able to add it into the code in my previous message please?
The modifications I made didn't affect the title of the summary, that part of the code was always above the "open etc..." code I posted in green as a marker.

Please tell me you backed up... Frown

- Mark


Astro-Boy!!
http://www.zip.com.au/~astroboy/
> > > >