コード例 #1
0
ファイル: client.py プロジェクト: devinrader/localtunnel
def start_client(**kwargs):
    host = kwargs['host']
    backend_port = kwargs.get('backend_port')

    if not backend_port:
        try:
            backend_port = util.discover_backend_port(host)
        except:
            print "  ERROR: Unable to connect to service."
            sys.exit(0)

    frontend_ip = socket.gethostbyname(host.split(':')[0])
    frontend_address, frontend_hostname = util.parse_address(host,
            default_ip=frontend_ip)
    backend = (frontend_address[0], backend_port)

    name = kwargs['name']

    client = util.client_name()
    target = util.parse_address(kwargs['target'])[0]
    try:
        control = eventlet.connect(backend)
        control.sendall(protocol.version)
        protocol.send_message(control,
            protocol.control_request(
                name=name,
                client=client,
        ))
        reply = protocol.recv_message(control)
        if reply and 'control' in reply:
            reply = reply['control']

            def maintain_proxy_backend_pool():
                pool = eventlet.greenpool.GreenPool(reply['concurrency'])
                while True:
                    pool.spawn_n(open_proxy_backend,
                            backend, target, name, client)
            proxying = eventlet.spawn(maintain_proxy_backend_pool)

            print "  {0}".format(reply['banner'])
            print "  Port {0} is now accessible from http://{1} ...\n".format(
                    target[1], reply['host'])

            try:
                while True:
                    message = protocol.recv_message(control)
                    assert message == protocol.control_ping()
                    protocol.send_message(control, protocol.control_pong())
            except (IOError, AssertionError):
                proxying.kill()

        elif reply and 'error' in reply:
            print "  ERROR: {0}".format(reply['message'])
        else:
            print "  ERROR: Unexpected server reply."
            print "         Make sure you have the latest version of the client."
    except KeyboardInterrupt:
        pass
コード例 #2
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
def start_client(**kwargs):
    host = kwargs["host"]
    backend_port = kwargs.get("backend_port")
    use_ssl = kwargs.get("use_ssl", False)
    ssl_opts = kwargs.get("ssl_opts", {})

    if not backend_port:
        try:
            backend_port = util.discover_backend_port(host)
        except:
            print "  ERROR: Unable to connect to service."
            sys.exit(0)

    frontend_ip = socket.gethostbyname(host.split(":")[0])
    frontend_address, frontend_hostname = util.parse_address(host, default_ip=frontend_ip)
    backend = (frontend_address[0], backend_port)

    name = kwargs["name"]

    client = util.client_name()
    target = util.parse_address(kwargs["target"])[0]
    try:
        control = eventlet.connect(backend)
        if use_ssl:
            control = eventlet.wrap_ssl(control, server_side=False, **ssl_opts)
        control.sendall(protocol.version)
        protocol.send_message(control, protocol.control_request(name=name, client=client))
        reply = protocol.recv_message(control)
        if reply and "control" in reply:
            reply = reply["control"]

            def maintain_proxy_backend_pool():
                pool = eventlet.greenpool.GreenPool(reply["concurrency"])
                while True:
                    pool.spawn_n(open_proxy_backend, backend, target, name, client, use_ssl, ssl_opts)

            proxying = eventlet.spawn(maintain_proxy_backend_pool)

            print "  {0}".format(reply["banner"])
            print "  Port {0} is now accessible from http://{1} ...\n".format(target[1], reply["host"])

            try:
                while True:
                    message = protocol.recv_message(control)
                    assert message == protocol.control_ping()
                    protocol.send_message(control, protocol.control_pong())
            except (IOError, AssertionError):
                proxying.kill()

        elif reply and "error" in reply:
            print "  ERROR: {0}".format(reply["message"])
        else:
            print "  ERROR: Unexpected server reply."
            print "         Make sure you have the latest version of the client."
    except KeyboardInterrupt:
        pass
