1 | Index: xpra/client/gtk_base/client_launcher.py |
---|
2 | =================================================================== |
---|
3 | --- xpra/client/gtk_base/client_launcher.py (revision 20967) |
---|
4 | +++ xpra/client/gtk_base/client_launcher.py (working copy) |
---|
5 | @@ -48,7 +48,9 @@ |
---|
6 | |
---|
7 | #what we save in the config file: |
---|
8 | SAVED_FIELDS = ["username", "password", "host", "port", "mode", "ssh_port", |
---|
9 | - "encoding", "quality", "min-quality", "speed", "min-speed"] |
---|
10 | + "encoding", "quality", "min-quality", "speed", "min-speed", |
---|
11 | + "sshproxy_ssh_port", "proxy_username", "sshproxy_pkey_path", |
---|
12 | + "sshproxy_password" ] |
---|
13 | |
---|
14 | #options not normally found in xpra config file |
---|
15 | #but which can be present in a launcher config: |
---|
16 | @@ -56,19 +58,29 @@ |
---|
17 | "host" : str, |
---|
18 | "port" : int, |
---|
19 | "username" : str, |
---|
20 | + "proxy_username" : str, |
---|
21 | + "sshproxy_host" : str, |
---|
22 | + "sshproxy_password" : str, |
---|
23 | + "sshproxy_pkey_path": str, |
---|
24 | "password" : str, |
---|
25 | "mode" : str, |
---|
26 | "autoconnect" : bool, |
---|
27 | "ssh_port" : int, |
---|
28 | + "sshproxy_ssh_port" : int, |
---|
29 | } |
---|
30 | LAUNCHER_DEFAULTS = { |
---|
31 | "host" : "", |
---|
32 | "port" : -1, |
---|
33 | "username" : get_username(), |
---|
34 | + "proxy_username" : get_username(), |
---|
35 | + "sshproxy_host" : "", |
---|
36 | + "sshproxy_pkey_path": "", |
---|
37 | "password" : "", |
---|
38 | - "mode" : "tcp", #tcp,ssh,.. |
---|
39 | + "sshproxy_password" : "", |
---|
40 | + "mode" : "ssh -> ssh", #tcp,ssh,.. |
---|
41 | "autoconnect" : False, |
---|
42 | "ssh_port" : 22, |
---|
43 | + "sshproxy_ssh_port" : 22, |
---|
44 | } |
---|
45 | |
---|
46 | |
---|
47 | @@ -128,6 +140,19 @@ |
---|
48 | def get_connection_modes(self): |
---|
49 | modes = ["ssh"] |
---|
50 | try: |
---|
51 | + # the next line will always fail on first call to get_connection_modes() |
---|
52 | + # because self.config doesn't exist yet |
---|
53 | + ssh_cmd = parse_ssh_string(self.config.ssh)[0].strip().lower() |
---|
54 | + is_putty = ssh_cmd.endswith("plink") or ssh_cmd.endswith("plink.exe") |
---|
55 | + is_paramiko = ssh_cmd=="paramiko" |
---|
56 | + # this mode not implemented for openssh (it is implemented for plink and paramiko) |
---|
57 | + if is_putty or is_paramiko: |
---|
58 | + modes.append("ssh -> ssh") |
---|
59 | + else: |
---|
60 | + log("ssh is not putty or paramiko, disabling 'ssh->ssh' mode") |
---|
61 | + except: |
---|
62 | + pass |
---|
63 | + try: |
---|
64 | import ssl |
---|
65 | assert ssl |
---|
66 | modes.append("ssl") |
---|
67 | @@ -221,19 +246,102 @@ |
---|
68 | vbox.pack_start(hbox) |
---|
69 | |
---|
70 | # Mode: |
---|
71 | - hbox = gtk.HBox(False, 20) |
---|
72 | - hbox.set_spacing(20) |
---|
73 | - hbox.pack_start(gtk.Label("Mode: ")) |
---|
74 | + hbox = gtk.HBox(False, 5) |
---|
75 | self.mode_combo = gtk.combo_box_new_text() |
---|
76 | for x in self.get_connection_modes(): |
---|
77 | self.mode_combo.append_text(x.upper()) |
---|
78 | self.mode_combo.connect("changed", self.mode_changed) |
---|
79 | - hbox.pack_start(self.mode_combo) |
---|
80 | + self.padding_label = gtk.Label("") |
---|
81 | + self.padding_label2 = gtk.Label("") |
---|
82 | + hbox.pack_start(self.padding_label, True, True) |
---|
83 | + hbox.pack_start(gtk.Label("Mode: "), False, False) |
---|
84 | + hbox.pack_start(self.mode_combo, False, False) |
---|
85 | + hbox.pack_start(self.padding_label2, True, True) |
---|
86 | vbox.pack_start(hbox) |
---|
87 | |
---|
88 | - # Username@Host:Port |
---|
89 | - hbox = gtk.HBox(False, 0) |
---|
90 | - hbox.set_spacing(5) |
---|
91 | + # Username@Host:Port (ssh -> ssh, proxy) |
---|
92 | + vbox_proxy = gtk.VBox(False, 15) |
---|
93 | + hbox = gtk.HBox(False, 5) |
---|
94 | + self.sshproxy_vbox = vbox_proxy |
---|
95 | + self.sshproxy_label = gtk.Label("proxy: ") |
---|
96 | + self.sshproxy_username_entry = gtk.Entry() |
---|
97 | + self.sshproxy_username_entry.set_max_length(128) |
---|
98 | + self.sshproxy_username_entry.set_width_chars(16) |
---|
99 | + self.sshproxy_username_entry.connect("changed", self.validate) |
---|
100 | + self.sshproxy_username_entry.connect("activate", self.connect_clicked) |
---|
101 | + self.sshproxy_username_entry.set_tooltip_text("username") |
---|
102 | + self.sshproxy_username_label = gtk.Label("@") |
---|
103 | + self.sshproxy_host_entry = gtk.Entry() |
---|
104 | + self.sshproxy_host_entry.set_max_length(128) |
---|
105 | + self.sshproxy_host_entry.set_width_chars(24) |
---|
106 | + self.sshproxy_host_entry.connect("changed", self.validate) |
---|
107 | + self.sshproxy_host_entry.connect("activate", self.connect_clicked) |
---|
108 | + self.sshproxy_host_entry.set_tooltip_text("hostname") |
---|
109 | + self.sshproxy_ssh_port_entry = gtk.Entry() |
---|
110 | + self.sshproxy_ssh_port_entry.set_max_length(5) |
---|
111 | + self.sshproxy_ssh_port_entry.set_width_chars(5) |
---|
112 | + self.sshproxy_ssh_port_entry.connect("changed", self.validate) |
---|
113 | + self.sshproxy_ssh_port_entry.connect("activate", self.connect_clicked) |
---|
114 | + self.sshproxy_ssh_port_entry.set_tooltip_text("SSH port") |
---|
115 | + hbox.pack_start(self.sshproxy_label, False, False) |
---|
116 | + hbox.pack_start(self.sshproxy_username_entry, True, True) |
---|
117 | + hbox.pack_start(self.sshproxy_username_label, False, False) |
---|
118 | + hbox.pack_start(self.sshproxy_host_entry, True, True) |
---|
119 | + hbox.pack_start(self.sshproxy_ssh_port_entry, False, False) |
---|
120 | + vbox_proxy.pack_start(hbox) |
---|
121 | + |
---|
122 | + # |
---|
123 | + # Password |
---|
124 | + # |
---|
125 | + hbox = gtk.HBox(False, 5) |
---|
126 | + self.sshproxy_password_entry = gtk.Entry() |
---|
127 | + self.sshproxy_password_entry.set_max_length(128) |
---|
128 | + self.sshproxy_password_entry.set_width_chars(30) |
---|
129 | + self.sshproxy_password_entry.set_text("") |
---|
130 | + self.sshproxy_password_entry.set_visibility(False) |
---|
131 | + self.sshproxy_password_entry.connect("changed", self.password_ok) |
---|
132 | + self.sshproxy_password_entry.connect("changed", self.validate) |
---|
133 | + self.sshproxy_password_entry.connect("activate", self.connect_clicked) |
---|
134 | + self.sshproxy_password_label = gtk.Label("Proxy password:") |
---|
135 | + hbox.pack_start(self.sshproxy_password_label, False, False) |
---|
136 | + hbox.pack_start(self.sshproxy_password_entry, True, True) |
---|
137 | + vbox_proxy.pack_start(hbox) |
---|
138 | + |
---|
139 | + hbox = gtk.HBox(False, 5) |
---|
140 | + self.pkey_hbox = hbox |
---|
141 | + self.sshproxy_pkey_path_l = gtk.Label("Proxy private key path (PPK):") |
---|
142 | + self.sshproxy_pkey_path_entry = gtk.Entry() |
---|
143 | + self.sshproxy_pkey_path_browse = gtk.Button("Browse") |
---|
144 | + self.sshproxy_pkey_path_browse.connect("clicked", self.sshproxy_pkey_path_browse_clicked) |
---|
145 | + hbox.pack_start(self.sshproxy_pkey_path_l, False, False) |
---|
146 | + hbox.pack_start(self.sshproxy_pkey_path_entry, True, True) |
---|
147 | + hbox.pack_start(self.sshproxy_pkey_path_browse, False, False) |
---|
148 | + vbox_proxy.pack_start(hbox) |
---|
149 | + |
---|
150 | + # |
---|
151 | + # Same as checkbox |
---|
152 | + # |
---|
153 | + hbox = gtk.HBox(False, 5) |
---|
154 | + self.password_scb = gtk.CheckButton("Server password same as proxy") |
---|
155 | + self.password_scb.set_mode(True) |
---|
156 | + self.password_scb.set_active(True) |
---|
157 | + self.password_scb.connect("toggled", self.validate) |
---|
158 | + self.username_scb = gtk.CheckButton("Server username same as proxy") |
---|
159 | + self.username_scb.set_mode(True) |
---|
160 | + self.username_scb.set_active(True) |
---|
161 | + self.username_scb.connect("toggled", self.validate) |
---|
162 | + self.spacer_scb = gtk.Label("") |
---|
163 | + hbox.pack_start(self.username_scb, False, False) |
---|
164 | + hbox.pack_start(self.spacer_scb, True, True) |
---|
165 | + hbox.pack_start(self.password_scb, False, False) |
---|
166 | + vbox_proxy.pack_start(hbox) |
---|
167 | + |
---|
168 | + vbox.pack_start(vbox_proxy) |
---|
169 | + |
---|
170 | + |
---|
171 | + # Username@Host:Port (main) |
---|
172 | + hbox = gtk.HBox(False, 5) |
---|
173 | + self.server_label = gtk.Label("Server:") |
---|
174 | self.username_entry = gtk.Entry() |
---|
175 | self.username_entry.set_max_length(128) |
---|
176 | self.username_entry.set_width_chars(16) |
---|
177 | @@ -260,17 +368,19 @@ |
---|
178 | self.port_entry.connect("activate", self.connect_clicked) |
---|
179 | self.port_entry.set_tooltip_text("port/display") |
---|
180 | |
---|
181 | - hbox.pack_start(self.username_entry) |
---|
182 | - hbox.pack_start(self.username_label) |
---|
183 | - hbox.pack_start(self.host_entry) |
---|
184 | - hbox.pack_start(self.ssh_port_entry) |
---|
185 | - hbox.pack_start(gtk.Label(":")) |
---|
186 | - hbox.pack_start(self.port_entry) |
---|
187 | + hbox.pack_start(self.server_label, False, False) |
---|
188 | + hbox.pack_start(self.username_entry, True, True) |
---|
189 | + hbox.pack_start(self.username_label, False, False) |
---|
190 | + hbox.pack_start(self.host_entry, True, True) |
---|
191 | + hbox.pack_start(self.ssh_port_entry, False, False) |
---|
192 | + hbox.pack_start(gtk.Label(":"), False, False) |
---|
193 | + hbox.pack_start(self.port_entry, False, False) |
---|
194 | vbox.pack_start(hbox) |
---|
195 | |
---|
196 | + # |
---|
197 | # Password |
---|
198 | - hbox = gtk.HBox(False, 0) |
---|
199 | - hbox.set_spacing(20) |
---|
200 | + # |
---|
201 | + hbox = gtk.HBox(False, 5) |
---|
202 | self.password_entry = gtk.Entry() |
---|
203 | self.password_entry.set_max_length(128) |
---|
204 | self.password_entry.set_width_chars(30) |
---|
205 | @@ -278,14 +388,13 @@ |
---|
206 | self.password_entry.set_visibility(False) |
---|
207 | self.password_entry.connect("changed", self.password_ok) |
---|
208 | self.password_entry.connect("changed", self.validate) |
---|
209 | - self.password_label = gtk.Label("Password: ") |
---|
210 | - hbox.pack_start(self.password_label) |
---|
211 | - hbox.pack_start(self.password_entry) |
---|
212 | + self.password_label = gtk.Label("Server Password:") |
---|
213 | + hbox.pack_start(self.password_label, False, False) |
---|
214 | + hbox.pack_start(self.password_entry, True, True) |
---|
215 | vbox.pack_start(hbox) |
---|
216 | |
---|
217 | - #strict host key check for SSL and SSH |
---|
218 | - hbox = gtk.HBox(False, 0) |
---|
219 | - hbox.set_spacing(20) |
---|
220 | + # strict host key check for SSL and SSH |
---|
221 | + hbox = gtk.HBox(False, 5) |
---|
222 | self.nostrict_host_check = gtk.CheckButton("Disable Strict Host Key Check") |
---|
223 | self.nostrict_host_check.set_active(False) |
---|
224 | al = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.0, yscale=0) |
---|
225 | @@ -412,10 +521,11 @@ |
---|
226 | |
---|
227 | def validate(self, *args): |
---|
228 | ssh = self.mode_combo.get_active_text()=="SSH" |
---|
229 | + sshtossh = self.mode_combo.get_active_text()=="SSH -> SSH" |
---|
230 | errs = [] |
---|
231 | host = self.host_entry.get_text() |
---|
232 | errs.append((self.host_entry, not bool(host), "specify the host")) |
---|
233 | - if ssh: |
---|
234 | + if ssh or sshtossh: |
---|
235 | #validate ssh port: |
---|
236 | ssh_port = self.ssh_port_entry.get_text() |
---|
237 | try: |
---|
238 | @@ -424,8 +534,21 @@ |
---|
239 | ssh_port = -1 |
---|
240 | errs.append((self.ssh_port_entry, ssh_port<0 or ssh_port>=2**16, "invalid SSH port number")) |
---|
241 | port = self.port_entry.get_text() |
---|
242 | - if ssh and not port: |
---|
243 | - port = 0 #port optional with ssh |
---|
244 | + if sshtossh: |
---|
245 | + if self.password_scb.get_active(): |
---|
246 | + self.password_entry.set_sensitive(False) |
---|
247 | + self.password_entry.set_text(self.sshproxy_password_entry.get_text()) |
---|
248 | + else: |
---|
249 | + self.password_entry.set_sensitive(True) |
---|
250 | + if self.username_scb.get_active(): |
---|
251 | + self.username_entry.set_sensitive(False) |
---|
252 | + self.username_entry.set_text(self.sshproxy_username_entry.get_text()) |
---|
253 | + else: |
---|
254 | + self.username_entry.set_sensitive(True) |
---|
255 | + sshproxy_host = self.sshproxy_host_entry.get_text() |
---|
256 | + errs.append((self.sshproxy_host_entry, not bool(sshproxy_host), "specify the proxy host")) |
---|
257 | + if ssh or sshtossh and not port: |
---|
258 | + port = 0 # port optional with ssh |
---|
259 | else: |
---|
260 | try: |
---|
261 | port = int(port) |
---|
262 | @@ -460,14 +583,25 @@ |
---|
263 | def mode_changed(self, *_args): |
---|
264 | mode = self.mode_combo.get_active_text().lower() |
---|
265 | ssh = mode=="ssh" |
---|
266 | - if ssh: |
---|
267 | + sshtossh = mode=="ssh -> ssh" |
---|
268 | + if ssh or sshtossh: |
---|
269 | self.port_entry.set_tooltip_text("Display number (optional)") |
---|
270 | self.port_entry.set_text("") |
---|
271 | - self.ssh_port_entry.set_text("22") |
---|
272 | self.ssh_port_entry.show() |
---|
273 | self.password_entry.set_tooltip_text("SSH Password") |
---|
274 | self.username_entry.set_tooltip_text("SSH Username") |
---|
275 | + if ssh: |
---|
276 | + self.sshproxy_vbox.hide() |
---|
277 | + self.password_scb.hide() |
---|
278 | + self.password_entry.set_sensitive(True) |
---|
279 | + self.username_entry.set_sensitive(True) |
---|
280 | + if sshtossh: |
---|
281 | + self.sshproxy_vbox.show() |
---|
282 | + self.password_scb.show() |
---|
283 | else: |
---|
284 | + self.password_entry.set_sensitive(True) |
---|
285 | + self.username_entry.set_sensitive(True) |
---|
286 | + self.sshproxy_vbox.hide() |
---|
287 | self.ssh_port_entry.hide() |
---|
288 | self.ssh_port_entry.set_text("") |
---|
289 | port_str = self.port_entry.get_text() |
---|
290 | @@ -479,10 +613,15 @@ |
---|
291 | if self.config.port>0: |
---|
292 | self.port_entry.set_text("%s" % self.config.port) |
---|
293 | can_use_password = True |
---|
294 | - if ssh: |
---|
295 | + if ssh or sshtossh: |
---|
296 | ssh_cmd = parse_ssh_string(self.config.ssh)[0].strip().lower() |
---|
297 | is_putty = ssh_cmd.endswith("plink") or ssh_cmd.endswith("plink.exe") |
---|
298 | is_paramiko = ssh_cmd=="paramiko" |
---|
299 | + if is_paramiko: |
---|
300 | + self.sshproxy_pkey_path_entry.set_text("paramiko automatically searches ~/.ssh/") |
---|
301 | + self.sshproxy_pkey_path_entry.set_editable(False) |
---|
302 | + self.sshproxy_pkey_path_entry.set_sensitive(False) |
---|
303 | + self.sshproxy_pkey_path_browse.hide() |
---|
304 | if is_putty or is_paramiko: |
---|
305 | can_use_password = True |
---|
306 | else: |
---|
307 | @@ -490,12 +629,19 @@ |
---|
308 | from xpra.platform.paths import get_sshpass_command |
---|
309 | sshpass = get_sshpass_command() |
---|
310 | can_use_password = bool(sshpass) |
---|
311 | + self.connect_btn.set_sensitive(len(err_text)==0) |
---|
312 | if can_use_password: |
---|
313 | self.password_label.show() |
---|
314 | self.password_entry.show() |
---|
315 | + if sshtossh: |
---|
316 | + self.sshproxy_password_label.show() |
---|
317 | + self.sshproxy_password_entry.show() |
---|
318 | else: |
---|
319 | self.password_label.hide() |
---|
320 | self.password_entry.hide() |
---|
321 | + if sshtossh: |
---|
322 | + self.sshproxy_password_label.hide() |
---|
323 | + self.sshproxy_password_entry.hide() |
---|
324 | self.validate() |
---|
325 | if mode=="ssl" or (mode=="ssh" and not WIN32): |
---|
326 | self.nostrict_host_check.show() |
---|
327 | @@ -546,6 +692,21 @@ |
---|
328 | def set_sensitive(self, s): |
---|
329 | glib.idle_add(self.window.set_sensitive, s) |
---|
330 | |
---|
331 | + def choose_pkey_file(self, title, action, action_button, callback): |
---|
332 | + file_filter = gtk.FileFilter() |
---|
333 | + file_filter.set_name("All Files") |
---|
334 | + file_filter.add_pattern("*") |
---|
335 | + choose_file(self.window, title, action, action_button, callback, file_filter) |
---|
336 | + |
---|
337 | + def sshproxy_pkey_path_browse_clicked(self, *args): |
---|
338 | + log("sshproxy_pkey_path_browse_clicked%s", args) |
---|
339 | + def do_choose(filename): |
---|
340 | + #make sure the file extension is .ppk |
---|
341 | + if os.path.splitext(filename)[-1]!=".ppk": |
---|
342 | + filename += ".ppk" |
---|
343 | + self.sshproxy_pkey_path_entry.set_text(filename) |
---|
344 | + self.choose_pkey_file("Choose SSH private key", FILE_CHOOSER_ACTION_SAVE, gtk.STOCK_SAVE, do_choose) |
---|
345 | + |
---|
346 | def connect_clicked(self, *args): |
---|
347 | log("connect_clicked%s", args) |
---|
348 | self.update_options_from_gui() |
---|
349 | @@ -591,7 +752,7 @@ |
---|
350 | #cooked vars used by connect_to |
---|
351 | params = {"type" : self.config.mode} |
---|
352 | username = self.config.username |
---|
353 | - if self.config.mode=="ssh": |
---|
354 | + if self.config.mode=="ssh" or self.config.mode=="ssh -> ssh": |
---|
355 | if self.config.socket_dir: |
---|
356 | params["socket_dir"] = self.config.socket_dir |
---|
357 | params["remote_xpra"] = self.config.remote_xpra |
---|
358 | @@ -627,6 +788,29 @@ |
---|
359 | params["username"] = username |
---|
360 | if self.nostrict_host_check.get_active(): |
---|
361 | full_ssh += ["-o", "StrictHostKeyChecking=no"] |
---|
362 | + if params["type"] == "ssh -> ssh": |
---|
363 | + log("2hop") |
---|
364 | + params["type"] = "ssh" |
---|
365 | + if is_putty: |
---|
366 | + proxyline = ssh_cmd |
---|
367 | + proxyline += " -nc %host:%port" |
---|
368 | + proxyline += " -P " + str(self.config.sshproxy_ssh_port) |
---|
369 | + proxyline += " -l " + self.config.sshproxy_username |
---|
370 | + ptext = self.config.sshproxy_password |
---|
371 | + if bool(ptext): |
---|
372 | + proxyline += " -pw " + ptext |
---|
373 | + ptext = self.config.sshproxy_pkey_path |
---|
374 | + ptext = ptext.replace("\\", "/") |
---|
375 | + if bool(ptext): |
---|
376 | + proxyline += " -i " + '"' + ptext + '"' |
---|
377 | + proxyline += " " + self.config.sshproxy_host |
---|
378 | + full_ssh += [ "-proxycmd", proxyline ] |
---|
379 | + if is_paramiko: |
---|
380 | + log("setting phost/pport") |
---|
381 | + params["phost"] = self.config.sshproxy_host |
---|
382 | + params["pport"] = self.config.sshproxy_ssh_port |
---|
383 | + params["pusername"] = self.config.sshproxy_username |
---|
384 | + params["ppassword"] = self.config.sshproxy_password |
---|
385 | params["host"] = host |
---|
386 | params["local"] = is_local(self.config.host) |
---|
387 | params["full_ssh"] = full_ssh |
---|
388 | @@ -784,8 +968,16 @@ |
---|
389 | return int(v) |
---|
390 | except ValueError: |
---|
391 | return 0 |
---|
392 | + self.config.sshproxy_ssh_port = pint(self.sshproxy_ssh_port_entry.get_text()) |
---|
393 | + self.config.sshproxy_host = self.sshproxy_host_entry.get_text() |
---|
394 | + self.config.sshproxy_username = self.sshproxy_username_entry.get_text() |
---|
395 | + ssh_cmd = parse_ssh_string(self.config.ssh)[0].strip().lower() |
---|
396 | + if ssh_cmd != "paramiko": |
---|
397 | + self.config.sshproxy_pkey_path = self.sshproxy_pkey_path_entry.get_text() |
---|
398 | self.config.host = self.host_entry.get_text() |
---|
399 | self.config.ssh_port = pint(self.ssh_port_entry.get_text()) |
---|
400 | + self.config.sshproxy_ssh_port = pint(self.sshproxy_ssh_port_entry.get_text()) |
---|
401 | + self.config.sshproxy_password = self.sshproxy_password_entry.get_text() |
---|
402 | self.config.port = pint(self.port_entry.get_text()) |
---|
403 | self.config.username = self.username_entry.get_text() |
---|
404 | self.config.encoding = self.get_selected_encoding() or self.config.encoding |
---|
405 | @@ -794,7 +986,7 @@ |
---|
406 | self.config.mode = "tcp" |
---|
407 | if mode_enc.find("aes")>0: |
---|
408 | self.config.encryption = "AES" |
---|
409 | - elif mode_enc in ("ssl", "ssh", "ws", "wss"): |
---|
410 | + elif mode_enc in ("ssl", "ssh", "ws", "wss", "ssh -> ssh"): |
---|
411 | self.config.mode = mode_enc |
---|
412 | self.config.encryption = "" |
---|
413 | self.config.password = self.password_entry.get_text() |
---|
414 | @@ -803,9 +995,14 @@ |
---|
415 | def update_gui_from_config(self): |
---|
416 | #mode: |
---|
417 | mode = (self.config.mode or "").lower() |
---|
418 | + got_one = False |
---|
419 | for i,e in enumerate(self.get_connection_modes()): |
---|
420 | if e.lower()==mode: |
---|
421 | + got_one = True |
---|
422 | self.mode_combo.set_active(i) |
---|
423 | + if not got_one: |
---|
424 | + log("Bad default for mode_combo, applying fallback default") |
---|
425 | + self.mode_combo.set_active(0) |
---|
426 | if self.config.encoding and self.encoding_combo: |
---|
427 | index = self.encoding_combo.get_menu().encoding_to_index.get(self.config.encoding, -1) |
---|
428 | log("setting encoding combo to %s / %s", self.config.encoding, index) |
---|
429 | @@ -815,8 +1012,14 @@ |
---|
430 | #then select it in the combo: |
---|
431 | if index>=0: |
---|
432 | self.encoding_combo.set_history(index) |
---|
433 | + self.sshproxy_username_entry.set_text(self.config.proxy_username) |
---|
434 | + self.sshproxy_host_entry.set_text(self.config.sshproxy_host) |
---|
435 | + ssh_cmd = parse_ssh_string(self.config.ssh)[0].strip().lower() |
---|
436 | + if(ssh_cmd != "paramiko"): |
---|
437 | + self.sshproxy_pkey_path_entry.set_text(self.config.sshproxy_pkey_path) |
---|
438 | self.username_entry.set_text(self.config.username) |
---|
439 | self.password_entry.set_text(self.config.password) |
---|
440 | + self.sshproxy_password_entry.set_text(self.config.sshproxy_password) |
---|
441 | self.host_entry.set_text(self.config.host) |
---|
442 | def get_port(v, default_port=""): |
---|
443 | try: |
---|
444 | @@ -827,11 +1030,12 @@ |
---|
445 | pass |
---|
446 | return str(default_port) |
---|
447 | dport = DEFAULT_PORT |
---|
448 | - if mode=="ssh": |
---|
449 | + if mode=="ssh" or mode=="ssh -> ssh": |
---|
450 | #not required, so don't specify one |
---|
451 | dport = "" |
---|
452 | self.port_entry.set_text(get_port(self.config.port, dport)) |
---|
453 | self.ssh_port_entry.set_text(get_port(self.config.ssh_port)) |
---|
454 | + self.sshproxy_ssh_port_entry.set_text(get_port(self.config.sshproxy_ssh_port)) |
---|
455 | |
---|
456 | def close_window(self, *_args): |
---|
457 | w = self.window |
---|
458 | @@ -986,7 +1190,6 @@ |
---|
459 | #file says we should connect, |
---|
460 | #do that only (not showing UI unless something goes wrong): |
---|
461 | glib.idle_add(app.do_connect) |
---|
462 | - if not has_file: |
---|
463 | app.reset_errors() |
---|
464 | if not app.config.autoconnect or app.config.debug: |
---|
465 | if OSX and not has_file: |
---|
466 | Index: xpra/net/ssh.py |
---|
467 | =================================================================== |
---|
468 | --- xpra/net/ssh.py (revision 20967) |
---|
469 | +++ xpra/net/ssh.py (working copy) |
---|
470 | @@ -79,6 +79,8 @@ |
---|
471 | env["XPRA_LOG_TO_FILE"] = "0" |
---|
472 | kwargs["env"] = env |
---|
473 | proc = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, **kwargs) |
---|
474 | + # without this the return code is always None in WSL (and becomes zero after communicate()) |
---|
475 | + proc.wait() |
---|
476 | stdout, stderr = proc.communicate() |
---|
477 | log("exec_dialog_subprocess(%s)", cmd) |
---|
478 | if stderr: |
---|
479 | @@ -187,7 +189,6 @@ |
---|
480 | port = display_desc.get("ssh-port", 22) |
---|
481 | ipv6 = display_desc.get("ipv6", False) |
---|
482 | from xpra.scripts.main import socket_connect |
---|
483 | - sock = socket_connect(dtype, host, port, ipv6) |
---|
484 | #ssh and command attributes: |
---|
485 | username = display_desc.get("username") |
---|
486 | if not username: |
---|
487 | @@ -199,8 +200,22 @@ |
---|
488 | proxy_command = display_desc["proxy_command"] #ie: "_proxy_start" |
---|
489 | socket_dir = display_desc.get("socket_dir") |
---|
490 | display_as_args = display_desc["display_as_args"] #ie: "--start=xterm :10" |
---|
491 | - with nogssapi_context(): |
---|
492 | - return do_ssh_paramiko_connect_to(sock, host, port, username, password, proxy_command, remote_xpra, socket_dir, display_as_args, target) |
---|
493 | + # Then we are using a proxy |
---|
494 | + if "phost" in display_desc: |
---|
495 | + phost = display_desc["phost"] |
---|
496 | + pport = display_desc.get("pport", 22) |
---|
497 | + pusername = display_desc.get("pusername", username) |
---|
498 | + ppassword = display_desc.get("ppassword", password) |
---|
499 | + sock = socket_connect(dtype, phost, pport, ipv6) |
---|
500 | + parachan = do_ssh_paramiko_connect_to(sock, host, port, pusername, ppassword) |
---|
501 | + with nogssapi_context(): |
---|
502 | + log("connecting after proxy") |
---|
503 | + return do_ssh_paramiko_connect_to(sock, host, port, username, password, proxy_command, remote_xpra, socket_dir, display_as_args, target, parachan) |
---|
504 | + else: |
---|
505 | + sock = socket_connect(dtype, host, port, ipv6) |
---|
506 | + with nogssapi_context(): |
---|
507 | + log("connecting after proxy") |
---|
508 | + return do_ssh_paramiko_connect_to(sock, host, port, username, password, proxy_command, remote_xpra, socket_dir, display_as_args, target) |
---|
509 | |
---|
510 | |
---|
511 | #workaround incompatibility between paramiko and gssapi: |
---|
512 | @@ -209,18 +224,23 @@ |
---|
513 | def __init__(self): |
---|
514 | nomodule_context.__init__(self, "gssapi") |
---|
515 | |
---|
516 | - |
---|
517 | -def do_ssh_paramiko_connect_to(sock, host, port, username, password, proxy_command, remote_xpra, socket_dir, display_as_args, target): |
---|
518 | +# (1) If the arguments after "proxy_command" are "None", then we're opening a port-forward |
---|
519 | +# (2) If "parachan" is set, that means we're using a port-forward |
---|
520 | +def do_ssh_paramiko_connect_to(sock, host, port, username, password, proxy_command=None, remote_xpra=None, socket_dir=None, display_as_args=None, target=None, parachan = None): |
---|
521 | from paramiko import SSHException, Transport, Agent, RSAKey, PasswordRequiredException |
---|
522 | from paramiko.hostkeys import HostKeys |
---|
523 | - transport = Transport(sock) |
---|
524 | - transport.use_compression(False) |
---|
525 | - log("SSH transport %s", transport) |
---|
526 | + if parachan is None: |
---|
527 | + transport = Transport(sock) |
---|
528 | + transport.use_compression(False) |
---|
529 | + else: |
---|
530 | + transport = Transport(parachan) |
---|
531 | + transport.use_compression(False) |
---|
532 | try: |
---|
533 | transport.start_client() |
---|
534 | except SSHException as e: |
---|
535 | log("start_client()", exc_info=True) |
---|
536 | raise InitException("SSH negotiation failed: %s" % e) |
---|
537 | + log("SSH transport %s", transport) |
---|
538 | |
---|
539 | host_key = transport.get_remote_server_key() |
---|
540 | assert host_key, "no remote server key" |
---|
541 | @@ -273,6 +293,7 @@ |
---|
542 | transport.close() |
---|
543 | raise InitExit(EXIT_SSH_KEY_FAILURE, "SSH Host key has changed") |
---|
544 | if not confirm_key(qinfo): |
---|
545 | + log("FLEIX IS A DOG") |
---|
546 | transport.close() |
---|
547 | raise InitExit(EXIT_SSH_KEY_FAILURE, "SSH Host key has changed") |
---|
548 | |
---|
549 | @@ -385,6 +406,29 @@ |
---|
550 | log("auth_password(..)", exc_info=True) |
---|
551 | log.info("SSH password authentication failed: %s", e) |
---|
552 | |
---|
553 | + def auth_interactive(): |
---|
554 | + log("trying interactive authentication") |
---|
555 | + class iauthhandler: |
---|
556 | + def __init__(self): |
---|
557 | + self.authcount = 0 |
---|
558 | + def handlestuff(self, title, instructions, prompt_list): |
---|
559 | + if self.authcount == 0: |
---|
560 | + self.authcount += 1 |
---|
561 | + return [ password ] |
---|
562 | + elif self.authcount == 1: |
---|
563 | + p = input_pass(prompt_list[0][0]) |
---|
564 | + self.authcount += 1 |
---|
565 | + return [ p ] |
---|
566 | + else: |
---|
567 | + return [ ] |
---|
568 | + log("trying interactive authentication2") |
---|
569 | + try: |
---|
570 | + myiauthhandler = iauthhandler() |
---|
571 | + transport.auth_interactive(username, myiauthhandler.handlestuff, '') |
---|
572 | + except SSHException as e: |
---|
573 | + log("auth_password(..)", exc_info=True) |
---|
574 | + log.info("SSH password authentication failed: %s", e) |
---|
575 | + |
---|
576 | banner = transport.get_banner() |
---|
577 | if banner: |
---|
578 | log.info("SSH server banner:") |
---|
579 | @@ -392,18 +436,24 @@ |
---|
580 | log.info(" %s", x) |
---|
581 | |
---|
582 | log("starting authentication") |
---|
583 | + # per the RFC we probably should do none first always and read off the supported |
---|
584 | + # methods, however, the current code seems to work fine with OpenSSH |
---|
585 | if not transport.is_authenticated() and NONE_AUTH: |
---|
586 | auth_none() |
---|
587 | |
---|
588 | + # Some people do two-factor using KEY_AUTH to kick things off, so this happens first |
---|
589 | + if not transport.is_authenticated() and KEY_AUTH: |
---|
590 | + auth_publickey() |
---|
591 | + |
---|
592 | if not transport.is_authenticated() and PASSWORD_AUTH and password: |
---|
593 | + auth_interactive() |
---|
594 | + |
---|
595 | + if not transport.is_authenticated() and PASSWORD_AUTH and password: |
---|
596 | auth_password() |
---|
597 | |
---|
598 | if not transport.is_authenticated() and AGENT_AUTH: |
---|
599 | auth_agent() |
---|
600 | |
---|
601 | - if not transport.is_authenticated() and KEY_AUTH: |
---|
602 | - auth_publickey() |
---|
603 | - |
---|
604 | if not transport.is_authenticated() and PASSWORD_AUTH and not password: |
---|
605 | for _ in range(1+PASSWORD_RETRY): |
---|
606 | password = input_pass("please enter the SSH password for %s@%s" % (username, host)) |
---|
607 | @@ -417,6 +467,10 @@ |
---|
608 | transport.close() |
---|
609 | raise InitException("SSH Authentication failed") |
---|
610 | |
---|
611 | + if(remote_xpra == None): |
---|
612 | + log("Opening proxy channel") |
---|
613 | + return transport.open_channel("direct-tcpip", (host, port), ('localhost', 0)) |
---|
614 | + |
---|
615 | assert len(remote_xpra)>0 |
---|
616 | log("will try to run xpra from: %s", remote_xpra) |
---|
617 | for xpra_cmd in remote_xpra: |
---|