Free CGI script?? (Tracker)

Anyone know where I can find a good CGI script that tracks hits?  (Not just a counter, but a tracker, that would tell domain names, etc.).  This tracker needs to have support for separate accounts, and the stats need to be separated (not just in one file).  Thanks!
LVL 1
eversoslightlyAsked:
Who is Participating?
 
mikegrbConnect With a Mentor Commented:
Here is a possiblity:

If you need help with it let me know.

#!/usr/bin/perl

print "Content-type: text/plain\n\n";

$logfile = '/var/lib/httpd/data/log';

if(-e "$logfile.lock") {
      sleep 1;
}


open(CLK,">$logfile.lock") || &CDie("Can't lock log: $!");
print CLK "$$\n";
close(CLK);

if(-e $log) {
      open(CNT,$counterdfile) || &CDie("Can't open $logfile: $!");
      while($line = <CNT>)
            $count++;
      close(CNT);
}


print $count++;
$time = scalar(localtime);
open(CNT,">>$counterdfile") || &CDie("Can't open $logfile: $!");
print CNT "$time: $ENV{REMOTE_HOST} - $ENV{REMOTE_ADDR} - $ENV{HTTP_USER_AGENT}\n";
close(CNT);

unlink "$logfile.lock" || &CDie("Can't unlock $logfile: $!");

sub CDie {
      print "$_[0]\n";
      exit 0;
}

0
 
happy1Commented:
Hi,
does your site support SSI?
If yes, give me please, temporarly access to your site (login-password)
and I will try to install one for you. I'm using that for myself, it's freeware.
I'm offering that because I know about your problems with CGI:)

Regards, Happy®One
Contact me: yanki@goplay.com
0
 
eversoslightlyAuthor Commented:
Yep... I do have SSI
Thanks a lot, but I wouldn't feel comfortable doing that.
If you could though, you could e-mail me the script.
That would be helpful!
Thanks a lot!
-Ever-So
everso@bstar.net
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
happy1Commented:
OK, check this script (Roblog 4.02) -
http://tdi.uregina.ca/~eislerr/cgi/roblog/index.html
Happy®One
0
 
eversoslightlyAuthor Commented:
Well, at the moment, I'm getting the error:

HTTP Proxy reports :
The proxy server has encountered an error (Connection refused).

just trying to log into that site... I'll try again later today.  The question is still open for other people's suggestions!
0
 
eversoslightlyAuthor Commented:
Well, I checked out that site.  That script doesn't support multiple accounts unless you make multiple copies of the script - which is not what I want.  I've seen quite a few scripts like this one.  Thanks anyways!

Anyone else found one?

-Ever-So
0
 
jcondeCommented:
Why not write your own ssi script!

You will need to create a simple database with int CLICKS and char *HOSTNAME
you can know what host the come from with the following C instruction.

getenv("REMOTE_HOST");  // You are reading the value of the REMOTE_HOST ambient variable.

If you need help please contact me!
jconde@securities.com


0
 
eversoslightlyAuthor Commented:
Well, I really don't know how to write in CGI... if you would be willing to write some simple code that would work and would be acceptable to me, I would raise the points to 150, and give you an A.

Thanks,
Ever-So
0
 
eversoslightlyAuthor Commented:
Idealy, I'd like it to have most of the functions that Nedstat has. ( http://usa.nedstat.net/cgi-bin/viewstat?name=everso ).  Referer isn't neccessary, but would be nice.
-Ever-So
0
 
jcondeCommented:
What operating system are you using Ever So?
0
 
eversoslightlyAuthor Commented:
My server is running Unix.
0
 
grnemstrCommented:
Yes here is the URL  ..i use these people and they're GREAT!!!
 http://www.extreme-dm.com/tracking
0
 
eversoslightlyAuthor Commented:
Sorry, I know about that, but thats not exactly what I want - I want a CGI script for -My- server - I don't want someone else to host it.  Thanks anyways!
0
 
