def render_GET(self, request): self.localize(request) if self.use_forwarded_header: h = request.getHeader("X-Forwarded-For") if h: ip = h.split(",")[-1].strip() try: IPAddress(ip) except ValueError: log.warn("Got weird forwarded-for value %r",h) ip = None else: ip = request.getClientIP() country = None if geoip: country = geoip.country_name_by_addr(clientip) if not country: country = _('Unknown') dest_ip = query.ip_from_string("78.47.18.106") src_ip = query.ip_from_string(ip) router = elist.tor_exit_search(src_ip, dest_ip, config['reachable_port']) # This *is* sane; we only know if TBB is out-of-date if it tells us UpToDate = True if 'uptodate' in request.args: if request.args['uptodate'][0] == '0': UpToDate = False if (router and UpToDate): return Template(filename=os.path.join(os.path.dirname(__file__), 'templates/success.html'), default_filters=['decode.utf8'], output_encoding='utf-8').render( exit={'ip':IPAddress(router.exit_address), 'country':country, 'nickname':router.nickname}, locale_descriptions=getLocales()) elif (router and not UpToDate): return Template(filename=os.path.join(os.path.dirname(__file__), 'templates/update.html'), default_filters=['decode.utf8'], output_encoding='utf-8').render( exit={'ip':IPAddress(router.exit_address), 'country':country, 'nickname':router.nickname}, locale_descriptions=getLocales()) else: return Template(filename=os.path.join(os.path.dirname(__file__), 'templates/fail.html'), default_filters=['decode.utf8'], output_encoding='utf-8').render( exit={'country':country,'ip':IPAddress(ip)}, locale_descriptions=getLocales())
def app(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html')]) ipstr = environ["REMOTE_ADDR"] ip = query.ip_from_string(ipstr) dest_ip = query.ip_from_string("78.47.18.106") router = elist.tor_exit_search(ip, dest_ip, port) yield '<h1>ARE YOU FROM TOR?</h1>' yield '<blink><strong>' if router: log.debug("Request from %s is from Tor: %s (%s).", ipstr, router.nickname, router.idhex) yield "YES! Exit from %s." % router.nickname else: log.debug("Request from %s is probably not from Tor.", ipstr) yield "NOPE!" yield '</strong></blink>'