Beispiel #1
0
def run(port, routes, sslport=None, dnsport=53, tld='dev', ip='127.0.0.1', verbose=False):

    req_callback, ssl_callback = make_callbacks(routes)

    dnsc = devdns.connect(port=dnsport)
    print 'devDNS :: *.%s. 60 IN A %s' % (tld, ip)

    mainloop = ioloop.IOLoop.instance()
    periodic = ioloop.PeriodicCallback(lambda : devdns.get_data(dnsc, tld, ip, verbose), 
                                       50.0, 
                                       io_loop=mainloop)
    periodic.start()

    all_methods = ['GET', 'POST', 'OPTIONS', 'PUT', 'DELETE', 'HEAD']
    quickproxy.run_proxy(port=port,
                         methods=all_methods, 
                         req_callback=req_callback,
                         debug_level=1 if verbose else 0,
                         start_ioloop=False)

    if sslport:
        # for ssl testing, run a second instance of the proxy on the ssl port
        quickproxy.run_proxy(port=sslport,
                             test_ssl=True,
                             methods=all_methods, 
                             req_callback=ssl_callback,
                             debug_level=1 if verbose else 0,
                             start_ioloop=False)

    try:
        print ("Starting HTTP proxy on port %d" % port)
        mainloop.start()
    except KeyboardInterrupt:
        dnsc.close()
Beispiel #2
0
def run(port,
        routes,
        sslport=None,
        dnsport=53,
        tld='dev',
        ip='127.0.0.1',
        verbose=False):

    req_callback, ssl_callback = make_callbacks(routes)

    dnsc = devdns.connect(port=dnsport)
    print 'devDNS :: *.%s. 60 IN A %s' % (tld, ip)

    mainloop = ioloop.IOLoop.instance()
    periodic = ioloop.PeriodicCallback(
        lambda: devdns.get_data(dnsc, tld, ip, verbose),
        50.0,
        io_loop=mainloop)
    periodic.start()

    all_methods = ['GET', 'POST', 'OPTIONS', 'PUT', 'DELETE', 'HEAD']
    quickproxy.run_proxy(port=port,
                         methods=all_methods,
                         req_callback=req_callback,
                         debug_level=1 if verbose else 0,
                         start_ioloop=False)

    if sslport:
        # for ssl testing, run a second instance of the proxy on the ssl port
        quickproxy.run_proxy(port=sslport,
                             test_ssl=True,
                             methods=all_methods,
                             req_callback=ssl_callback,
                             debug_level=1 if verbose else 0,
                             start_ioloop=False)

    try:
        print("Starting HTTP proxy on port %d" % port)
        mainloop.start()
    except KeyboardInterrupt:
        dnsc.close()
 def setup_proxy():
     quickproxy.run_proxy(port=TEST_HTTP_REVPROXY_PORT,
                          req_callback=req_callback,
                          start_ioloop=False)
 def setup_proxy():
     quickproxy.run_proxy(port=TEST_HTTP_PROXY_PORT,
                          start_ioloop=False)
Beispiel #5
0
def main():
    def callback(response):
        response.port = 4040
        return response

    quickproxy.run_proxy(port=8080, req_callback=callback)
Beispiel #6
0
 def setup_proxy():
     quickproxy.run_proxy(port=TEST_HTTP_SERVER2_PORT,
                          req_callback=req_callback,
                          start_ioloop=False)
Beispiel #7
0
 def setup_proxy():
     quickproxy.run_proxy(port=TEST_HTTP_PROXY_PORT, start_ioloop=False)
Beispiel #8
0
def main():
    def callback(response):
        response.port = 4040
        return response

    quickproxy.run_proxy(port=8080, req_callback=callback)
Beispiel #9
0
        return request

    logger.info('denied ' + request.method + ' request from ' +
                first_remote_ip)

    return quickproxy.ResponseObj(code=403, body='')


def address_in_network(ip, net_n_bits):
    ''' from https://stackoverflow.com/a/30676234 '''
    ipaddr = struct.unpack('!L', socket.inet_aton(ip))[0]
    net, bits = net_n_bits.split('/')
    netaddr = struct.unpack('!L', socket.inet_aton(net))[0]
    netmask = (0xFFFFFFFF >> int(bits)) ^ 0xFFFFFFFF
    return ipaddr & netmask == netaddr


def ip_passes(test_ip, test_method):
    for rule in rules['rules']:
        for method in rule['methods']:
            if method == test_method:
                for source in rule['source']:
                    if address_in_network(test_ip, source):
                        return rule['effect'] == 'ALLOW' and True
    return False


rules = json.loads(open(settings.RULES_FILE).read())

quickproxy.run_proxy(port=settings.LISTENER_PORT, req_callback=callback)