feat: ajouter la prise en charge de ~/.ssh/config
Support minimum : Host, HostName, User, Port, IdentityFile, ProxyJump, ForwardAgent, ServerAliveInterval, ServerAliveCountMax. - app/openssh/config.py : load_openssh_hosts() lit ~/.ssh/config via paramiko.SSHConfig (gere nativement les blocs "Host *" fusionnes, les alias multiples sur une meme ligne Host, et l'expansion ~ des IdentityFile). Fichier absent = liste vide, pas une erreur. session_from_openssh_host() convertit un Host en Session PySSH (groupe "OpenSSH", cle si IdentityFile presente sinon authentification auto). - Nouvelle section "Configuration OpenSSH" dans le panneau lateral (SessionController), sous Sessions SSH : double-clic ou menu contextuel pour se connecter directement ou importer comme session (editeur pre-rempli, ajustable avant enregistrement) ; rafraichissement via le menu ⚙ ou le menu contextuel de l'hote. - ConnectionController.open_openssh_host() ouvre une connexion directe sans enregistrer de session, comme une connexion rapide. Le ProxyJump est detecte, affiche (badge "· via <bastion>", tooltip) et reporte dans les notes d'une session importee, mais pas encore applique automatiquement a la connexion : ce sera l'objet de la Phase 3 (Bastion / Jump Host), qui prendra en charge toutes ses sources (OpenSSH, session PySSH, config manuelle) via un mecanisme commun. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,7 @@ from app.local_terminal import DEFAULT_SHELL, SHELL_LABELS
|
||||
from app.dialogs.session_dialog import SessionDialog
|
||||
from app.dialogs.connect_prompt import ask_secret
|
||||
from app.services.ssh_target import detect_ssh_target
|
||||
from app.openssh.config import OpenSSHHost, session_from_openssh_host
|
||||
from app.controllers.broadcast_manager import BroadcastManager
|
||||
from app.ui.tabs import BaseTerminalTab, SessionTabWidget, SFTPTabWidget, LocalTerminalTabWidget
|
||||
|
||||
@@ -74,6 +75,11 @@ class ConnectionController(QObject):
|
||||
index = self.tabs.addTab(tab, f"📁 {session.name}")
|
||||
self.tabs.setCurrentIndex(index)
|
||||
|
||||
def open_openssh_host(self, host: OpenSSHHost) -> None:
|
||||
"""Connexion directe a un Host de ~/.ssh/config, sans l'enregistrer comme
|
||||
session. Le ProxyJump eventuel n'est pas encore applique (Phase 3)."""
|
||||
self.open_session(session_from_openssh_host(host))
|
||||
|
||||
def open_local_terminal(self, shell: str = DEFAULT_SHELL) -> None:
|
||||
tab = LocalTerminalTabWidget(shell)
|
||||
tab.sftp_requested.connect(self.quick_sftp)
|
||||
|
||||
@@ -16,15 +16,20 @@ from app.session_manager import SessionStore, Session
|
||||
from app.key_manager import KeyManager
|
||||
from app.local_terminal import SHELL_LABELS
|
||||
from app.dialogs.session_dialog import SessionDialog
|
||||
from app.openssh.config import (
|
||||
OpenSSHHost, default_config_path, load_openssh_hosts, session_from_openssh_host,
|
||||
)
|
||||
|
||||
SESSION_ROLE = Qt.UserRole + 10
|
||||
LOCAL_SHELL_ROLE = Qt.UserRole + 11
|
||||
OPENSSH_HOST_ROLE = Qt.UserRole + 12
|
||||
|
||||
|
||||
class SessionController(QObject):
|
||||
open_session_requested = Signal(object) # Session
|
||||
open_sftp_requested = Signal(object) # Session
|
||||
open_local_shell_requested = Signal(str) # identifiant de shell
|
||||
open_session_requested = Signal(object) # Session
|
||||
open_sftp_requested = Signal(object) # Session
|
||||
open_local_shell_requested = Signal(str) # identifiant de shell
|
||||
open_openssh_host_requested = Signal(object) # OpenSSHHost
|
||||
quick_sftp_requested = Signal()
|
||||
manage_keys_requested = Signal()
|
||||
manage_known_hosts_requested = Signal()
|
||||
@@ -35,11 +40,13 @@ class SessionController(QObject):
|
||||
key_manager: KeyManager,
|
||||
broadcast_button: QToolButton,
|
||||
parent_widget: QWidget | None = None,
|
||||
openssh_config_path=None,
|
||||
):
|
||||
super().__init__(parent_widget)
|
||||
self.session_store = session_store
|
||||
self.key_manager = key_manager
|
||||
self._parent_widget = parent_widget
|
||||
self._openssh_config_path = openssh_config_path or default_config_path()
|
||||
|
||||
self.widget = QWidget(parent_widget)
|
||||
layout = QVBoxLayout(self.widget)
|
||||
@@ -79,6 +86,8 @@ class SessionController(QObject):
|
||||
manage_menu = QMenu(manage_btn)
|
||||
manage_menu.addAction("Gestionnaire de cles SSH...", self.manage_keys_requested.emit)
|
||||
manage_menu.addAction("Gestionnaire des hotes connus...", self.manage_known_hosts_requested.emit)
|
||||
manage_menu.addSeparator()
|
||||
manage_menu.addAction("Rafraichir la configuration OpenSSH (~/.ssh/config)", self.reload)
|
||||
manage_btn.setMenu(manage_menu)
|
||||
toolbar.addWidget(manage_btn)
|
||||
|
||||
@@ -145,6 +154,33 @@ class SessionController(QObject):
|
||||
hint.setForeground(0, Qt.gray)
|
||||
sessions_header.addChild(hint)
|
||||
|
||||
openssh_header = QTreeWidgetItem(["⚙ Configuration OpenSSH"])
|
||||
openssh_header.setFlags(openssh_header.flags() & ~Qt.ItemIsSelectable)
|
||||
openssh_header.setFont(0, font)
|
||||
openssh_header.setToolTip(0, str(self._openssh_config_path))
|
||||
self.tree.addTopLevelItem(openssh_header)
|
||||
|
||||
hosts = load_openssh_hosts(self._openssh_config_path)
|
||||
for host in hosts:
|
||||
label = f"🖥 {host.alias} ({host.display_target})"
|
||||
if host.proxy_jump:
|
||||
label += f" · via {host.proxy_jump}"
|
||||
item = QTreeWidgetItem([label])
|
||||
item.setData(0, OPENSSH_HOST_ROLE, host)
|
||||
if host.proxy_jump:
|
||||
item.setToolTip(
|
||||
0,
|
||||
f"ProxyJump : {host.proxy_jump} (pas encore applique automatiquement, "
|
||||
"connexion directe pour l'instant)",
|
||||
)
|
||||
openssh_header.addChild(item)
|
||||
|
||||
if not hosts:
|
||||
hint = QTreeWidgetItem([f" (aucun host trouve dans {self._openssh_config_path})"])
|
||||
hint.setFlags(hint.flags() & ~Qt.ItemIsSelectable)
|
||||
hint.setForeground(0, Qt.gray)
|
||||
openssh_header.addChild(hint)
|
||||
|
||||
self.tree.expandAll()
|
||||
|
||||
def _session_from_item(self, item: QTreeWidgetItem) -> Session | None:
|
||||
@@ -160,6 +196,11 @@ class SessionController(QObject):
|
||||
return None
|
||||
return item.data(0, LOCAL_SHELL_ROLE)
|
||||
|
||||
def _openssh_host_from_item(self, item: QTreeWidgetItem) -> OpenSSHHost | None:
|
||||
if not item:
|
||||
return None
|
||||
return item.data(0, OPENSSH_HOST_ROLE)
|
||||
|
||||
def _on_tree_double_click(self, item: QTreeWidgetItem, _col: int) -> None:
|
||||
session = self._session_from_item(item)
|
||||
if session:
|
||||
@@ -168,12 +209,17 @@ class SessionController(QObject):
|
||||
shell = self._shell_from_item(item)
|
||||
if shell:
|
||||
self.open_local_shell_requested.emit(shell)
|
||||
return
|
||||
host = self._openssh_host_from_item(item)
|
||||
if host:
|
||||
self.open_openssh_host_requested.emit(host)
|
||||
|
||||
def _on_tree_context_menu(self, pos) -> None:
|
||||
item = self.tree.itemAt(pos)
|
||||
menu = QMenu(self.widget)
|
||||
session = self._session_from_item(item) if item else None
|
||||
shell = self._shell_from_item(item) if item else None
|
||||
openssh_host = self._openssh_host_from_item(item) if item else None
|
||||
|
||||
if session:
|
||||
connect_action = menu.addAction("🖥 Ouvrir un terminal SSH")
|
||||
@@ -198,6 +244,18 @@ class SessionController(QObject):
|
||||
action = menu.exec(self.tree.viewport().mapToGlobal(pos))
|
||||
if action == open_action:
|
||||
self.open_local_shell_requested.emit(shell)
|
||||
elif openssh_host:
|
||||
connect_action = menu.addAction("🖥 Se connecter")
|
||||
import_action = menu.addAction("Importer comme session PySSH...")
|
||||
menu.addSeparator()
|
||||
refresh_action = menu.addAction("🔄 Rafraichir la configuration")
|
||||
action = menu.exec(self.tree.viewport().mapToGlobal(pos))
|
||||
if action == connect_action:
|
||||
self.open_openssh_host_requested.emit(openssh_host)
|
||||
elif action == import_action:
|
||||
self.import_openssh_host(openssh_host)
|
||||
elif action == refresh_action:
|
||||
self.reload()
|
||||
else:
|
||||
new_action = menu.addAction("Nouvelle session...")
|
||||
action = menu.exec(self.tree.viewport().mapToGlobal(pos))
|
||||
@@ -230,3 +288,15 @@ class SessionController(QObject):
|
||||
) == QMessageBox.Yes:
|
||||
self.session_store.delete(session.id)
|
||||
self.reload()
|
||||
|
||||
# ---------- OpenSSH config ----------
|
||||
def import_openssh_host(self, host: OpenSSHHost) -> None:
|
||||
"""Ouvre l'editeur de session pre-rempli depuis ce Host, pour permettre
|
||||
d'ajuster avant d'enregistrer (comme une connexion rapide)."""
|
||||
dialog = SessionDialog(
|
||||
self.key_manager, session=session_from_openssh_host(host), parent=self._parent_widget,
|
||||
title=f"Importer « {host.alias} » comme session",
|
||||
)
|
||||
if dialog.exec():
|
||||
self.session_store.add(dialog.result_session())
|
||||
self.reload()
|
||||
|
||||
Reference in New Issue
Block a user