diff --git a/dashboard/js/api.js b/dashboard/js/api.js index 20b0f1f..eb5c6d0 100644 --- a/dashboard/js/api.js +++ b/dashboard/js/api.js @@ -1,3 +1,14 @@ +// Échappe les valeurs serveur avant injection dans innerHTML +function esc(s) { + if (s == null) return '—'; + return String(s) + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + .replace(/'/g, '''); +} + const API = (() => { const BASE = ''; // même origine, proxy Nginx vers le serveur Go diff --git a/dashboard/js/app.js b/dashboard/js/app.js index 1489009..4546ba4 100644 --- a/dashboard/js/app.js +++ b/dashboard/js/app.js @@ -1,6 +1,7 @@ const App = (() => { let _ws = null; let _reconnectDelay = 1000; + let _reconnectTimer = null; let _serverConfig = null; // Tooltip global position:fixed @@ -62,7 +63,8 @@ const App = (() => { }; _ws.onclose = () => { - setTimeout(connectWS, _reconnectDelay); + clearTimeout(_reconnectTimer); + _reconnectTimer = setTimeout(connectWS, _reconnectDelay); _reconnectDelay = Math.min(_reconnectDelay * 2, 30000); }; } diff --git a/dashboard/js/grid.js b/dashboard/js/grid.js index 649f11b..06dcf65 100644 --- a/dashboard/js/grid.js +++ b/dashboard/js/grid.js @@ -61,12 +61,12 @@ const Grid = (() => { `; - return `
+ return `
${iconContent}
-
${agent.hostname}
-
${agent.ip || '—'}
+
${esc(agent.hostname)}
+
${esc(agent.ip) || '—'}
diff --git a/dashboard/js/popups.js b/dashboard/js/popups.js index 6a7b3a1..b8e624f 100644 --- a/dashboard/js/popups.js +++ b/dashboard/js/popups.js @@ -1,6 +1,7 @@ const Popups = (() => { let _currentAgentId = null; let _agentCfgData = null; + let _resizeObs = null; // ══ POPUP DÉTAIL ══ async function showDetail(agentId) { @@ -50,7 +51,7 @@ const Popups = (() => { const memPts = Charts.historyToMemPts(history); const smartBtn = metrics?.smart - ? `
+ ? `
SMART · @@ -116,8 +117,8 @@ const Popups = (() => {
INFORMATIONS
-
HOSTNAME
${agent.hostname}
-
ADRESSE IP
${agent.ip || '—'}
+
HOSTNAME
${esc(agent.hostname)}
+
ADRESSE IP
${esc(agent.ip) || '—'}
PROTOCOLES ACTIFS
${protos || '—'}
DERNIER CONTACT
${new Date(agent.last_seen * 1000).toLocaleTimeString('fr-FR')}
@@ -129,14 +130,16 @@ const Popups = (() => { }); // Resize → sauvegarder sur serveur + if (_resizeObs) _resizeObs.disconnect(); const pd = document.getElementById('popup-detail'); - new ResizeObserver(() => { + _resizeObs = new ResizeObserver(() => { API.putServerConfig({ ...App.serverConfig, popup_detail_w: pd.offsetWidth, popup_detail_h: pd.offsetHeight, }).catch(() => {}); - }).observe(pd); + }); + _resizeObs.observe(pd); document.getElementById('overlay-detail').style.display = 'flex'; }