You are not logged in Log in Join
You are here: Home » Members » Ioan's Zope Documents » Host Tracker

Log in
Name

Password

 

Host Tracker

If you would like to know who is connecting to your pages, this the how-to you need.
In this how-to you will
  • Count host access
  • List all tables with tracks of hosts
  • Clean some entries from statistic tables


You must create a few files:

A TinyTablePlus

This is the data table.
Id: hosts
Columns: name count
Leave it blank, but empty this table sometimes.

A DTML method

This document will update the table.
Id: usercnt
body:
<dtml-unless tracktable><dtml-call "REQUEST.set('tracktable','hosts')"></dtml-unless>
<dtml-call "REQUEST.set('hostname',get_hostname(REMOTE_ADDR))">
<dtml-in "_.getitem(tracktable)(name=hostname)">
 <dtml-call "_.getitem(tracktable).delRows(name=hostname)">
 <dtml-call "_.getitem(tracktable).setRow(name=hostname,count=_.int(count)+1)">
<dtml-else>
 <dtml-call "_.getitem(tracktable).setRow(name=hostname,count=1)">
</dtml-in>

Another DTML method

This document will draw the graphic.
Id: ugraph
body:
<dtml-var standard_html_header>
<dtml-if QUERY_STRING>
 <dtml-call "REQUEST.set('tracktable',QUERY_STRING)">
<dtml-else>
 <dtml-call "REQUEST.set('tracktable','hosts')">
</dtml-if>

<dtml-with "_.getitem(tracktable)">
<h1><dtml-var title_or_id></h1>
</dtml-with>
Select
<dtml-in "objectItems(['TinyTablePlus'])">
<dtml-comment>
<IMG SRC="/misc_/TinyTablePlus/icon" ALT="[TinyTablePlus]" BORDER="0">
</dtml-comment> -
[<a href="ugraph?<dtml-var id>"><dtml-var id></a>]
</dtml-in>
<table border=1>
<tr><th>Computer</th><th>Count</th><th>Graph</th></tr>
<dtml-in "_.getitem(tracktable)()" sort=name>
<tr>
<td><dtml-var name></td>
<td><dtml-var count></td>
<td><img src="/img/box/blue_box.jpg" height=10 width=<dtml-var "_.int(count)*10">></td>
</tr>
</dtml-in>
</table>
<br>
<dtml-var standard_html_footer>

A picture

This is just a blue square. Size does not matter (make it 5x5 or less).
Id: blue_box.jpg

A Python script

Use this if you want to store hostname instead IP address
Add external method with :
Id: get_hostname
Title: **anything***
Module Name: mylib
Function Name : get_hostname

Before to add this Zope object you must create a file (into extension folder of zope instalation folder) called mylib.py with this content :
import socket
import string

def get_hostname(addr):
 try:
  z=socket.gethostbyaddr(addr)
 except:
  z=[string.replace(addr,".",",")]
 a=z[0]+'.'
 p=string.find(a,'.')
 return a[:p]

If you hate Python

You can avoid use of python function get_hostname().
To do that usercnt will to look like:
<dtml-unless tracktable><dtml-call "REQUEST.set('tracktable','hosts')"></dtml-unless>
<dtml-call "REQUEST.set('hostname',REMOTE_ADDR)">
<dtml-in "_.getitem(tracktable)(name=hostname)">
 <dtml-call "_.getitem(tracktable).delRows(name=hostname)">
 <dtml-call "_.getitem(tracktable).setRow(name=hostname,count=_.int(count)+1)">
<dtml-else>
 <dtml-call "_.getitem(tracktable).setRow(name=hostname,count=1)">
</dtml-in>





Don't forget to allow Change TinyTable and Query TinyTable Data permissions to Anonymous.
You can do that with this:
Go on root folder (or where you keep TinyTable objects)
and the into security tab.
Find  Change TinyTable and Query TinyTable Data
and TinyTablePlus, then check that property for Anonimous.
I see that in Zope 2.3.0 I have TinyTablePlus installed,
but I don't see all security features of TinyTablePlus.
I don't know why, something is missing.

You can update by scripts only TinyTablePlus,
so try to focus on TinyTablePlus.


How to use it

Insert this code at first line of your DTML Document:
<dtml-call "REQUEST.set('tracktable','hosts')">
<dtml-call usercnt>
That means you select tracktable=hosts and call usercnt.

To store the data into another table use:
<dtml-call "REQUEST.set('tracktable','another_table')">
<dtml-call usercnt>
If you want to display the content of your table use a link like:

<a href="ugraph?hosts">Hosts</a>
or <a href="ugraph?another_table">Another Table</a>


How to clean tracker table

Sometimes you need to remove some hosts from statistics.
(Let's say you want to erase tracks of your own computer or server.) Use this script:
<dtml-var standard_html_header>
<dtml-if host>
<h1>Clean</h1>
<dtml-var host>
<dtml-in "objectItems(['TinyTablePlus'])">
<dtml-with "_.getitem(id)">
<dtml-call "delRows(name=host)">
</dtml-with>
</dtml-in>

<dtml-else>
<h1>Which host</h1>
<form name="sel_host">
<select name="lista" onchange="document.forms.sel_host.host.value=document.forms.sel_host.lista.options[document.forms.sel_host.lista.selectedIndex].value">
<dtml-in "['EBRWICOM01','LOGOS','EPOWGDAR01']">
<option value="<dtml-var sequence-item>"><dtml-var sequence-item>
</dtml-in>
</select>
<input type="text" name="host" size=15>
<input type="submit" value="Erase">
</form>
</dtml-if>
<dtml-var standard_html_footer>
Just select from your own list, or fill the form and clean