fix: SSHAuthenticator vide après installation + logs debug

Bug principal : l'SSHAuthenticator est créé au démarrage avec host=""
(DB vide avant installation). Après configure, il gardait host vide.
Le login lisait maintenant le ssh_host depuis la DB à chaque requête.

Logs ajoutés :
- ssh_auth.go : dial SSH, succès, échec avec détail d'erreur
- auth.go : host SSH utilisé, résultat auth à chaque login
- updates.go : credentials SSH, démarrage/fin de job
- terminal.go : ouverture/échec session SSH

Frontend :
- auth.store.ts : gère les réponses non-JSON sur erreur HTTP

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
enzo 2026-03-20 23:39:52 +01:00
parent 15965082ce
commit 07af66ad81
5 changed files with 46 additions and 7 deletions

View file

@ -5,6 +5,8 @@ package api
import (
"fmt"
"log"
"math/rand"
"net/http"
"time"
@ -14,7 +16,6 @@ import (
"git.geronzi.fr/proxmoxPanel/core/backend/internal/ssh"
"git.geronzi.fr/proxmoxPanel/core/backend/internal/websocket"
"github.com/go-chi/chi/v5"
"math/rand"
)
// UpdatesHandler contient les handlers de mises à jour.
@ -56,7 +57,9 @@ func (h *UpdatesHandler) RunUpdate(w http.ResponseWriter, r *http.Request) {
sshUser, _, _ := h.db.GetSetting("ssh_username")
encryptedPass, _, _ := h.db.GetSetting("ssh_password")
sshPass, _ := h.encryptor.Decrypt(encryptedPass)
log.Printf("[updates/run] Credentials SSH — host=%s user=%s password_len=%d", sshHost, sshUser, len(sshPass))
if sshHost == "" || sshUser == "" || sshPass == "" {
log.Printf("[updates/run] SSH non configuré — host=%q user=%q password_empty=%v", sshHost, sshUser, sshPass == "")
JSONError(w, "SSH non configuré", http.StatusServiceUnavailable)
return
}
@ -71,7 +74,7 @@ func (h *UpdatesHandler) RunUpdate(w http.ResponseWriter, r *http.Request) {
h.auditLogger.Log(&claims.UserID, claims.Username, "update_start", body.Target, nil, clientIP(r))
// Lancer la mise à jour en arrière-plan
log.Printf("[updates/run] Job %s démarré — target=%s user=%d", jobID, body.Target, claims.UserID)
go h.executeUpdate(jobID, body.Target, sshHost, sshUser, sshPass, claims.UserID)
JSONResponse(w, http.StatusAccepted, map[string]string{
@ -164,8 +167,14 @@ func (h *UpdatesHandler) executeUpdate(jobID, target, sshHost, sshUser, sshPass
}
// Lancer le streaming SSH
cmdPreview := command
if len(cmdPreview) > 80 {
cmdPreview = cmdPreview[:80] + "..."
}
log.Printf("[updates/execute] Job %s — SSH %s@%s commande: %s", jobID, sshUser, sshHost, cmdPreview)
err := h.sshPool.StreamCommand(sshHost, sshUser, sshPass, command, outputChan)
if err != nil {
log.Printf("[updates/execute] Job %s — Erreur SSH : %v", jobID, err)
h.db.Exec(`UPDATE update_history SET status='error', output=?, finished_at=CURRENT_TIMESTAMP WHERE job_id=?`,
"Erreur SSH : "+err.Error(), jobID)
h.hub.Publish("update:"+jobID, "update_error", map[string]string{"error": err.Error()})
@ -180,6 +189,7 @@ func (h *UpdatesHandler) executeUpdate(jobID, target, sshHost, sshUser, sshPass
}
// Finaliser le job
log.Printf("[updates/execute] Job %s — terminé (%d octets de sortie)", jobID, len(fullOutput))
h.db.Exec(`UPDATE update_history SET status='success', output=?, finished_at=CURRENT_TIMESTAMP WHERE job_id=?`,
fullOutput, jobID)
h.hub.Publish("update:"+jobID, "update_done", map[string]string{"job_id": jobID})