@@ -1078,6 +1078,8 @@ def _apri_rdp(self, nome: str, dati: dict):
10781078
10791079 def _apri_vnc (self , nome : str , dati : dict ):
10801080 self ._resolve_credentials (dati )
1081+ sftp_enabled = dati .get ("sftp_browser" , False )
1082+
10811083 if dati .get ("vnc_internal" , False ):
10821084 # Viewer integrato
10831085 def _salva_password_vnc (pwd : str ):
@@ -1095,16 +1097,81 @@ def _salva_password_vnc(pwd: str):
10951097 except Exception :
10961098 pass
10971099
1098- widget = VncWebWidget (
1099- host = dati .get ("host" ,"" ),
1100- port = dati .get ("port" ,"5900" ),
1101- password = dati .get ("password" ,"" ),
1102- color_depth = dati .get ("vnc_color" , 0 ),
1103- quality = dati .get ("vnc_quality" , 2 ),
1104- on_save_password = _salva_password_vnc ,
1105- )
1106- widget .show_all ()
1107- container = self ._sftp_browser_paned (widget , dati )
1100+ if sftp_enabled :
1101+ # Pannello SFTP differito: aperto solo dopo che VNC è connesso
1102+ # e solo se la porta SSH risponde.
1103+ ssh_host = dati .get ("host" , "" )
1104+ ssh_port = int (dati .get ("mon_ssh_port" , 22 ))
1105+ sftp_dati = dict (dati )
1106+ sftp_dati ["port" ] = ssh_port
1107+
1108+ ph_lbl = Gtk .Label (label = "In attesa della connessione VNC…" )
1109+ ph_lbl .set_valign (Gtk .Align .CENTER )
1110+ ph_lbl .set_halign (Gtk .Align .CENTER )
1111+ ph_lbl .set_line_wrap (True )
1112+ ph_lbl .set_margin_start (8 )
1113+ ph_lbl .set_margin_end (8 )
1114+ placeholder = Gtk .Box (orientation = Gtk .Orientation .VERTICAL )
1115+ placeholder .set_size_request (220 , - 1 )
1116+ placeholder .pack_start (ph_lbl , True , True , 0 )
1117+
1118+ paned = Gtk .Paned (orientation = Gtk .Orientation .HORIZONTAL )
1119+
1120+ def _on_vnc_ready ():
1121+ import socket as _sock
1122+ ph_lbl .set_text (f"Verifica SSH { ssh_host } :{ ssh_port } …" )
1123+
1124+ def _probe ():
1125+ try :
1126+ s = _sock .create_connection ((ssh_host , ssh_port ), timeout = 3 )
1127+ s .close ()
1128+ GLib .idle_add (_ssh_aperta )
1129+ except OSError :
1130+ GLib .idle_add (_ssh_chiusa )
1131+
1132+ def _ssh_aperta ():
1133+ sftp = SftpBrowserWidget (
1134+ sftp_dati ,
1135+ on_apri_editor = lambda c , p : self ._apri_sftp_editor (c , p ),
1136+ )
1137+ paned .remove (placeholder )
1138+ paned .pack2 (sftp , False , False )
1139+ sftp .show_all ()
1140+
1141+ def _ssh_chiusa ():
1142+ ph_lbl .set_markup (
1143+ f"<small>Porta SSH { ssh_port } \n non raggiungibile\n su { ssh_host } </small>"
1144+ )
1145+
1146+ threading .Thread (target = _probe , daemon = True ).start ()
1147+
1148+ widget = VncWebWidget (
1149+ host = dati .get ("host" , "" ),
1150+ port = dati .get ("port" , "5900" ),
1151+ password = dati .get ("password" , "" ),
1152+ color_depth = dati .get ("vnc_color" , 0 ),
1153+ quality = dati .get ("vnc_quality" , 2 ),
1154+ on_save_password = _salva_password_vnc ,
1155+ on_vnc_ready = _on_vnc_ready ,
1156+ )
1157+ widget .show_all ()
1158+ paned .pack1 (widget , True , True )
1159+ paned .pack2 (placeholder , False , True )
1160+ paned .set_position (700 )
1161+ paned .show_all ()
1162+ container = paned
1163+ else :
1164+ widget = VncWebWidget (
1165+ host = dati .get ("host" , "" ),
1166+ port = dati .get ("port" , "5900" ),
1167+ password = dati .get ("password" , "" ),
1168+ color_depth = dati .get ("vnc_color" , 0 ),
1169+ quality = dati .get ("vnc_quality" , 2 ),
1170+ on_save_password = _salva_password_vnc ,
1171+ )
1172+ widget .show_all ()
1173+ container = widget
1174+
11081175 container ._pcm_dati = dati
11091176 self ._append_tab (container , nome , lambda : self ._chiudi_tab (container ))
11101177 else :
@@ -1119,7 +1186,58 @@ def _salva_password_vnc(pwd: str):
11191186 widget = TerminalWidget .da_profilo (dati )
11201187 widget .comando_display = nome
11211188 widget .show_all ()
1122- container = self ._sftp_browser_paned (widget , dati )
1189+
1190+ if sftp_enabled :
1191+ # Pannello SFTP differito: probe SSH in background senza attendere VNC
1192+ ssh_host = dati .get ("host" , "" )
1193+ ssh_port = int (dati .get ("mon_ssh_port" , 22 ))
1194+ sftp_dati = dict (dati )
1195+ sftp_dati ["port" ] = ssh_port
1196+
1197+ ph_lbl = Gtk .Label (label = f"Verifica SSH { ssh_host } :{ ssh_port } …" )
1198+ ph_lbl .set_valign (Gtk .Align .CENTER )
1199+ ph_lbl .set_halign (Gtk .Align .CENTER )
1200+ ph_lbl .set_line_wrap (True )
1201+ ph_lbl .set_margin_start (8 )
1202+ ph_lbl .set_margin_end (8 )
1203+ placeholder = Gtk .Box (orientation = Gtk .Orientation .VERTICAL )
1204+ placeholder .set_size_request (220 , - 1 )
1205+ placeholder .pack_start (ph_lbl , True , True , 0 )
1206+
1207+ paned = Gtk .Paned (orientation = Gtk .Orientation .HORIZONTAL )
1208+ paned .pack1 (widget , True , True )
1209+ paned .pack2 (placeholder , False , True )
1210+ paned .set_position (700 )
1211+ paned .show_all ()
1212+ container = paned
1213+
1214+ def _ssh_aperta_ext ():
1215+ sftp = SftpBrowserWidget (
1216+ sftp_dati ,
1217+ on_apri_editor = lambda c , p : self ._apri_sftp_editor (c , p ),
1218+ )
1219+ paned .remove (placeholder )
1220+ paned .pack2 (sftp , False , False )
1221+ sftp .show_all ()
1222+
1223+ def _ssh_chiusa_ext ():
1224+ ph_lbl .set_markup (
1225+ f"<small>Porta SSH { ssh_port } \n non raggiungibile\n su { ssh_host } </small>"
1226+ )
1227+
1228+ def _probe_ext ():
1229+ import socket as _sock
1230+ try :
1231+ s = _sock .create_connection ((ssh_host , ssh_port ), timeout = 3 )
1232+ s .close ()
1233+ GLib .idle_add (_ssh_aperta_ext )
1234+ except OSError :
1235+ GLib .idle_add (_ssh_chiusa_ext )
1236+
1237+ threading .Thread (target = _probe_ext , daemon = True ).start ()
1238+ else :
1239+ container = widget
1240+
11231241 container ._pcm_dati = dati
11241242 self ._append_tab (container , nome )
11251243 GLib .idle_add (widget .grab_focus )
0 commit comments