Soportar autenticacion SSH por clave privada

This commit is contained in:
2026-06-03 00:49:10 +02:00
parent 8a0e1e83ed
commit ffdf787aa3
6 changed files with 86 additions and 14 deletions
+42 -2
View File
@@ -192,6 +192,20 @@
.field-id { grid-column: span 2; }
.field-role { grid-column: span 2; }
.field-location { grid-column: span 2; }
.field-auth { grid-column: span 1; }
.device[data-auth-method="password"] .key-credential { display: none; }
.device[data-auth-method="key"] .password-credential { display: none; }
.credential-note {
grid-column: span 2;
color: var(--muted);
font-size: 12px;
line-height: 1.35;
align-self: center;
}
.device[data-auth-method="key"] .credential-note strong { color: var(--info); }
.device[data-auth-method="password"] .credential-note strong { color: var(--ok); }
label {
display: grid;
@@ -547,8 +561,9 @@
const dashboardLink = document.querySelector("#dashboardLink");
function deviceTemplate(device, index) {
const authMethod = device.privateKeyPath ? "key" : "password";
return `
<div class="device" data-index="${index}">
<div class="device" data-index="${index}" data-auth-method="${authMethod}">
<label title="Si esta activo, este dispositivo se consulta por SSH. Si esta inactivo, se muestra deshabilitado y no se escanea.">Activo
<input data-field="active" type="checkbox" ${device.active ? "checked" : ""}>
</label>
@@ -561,9 +576,21 @@
<label title="Usuario SSH para este dispositivo.">Usuario
<input data-field="username" value="${device.username || ""}">
</label>
<label title="Password SSH. Se guarda en config.json dentro del volumen persistente.">Password
<label class="field-auth" title="Metodo de autenticacion SSH que usara el monitor para este dispositivo.">Auth SSH
<select data-auth-method>
<option value="password" ${authMethod === "password" ? "selected" : ""}>Password</option>
<option value="key" ${authMethod === "key" ? "selected" : ""}>Clave privada</option>
</select>
</label>
<label class="password-credential" title="Password SSH. Se guarda en config.json dentro del volumen persistente. Si eliges clave privada, se guardara vacio.">Password
<input data-field="password" type="password" value="${device.password || ""}">
</label>
<label class="key-credential" title="Ruta de la clave privada SSH dentro del contenedor. Ejemplo: /ssh/carabanes_monitor_ed25519. Si eliges password, se guardara vacia.">Clave privada
<input data-field="privateKeyPath" value="${device.privateKeyPath || ""}">
</label>
<div class="credential-note">
Metodo activo: <strong>${authMethod === "key" ? "Clave privada" : "Password"}</strong>
</div>
<label class="field-id" title="Identificador interno unico. Se usa para tracking de metricas como red.">ID
<input data-field="id" value="${device.id || ""}">
</label>
@@ -652,6 +679,9 @@
else if (input.type === "number") device[field] = Number(input.value);
else device[field] = input.value;
});
const authMethod = row.querySelector("[data-auth-method]")?.value || "password";
if (authMethod === "key") device.password = "";
else device.privateKeyPath = "";
return device;
});
}
@@ -702,6 +732,7 @@
port: 22,
username: "pi",
password: "",
privateKeyPath: "",
model: "RPi 4",
role: "",
location: "Rack",
@@ -731,6 +762,15 @@
render();
});
devicesEl.addEventListener("change", (event) => {
const selector = event.target.closest("[data-auth-method]");
if (!selector) return;
const row = selector.closest(".device");
row.dataset.authMethod = selector.value;
const note = row.querySelector(".credential-note strong");
if (note) note.textContent = selector.value === "key" ? "Clave privada" : "Password";
});
load().catch((error) => {
statusEl.textContent = `Error cargando configuracion: ${error.message}`;
});