#!/usr/bin/env python
import os.path, os
import sys

#fileName = sys.argv[1]


path = sys.argv[1]

listing = os.listdir(path)

for infile in listing:

	fileName = path + infile
	# print "**** " + fileName

	f = open(fileName, 'rb')
	# read first line of squid cache file
	#	line1 = f.readline()
	# f.close()

	# parse squid proxy secret number from cache file
	#   - in squid cache file, key is offset 0x0a - 0x19 of file
	line1 = ""
	
	tempIndex = 0
	# *** crappy hack - read first 1000 chars of file to 
	# *** parse interesting data - need to fix!
	while  tempIndex < 1000:
		line1 = line1 + str(f.read(8))
		tempIndex = tempIndex + 1

	key = line1[0x0a:0x19]
	
	# in squid proxy cache files, URL starts at offset 0x3c
	index=0x3c
	url = ""
	
	# parse out URI from squid proxy cache header data
	while line1[index].encode("hex") != "00":
		# print str(index) + " " + url

		url = url + line1[index]
		index = index + 1


	print fileName + " " + key.encode("hex") + " " + url