moonlightCommented:
I could give you my own cgi script for unix (perl script)
but I have made it for just one page. You would need to alter it a little for several pages. I actually need to expand it myself to work with several pages but it would take some time. Meanwhile you could always just copy the script several times, and give each a unique name. This would give you one script, and one logfile for every page. Tell me if you want MY script.
0
 
eversoslightlyAuthor Commented:
Well, as I've said before, I want a script that will be able to have multiple accounts, although, I do not want to have multiple copies of the script.  Seeing as I do not know how to use CGI and perl, and such, I would not know how to edit the script.  If you would be willing to fix your script up so it can have unlimited accounts, I would raise the points to 150 and give you an A.  (As long, as I stated above, that it had many of the same features as nedstat).

Thank-you much for all your help!

-Ever-So.
0
 
mikegrbCommented:
Ooops just noticed the multiple accounts part... let me tweek it a little....
0
 
mikegrbCommented:
Make the beggining look like this (up to the lock check):

#!/usr/bin/perl

$confile = '/var/lib/httpd/data/config';

$acnt = $ARGV[0];

open(CNFG, $confile) || &CDie("Can't open conf file: $!");
IT: while($line = <CNFG>) {
      chop($line);
      if($line =~ /^$acnt\|:\|(.*?)$/) { $logfile = $1; last IT }
}

unless($logfile) &CDie("Undefined Account");

if(-e "$logfile.lock") {
      sleep 1;
}
----------------
Now make you config file look like
<account id>|:|<log file>
one per line and execute it like this:
<!--#exec cmd="/var/lib/httpd/cgi-bin/logger <account id>" -->
it will place a text counter on the page and log the time, date,
remote host, remote ip, and browser type... to change the format
change the print CNT line. To add refferer make that line:

   print CNT "$time: $ENV{REMOTE_HOST} - $ENV{REMOTE_ADDR} - $ENV{HTTP_USER_AGENT} - $ENV{HTTP_REFERER}\n";

oh and additionaly I had one bug (that I can find):
open(CNT,">>$counterdfile") || &CDie("Can't open $logfile: $!");
should be
open(CNT,">>$logfile") || &CDie("Can't open $logfile: $!");

0
 
ozoCommented:
That lock check doesn't look very reliable.
What if two processes simultaneously test the lock file, then simultaneously create it?
Why not use the built in flock function?
0
 
mikegrbCommented:
upon reconsidering a lock in not necessary at all as there is no
negative result other than an incorrect count...

I have fixed some other probs now... I havn't run it but it parses okay.

Here is a `new' version :) in its entirety:
#!/usr/bin/perl

$confile = '/var/lib/httpd/data/config';

$acnt = $ARGV[0];

open(CNFG, $confile) || &CDie("Can't open conf file: $!");
IT: while($line = <CNFG>) {
      chop($line);
      if($line =~ /^$acnt\|:\|(.*?)$/) { $logfile = $1; last IT }
}

&CDie("Undefined Account") unless($logfile);
if(-e $logfile) {
      open(CNT,$logfile) || &CDie("Can't open $logfile: $!");
      while($line = <CNT>) { $count++; }
      close(CNT);
}

print $count++;

$time = scalar(localtime);
open(CNT,">>$logfile") || &CDie("Can't open $logfile: $!");
print CNT "$time: $ENV{REMOTE_HOST} - $ENV{REMOTE_ADDR} - $ENV{HTTP_USER_AGENT}\n";
close(CNT);

sub CDie {
      print "Error: $_[0]\n";
      exit 0;
}

0
 
mikegrbCommented:
argh I didn't include the refferer :/


print CNT "$time: $ENV{REMOTE_HOST} - $ENV{REMOTE_ADDR} - $ENV{HTTP_USER_AGENT}\n";
should be
print CNT "$time: $ENV{REMOTE_HOST} - $ENV{REMOTE_ADDR} - $ENV{HTTP_USER_AGENT} - $ENV{HTTP_REFERER}\n";
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.