def log_hit(self): # Make sure we get plain strings, not unicode #self.request.charset = None cur = self.request.str_GET.get('cur', None) ref = self.request.str_GET.get('ref', None) title = self.request.str_GET.get('title', None) if not cur: cur = self.request.headers.get('referer', None) if cur is not None: cur = get_unicode(unquote_plus(cur)) if ref is not None: ref = get_unicode(unquote_plus(ref)) if title is not None: title = get_unicode(unquote_plus(title)).strip() response = Response() response.headers['Content-Type'] = "image/gif" response.headers['Expires'] = "Sat, 26 Jul 1997 05:00:00 GMT" response.headers['Cache-Control'] = "no-cache, must-revalidate" response.body = self._image if not cur: return response visitor_ip = self.request.headers.get('X-Forwarded-For', None) if visitor_ip is None: visitor_ip = self.request.remote_addr hit = Hit(self._conf, cur, referrer=ref, title=title, visitor_ip=visitor_ip) if hit.is_whitelisted() and not hit.is_blacklisted(): self._storage.add_hit(hit) return response
def source(self, url, ref): if ref is None or ref[1] == '': return u'direct' if url[1] == ref[1]: return u'internal' query = self.searchquery(ref) if query is not None: return (u'searches - ' + query[0] + u': ' + query[1]) return u'external: ' + get_unicode(ref[1])