#! /usr/bin/env python ############################################################ # # The Silent Page Counter v 0.3 # # (c) 1998 Cristian Tibirna # # This is *the first* CGI script I wrote in python # In fact, this can really be seen in here # # It was written and tested in Linux only. It is Unix-specific # # Usage: * just install it in your /cgi-bin directory and chmod it to 755 # * then create a data directory somewhere in your account # and chmod it to 777 # * write the name in the appropriate place below # * then replace your selected links to files in your html documents # with: http://your_server/your_cgi_dir/spc.cgi?u=http://real_url # * or include this line at the end of your local file (before ), # replacing the indicator with the name of the file: # # # # That's all # This code is free for you to use, modify and distribute. # This code is provided AS IS, and with NO WARRANTY. The author # shall not be kept responsible for any consequences from the use, # distribution and modifications of this code. No responsability # is accepted for the results generated with this script or for # their interpretation # # Version 0.1 - 11Dec1998 # # Version 0.3 - better DNS check, nslookup error trapping # # Version 1.2 - 15Mar2002 # better DNS check (use socket module), # functionalize, # support for hidden watermarks # (one-pixel image in any local document) # # Version 1.3 - 19Mar2002 # don't open the repository file if not necessary ##### Change this at your needs saver = '/users/ctibirna/public_html/cgi-bin/data/' my_host = '132.203.7.101' ##### import os import string import cgi def resolve_IP(requesterIP): import socket if requesterIP <> '': try: realname = socket.gethostbyaddr(requesterIP)[0] except socket.error: realname = requesterIP + ' [erreur DNS]' else: realname = 'no IP [???]' return realname # predefined: # the data file ############# YOU DON'T NEED TO CHANGE THE REMAINING CODE # get the requested file's name fields = cgi.parse_qs(os.environ['QUERY_STRING']) dot_image = 0 if fields.has_key('t') and fields['t'][0] == 'dot': dot_image = 1 url = '' if fields.has_key('u'): url = fields['u'][0] if (not dot_image) and (url == ''): print "Content-type: text/html" print print "There is an error in the page you visited" import sys sys.exit() # now store the info if it's not myself requesterIP = os.environ['REMOTE_ADDR'] if requesterIP <> my_host: from time import asctime, localtime, time moment = asctime(localtime(time())) realname = resolve_IP(requesterIP) entry = url + ' : ' + realname + ' : ' + moment + '\n' f = open(saver + 'repository','a'); f.write(entry) f.close() if dot_image: print "Location: http://giref.ulaval.ca/~ctibirna/img/dot.png" print "Content-type: image/png" print else: print "Location: " + url print "Content-type: text/html" print