Exemple #1
0
def start_server(port, reactor):
    factory = HTTPFactory()
    factory.protocol = proxy.Proxy
    factory.protocol.requestFactory = WPADProxyRequest

    yield reactor.listenTCP(port, factory, interface="127.0.0.1")
    
    servicemanager.notify_ready();
Exemple #2
0
def start_server(port, reactor):
    factory = HTTPFactory()
    factory.protocol = proxy.Proxy
    factory.protocol.requestFactory = WPADProxyRequest

    yield reactor.listenTCP(port, factory, interface="127.0.0.1")

    systemd.daemon.notify(systemd.daemon.Notification.READY)
Exemple #3
0
def listenHttp(httpoprt):
    factory = HTTPFactory()

    def _dummy(*args, **argd):
        pass

    factory.log = _dummy
    factory.protocol = TyHttpChannel
    reactor.listenTCP(httpoprt, factory)
Exemple #4
0
def start_proxy(port):
    """Start the internal HTTP proxy server.

    The proxy, which runs locally, serves as a middleware,
    i.e. the client handler forwards clients' requests to the proxy,
    and the proxy is reponsible for communicating with the target server.

    It is suggested that an external HTTP proxy is specified
    in place of the internal one,
    for performance and stability considerations.
    See command line arguments for detailed information.
    """
    factory = HTTPFactory()
    factory.protocol = ConnectProxy
    reactor.listenTCP(port, factory, interface="127.0.0.1")
Exemple #5
0
def protoParser(protos, proto_func, ptype):
    """
        根据server.json中配置的server和client字段,进行
        监听和连接操作
        #service server protocol config example:
        "protocols": { 
            "server":{"co-udp":5000, "co-tcp":5001},
            "client":{"query-udp":["LO*:co-udp"]}
        } 
        这里只处理业务进程的protocol,
        Agent的相关处理在support.tcpagent.wrapper中
    """
    is_server = (ptype == "server")
    if ptype not in protos:
        return
    ps = protos[ptype]
    for p in ps:
        # get class by proto short name...
        _c = proto_func(p)
        if is_server:
            if p.endswith("-udp"):
                pinst = _c()
                reactor.listenUDP(ps[p], pinst)
            if p.endswith("-tcp"):
                factory = Factory()
                factory.protocol = _c
                reactor.listenTCP(ps[p], factory)
            if p.endswith("-http"):

                def _dummy(*args, **argd):
                    pass

                factory = HTTPFactory()
                factory.log = _dummy
                factory.protocol = _c
                reactor.listenTCP(ps[p], factory)
        else:
            if p == "query-udp":
                for target in ps[p]:
                    target_server, target_pro_name = target.split(":")
                    if target_server.endswith("*"):
                        tss = server_type_map[target_server[:-1]]
                        for target_svr_id in tss:
                            _init_query_udp(target_svr_id, target_pro_name)
                    else:
                        _init_query_udp(target_server, target_pro_name)
Exemple #6
0
def start_server(interface, port, reactor):
    factory = HTTPFactory()
    factory.protocol = proxy.Proxy
    factory.protocol.requestFactory = WPADProxyRequest

    interface_ips = resolve(interface)
    print(interface_ips)
    for interface_ip in interface_ips:
        logger.info("Binding to interface: '%s'" % interface_ip)
        try:
            yield reactor.listenTCP(port, factory, interface=interface_ip)
        except OSError as e:
            # Most likely the most famous reason we will see this log for,
            # is that we are trying to bind to an IPv6 interface on a
            # system that has the IPv6 stack disabled.
            logger.error("Failed to bind to interface '%s'" % interface_ip)
            continue

    servicemanager.notify_ready()
Exemple #7
0
        self.port = port

    def clientConnectionFailed(self, connector, reason):
        self.request.fail("Gateway Error", str(reason))


if __name__ == '__main__':
    _log.startLogging(sys.stdout)

    ap = argparse.ArgumentParser()
    ap.add_argument('port', default=8090, nargs='?', type=int)
    ap.add_argument('--ssl-cert', type=str)
    ap.add_argument('--ssl-key', type=str)
    ns = ap.parse_args()

    factory = HTTPFactory()
    factory.protocol = ConnectProxy

    if ns.ssl_key and not ns.ssl_cert:
        log.info("--ssl-key must be used with --ssl-cert")
        sys.exit(1)
    if ns.ssl_cert:
        with open(ns.ssl_cert, 'rb') as fp:
            ssl_cert = fp.read()
        if ns.ssl_key:
            from OpenSSL import crypto
            with open(ns.ssl_key, 'rb') as fp:
                ssl_key = fp.read()
            certificate = ssl.PrivateCertificate.load(
                ssl_cert, ssl.KeyPair.load(ssl_key, crypto.FILETYPE_PEM),
                crypto.FILETYPE_PEM)
Exemple #8
0
def Proxy(createEndpoint, **kwargs):
    factory = HTTPFactory()
    factory.protocol = _Proxy
    factory.protocol.createEndpoint = createEndpoint
    return factory
Exemple #9
0
All requests will be rewritten to https.""")
    parser.add_argument('-c',
                        '--cert',
                        dest="cert",
                        type=str,
                        required=True,
                        help="The certificate to use in pem format.")
    parser.add_argument('-k',
                        '--key',
                        dest="key",
                        type=str,
                        required=True,
                        help="The private key to use in pem format.")
    parser.add_argument(
        '-p',
        '--port',
        dest='port',
        type=int,
        default=8080,
        help="The port the HTTP proxy listens on (default: 8080).")
    args = parser.parse_args()

    CERTFILE = args.cert
    KEYFILE = args.key

    httpFactory = HTTPFactory()
    httpFactory.protocol = HTTPSClientCertProxyChannel
    reactor.listenTCP(args.port, httpFactory)
    print "now starting..."
    reactor.run()