def mode_changed(self, *_args): mode = self.mode_combo.get_active_text().lower() ssh = mode == "ssh" if ssh: self.port_entry.set_tooltip_text("Display number (optional)") self.port_entry.set_text("") self.ssh_port_entry.set_text("22") self.ssh_port_entry.show() self.password_entry.set_tooltip_text("SSH Password") self.username_entry.set_tooltip_text("SSH Username") else: self.ssh_port_entry.hide() self.ssh_port_entry.set_text("") port_str = self.port_entry.get_text() if not port_str: self.port_entry.set_text( str(max(0, self.config.port) or DEFAULT_PORT)) self.port_entry.set_tooltip_text("xpra server port number") self.password_entry.set_tooltip_text("Session Password (optional)") self.username_entry.set_tooltip_text("Session Username (optional)") if self.config.port > 0: self.port_entry.set_text("%s" % self.config.port) can_use_password = True if ssh: ssh_cmd = parse_ssh_string(self.config.ssh)[0].strip().lower() is_putty = ssh_cmd.endswith("plink") or ssh_cmd.endswith( "plink.exe") is_paramiko = ssh_cmd == "paramiko" if is_putty or is_paramiko: can_use_password = True else: #we can also use password if sshpass is installed: from xpra.platform.paths import get_sshpass_command sshpass = get_sshpass_command() can_use_password = bool(sshpass) if can_use_password: self.password_label.show() self.password_entry.show() else: self.password_label.hide() self.password_entry.hide() self.validate() if mode == "ssl" or (mode == "ssh" and not WIN32): self.nostrict_host_check.show() else: self.nostrict_host_check.hide()
def connect_builtin(self): #cooked vars used by connect_to params = {"type": self.config.mode} username = self.config.username if self.config.mode == "ssh": if self.config.socket_dir: params["socket_dir"] = self.config.socket_dir params["remote_xpra"] = self.config.remote_xpra params["proxy_command"] = ["_proxy"] if self.config.port and self.config.port > 0: params["display"] = ":%s" % self.config.port params["display_as_args"] = [params["display"]] else: params["display"] = "auto" params["display_as_args"] = [] full_ssh = parse_ssh_string(self.config.ssh) ssh_cmd = full_ssh[0].lower() is_putty = ssh_cmd.endswith("plink") or ssh_cmd.endswith( "plink.exe") is_paramiko = ssh_cmd == "paramiko" params["is_putty"] = is_putty params["is_paramiko"] = is_paramiko password = self.config.password host = self.config.host upos = host.find("@") if upos >= 0: #found at sign: username@host username = host[:upos] host = host[upos + 1:] ppos = username.find(":") if ppos >= 0: #found separator: username:password@host password = username[ppos + 1:] username = username[:ppos] if self.config.ssh_port and self.config.ssh_port != 22: params["ssh-port"] = self.config.ssh_port full_ssh += add_ssh_args(username, password, host, self.config.ssh_port, is_putty, is_paramiko) if username: params["username"] = username if self.nostrict_host_check.get_active(): full_ssh += ["-o", "StrictHostKeyChecking=no"] params["host"] = host params["local"] = is_local(self.config.host) params["full_ssh"] = full_ssh params["password"] = password params["display_name"] = "ssh:%s:%s" % (self.config.host, self.config.port) elif self.config.mode == "unix-domain": params["display"] = ":%s" % self.config.port params["display_name"] = "unix-domain:%s" % self.config.port else: assert self.config.mode in ( "tcp", "ssl", "ws", "wss"), "invalid / unsupported mode %s" % self.config.mode params["host"] = self.config.host params["local"] = is_local(self.config.host) params["port"] = int(self.config.port) params["display_name"] = "%s:%s:%s" % ( self.config.mode, self.config.host, self.config.port) if self.config.mode == "ssl" and self.nostrict_host_check.get_active( ): params["strict-host-check"] = False #print("connect_to(%s)" % params) #UGLY warning: the username may have been updated during display parsing, #or the config file may contain a username which is different from the default one #which is used for initializing the client during init, #so update the client now: def raise_exception(*args): raise Exception(*args) self.client = make_client(raise_exception, self.config) self.client.init(self.config) self.client.username = username self.set_info_text("Connecting...") thread.start_new_thread(self.do_connect_builtin, (params, ))
def connect_builtin(self): #cooked vars used by connect_to params = {"type": self.config.mode} self.config.sharing = self.sharing.get_active() username = self.config.username if self.config.mode == "ssh" or self.config.mode == "ssh -> ssh": if self.config.socket_dir: params["socket_dir"] = self.config.socket_dir params["remote_xpra"] = self.config.remote_xpra params["proxy_command"] = ["_proxy"] if self.config.port and self.config.port > 0: params["display"] = ":%s" % self.config.port params["display_as_args"] = [params["display"]] else: params["display"] = "auto" params["display_as_args"] = [] params["ssh"] = self.config.ssh params["is_putty"] = self.is_putty params["is_paramiko"] = self.is_paramiko password = self.config.password host = self.config.host upos = host.find("@") if upos >= 0: #found at sign: username@host username = host[:upos] host = host[upos + 1:] ppos = username.find(":") if ppos >= 0: #found separator: username:password@host password = username[ppos + 1:] username = username[:ppos] if self.config.ssh_port and self.config.ssh_port != 22: params["ssh-port"] = self.config.ssh_port ssh_cmd = parse_ssh_string(self.config.ssh) ssh_cmd_0 = ssh_cmd[0].strip().lower() self.is_putty = ssh_cmd_0.endswith("plink") or ssh_cmd_0.endswith( "plink.exe") self.is_paramiko = ssh_cmd_0 == "paramiko" full_ssh = ssh_cmd[:] full_ssh += add_ssh_args(username, password, host, self.config.ssh_port, None, self.is_putty, self.is_paramiko) if username: params["username"] = username if self.nostrict_host_check.get_active(): full_ssh += ["-o", "StrictHostKeyChecking=no"] if params["type"] == "ssh -> ssh": params["type"] = "ssh" params["proxy_host"] = self.config.proxy_host params["proxy_port"] = self.config.proxy_port params["proxy_username"] = self.config.proxy_username params["proxy_password"] = self.config.proxy_password full_ssh += add_ssh_proxy_args(self.config.proxy_username, self.config.proxy_password, self.config.proxy_host, self.config.proxy_port, self.config.proxy_key, ssh_cmd, self.is_putty, self.is_paramiko) params["host"] = host params["local"] = is_local(self.config.host) params["full_ssh"] = full_ssh params["password"] = password params["display_name"] = "ssh:%s:%s" % (self.config.host, self.config.port) elif self.config.mode == "unix-domain": params["display"] = ":%s" % self.config.port params["display_name"] = "unix-domain:%s" % self.config.port else: assert self.config.mode in ( "tcp", "ssl", "ws", "wss"), "invalid / unsupported mode %s" % self.config.mode params["host"] = self.config.host params["local"] = is_local(self.config.host) params["port"] = int(self.config.port) params["display_name"] = "%s:%s:%s" % ( self.config.mode, self.config.host, self.config.port) if self.config.mode in ( "ssl", "wss") and self.nostrict_host_check.get_active(): params["strict-host-check"] = False #print("connect_to(%s)" % params) #UGLY warning: the username may have been updated during display parsing, #or the config file may contain a username which is different from the default one #which is used for initializing the client during init, #so update the client now: def raise_exception(*args): raise Exception(*args) configure_env(self.config.env) configure_logging(self.config, "attach") configure_network(self.config) self.client = make_client(raise_exception, self.config) self.client.show_progress(30, "client configuration") self.client.init(self.config) self.client.show_progress(40, "loading user interface") self.client.init_ui(self.config) self.client.username = username def handshake_complete(*_args): self.client.show_progress(100, "connection established") self.client.after_handshake(handshake_complete) self.set_info_text("Connecting...") start_thread(self.do_connect_builtin, "connect", daemon=True, args=(params, ))
def parse_ssh(self): ssh_cmd = parse_ssh_string(self.config.ssh)[0].strip().lower() self.is_putty = ssh_cmd.endswith("plink") or ssh_cmd.endswith( "plink.exe") self.is_paramiko = ssh_cmd.startswith("paramiko")
def pssh(s, e): r = parse_ssh_string(s)[0] assert r == e, "expected %s got %s" % (e, r)
def test_ssh_parsing(self): assert parse_ssh_string("auto")[0] in ("paramiko", "ssh") assert parse_ssh_string("ssh") == ["ssh"] assert parse_ssh_string("ssh -v") == ["ssh", "-v"] with nomodule_context("paramiko"): add_debug_category("ssh") def pssh(s, e): r = parse_ssh_string(s)[0] assert r == e, "expected %s got %s" % (e, r) if WIN32: pssh("auto", "plink.exe") else: pssh("auto", "ssh") remove_debug_category("ssh") #args: def targs(e, *args, **kwargs): r = add_ssh_args(*args, **kwargs) assert r == e, "expected %s but got %s" % (e, r) targs([], None, None, None, None, None, is_paramiko=True) targs( ["-pw", "password", "-l", "username", "-P", "2222", "-T", "host"], "username", "password", "host", 2222, None, is_putty=True) if not WIN32: targs([ "-l", "username", "-p", "2222", "-T", "host", "-i", "/tmp/key" ], "username", "password", "host", 2222, "/tmp/key") #proxy: def pargs(e, n, *args, **kwargs): r = add_ssh_proxy_args(*args, **kwargs)[:n] assert r == e, "expected %s but got %s" % (e, r) pargs(["-o"], 1, "username", "password", "host", 222, None, ["ssh"]) pargs(["-proxycmd"], 1, "username", "password", "host", 222, None, ["putty.exe"], is_putty=True) #proxy attributes: assert parse_proxy_attributes("somedisplay") == ("somedisplay", {}) attr = parse_proxy_attributes("10?proxy=username:password@host:222")[1] assert attr == { "proxy_host": "host", "proxy_port": 222, "proxy_username": "******", "proxy_password": "******" } def f(s): v = parse_proxy_attributes(s) assert v[1] == {}, "parse_proxy_attributes(%s) should fail" % s f("somedisplay?proxy=") f("somedisplay?proxy=:22") f("somedisplay?proxy=:@host:22") f("somedisplay?proxy=:password@host:22")