View Full Version : User Info Log Help?


rundellt2000
08-07-2003, 11:14 AM
Hi, well, I use a HTML editor, and found a cool CGI script which logs user information, like time visited, IP address, etc.

But anyone know how it works, like where can I access the logged information? Here's the script.


#!/usr/local/bin/perl
#
# "Book 'em, Dan-O" Logger Script by Spider
# Created 9 July 1996
# Email me at spider@servtech.com
# http://www.servtech.com/public/spider
#
# Secret Decoder Ring - aka Organization of Log File
# Time Stamp / Person\Machine / Referring URL / Browser Used
#
# This script can be run as a SSI or used
# in a "redirect" fashion via *normal* CGI calls.

########## Set Variables ############

$SSI = 0;
# 0 if not used as a SSI - 1 if used as a SSI

$logfile = "/absolute/path/to/dan_o.dat";
# change the directory path, silly!

$exclude = 0;
# 1 if you want to exclude YOUR IP/Domain/Machine Name - 0 otherwise

$my_addr = "your.machine.name";
# used with the "exclude" portion

$HomeDirURL = "http://yourdomain.com/your/path/";
# change this if you're not using SSI's

$nextfile = "file.html";
# again, change if you're not using SSI's

########## So much for that.. On with the show! #######

# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

# Split the name-value pairs
@pairs = split(/&/, $buffer);

foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);

# Un-Webify plus signs and %-encoding
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

# Stop people from using subshells to execute commands
# Not a big deal when using sendmail, but very important
# when using UCB mail (aka mailx).
$value =~ s/~!/ ~!/g;

# Uncomment for debugging purpose
# print "Setting $name to $value<P>";
$FORM{$name} = $value;
}

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isd st) = localtime(time);

if ($sec < 10) {
$sec = "0$sec";
}
if ($min < 10) {
$min = "0$min";
}
if ($hour < 10) {
$hour = "0$hour";
}
if ($mon < 10) {
$mon = "0$mon";
}
if ($mday < 10) {
$mday = "0$mday";
}

$month = ($mon + 1);
@months = ("January","February","March","April","May","June","July","August","September","October","November","December");
$date = "$hour\:$min\:$sec $month/$mday/$year";

# Now that we know what the time/date is.. let's have fun

if ($SSI == 1) {
if ($exclude == 1) {
&log unless ($ENV{'REMOTE_HOST'} eq $my_addr);
} else {
&log;
}
exit;
}

if ($SSI == 0) {
if ($exclude == 1) {
&log unless ($ENV{'REMOTE_HOST'} eq $my_addr);
} else {
&log;
}
&redir;
exit;
}

sub log {

if (! open(LOG,">>$logfile")) {
print "Content-type: text/html\n\n";
print "Couldn't open $logfile so I'm bugging out..\n";
exit;
}
print LOG "At $date, $ENV{'REMOTE_HOST'} came here from $ENV{'HTTP_REFERER'} using $ENV{'HTTP_USER_AGENT'}.\n";
close (LOG);
}

sub redir {
print "Location: $HomeDirURL$nextfile\n\n";
}



there's no Perl parser, so I'm using the PHP parser. (close enough, isn't it?)

chrishawthorne
08-07-2003, 11:17 AM
I think this is where it goes....Im not sure though

#!/usr/local/bin/perl

rundellt2000
08-07-2003, 11:40 AM
I'm so silly, look here:


$logfile = "/absolute/path/to/dan_o.dat";
# change the directory path, silly!


hehe...
but does anyone know how to edit the script to my needs?
i just wanna have some fun.

localh0st
08-07-2003, 02:25 PM
PHP and Perl are two different things. PHP cannot parse Perl and vice versa.

Make sure you have that in your cgi-bin directory and chmodded to 777.

make sure the shbang (#!/usr/local/bin/perl) is correct to where the perl path is.

and sicne the script wont run automatically, you need to get it to load someway in one of your html pages.

To view the results, check your log file that it generates.

rundellt2000
08-08-2003, 08:05 AM
I'll probably use includes (i.e. SSI, PHP, JS) to put it on my page.
That'd work, right?

localh0st
08-08-2003, 11:02 AM
Yeah but only if your server has a perl interpretor. PHP cant interpret perl.

Football Bandit
08-08-2003, 01:42 PM
I think that he was talking about the Perl script on Lissa's forums, I think that he meant he couldn't display the code well unless it was in the PHP thing... just what I am assuming.

rundellt2000
08-09-2003, 03:55 AM
Yeah, football bandit, that's wat i mean. I just used the PHP Parser here. I'll use perl parser when it's on the net.

*nudges Lissa*
*says to her, get to work on a perl parser PLEASE?*