コード例 #3
0
def start_client(**kwargs):
    host = kwargs['host']

    try:
        backend_port = util.discover_backend_port(host)
    except:
        print "  ERROR: Unable to connect to service."
        sys.exit(0)
    frontend_ip = socket.gethostbyname(host.split(':')[0])
    frontend_address, frontend_hostname = util.parse_address(
        host, default_ip=frontend_ip)
    backend = (frontend_address[0], backend_port)

    name = kwargs['name']

    client = util.client_name()
    target = util.parse_address(kwargs['target'])[0]
    try:
        control = eventlet.connect(backend)
        control.sendall(protocol.version)
        protocol.send_message(
            control, protocol.control_request(
                name=name,
                client=client,
            ))
        reply = protocol.recv_message(control)
        if reply and 'control' in reply:
            reply = reply['control']

            def maintain_proxy_backend_pool():
                pool = eventlet.greenpool.GreenPool(reply['concurrency'])
                while True:
                    pool.spawn_n(open_proxy_backend, backend, target, name,
                                 client)

            proxying = eventlet.spawn(maintain_proxy_backend_pool)

            print "  {0}".format(reply['banner'])
            print "  Port {0} is now accessible from http://{1} ...\n".format(
                target[1], reply['host'])

            try:
                while True:
                    message = protocol.recv_message(control)
                    assert message == protocol.control_ping()
                    protocol.send_message(control, protocol.control_pong())
            except (IOError, AssertionError):
                proxying.kill()

        elif reply and 'error' in reply:
            print "  ERROR: {0}".format(reply['message'])
        else:
            print "  ERROR: Unexpected server reply."
            print "         Make sure you have the latest version of the client."
    except KeyboardInterrupt:
        pass
コード例 #4
0
def run():
    eventlet.debug.hub_prevent_multiple_readers(False)
    eventlet.monkey_patch(socket=True)

    logging.basicConfig(
        format="%(asctime)s %(levelname) 7s %(module)s: %(message)s",
        level=logging.DEBUG)

    parser = argparse.ArgumentParser(description='Localtunnel server daemon')
    parser.add_argument(
        'frontend',
        metavar='frontend_listener',
        type=str,
        help='hostname to run frontend on (default: vcap.me:8000)',
        default='vcap.me:8000')
    parser.add_argument(
        'backend',
        metavar='backend_listener',
        type=str,
        help='port or address to run backend server on (default: 8001)',
        default='8001')
    args = parser.parse_args()

    frontend_address, frontend_hostname = util.parse_address(args.frontend)
    backend_address, backend_hostname = util.parse_address(args.backend)

    logging.info("starting frontend on {0} for {1}...".format(
        frontend_address, frontend_hostname))
    logging.info("starting backend on {0}...".format(backend_address))

    Tunnel.backend_port = backend_address[1]
    if frontend_address[1] == 80:
        Tunnel.domain_suffix = frontend_hostname
    else:
        Tunnel.domain_suffix = ":".join(
            [frontend_hostname, str(frontend_address[1])])

    stats_key = os.environ.get('STATHAT_EZKEY', None)
    if stats_key:
        metrics.run_reporter(stats_key)

    frontend_listener = eventlet.listen(frontend_address)
    backend_listener = eventlet.listen(backend_address)

    try:
        Tunnel.schedule_idle_scan()
        pool = eventlet.greenpool.GreenPool(size=2)
        pool.spawn_n(eventlet.serve, frontend_listener,
                     frontend.connection_handler)
        pool.spawn_n(eventlet.serve, backend_listener,
                     backend.connection_handler)
        pool.waitall()
    except KeyboardInterrupt:
        pass
