def create_sockets(opts, error_cb): bind_tcp = parse_bind_ip(opts.bind_tcp) bind_udp = parse_bind_ip(opts.bind_udp) bind_ssl = parse_bind_ip(opts.bind_ssl, 443) bind_ssh = parse_bind_ip(opts.bind_ssh, 22) bind_ws = parse_bind_ip(opts.bind_ws, 80) bind_wss = parse_bind_ip(opts.bind_wss, 443) bind_rfb = parse_bind_ip(opts.bind_rfb, 5900) bind_vsock = parse_bind_vsock(opts.bind_vsock) sockets = {} min_port = int(opts.min_port) def add_tcp_socket(socktype, host_str, iport, options): if iport != 0 and iport < min_port: error_cb("invalid %s port number %i (minimum value is %i)" % (socktype, iport, min_port)) for host in hosts(host_str): sock = setup_tcp_socket(host, iport, socktype) host, iport = sock[2] sockets[sock] = options def add_udp_socket(socktype, host_str, iport, options): if iport != 0 and iport < min_port: error_cb("invalid %s port number %i (minimum value is %i)" % (socktype, iport, min_port)) for host in hosts(host_str): sock = setup_udp_socket(host, iport, socktype) host, iport = sock[2] sockets[sock] = options # Initialize the TCP sockets before the display, # That way, errors won't make us kill the Xvfb # (which may not be ours to kill at that point) ssh_upgrades = opts.ssh_upgrade if ssh_upgrades: try: from xpra.net.ssh import nogssapi_context with nogssapi_context(): import paramiko assert paramiko except ImportError as e: from xpra.log import Logger sshlog = Logger("ssh") sshlog("import paramiko", exc_info=True) sshlog.error("Error: cannot enable SSH socket upgrades:") sshlog.error(" %s", e) ssh_upgrades = False log = get_network_logger() for socktype, defs in { "tcp": bind_tcp, "ssl": bind_ssl, "ssh": bind_ssh, "ws": bind_ws, "wss": bind_wss, "rfb": bind_rfb, }.items(): log("setting up %s sockets: %s", socktype, csv(defs.items())) for (host, iport), options in defs.items(): add_tcp_socket(socktype, host, iport, options) log("setting up UDP sockets: %s", csv(bind_udp.items())) for (host, iport), options in bind_udp.items(): add_udp_socket("udp", host, iport, options) log("setting up vsock sockets: %s", csv(bind_vsock.items())) for (cid, iport), options in bind_vsock.items(): sock = setup_vsock_socket(cid, iport) sockets[sock] = options # systemd socket activation: if POSIX and not OSX: try: from xpra.platform.xposix.sd_listen import get_sd_listen_sockets except ImportError as e: log("no systemd socket activation: %s", e) else: sd_sockets = get_sd_listen_sockets() log("systemd sockets: %s", sd_sockets) for stype, sock, addr in sd_sockets: sock = setup_sd_listen_socket(stype, sock, addr) sockets[sock] = {} log("%s : %s", (stype, [addr]), sock) return sockets
def create_sockets(opts, error_cb): log = get_network_logger() bind_tcp = parse_bind_ip(opts.bind_tcp) bind_udp = parse_bind_ip(opts.bind_udp) bind_ssl = parse_bind_ip(opts.bind_ssl) bind_ssh = parse_bind_ip(opts.bind_ssh) bind_ws = parse_bind_ip(opts.bind_ws) bind_wss = parse_bind_ip(opts.bind_wss) bind_rfb = parse_bind_ip(opts.bind_rfb, 5900) bind_vsock = parse_bind_vsock(opts.bind_vsock) sockets = [] min_port = int(opts.min_port) def add_tcp_socket(socktype, host_str, iport): if iport!=0 and iport<min_port: error_cb("invalid %s port number %i (minimum value is %i)" % (socktype, iport, min_port)) for host in hosts(host_str): sock = setup_tcp_socket(host, iport, socktype) host, iport = sock[2] sockets.append(sock) def add_udp_socket(socktype, host_str, iport): if iport!=0 and iport<min_port: error_cb("invalid %s port number %i (minimum value is %i)" % (socktype, iport, min_port)) for host in hosts(host_str): sock = setup_udp_socket(host, iport, socktype) host, iport = sock[2] sockets.append(sock) # Initialize the TCP sockets before the display, # That way, errors won't make us kill the Xvfb # (which may not be ours to kill at that point) ssh_upgrades = opts.ssh_upgrade if ssh_upgrades: try: from xpra.net.ssh import nogssapi_context with nogssapi_context(): import paramiko assert paramiko except ImportError as e: from xpra.log import Logger sshlog = Logger("ssh") sshlog("import paramiko", exc_info=True) ssh_upgrades = False sshlog.error("Error: cannot enable SSH socket upgrades:") sshlog.error(" %s", e) log("setting up SSL sockets: %s", csv(bind_ssl)) for host, iport in bind_ssl: add_tcp_socket("ssl", host, iport) log("setting up SSH sockets: %s", csv(bind_ssh)) for host, iport in bind_ssh: add_tcp_socket("ssh", host, iport) log("setting up https / wss (secure websockets): %s", csv(bind_wss)) for host, iport in bind_wss: add_tcp_socket("wss", host, iport) log("setting up TCP sockets: %s", csv(bind_tcp)) for host, iport in bind_tcp: add_tcp_socket("tcp", host, iport) log("setting up UDP sockets: %s", csv(bind_udp)) for host, iport in bind_udp: add_udp_socket("udp", host, iport) log("setting up http / ws (websockets): %s", csv(bind_ws)) for host, iport in bind_ws: add_tcp_socket("ws", host, iport) log("setting up rfb sockets: %s", csv(bind_rfb)) for host, iport in bind_rfb: add_tcp_socket("rfb", host, iport) log("setting up vsock sockets: %s", csv(bind_vsock)) for cid, iport in bind_vsock: sock = setup_vsock_socket(cid, iport) sockets.append(sock) # systemd socket activation: if POSIX and not OSX: try: from xpra.platform.xposix.sd_listen import get_sd_listen_sockets except ImportError as e: log("no systemd socket activation: %s", e) else: sd_sockets = get_sd_listen_sockets() log("systemd sockets: %s", sd_sockets) for stype, sock, addr in sd_sockets: sockets.append(setup_sd_listen_socket(stype, sock, addr)) log("%s : %s", (stype, [addr]), sock) return sockets
def create_sockets(opts, error_cb): from xpra.server.socket_util import ( parse_bind_ip, parse_bind_vsock, get_network_logger, setup_tcp_socket, setup_udp_socket, setup_vsock_socket, ) log = get_network_logger() bind_tcp = parse_bind_ip(opts.bind_tcp) bind_udp = parse_bind_ip(opts.bind_udp) bind_ssl = parse_bind_ip(opts.bind_ssl) bind_ssh = parse_bind_ip(opts.bind_ssh) bind_ws = parse_bind_ip(opts.bind_ws) bind_wss = parse_bind_ip(opts.bind_wss) bind_rfb = parse_bind_ip(opts.bind_rfb, 5900) bind_vsock = parse_bind_vsock(opts.bind_vsock) mdns_recs = {} sockets = [] rfb_upgrades = int(opts.rfb_upgrade) > 0 #SSL sockets: wrap_socket_fn = None need_ssl = False ssl_opt = opts.ssl.lower() if ssl_opt in TRUE_OPTIONS or bind_ssl or bind_wss: need_ssl = True if opts.bind_tcp or opts.bind_ws: if ssl_opt == "auto" and opts.ssl_cert: need_ssl = True elif ssl_opt == "tcp" and opts.bind_tcp: need_ssl = True elif ssl_opt == "www": need_ssl = True if need_ssl: from xpra.scripts.main import ssl_wrap_socket_fn try: wrap_socket_fn = ssl_wrap_socket_fn(opts, server_side=True) log("wrap_socket_fn=%s", wrap_socket_fn) except Exception as e: log("SSL error", exc_info=True) cpaths = csv("'%s'" % x for x in (opts.ssl_cert, opts.ssl_key) if x) raise InitException( "cannot create SSL socket, check your certificate paths (%s): %s" % (cpaths, e)) min_port = int(opts.min_port) def add_tcp_socket(socktype, host_str, iport): if iport != 0 and iport < min_port: error_cb("invalid %s port number %i (minimum value is %i)" % (socktype, iport, min_port)) for host in hosts(host_str): socket = setup_tcp_socket(host, iport, socktype) host, iport = socket[2] sockets.append(socket) add_mdns(mdns_recs, socktype, host, iport) def add_udp_socket(socktype, host_str, iport): if iport != 0 and iport < min_port: error_cb("invalid %s port number %i (minimum value is %i)" % (socktype, iport, min_port)) for host in hosts(host_str): socket = setup_udp_socket(host, iport, socktype) host, iport = socket[2] sockets.append(socket) add_mdns(mdns_recs, socktype, host, iport) # Initialize the TCP sockets before the display, # That way, errors won't make us kill the Xvfb # (which may not be ours to kill at that point) ws_upgrades = opts.html and (os.path.isabs(opts.html) or opts.html.lower() in list(TRUE_OPTIONS) + ["auto"]) ssh_upgrades = opts.ssh_upgrade if ssh_upgrades: try: from xpra.net.ssh import nogssapi_context with nogssapi_context(): import paramiko assert paramiko except ImportError as e: from xpra.log import Logger sshlog = Logger("ssh") sshlog("import paramiko", exc_info=True) sshlog.error("Error: cannot enable SSH socket upgrades:") sshlog.error(" %s", e) log("setting up SSL sockets: %s", csv(bind_ssl)) for host, iport in bind_ssl: add_tcp_socket("ssl", host, iport) if ws_upgrades: add_tcp_socket("wss", host, iport) log("setting up SSH sockets: %s", csv(bind_ssh)) for host, iport in bind_ssh: add_tcp_socket("ssh", host, iport) log("setting up https / wss (secure websockets): %s", csv(bind_wss)) for host, iport in bind_wss: add_tcp_socket("wss", host, iport) tcp_ssl = ssl_opt in TRUE_OPTIONS or (ssl_opt == "auto" and opts.ssl_cert) log("setting up TCP sockets: %s", csv(bind_tcp)) for host, iport in bind_tcp: add_tcp_socket("tcp", host, iport) if tcp_ssl: add_mdns(mdns_recs, "ssl", host, iport) if ws_upgrades: add_mdns(mdns_recs, "ws", host, iport) if ws_upgrades and tcp_ssl: add_mdns(mdns_recs, "wss", host, iport) if ssh_upgrades: add_mdns(mdns_recs, "ssh", host, iport) if rfb_upgrades: add_mdns(mdns_recs, "rfb", host, iport) log("setting up UDP sockets: %s", csv(bind_udp)) for host, iport in bind_udp: add_udp_socket("udp", host, iport) log("setting up http / ws (websockets): %s", csv(bind_ws)) for host, iport in bind_ws: add_tcp_socket("ws", host, iport) if tcp_ssl: add_mdns(mdns_recs, "wss", host, iport) log("setting up rfb sockets: %s", csv(bind_rfb)) for host, iport in bind_rfb: add_tcp_socket("rfb", host, iport) add_mdns(mdns_recs, "rfb", host, iport) log("setting up vsock sockets: %s", csv(bind_vsock)) for cid, iport in bind_vsock: socket = setup_vsock_socket(cid, iport) sockets.append(socket) #add_mdns(mdns_recs, "vsock", str(cid), iport) # systemd socket activation: if POSIX: try: from xpra.platform.xposix.sd_listen import get_sd_listen_sockets except ImportError: pass else: sd_sockets = get_sd_listen_sockets() log("systemd sockets: %s", sd_sockets) for stype, socket, addr in sd_sockets: sockets.append((stype, socket, addr)) log("%s : %s", (stype, [addr]), socket) if stype == "tcp": host, iport = addr add_mdns(mdns_recs, "tcp", host, iport) return sockets, mdns_recs, wrap_socket_fn
def create_sockets(opts, error_cb, retry=0): bind_tcp = parse_bind_ip(opts.bind_tcp) bind_ssl = parse_bind_ip(opts.bind_ssl, 443) bind_ssh = parse_bind_ip(opts.bind_ssh, 22) bind_ws = parse_bind_ip(opts.bind_ws, 80) bind_wss = parse_bind_ip(opts.bind_wss, 443) bind_rfb = parse_bind_ip(opts.bind_rfb, 5900) bind_vsock = parse_bind_vsock(opts.bind_vsock) min_port = int(opts.min_port) # Initialize the TCP sockets before the display, # That way, errors won't make us kill the Xvfb # (which may not be ours to kill at that point) ssh_upgrades = opts.ssh_upgrade if ssh_upgrades: try: from xpra.net.ssh import nogssapi_context with nogssapi_context(): import paramiko assert paramiko except ImportError as e: from xpra.log import Logger sshlog = Logger("ssh") sshlog("import paramiko", exc_info=True) sshlog.error("Error: cannot enable SSH socket upgrades:") sshlog.error(" %s", e) ssh_upgrades = False log = get_network_logger() #prepare tcp socket definitions: tcp_defs = [] for socktype, defs in { "tcp": bind_tcp, "ssl": bind_ssl, "ssh": bind_ssh, "ws": bind_ws, "wss": bind_wss, "rfb": bind_rfb, }.items(): log("setting up %s sockets: %s", socktype, csv(defs.items())) for (host, iport), options in defs.items(): if iport != 0 and iport < min_port: error_cb("invalid %s port number %i (minimum value is %i)" % (socktype, iport, min_port)) for h in hosts(host): tcp_defs.append((socktype, h, iport, options, None)) sockets = {} for attempt in range(retry + 1): if not tcp_defs: break try_list = tuple(tcp_defs) tcp_defs = [] for socktype, host, iport, options, _ in try_list: try: sock = setup_tcp_socket(host, iport, socktype) except Exception as e: log("setup_tcp_socket%s attempt=%s", (host, iport, options), attempt) tcp_defs.append((socktype, host, iport, options, e)) else: host, iport = sock[2] sockets[sock] = options if tcp_defs: sleep(1) if tcp_defs: #failed to create some sockets: for socktype, host, iport, options, exception in tcp_defs: log.error("Error creating %s socket", socktype) log.error(" on %s:%s", host, iport) log.error(" %s", exception) raise InitException("failed to create %s socket: %s" % (socktype, exception)) log("setting up vsock sockets: %s", csv(bind_vsock.items())) for (cid, iport), options in bind_vsock.items(): sock = setup_vsock_socket(cid, iport) sockets[sock] = options # systemd socket activation: if POSIX and not OSX: try: from xpra.platform.xposix.sd_listen import get_sd_listen_sockets except ImportError as e: log("no systemd socket activation: %s", e) else: sd_sockets = get_sd_listen_sockets() log("systemd sockets: %s", sd_sockets) for stype, sock, addr in sd_sockets: sock = setup_sd_listen_socket(stype, sock, addr) sockets[sock] = {} log("%s : %s", (stype, [addr]), sock) return sockets