Esempio n. 1
0
class Deproxy(Observable):
    def __init__(self, deproxyForIps=None, deproxyForIpRanges=None, name=None):
        Observable.__init__(self, name=name)
        self._ipfilter = IpFilter(allowedIps=deproxyForIps, allowedIpRanges=deproxyForIpRanges)

    def handleRequest(self, Client, Headers, port=80, **kwargs):
        clientHost, clientPort = Client
        OriginalClient = None
        if self._ipfilter.filterIpAddress(ipaddress=clientHost, Headers=Headers):
            OriginalClient = clientHost, clientPort
            clientHost = _lastFromCommaSeparated(Headers.get("X-Forwarded-For", clientHost))
            host = _lastFromCommaSeparated(Headers.get("X-Forwarded-Host",  Headers.get('Host', '')))
            if host != '':
                Headers['Host'] = host
                port = int(host.partition(':')[2] or '80')
        yield self.all.handleRequest(Client=(clientHost, clientPort), Headers=Headers, port=port, OriginalClient=OriginalClient, **kwargs)

    def updateIps(self, ipAddresses=None, ipRanges=None):
        self._ipfilter.updateIps(ipAddresses=ipAddresses, ipRanges=ipRanges)
Esempio n. 2
0
 def __init__(self, deproxyForIps=None, deproxyForIpRanges=None, name=None):
     Observable.__init__(self, name=name)
     self._ipfilter = IpFilter(allowedIps=deproxyForIps, allowedIpRanges=deproxyForIpRanges)