コード例 #5
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
def run():
    eventlet.debug.hub_prevent_multiple_readers(False)
    eventlet.monkey_patch(socket=True)

    logging.basicConfig(format="%(asctime)s %(levelname) 7s %(module)s: %(message)s", level=logging.DEBUG)

    parser = argparse.ArgumentParser(description="Localtunnel server daemon")
    parser.add_argument(
        "frontend",
        metavar="frontend_listener",
        type=str,
        help="hostname to run frontend on (default: vcap.me:8000)",
        default="vcap.me:8000",
    )
    parser.add_argument(
        "backend",
        metavar="backend_listener",
        type=str,
        help="port or address to run backend server on (default: 8001)",
        default="8001",
    )
    args = parser.parse_args()

    frontend_address, frontend_hostname = util.parse_address(args.frontend)
    backend_address, backend_hostname = util.parse_address(args.backend)

    logging.info("starting frontend on {0} for {1}...".format(frontend_address, frontend_hostname))
    logging.info("starting backend on {0}...".format(backend_address))

    Tunnel.backend_port = backend_address[1]
    if frontend_address[1] == 80:
        Tunnel.domain_suffix = frontend_hostname
    else:
        Tunnel.domain_suffix = ":".join([frontend_hostname, str(frontend_address[1])])

    stats_key = os.environ.get("STATHAT_EZKEY", None)
    if stats_key:
        metrics.run_reporter(stats_key)

    frontend_listener = eventlet.listen(frontend_address)
    backend_listener = eventlet.listen(backend_address)

    try:
        Tunnel.schedule_idle_scan()
        pool = eventlet.greenpool.GreenPool(size=2)
        pool.spawn_n(eventlet.serve, frontend_listener, frontend.connection_handler)
        pool.spawn_n(eventlet.serve, backend_listener, backend.connection_handler)
        pool.waitall()
    except KeyboardInterrupt:
        pass
コード例 #6
0
ファイル: client.py プロジェクト: brankob/localtunnel
def run():
    parser = argparse.ArgumentParser(
                description='Open a public HTTP tunnel to a local server')
    parser.add_argument('-s', dest='host', metavar='address',
                default='v2.localtunnel.com',
                help='localtunnel server address (default: v2.localtunnel.com)')
    parser.add_argument('--version', action='store_true',
                help='show version information for client and server')
    parser.add_argument('-m', action='store_true',
                help='show server metrics and exit')


    if '--version' in sys.argv:
        args = parser.parse_args()
        print "client: {}".format(__version__)
        try:
            server_version = util.lookup_server_version(args.host)
        except:
            server_version = '??'
        print "server: {} ({})".format(server_version, args.host)
        sys.exit(0)
    elif '-m' in sys.argv:
        args = parser.parse_args()
        util.print_server_metrics(args.host)
        sys.exit(0)

    parser.add_argument('-n', dest='name', metavar='name',
                default=str(uuid.uuid4()).split('-')[-1],
                help='name of the tunnel (default: randomly generate)')
    parser.add_argument('-c', dest='concurrency', type=int,
                metavar='concurrency', default=3,
                help='number of concurrent backend connections')
    parser.add_argument('target', metavar='target', type=str,
                help='local target port or address of server to tunnel to')
    args = parser.parse_args()


    backend_port = util.discover_backend_port(args.host)
    frontend_address, frontend_hostname = util.parse_address(args.host)
    backend = (frontend_address[0], backend_port)

    name = args.name
    client = util.client_name()
    target = util.parse_address(args.target)[0]

    try:
        control = eventlet.connect(backend)
        control.sendall(protocol.version)
        protocol.send_message(control,
            protocol.control_request(
                name=name,
                client=client,
        ))
        reply = protocol.recv_message(control)
        if reply and 'control' in reply:
            reply = reply['control']

            def maintain_proxy_backend_pool():
                pool = eventlet.greenpool.GreenPool(reply['concurrency'])
                while True:
                    pool.spawn_n(open_proxy_backend,
                            backend, target, name, client)
            proxying = eventlet.spawn(maintain_proxy_backend_pool)

            print "  {0}".format(reply['banner'])
            print "  Port {0} is now accessible from http://{1} ...\n".format(
                    target[1], reply['host'])

            try:
                while True:
                    message = protocol.recv_message(control)
                    assert message == protocol.control_ping()
                    protocol.send_message(control, protocol.control_pong())
            except (IOError, AssertionError):
                proxying.kill()

        elif reply and 'error' in reply:
            print "  ERROR: {0}".format(reply['message'])
        else:
            print "  ERROR: Unexpected server reply."
            print "         Make sure you have the latest version of the client."
    except KeyboardInterrupt:
        pass