#!/usr/bin/python # Required libraries import cgi, urllib, md5, time, Cookie # Set domain name on which the redirect-page runs, WITHOUT "www.". domainName = '' urlParams = cgi.FieldStorage() if 'tt' in urlParams: # Setup vars. paramList = urlParams['tt'].value.split('_') # Grab the campaign specific data. if len(paramList) >= 3: campaignID = paramList[0] materialID = paramList[1] affiliateID = paramList[2] # Optional. reference = paramList[3] if paramList[3] else '' # Calculate MD5 checksum. md5hash = md5.new() md5hash.update('CHK_' + campaignID + '::' + materialID + '::' + affiliateID + '::' + reference) checkSum = md5hash.hexdigest() # Set session/cookie arguments. trackingCookie = Cookie.SimpleCookie(); cookieName = 'TT2_' + campaignID; cookieValue = materialID + '::' + affiliateID + '::' + reference + '::' + checkSum + '::' + str(int(time.time())) expires = time.gmtime(time.time() + 31536000) trackingCookie[cookieName] = cookieValue; trackingCookie[cookieName]['expires'] = time.strftime('%a, %d-%b-%Y %H:%M:%S UTC', expires) trackingCookie[cookieName]['path'] = '/' if domainName != '': trackingCookie[cookieName]['domain'] = '.' + domainName # Set the tracking cookie. print trackingCookie else: quit() trackBackURL = 'http://tc.tradetracker.net/?c=' + urllib.quote_plus(campaignID) + '&m=' + urllib.quote_plus(materialID) + '&a=' + urllib.quote_plus(affiliateID) + '&r=' + urllib.quote_plus(reference) + '&u=' + urllib.quote_plus('' if 'r' not in urlParams else urlParams['r'].value) print 'Status: 301 Moved Permanently' print 'Location: ' + trackBackURL print print