commit 3e2882752557ff9635da87c3ab439077a0ea3dfa Author: aagbsn aagbsn@extc.org Date: Thu Dec 15 02:58:35 2011 -0800
4297 - Update BridgeDB's front-end Server.py
Front-end's to the HTTPS and email distributors now make use of the address class filtering available in IPBasedDistributor --- lib/bridgedb/Dist.py | 1 + lib/bridgedb/Server.py | 55 ++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 52 insertions(+), 4 deletions(-)
diff --git a/lib/bridgedb/Dist.py b/lib/bridgedb/Dist.py index 285e088..afc3592 100644 --- a/lib/bridgedb/Dist.py +++ b/lib/bridgedb/Dist.py @@ -287,6 +287,7 @@ class EmailBasedDistributor(bridgedb.Bridges.BridgeHolder): # XXXX clear the store when the period rolls over! self.domainmap = domainmap self.domainrules = domainrules + self.answerParameters = answerParameters
#XXX cache options not implemented self.splitter = bridgedb.Bridges.FilteredBridgeSplitter(key2, diff --git a/lib/bridgedb/Server.py b/lib/bridgedb/Server.py index b67edf2..45cbee0 100644 --- a/lib/bridgedb/Server.py +++ b/lib/bridgedb/Server.py @@ -31,6 +31,7 @@ from random import randint from bridgedb.Raptcha import Raptcha import base64 import textwrap +from ipaddr import IPv4Address, IPv6Address
try: import GeoIP @@ -147,13 +148,25 @@ class WebResource(twisted.web.resource.Resource): format = request.args.get("format", None) if format and len(format): format = format[0] # choose the first arg
+ # do want ipv6 support? + ipv6 = False + if "ipv6" in request.postpath: ipv6 = True + if ip: + if ipv6: + rules=[filterBridgesByIP6] + else: + rules=[filterBridgesByIP4] + bridges = self.distributor.getBridgesForIP(ip, interval, self.nBridgesToGive, - countryCode) + countryCode, + bridgeFilterRules=rules) + if bridges: answer = "".join("%s %s\n" % ( - b.getConfigLine(self.includeFingerprints), + b.getConfigLine(self.includeFingerprints,needIPv6=ipv6, + selectFromORAddresses=ipv6), (I18n.BRIDGEDB_TEXT[16] if b.isBlocked(countryCode) else "") ) for b in bridges) else: @@ -379,11 +392,22 @@ def getMailResponse(lines, ctx): # return None,None
# Figure out which bridges to send + + # read subject, see if they want ipv6 + ipv6 = False + for ln in lines: + if "ipv6" in ln.strip().lower(): + ipv6 = True + rules=[filterBridgesByIP6] + else: + rules=[filterBridgesByIP4] + try: interval = ctx.schedule.getInterval(time.time()) bridges = ctx.distributor.getBridgesForEmail(clientAddr, interval, ctx.N, - countryCode=None) + countryCode=None, + bridgeFilterRules=rules) except bridgedb.Dist.BadEmail, e: logging.info("Got a mail from a bad email address %r: %s.", clientAddr, e) @@ -433,7 +457,8 @@ def getMailResponse(lines, ctx):
if bridges: with_fp = ctx.cfg.EMAIL_INCLUDE_FINGERPRINTS - answer = "".join(" %s\n" % b.getConfigLine(with_fp) for b in bridges) + answer = "".join(" %s\n" % b.getConfigLine(with_fp, needIPv6=ipv6,\ + selectFromORAddresses=ipv6) for b in bridges) else: answer = "(no bridges currently available)"
@@ -646,3 +671,25 @@ def getCCFromRequest(request): if len(path) == 2: return path.lower() return None + +def filterBridgesByIP4(bridge): + try: + if IPv4Address(bridge.ip): return True + except ValueError: + pass + + for k in bridge.or_addresses.keys(): + if type(k) is IPv4Address: + return True + return False + +def filterBridgesByIP6(bridge): + try: + if IPv6Address(bridge.ip): return True + except ValueError: + pass + + for k in bridge.or_addresses.keys(): + if type(k) is IPv6Address: + return True + return False
tor-commits@lists.torproject.org