Set-OPS-Public/scripts/carte/gabarit.html

769 lines
48 KiB
HTML
Raw Normal View History

<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
<title>Carte céleste des réseaux</title>
<!-- GENERE par scripts/carte_reseaux.py (make carte). Ne pas editer : regenerer.
Page autonome : polices embarquees (OFL), aucun appel exterieur. Elle porte des adresses
internes : ne pas la publier. -->
<style>
/*__POLICES__*/
</style>
<style>
/* Un atlas céleste : chaque site est une colonne du ciel, sa frontière un astre majeur, ses
zones des nébuleuses ; les VRF des locataires sont des bandes sous les hyperviseurs.
Un seul monde visuel, la nuit : thème sombre assumé. */
:root {
color-scheme: dark;
--nuit: #0A0E1C;
--nuit-2: #121831;
--nuit-3: #1B2346;
--astre: #F2ECDD;
--astre-2:#BEC0D4;
--astre-3:#7D83A6;
--filet: #2C3560;
--or: #F2C878;
--site: #8FC4FF;
--t0: #7FE3B6;
--t1: #E9A3DA;
--t2: #F0B37E;
--t3: #C8E07A;
--tunnel: #B7A2FF;
--f-titre: "IM Fell English SC", "IM Fell English", Georgia, serif;
--f-orne: "IM Fell English", Georgia, serif;
--f-txt: "Spectral", Georgia, "Times New Roman", serif;
--f-mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
}
html, body { background: var(--nuit); color: var(--astre); margin: 0; }
body { font-family: var(--f-txt); font-size: 16px; line-height: 1.55; -webkit-font-smoothing: antialiased; }
.page { max-width: 96rem; margin: 0 auto; padding-inline: clamp(16px, 3vw, 40px); padding-block: clamp(20px, 4vw, 48px) 56px;
display: flex; flex-direction: column; gap: 28px; }
header.tete { display: grid; gap: 10px; max-width: 62rem; }
.sur { font-family: var(--f-mono); font-size: .72rem; letter-spacing: .16em; text-transform: uppercase; color: var(--astre-3); }
h1 { font-family: var(--f-titre); font-weight: 400; font-size: clamp(2.2rem, 6vw, 4rem); line-height: 1.02; margin: 0;
letter-spacing: .01em; text-wrap: balance; }
h1 em { font-family: var(--f-orne); font-style: italic; color: var(--or); }
.chapeau { font-weight: 300; font-size: 1.12rem; color: var(--astre-2); max-width: 60ch; margin: 0; }
.compte { display: flex; flex-wrap: wrap; gap: 8px 18px; font-family: var(--f-mono); font-size: .8rem; color: var(--astre-2); margin-top: 4px; }
.compte b { color: var(--astre); font-weight: 400; }
.ciel { display: flex; flex-direction: column; gap: 10px; }
.outils { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.outils label { font-family: var(--f-mono); font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--astre-3); }
.outils input { flex: 1 1 16rem; min-width: 0; max-width: 26rem; background: var(--nuit-2); border: 1px solid var(--filet); color: var(--astre);
font-family: var(--f-mono); font-size: .85rem; padding: 8px 10px; border-radius: 3px; }
.outils input::placeholder { color: var(--astre-3); }
.outils button { background: var(--nuit-2); border: 1px solid var(--filet); color: var(--astre); font-family: var(--f-mono);
font-size: .85rem; padding: 7px 11px; border-radius: 3px; cursor: pointer; min-width: 2.4rem; }
.outils button:hover { border-color: var(--or); color: var(--or); }
.outils :focus-visible, .registre summary:focus-visible { outline: 2px solid var(--or); outline-offset: 2px; }
.outils .trouve { font-family: var(--f-mono); font-size: .78rem; color: var(--astre-3); }
.cadre { position: relative; border: 1px solid var(--filet); border-radius: 4px; overflow: hidden; background: var(--nuit);
height: min(80vh, 980px); min-height: 420px; touch-action: none; cursor: grab; }
.cadre.tire { cursor: grabbing; }
.cadre svg { display: block; width: 100%; height: 100%; user-select: none; }
.aide { font-family: var(--f-mono); font-size: .72rem; color: var(--astre-3); }
svg text { font-family: var(--f-txt); fill: var(--astre); }
.t-region { font-family: var(--f-titre); fill: var(--astre); opacity: .055; letter-spacing: .18em; }
.t-astre { font-family: var(--f-titre); font-size: 26px; fill: var(--or); }
.t-astre-s { font-family: var(--f-orne); font-style: italic; font-size: 14px; fill: var(--astre-2); }
.t-zone { font-family: var(--f-titre); font-size: 17px; }
.t-mono { font-family: var(--f-mono); font-size: 11.5px; fill: var(--astre-2); }
.t-mono-f { font-family: var(--f-mono); font-size: 11px; fill: var(--astre-3); }
.t-vm { font-size: 13px; fill: var(--astre); }
.t-ip { font-family: var(--f-mono); font-size: 11.5px; fill: var(--astre-2); }
.t-cart { font-family: var(--f-titre); font-size: 15px; fill: var(--astre); }
.t-ligne { font-family: var(--f-orne); font-style: italic; font-size: 13px; fill: var(--astre-2); }
.t-horizon { font-family: var(--f-titre); font-size: 15px; letter-spacing: .6em; fill: var(--astre-3); }
.t-pub { font-family: var(--f-mono); font-size: 12px; fill: var(--astre); }
.t-pub-s { font-family: var(--f-orne); font-style: italic; font-size: 12.5px; fill: var(--astre-3); }
.fond-etoile { fill: var(--astre); }
.rayon { fill: none; stroke: var(--or); stroke-width: 1; opacity: .28; }
.trame { fill: none; stroke: var(--astre-3); stroke-width: .8; opacity: .45; }
.anycast { fill: none; stroke: var(--site); stroke-width: 1; stroke-dasharray: 2 5; opacity: .5; }
.transit { stroke: var(--or); stroke-width: 2; opacity: .55; }
.tun { fill: none; stroke: var(--tunnel); stroke-width: 1.6; stroke-dasharray: 6 4; opacity: .85; }
.arc-sites { fill: none; stroke: url(#aurore); stroke-width: 3.5; filter: url(#lueur); }
.pub-fil { fill: none; stroke: var(--astre-3); stroke-width: .8; stroke-dasharray: 1 4; opacity: .9; }
.constel { fill: none; stroke-width: .8; opacity: .45; }
.cart-fond { fill: var(--nuit-2); fill-opacity: .82; stroke: var(--filet); stroke-width: 1; }
.bande { fill: var(--nuit); fill-opacity: .78; stroke-width: 1.2; }
.bande.fantome { fill-opacity: .55; stroke-dasharray: 3 6; }
.neb-trait { fill: none; stroke-width: 1; stroke-dasharray: 2 4; opacity: .7; }
.vm .glyphe { filter: url(#lueur-f); }
.vm:hover .t-vm, .vm:focus .t-vm { fill: var(--or); }
.vm:focus { outline: none; }
svg.cherche .vm, svg.cherche .neb-titre { opacity: .18; transition: opacity .2s; }
svg.cherche .vm.touche { opacity: 1; }
svg.cherche .vm.touche .t-vm { fill: var(--or); }
svg.cherche .vm.touche .glyphe { transform-box: fill-box; transform-origin: center; transform: scale(1.8); }
.aurore-voile { opacity: .26; }
@media (prefers-reduced-motion: no-preference) {
.aurore-voile { animation: onde 14s ease-in-out infinite alternate; }
.scint { animation: scint 5s ease-in-out infinite alternate; }
}
@keyframes onde { from { opacity: .16; } to { opacity: .34; } }
@keyframes scint { from { opacity: .25; } to { opacity: .9; } }
.registre { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 34rem), 1fr)); gap: 18px; }
.registre details { background: var(--nuit-2); border: 1px solid var(--filet); border-radius: 4px; padding: 14px 16px; min-width: 0; }
.registre summary { cursor: pointer; list-style: none; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.registre summary::-webkit-details-marker { display: none; }
.registre summary h2 { font-family: var(--f-titre); font-weight: 400; font-size: 1.35rem; margin: 0; }
.registre summary .meta { font-family: var(--f-mono); font-size: .76rem; color: var(--astre-3); }
.registre summary::after { content: "+"; margin-left: auto; color: var(--astre-3); font-family: var(--f-mono); }
.registre details[open] summary::after { content: "−"; }
.pastille { display: inline-block; width: .7rem; height: .7rem; border-radius: 50%; transform: translateY(1px); }
.defile { overflow-x: auto; margin-top: 10px; }
table { border-collapse: collapse; width: 100%; font-size: .86rem; font-variant-numeric: tabular-nums; }
th { text-align: left; font-family: var(--f-mono); font-weight: 400; font-size: .68rem; letter-spacing: .12em; text-transform: uppercase;
color: var(--astre-3); padding: 6px 8px; border-bottom: 1px solid var(--filet); }
td { padding: 6px 8px; border-bottom: 1px solid var(--nuit-3); vertical-align: top; }
td.m { font-family: var(--f-mono); font-size: .8rem; color: var(--astre-2); white-space: nowrap; }
td.z { font-family: var(--f-titre); font-size: .98rem; white-space: nowrap; }
td .vmn { white-space: nowrap; }
td .vmn + .vmn::before { content: " · "; color: var(--astre-3); }
.vmn code { font-family: var(--f-mono); font-size: .78rem; color: var(--astre-2); }
.note { font-size: .9rem; color: var(--astre-2); margin: 10px 0 0; }
footer { display: grid; gap: 8px; font-size: .88rem; color: var(--astre-3); max-width: 75ch; border-top: 1px solid var(--filet); padding-top: 16px; }
footer code { font-family: var(--f-mono); font-size: .8rem; color: var(--astre-2); }
</style>
</head>
<body>
<div class="page">
<header class="tete">
<div class="sur" id="sur"></div>
<h1>Carte céleste <em>des réseaux</em></h1>
<p class="chapeau" id="chapeau"></p>
<div class="compte" id="compte"></div>
</header>
<section class="ciel" aria-label="Carte des réseaux">
<div class="outils">
<label for="q">Chercher</label>
<input id="q" type="search" placeholder="un nom ou une adresse : dns, 10.17.19, mon-01…" autocomplete="off">
<span class="trouve" id="trouve" aria-live="polite"></span>
<button type="button" id="zplus" aria-label="Rapprocher">+</button>
<button type="button" id="zmoins" aria-label="Éloigner">−</button>
<button type="button" id="zfit" aria-label="Voir tout le ciel">Tout</button>
<button type="button" id="zplein" aria-label="Plein écran">Plein écran</button>
</div>
<div class="cadre" id="cadre"><svg id="ciel" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Plan de la couche 3 : sites, locataires, zones, machines et adresses"></svg></div>
<div class="aide">Glisser pour se déplacer · molette ou +/− pour s'approcher · Entrée dans la recherche centre la première étoile trouvée · survoler une étoile donne son VMID et son nœud.</div>
</section>
<section class="registre" id="registre" aria-label="Registre des adresses"></section>
<footer id="pied"></footer>
</div>
<script>
const D = __DONNEES__;
const NS = "http://www.w3.org/2000/svg";
const svg = document.getElementById("ciel");
// --- outils de dessin ----------------------------------------------------------------------
function el(tag, attrs, parent) {
const e = document.createElementNS(NS, tag);
for (const k in attrs) if (attrs[k] !== undefined && attrs[k] !== null) e.setAttribute(k, attrs[k]);
(parent || svg).appendChild(e);
return e;
}
function tx(x, y, s, cls, parent, anchor) {
const t = el("text", { x, y, class: cls, "text-anchor": anchor || "middle" }, parent);
t.textContent = s;
return t;
}
function surChemin(id, texte, cls, dy, parent) {
const t = el("text", { class: cls, dy }, parent);
const p = el("textPath", { href: "#" + id, startOffset: "50%", "text-anchor": "middle" }, t);
p.textContent = texte;
}
const oct = ip => "." + String(ip || "").split("/")[0].split(".").pop();
const esc = s => String(s ?? "").replace(/[&<>"]/g, c => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" }[c]));
const majuscule = s => s ? s.charAt(0).toUpperCase() + s.slice(1) : s;
const nomEtoile = s => majuscule(String(s.etoile || "").replace(/\d+$/, ""));
function etoile4(x, y, r) {
const k = r * 0.22;
return `M${x},${y - r} Q${x + k},${y - k} ${x + r},${y} Q${x + k},${y + k} ${x},${y + r} Q${x - k},${y + k} ${x - r},${y} Q${x - k},${y - k} ${x},${y - r}Z`;
}
function etoile8(x, y, r) {
let d = "";
for (let i = 0; i < 16; i++) {
const a = -Math.PI / 2 + i * Math.PI / 8;
const rr = i % 2 ? r * 0.22 : (i % 4 ? r * 0.55 : r);
d += (i ? "L" : "M") + (x + rr * Math.cos(a)).toFixed(1) + "," + (y + rr * Math.sin(a)).toFixed(1);
}
return d + "Z";
}
function enLignes(items, max) {
const out = []; let cur = "";
for (const it of items) {
if (cur && (cur + " · " + it).length > max) { out.push(cur); cur = it; }
else cur = cur ? cur + " · " + it : it;
}
if (cur) out.push(cur);
return out;
}
// --- vocabulaire --------------------------------------------------------------------------
const NOMS_ZONE = { pilotage: "Pilotage", autorite: "Autorité", genome: "Génome", service: "Service",
sauvegarde: "Sauvegarde", supervision: "Supervision", publication: "Publication" };
const nomZone = n => { const k = String(n).replace(/^site-/, ""); return NOMS_ZONE[k] || majuscule(k); };
const NOMS_TZONE = { Frontiere: "Frontière", Identite: "Identité", Donnees: "Données", Observabilite: "Observabilité" };
const nomTZone = l => NOMS_TZONE[l] || l;
const COURT = { "transit-frontiere": "transit", "underlay-vxlan": "vxlan", management: "mgmt", "grappe-controle": "grappe" };
const court = n => COURT[n] || n;
// Une teinte par locataire, la même partout où il paraît (hébergé ou repris).
const nomsLoc = [...new Set(D.sites.flatMap(s => [...s.locataires, ...s.reprises].map(t => t.nom)))].sort();
const teinte = nom => "t" + (nomsLoc.indexOf(nom) % 4);
// --- géométrie ------------------------------------------------------------------------------
const CW = 104, RH = 56, CORRIDOR = 150, GAP_Z = 16, GAP_T = 26, FY = 330, MARGE = 40, ECART = 110;
function taille(n) {
const cols = n <= 1 ? 1 : 2, rows = Math.max(1, Math.ceil(n / 2));
return { cols, rows, w: cols === 1 ? 140 : 230, h: rows === 1 ? 100 : 156 };
}
const largeurCart = c => Math.min(470, Math.max(300, Math.max(c.titre.length * 7.6, ...c.lignes.map(l => l.length * 7)) + 34));
const hauteurCart = c => 30 + c.lignes.length * 17;
function ranger(zones, cible) {
const rangs = []; let cur = [], w = 0;
for (const z of zones) {
const zw = taille(z.vms.length).w;
if (cur.length && w + GAP_Z + zw + CORRIDOR > cible) { rangs.push(cur); cur = []; w = 0; }
w += (cur.length ? GAP_Z : 0) + zw; cur.push(z);
}
if (cur.length) rangs.push(cur);
return rangs.map(r => {
const larg = zs => zs.reduce((a, z) => a + taille(z.vms.length).w, 0) + Math.max(0, zs.length - 1) * GAP_Z;
let meilleur = null;
for (let k = 0; k <= r.length; k++) {
const wl = larg(r.slice(0, k)), wr = larg(r.slice(k));
if (!meilleur || Math.abs(wl - wr) < meilleur.ecart - 0.1) meilleur = { k, wl, wr, ecart: Math.abs(wl - wr) };
}
return { gauche: r.slice(0, meilleur.k), droite: r.slice(meilleur.k), wl: meilleur.wl, wr: meilleur.wr,
h: Math.max(...r.map(z => taille(z.vms.length).h)) };
});
}
function cartFabric(f, s) {
const hs = f.hotes.map(h => `${h.nom} ${oct(h.ip)}${h.etat === "reserve" ? " (réserve)" : ""}`);
return { titre: `${f.nom} · ${f.sous_reseau || "—"}`, couleur: f.tunnel ? "var(--tunnel)" : "var(--or)",
lignes: [`${f.tunnel ? "WireGuard" : (f.vlan ? "VLAN " + f.vlan : "non étiqueté")}${f.mtu ? " · MTU " + f.mtu : ""}`, ...enLignes(hs, 46)] };
}
function cartAdmins(s) {
const a = s.admins;
const arrivee = s.publiques.length ? [`point d'arrivée : ${s.publiques[0].ip}:${a.port}`] : [];
return { titre: `admins · ${a.reseau}`, couleur: "var(--tunnel)",
lignes: [`WireGuard :${a.port}${a.mtu ? " · MTU " + a.mtu : ""}`,
...enLignes([`${s.frontiere} ${oct(a.frontiere)}`, ...a.pairs.map(p => `${p.nom} ${oct(p.adresse)}`)], 46), ...arrivee] };
}
function cartTunnels(s) {
const l = [];
s.locataires.filter(t => t.tunnel && t.tunnel.reseau).forEach(t => {
l.push(`${t.tunnel.reseau} :${t.tunnel.port} · ${t.nom}`);
l.push(...enLignes(t.tunnel.pairs.map(p => `${p.nom} ${oct(p.adresse)}`), 42).map(x => " " + x));
});
return { titre: "tunnels des locataires", couleur: "var(--tunnel)", lignes: l };
}
// 1. Chaque colonne se mesure seule.
const cols = D.sites.map((s, i) => {
const c = { s, i };
// Les cartouches vont du côté libre : à l'opposé du relais (toujours dessiné à gauche des
// adresses), sinon à l'opposé du site pair. Un pair absent de la carte part du côté libre.
const pairs = s.liens.map(l => D.sites.findIndex(x => x.nom === l.pair.site)).filter(j => j >= 0);
const pairReel = pairs.length ? (pairs.some(j => j < i) ? -1 : 1) : 0;
c.coteCart = s.relais ? 1 : (pairReel ? -pairReel : -1);
c.cotePair = pairReel || -c.coteCart;
c.cartsSousArc = c.cotePair === c.coteCart;
const seulsHyp = f => f.hotes.length && f.hotes.every(h => h.role === "hyperviseur");
c.hautes = s.fabric.filter(f => !f.transit && f.fabric !== "stockage" && !seulsHyp(f)).map(f => cartFabric(f, s));
if (s.admins) c.hautes.push(cartAdmins(s));
c.basses = s.locataires.some(t => t.tunnel && t.tunnel.reseau) ? [cartTunnels(s)] : [];
const stock = s.fabric.filter(f => f.fabric === "stockage");
c.cartStock = stock.length ? { titre: `fabric de stockage${stock[0].mtu ? " · MTU " + stock[0].mtu : ""}`, couleur: "var(--astre-3)",
lignes: stock.map(f => `${f.nom} · VLAN ${f.vlan} · ${f.sous_reseau}`) } : null;
c.cartSdn = s.sdn && s.sdn.controleur ? { titre: `SDN ${s.sdn.controleur}`, couleur: "var(--site)",
lignes: [`ASN ${s.sdn.asn}`, "un VRF par locataire", "passerelle .1 anycast", "sur chaque hyperviseur"] } : null;
const wH = Math.max(0, ...c.hautes.map(largeurCart)), wB = Math.max(0, ...c.basses.map(largeurCart));
const wS = c.cartStock ? largeurCart(c.cartStock) : 0, wD = c.cartSdn ? largeurCart(c.cartSdn) : 0;
c.wH = wH; c.wB = wB; c.wS = wS; c.wD = wD;
const tw = t => t.zones.reduce((a, z) => a + taille(z.vms.length).w, 0) + (t.zones.length - 1) * GAP_T + 80;
c.largT = Math.max(0, ...s.locataires.map(tw));
c.rangs = ranger(s.zones, Math.max(1000, c.largT));
const nH = Math.max(1, s.hyperviseurs.length);
c.pasH = 300;
const demiH = (nH - 1) * c.pasH / 2 + 95;
const nPub = s.publiques.length;
c.largPub = (s.relais ? 190 : 0) + Math.max(0, nPub - 1) * 150;
const ext = [
[210 + (c.coteCart < 0 ? wH : 0), 210 + (c.coteCart > 0 ? wH : 0)],
[c.coteCart > 0 ? 210 + wB : 0, c.coteCart < 0 ? 210 + wB : 0],
...c.rangs.map(r => [CORRIDOR / 2 + r.wl, CORRIDOR / 2 + r.wr]),
[c.largT / 2, c.largT / 2],
[demiH + (wS ? wS + 30 : 0), demiH + (wD ? wD + 30 : 0)],
[c.largPub / 2 + 90, c.largPub / 2 + 90],
[s.reprises.length ? 470 : 0, s.reprises.length ? 470 : 0],
[520, 520],
];
c.extG = Math.max(...ext.map(e => e[0])); c.extD = Math.max(...ext.map(e => e[1]));
return c;
});
// 2. Les colonnes se posent côte à côte ; chacune déroule son ciel de haut en bas.
let xCourant = MARGE;
cols.forEach(c => {
c.gauche = xCourant; c.cx = xCourant + c.extG; c.droite = c.cx + c.extD; xCourant = c.droite + ECART;
let y = c.cartsSousArc ? FY + 40 : 186;
c.posHautes = c.hautes.map(k => { const p = { x: c.coteCart < 0 ? c.cx - 210 - c.wH : c.cx + 210, y, w: c.wH }; y += hauteurCart(k) + 10; return p; });
const basHautes = y;
y = FY + 40;
c.posBasses = c.basses.map(k => { const p = { x: c.coteCart > 0 ? c.cx - 210 - c.wB : c.cx + 210, y, w: c.wB }; y += hauteurCart(k) + 10; return p; });
const basBasses = y;
let yt = Math.max(FY + 160, basHautes + 50, basBasses + 50);
c.yRangs = c.rangs.map(r => { const cy = yt + 46 + r.h / 2; yt = cy + r.h / 2 + 40; return cy; });
c.TY = yt + 40;
c.HY = c.TY + 66;
const lignesH = Math.max(1, ...c.s.hyperviseurs.map(h => Object.keys(h.adresses).length + 1));
const basHyp = c.HY + 10 + 34 + lignesH * 15;
const basCarts = c.TY - 42 + Math.max(c.cartStock ? hauteurCart(c.cartStock) : 0, c.cartSdn ? hauteurCart(c.cartSdn) : 0);
y = Math.max(basHyp, basCarts) + 46;
c.bandes = c.s.locataires.map(t => {
const rangs = rangerT(t.zones, c.droite - c.gauche - 60);
const h = 64 + rangs.reduce((a, r) => a + 50 + r.h, 0) + 14;
const b = { t, y, h, rangs }; y += h + 24; return b;
});
c.fantomes = c.s.reprises.map(t => {
const h = Math.max(112, 34 + Math.ceil(t.zones.length / 3) * 40 + 18);
const b = { t, y, h }; y += h + 22; return b;
});
c.bas = y;
});
function rangerT(zones, largeur) {
const rangs = []; let cur = [], w = 0;
for (const z of zones) {
const zw = taille(z.vms.length).w;
if (cur.length && w + GAP_T + zw > largeur) { rangs.push(cur); cur = []; w = 0; }
w += (cur.length ? GAP_T : 0) + zw; cur.push(z);
}
if (cur.length) rangs.push(cur);
return rangs.map(r => ({ zones: r, w: r.reduce((a, z) => a + taille(z.vms.length).w, 0) + (r.length - 1) * GAP_T,
h: Math.max(...r.map(z => taille(z.vms.length).h)) }));
}
// La légende va sous la colonne la plus courte, si elle y tient ; sinon sous tout le ciel.
const LEG = { w: 900, h: 190 };
const plusCourte = cols.reduce((a, c) => (!a || c.bas < a.bas ? c : a), null);
const W = (cols.length ? cols[cols.length - 1].droite : 900) + MARGE;
let legende;
if (plusCourte && plusCourte.droite - plusCourte.gauche >= LEG.w) {
legende = { x: plusCourte.gauche + (plusCourte.droite - plusCourte.gauche - LEG.w) / 2, y: plusCourte.bas + 8 };
} else {
legende = { x: MARGE, y: Math.max(0, ...cols.map(c => c.bas)) + 10 };
}
const H = Math.max(legende.y + LEG.h + 30, ...cols.map(c => c.bas + 20));
// --- 3. dessin ------------------------------------------------------------------------------
const defs = el("defs", {});
defs.innerHTML = `
<linearGradient id="aurore" x1="0" x2="1" y1="0" y2="0">
<stop offset="0" stop-color="var(--t0)"/><stop offset=".5" stop-color="var(--tunnel)"/><stop offset="1" stop-color="var(--t1)"/>
</linearGradient>
<linearGradient id="voile" x1="0" x2="0" y1="0" y2="1">
<stop offset="0" stop-color="var(--t0)" stop-opacity="0"/><stop offset=".45" stop-color="var(--t0)" stop-opacity=".55"/>
<stop offset="1" stop-color="var(--tunnel)" stop-opacity="0"/>
</linearGradient>
<linearGradient id="voile2" x1="0" x2="0" y1="0" y2="1">
<stop offset="0" stop-color="var(--t1)" stop-opacity="0"/><stop offset=".5" stop-color="var(--tunnel)" stop-opacity=".5"/>
<stop offset="1" stop-color="var(--tunnel)" stop-opacity="0"/>
</linearGradient>
<radialGradient id="voie" cx=".5" cy=".5" r=".5">
<stop offset="0" stop-color="var(--nuit-3)" stop-opacity=".9"/><stop offset="1" stop-color="var(--nuit)" stop-opacity="0"/>
</radialGradient>
${["site", "t0", "t1", "t2", "t3"].map(c => `
<radialGradient id="neb-${c}" cx=".5" cy=".55" r=".55">
<stop offset="0" stop-color="var(--${c})" stop-opacity=".22"/><stop offset=".6" stop-color="var(--${c})" stop-opacity=".08"/>
<stop offset="1" stop-color="var(--${c})" stop-opacity="0"/>
</radialGradient>`).join("")}
<filter id="lueur" x="-20%" y="-50%" width="140%" height="200%">
<feGaussianBlur stdDeviation="4" result="b"/><feMerge><feMergeNode in="b"/><feMergeNode in="SourceGraphic"/></feMerge>
</filter>
<filter id="lueur-f" x="-200%" y="-200%" width="500%" height="500%">
<feGaussianBlur stdDeviation="2.2" result="b"/><feMerge><feMergeNode in="b"/><feMergeNode in="SourceGraphic"/></feMerge>
</filter>
<filter id="flou-large"><feGaussianBlur stdDeviation="28"/></filter>`;
const monde = el("g", { id: "monde" });
// Le fond : voie lactée, champ d'étoiles (tirage fixe : la même carte donne le même ciel), aurore.
(function fond() {
const g = el("g", { "aria-hidden": "true" }, monde);
el("rect", { x: -600, y: -600, width: W + 1200, height: H + 1200, fill: "var(--nuit)" }, g);
el("ellipse", { cx: W * .52, cy: H * .55, rx: W * .7, ry: 260, fill: "url(#voie)", transform: `rotate(-14 ${W * .52} ${H * .55})` }, g);
let s = 31037;
const alea = () => (s = (s * 16807) % 2147483647) / 2147483647;
const n = Math.round(W * H / 5800);
for (let i = 0; i < n; i++) {
const x = alea() * W, y = alea() * H, r = alea() < .93 ? alea() * .9 + .25 : alea() * 1.4 + 1;
const c = el("circle", { cx: x.toFixed(1), cy: y.toFixed(1), r: r.toFixed(2), class: "fond-etoile", opacity: (alea() * .55 + .15).toFixed(2) }, g);
if (i % 23 === 0) { c.setAttribute("class", "fond-etoile scint"); c.style.animationDelay = (alea() * 5).toFixed(2) + "s"; }
}
const a = el("g", { class: "aurore-voile", filter: "url(#flou-large)" }, g);
el("path", { d: `M-50,40 C ${W * .17},180 ${W * .33},-20 ${W * .5},110 S ${W * .83},10 ${W + 50},120 L ${W + 50},240 C ${W * .78},150 ${W * .62},250 ${W * .45},200 S ${W * .12},260 -50,170Z`, fill: "url(#voile)" }, a);
el("path", { d: `M${W * .12},0 C ${W * .29},120 ${W * .54},40 ${W * .7},140 S ${W * .95},60 ${W},90 L ${W},180 C ${W * .87},160 ${W * .7},240 ${W * .54},150 S ${W * .25},190 ${W * .12},90Z`, fill: "url(#voile2)" }, a);
})();
// L'horizon : au-dessus, Internet et les adresses publiques.
el("path", { d: `M0,168 Q ${W / 2},118 ${W},168`, fill: "none", stroke: "var(--astre-3)", "stroke-width": .8, opacity: .5 }, monde);
tx(W / 2, 40, "INTERNET", "t-horizon", monde);
tx(W / 2, 60, "au-dessus de l'horizon, les adresses publiques", "t-pub-s", monde);
// Le nom de chaque site, en filigrane.
cols.forEach(c => {
if (!c.yRangs.length) return;
const t = tx(c.cx, c.yRangs[c.yRangs.length - 1] + 120, `${nomEtoile(c.s).toUpperCase()} ${c.s.index}`, "t-region", monde);
t.setAttribute("font-size", Math.round(Math.min(150, (c.droite - c.gauche) / 7)));
});
const etoilesVM = [];
function nebuleuse(z, cx, cy, coul, titre, sous, ecosys, porteur) {
const t = taille(z.vms.length);
const g = el("g", { class: "neb" }, monde);
el("ellipse", { cx, cy, rx: t.w / 2 + 6, ry: t.h / 2 + 4, fill: `url(#neb-${coul})` }, g);
el("ellipse", { cx, cy, rx: t.w / 2, ry: t.h / 2, class: "neb-trait", stroke: `var(--${coul})` }, g);
const top = cy - t.h / 2;
const gt = el("g", { class: "neb-titre" }, g);
tx(cx, top - 40, titre, "t-zone", gt).setAttribute("fill", `var(--${coul})`);
tx(cx, top - 23, sous[0], "t-mono-f", gt);
tx(cx, top - 9, sous[1], "t-mono-f", gt);
const pos = z.vms.map((v, i) => {
const row = Math.floor(i / 2), col = i % 2;
const seul = (z.vms.length % 2 === 1) && i === z.vms.length - 1;
return [t.cols === 1 || seul ? cx : cx + (col ? CW / 2 : -CW / 2), cy - (t.rows - 1) * RH / 2 + row * RH];
});
if (pos.length > 1) el("path", { d: "M" + pos.map(p => `${p[0]},${p[1] - 11}`).join(" L"), class: "constel", stroke: `var(--${coul})` }, g);
z.vms.forEach((v, i) => {
const [x, y] = pos[i];
const gv = el("g", { class: "vm", tabindex: 0 }, g);
gv.dataset.k = `${v.nom} ${v.ip} ${ecosys} ${titre}`.toLowerCase();
gv.dataset.x = x; gv.dataset.y = y;
el("title", {}, gv).textContent = `${v.nom} — ${v.ip}\n${ecosys} · zone ${titre}\nVMID ${v.vmid ?? "—"} · nœud ${v.noeud ?? "—"}\npasserelle ${z.passerelle} (${porteur})`;
const gl = el("g", { class: "glyphe" }, gv);
el("path", { d: etoile4(x, y - 11, 8), fill: `var(--${coul})` }, gl);
el("circle", { cx: x, cy: y - 11, r: 1.8, fill: "var(--astre)" }, gl);
tx(x, y + 8, v.nom, "t-vm", gv);
tx(x, y + 22, v.ip, "t-ip", gv);
etoilesVM.push(gv);
});
}
function cartouche(p, c) {
const g = el("g", {}, monde);
const h = hauteurCart(c);
el("rect", { x: p.x, y: p.y, width: p.w, height: h, rx: 3, class: "cart-fond" }, g);
el("rect", { x: p.x, y: p.y, width: 3, height: h, fill: c.couleur, opacity: .8 }, g);
tx(p.x + 14, p.y + 20, c.titre, "t-cart", g, "start");
c.lignes.forEach((l, i) => tx(p.x + 14, p.y + 38 + i * 17, l, "t-mono", g, "start"));
return { ...p, h };
}
function astre(x, y, nom, sous) {
const g = el("g", {}, monde);
el("circle", { cx: x, cy: y, r: 34, fill: "var(--or)", opacity: .08 }, g);
el("circle", { cx: x, cy: y, r: 18, fill: "var(--or)", opacity: .14 }, g);
el("path", { d: etoile8(x, y, 26), fill: "var(--or)", filter: "url(#lueur)" }, g);
el("circle", { cx: x, cy: y, r: 3.5, fill: "var(--astre)" }, g);
tx(x, y + 52, nom, "t-astre", g);
sous.forEach((s, i) => tx(x, y + 72 + i * 17, s, i ? "t-mono-f" : "t-astre-s", g));
}
function petitAstre(x, y, nom, lignes, couleur, r) {
const g = el("g", {}, monde);
el("circle", { cx: x, cy: y, r: r + 8, fill: couleur, opacity: .1 }, g);
el("path", { d: etoile8(x, y, r), fill: couleur, filter: "url(#lueur-f)" }, g);
tx(x, y + r + 18, nom, "t-cart", g);
lignes.forEach((s, i) => tx(x, y + r + 34 + i * 15, s, "t-mono-f", g));
}
// Les liens entre les sites : un arc d'aurore entre deux frontières de la carte, ou un départ
// vers un site qu'elle ne montre pas.
cols.forEach(c => c.s.liens.forEach((l, k) => {
const j = cols.findIndex(o => o.s.nom === l.pair.site);
if (j >= 0 && j < c.i) return; // dessiné depuis l'autre bout
const id = `lien-${c.i}-${k}`;
const reciproque = j >= 0 ? cols[j].s.liens.find(m => m.pair.site === c.s.nom) : null;
const initie = l.pair.point_arrivee ? `${l.local.nom} l'initie vers ${l.pair.point_arrivee}`
: (reciproque && reciproque.pair.point_arrivee ? `${reciproque.local.nom} l'initie vers ${reciproque.pair.point_arrivee}` : "");
const sous = [l.dns_public ? "réplication du DNS public" : "", initie].filter(Boolean).join(" · ");
if (j >= 0) {
const o = cols[j], ax = c.cx + 30, bx = o.cx - 30, d = bx - ax, hy = 200 - 30 * (j - c.i - 1);
el("path", { d: `M${ax},${FY - 10} C ${ax + d * .3},${hy} ${bx - d * .4},${hy} ${bx},${FY - 10}`, class: "arc-sites", id }, monde);
tx(ax + 16, FY - 30, oct(l.local.ip), "t-mono", monde, "start");
tx(bx - 10, FY + 4, oct(l.pair.ip), "t-mono", monde, "end");
} else {
const s = c.cotePair, bx = c.cx + s * ((s > 0 ? c.extD : c.extG) - 20), ax = c.cx + s * 30;
el("path", { d: `M${ax},${FY - 10} C ${ax + s * 200},${210} ${bx - s * 160},${210} ${bx},${200}`, class: "arc-sites", id }, monde);
tx(bx, 186, `vers ${l.pair.site} · ${l.pair.nom} ${oct(l.pair.ip)}`, "t-ligne", monde, s > 0 ? "end" : "start");
tx(ax + s * 16, FY - 30, oct(l.local.ip), "t-mono", monde, s > 0 ? "start" : "end");
}
surChemin(id, `inter-sites · ${l.sous_reseau} · WireGuard${l.mtu ? " · MTU " + l.mtu : ""}`, "t-ligne", -10, monde);
if (sous) surChemin(id, sous, "t-mono-f", 20, monde);
}));
cols.forEach(c => {
const s = c.s, cx = c.cx;
// Les adresses publiques du site, et le relais s'il les lui apporte.
const nP = s.publiques.length;
let x0 = cx - c.largPub / 2;
const nomsHeberges = new Set(s.locataires.map(t => t.nom)), nomsRepris = new Set(s.reprises.map(t => t.nom));
const quoi = p => p.pour === s.nom ? ["site" + (s.dns_public_nom && p === s.publiques[0] ? " · " + s.dns_public_nom : ""), false]
: p.pour === "libre" ? ["libre", true]
: nomsRepris.has(p.pour) && !nomsHeberges.has(p.pour) ? ["reprise · " + p.pour, false] : [p.pour, false];
if (s.relais) {
const rx = x0, ry = 98;
petitAstre(rx, ry, s.relais.nom, [`console ${s.relais.console}`], "var(--tunnel)", 11);
x0 += 190;
const id = `relais-${c.i}`;
el("path", { d: `M${rx + 8},${ry + 34} C ${rx + 120},${ry + 170} ${cx - 160},${FY - 120} ${cx - 26},${FY - 14}`, class: "tun", id }, monde);
surChemin(id, `${s.relais.nom} · ${s.relais.sous_reseau}${s.relais.mtu ? " · MTU " + s.relais.mtu : ""}`, "t-ligne", -6, monde);
tx(rx + 34, ry + 84, oct(s.relais.ip), "t-mono", monde, "start");
tx(cx - 50, FY - 34, oct(s.relais.ip_frontiere), "t-mono", monde, "end");
tx(x0 + (nP - 1) * 75, 152, `relayées par ${s.relais.nom} jusqu'à ${s.frontiere}`, "t-pub-s", monde);
}
s.publiques.forEach((p, i) => {
const x = x0 + i * 150, y = 98, [legende, libre] = quoi(p);
const vers = s.relais ? `M${x - 6},${y} Q ${(x + x0 - 190) / 2},${y + 30} ${x0 - 176},${y}` : `M${x},${y + 8} Q ${(x + cx) / 2},${(y + FY) / 2 - 10} ${cx},${FY - 30}`;
el("path", { d: vers, class: "pub-fil", opacity: libre ? .35 : .9 }, monde);
el("path", { d: etoile4(x, y, libre ? 5 : 7), fill: libre ? "var(--astre-3)" : (s.relais ? "var(--tunnel)" : "var(--or)"), filter: "url(#lueur-f)" }, monde);
tx(x, y - 16, p.ip, "t-pub", monde).setAttribute("opacity", libre ? .55 : 1);
tx(x, y + 26, legende, "t-pub-s", monde);
});
// Les rayons de la frontière vers ses zones, puis les zones.
const poser = (r, cy, dessin) => {
let x = cx - CORRIDOR / 2;
for (let i = r.gauche.length - 1; i >= 0; i--) { const w = taille(r.gauche[i].vms.length).w; dessin(r.gauche[i], x - w / 2, cy); x -= w + GAP_Z; }
x = cx + CORRIDOR / 2;
for (const z of r.droite) { const w = taille(z.vms.length).w; dessin(z, x + w / 2, cy); x += w + GAP_Z; }
};
c.rangs.forEach((r, k) => poser(r, c.yRangs[k], (z, zx, zy) =>
el("path", { d: `M${cx},${FY + 30} Q ${(cx + zx) / 2},${FY + 70} ${zx},${zy - r.h / 2 - 52}`, class: "rayon" }, monde)));
c.rangs.forEach((r, k) => poser(r, c.yRangs[k], (z, zx, zy) =>
nebuleuse(z, zx, zy, "site", nomZone(z.nom), [z.sous_reseau, `VLAN ${z.vlan}`], s.nom, s.frontiere)));
const dom = s.domaine && s.domaine !== s.etoile ? `${s.domaine} → ${s.etoile}` : s.etoile;
astre(cx, FY, s.frontiere, [`${s.opnsense ? "OPNsense · " : ""}frontière de ${s.nom}`, `${dom} · .1 sur ${s.zones.length} zones`]);
c.hautes.forEach((k, n) => { const p = cartouche(c.posHautes[n], k);
const bord = c.coteCart < 0 ? p.x + p.w : p.x;
el("path", { d: `M${bord},${p.y + p.h / 2} Q ${bord - c.coteCart * 110},${p.y + p.h / 2} ${cx + c.coteCart * 34},${FY}`, class: "trame" }, monde); });
c.basses.forEach((k, n) => { const p = cartouche(c.posBasses[n], k);
const bord = c.coteCart > 0 ? p.x + p.w : p.x;
el("path", { d: `M${bord},${p.y + p.h / 2} Q ${bord + c.coteCart * 90},${p.y + 20} ${cx - c.coteCart * 34},${FY + 6}`, class: "trame" }, monde); });
// Le transit et les hyperviseurs.
const TY = c.TY, HY = c.HY;
const xT0 = c.gauche + (c.wS ? c.wS + 30 : 60), xT1 = c.droite - (c.wD ? c.wD + 30 : 60);
el("line", { x1: xT0, y1: TY, x2: xT1, y2: TY, class: "transit" }, monde);
el("line", { x1: cx, y1: FY + 100, x2: cx, y2: TY, class: "transit", "stroke-dasharray": "2 5" }, monde);
if (s.transit.nom) tx(xT0 + 8, TY - 8, `${s.transit.nom} · VLAN ${s.transit.vlan} · ${s.transit.sous_reseau}`, "t-ligne", monde, "start");
tx(cx + 8, TY - 8, `${oct(s.transit.sortie)} ${s.frontiere}`, "t-mono", monde, "start");
const ft = s.fabric.find(f => f.transit);
const autres = ft ? ft.hotes.filter(h => h.role === "frontiere" && h.nom !== s.frontiere) : [];
if (autres.length) tx(xT1 - 4, TY + 18, autres.map(h => `${h.nom} ${oct(h.ip)}${h.etat === "reserve" ? " (réserve)" : ""}`).join(" · "), "t-mono-f", monde, "end");
const n = s.hyperviseurs.length;
const sorties = (s.sdn && s.sdn.noeuds_de_sortie) || [];
c.xHyp = s.hyperviseurs.map((h, k) => cx + (k - (n - 1) / 2) * c.pasH);
s.hyperviseurs.forEach((h, k) => {
const x = c.xHyp[k];
el("line", { x1: x, y1: TY, x2: x, y2: HY - 14, class: "transit", opacity: .4 }, monde);
const role = sorties.includes(h.nom) ? (n === 1 ? "sortie unique" : h.nom === s.sdn.sortie_primaire ? "sortie primaire" : "sortie") : "";
petitAstre(x, HY, h.nom, [...Object.entries(h.adresses).map(([r, ip]) => `${court(r)} ${ip}`), role].filter(Boolean), "var(--site)", 10);
});
if (c.cartStock) cartouche({ x: c.gauche, y: TY - 42, w: c.wS }, c.cartStock);
if (c.cartSdn) cartouche({ x: c.droite - c.wD, y: TY - 42, w: c.wD }, c.cartSdn);
// Les VRF des locataires hébergés.
c.bandes.forEach(b => {
const t = b.t, coul = teinte(t.nom), g = el("g", {}, monde);
c.xHyp.forEach(x => el("path", { d: `M${x},${HY + 60} C ${x},${b.y - 30} ${x},${b.y - 30} ${x + (cx - x) * .15},${b.y}`, class: "anycast" }, g));
el("rect", { x: c.gauche, y: b.y, width: c.droite - c.gauche, height: b.h, rx: 26, class: "bande", stroke: `var(--${coul})`, "stroke-opacity": .55 }, g);
const tt = tx(c.gauche + 26, b.y + 32, `VRF ${t.vrf}`, "t-zone", g, "start"); tt.setAttribute("fill", `var(--${coul})`); tt.setAttribute("font-size", 22);
tx(c.gauche + 120, b.y + 32, `${t.nom} · ${t.domaine} · ${t.supernet} · VNI ${t.vni}`, "t-mono", g, "start");
const droite = [t.ip_publique ? `face publique ${t.ip_publique}` : "", t.dns_public && t.dns_public.primaire ? `DNS public ${t.dns_public.primaire}:${t.dns_public.port}` : ""].filter(Boolean).join(" · ");
if (droite) tx(c.droite - 24, b.y + 52, droite, "t-mono-f", g, "end");
let y = b.y + 64;
b.rangs.forEach(r => {
const cy = y + 50 + r.h / 2;
let x = cx - r.w / 2;
r.zones.forEach(z => {
const w = taille(z.vms.length).w;
nebuleuse(z, x + w / 2, cy, coul, nomTZone(z.libelle), [z.sous_reseau, `${z.vnet} · VNI ${z.tag}`], t.nom, "anycast " + t.vrf);
x += w + GAP_T;
});
y = cy + r.h / 2;
});
});
// Les VRF que ce site peut reprendre : réservées, rien n'y tourne.
c.fantomes.forEach(b => {
const t = b.t, coul = teinte(t.nom), g = el("g", {}, monde);
c.xHyp.forEach(x => el("path", { d: `M${x},${HY + 60} C ${x},${b.y - 20} ${x},${b.y - 20} ${x + (cx - x) * .2},${b.y}`, class: "anycast", opacity: .35 }, g));
el("rect", { x: c.gauche, y: b.y, width: c.droite - c.gauche, height: b.h, rx: 22, class: "bande fantome", stroke: `var(--${coul})`, "stroke-opacity": .5 }, g);
const tt = tx(c.gauche + 26, b.y + 32, `VRF ${t.vrf} · reprise`, "t-zone", g, "start"); tt.setAttribute("fill", `var(--${coul})`); tt.setAttribute("opacity", .75);
tx(c.gauche + 26, b.y + 56, `${t.nom} · ${t.supernet} · mêmes zones, mêmes adresses`, "t-mono", g, "start");
tx(c.gauche + 26, b.y + 78, `aucune machine en temps normal${t.ip_publique ? " · face publique de reprise " + t.ip_publique : ""}`, "t-mono-f", g, "start");
t.zones.forEach((sr, i) => {
const x = c.droite - 3 * 120 + 40 + (i % 3) * 120, y = b.y + 34 + Math.floor(i / 3) * 40;
el("ellipse", { cx: x, cy: y, rx: 52, ry: 15, fill: `url(#neb-${coul})`, stroke: `var(--${coul})`, "stroke-opacity": .35, "stroke-dasharray": "2 4" }, g);
tx(x, y + 4, sr.replace(".0/24", ""), "t-mono-f", g);
});
});
});
// La légende.
(function () {
const { x: x0, y: y0 } = legende, g = el("g", {}, monde);
el("rect", { x: x0, y: y0, width: LEG.w, height: LEG.h, rx: 4, class: "cart-fond" }, g);
tx(x0 + 22, y0 + 28, "Légende", "t-cart", g, "start");
const items = [["astre", "var(--or)", "frontière : porte le .1 de chaque zone de son site"], ["e4", "var(--site)", "machine d'un site · zone en bleu"],
...nomsLoc.map(n => ["e4", `var(--${teinte(n)})`, `machine de ${n}`]),
["tun", "", "tunnel WireGuard"], ["tr", "", "transit : la seule sortie des VRF"], ["any", "", "passerelle anycast du SDN"], ["arc", "", "lien entre les sites"]];
items.forEach(([k, c, s], i) => {
const x = x0 + 30 + (i % 2) * 440, y = y0 + 58 + Math.floor(i / 2) * 28;
if (k === "astre") el("path", { d: etoile8(x, y - 4, 10), fill: c }, g);
if (k === "e4") el("path", { d: etoile4(x, y - 4, 7), fill: c }, g);
if (k === "tun") el("line", { x1: x - 14, y1: y - 4, x2: x + 14, y2: y - 4, class: "tun" }, g);
if (k === "tr") el("line", { x1: x - 14, y1: y - 4, x2: x + 14, y2: y - 4, class: "transit" }, g);
if (k === "any") el("line", { x1: x - 14, y1: y - 4, x2: x + 14, y2: y - 4, class: "anycast", opacity: 1 }, g);
if (k === "arc") el("rect", { x: x - 14, y: y - 6, width: 28, height: 4, rx: 2, fill: "url(#aurore)" }, g);
tx(x + 26, y, s, "t-mono", g, "start");
});
})();
// --- 4. vue : déplacement et zoom ---------------------------------------------------------
const cadre = document.getElementById("cadre");
let vb = { x: 0, y: 0, w: W, h: H };
const poserVue = () => svg.setAttribute("viewBox", `${vb.x} ${vb.y} ${vb.w} ${vb.h}`);
function toutVoir() {
const r = cadre.getBoundingClientRect(), ratio = r.width / Math.max(1, r.height);
if (ratio > W / H) { vb.h = H; vb.w = H * ratio; vb.x = (W - vb.w) / 2; vb.y = 0; }
else { vb.w = W; vb.h = W / ratio; vb.x = 0; vb.y = (H - vb.h) / 2; }
poserVue();
}
function zoom(f, px, py) {
const r = cadre.getBoundingClientRect();
const fx = px === undefined ? .5 : (px - r.left) / r.width, fy = py === undefined ? .5 : (py - r.top) / r.height;
const nw = Math.min(Math.max(vb.w * f, 240), W * 2.2), nh = nw * vb.h / vb.w;
vb.x += (vb.w - nw) * fx; vb.y += (vb.h - nh) * fy; vb.w = nw; vb.h = nh;
poserVue();
}
function centrer(x, y, largeur) {
const r = cadre.getBoundingClientRect();
vb.w = largeur; vb.h = largeur * r.height / Math.max(1, r.width); vb.x = x - vb.w / 2; vb.y = y - vb.h / 2;
poserVue();
}
cadre.addEventListener("wheel", e => { e.preventDefault(); zoom(e.deltaY > 0 ? 1.15 : 1 / 1.15, e.clientX, e.clientY); }, { passive: false });
let tire = null;
cadre.addEventListener("pointerdown", e => { tire = { x: e.clientX, y: e.clientY, vx: vb.x, vy: vb.y }; cadre.setPointerCapture(e.pointerId); cadre.classList.add("tire"); });
cadre.addEventListener("pointermove", e => {
if (!tire) return;
const r = cadre.getBoundingClientRect();
vb.x = tire.vx - (e.clientX - tire.x) * vb.w / r.width; vb.y = tire.vy - (e.clientY - tire.y) * vb.h / r.height;
poserVue();
});
const lacher = () => { tire = null; cadre.classList.remove("tire"); };
cadre.addEventListener("pointerup", lacher);
cadre.addEventListener("pointercancel", lacher);
cadre.addEventListener("dblclick", e => zoom(1 / 1.8, e.clientX, e.clientY));
document.getElementById("zplus").onclick = () => zoom(1 / 1.3);
document.getElementById("zmoins").onclick = () => zoom(1.3);
document.getElementById("zfit").onclick = toutVoir;
document.getElementById("zplein").onclick = () => { const p = cadre.requestFullscreen ? cadre.requestFullscreen() : null; if (p && p.catch) p.catch(() => {}); };
document.addEventListener("fullscreenchange", () => setTimeout(toutVoir, 60));
window.addEventListener("resize", toutVoir);
toutVoir();
// --- 5. recherche ----------------------------------------------------------------------------
const q = document.getElementById("q"), trouve = document.getElementById("trouve");
q.addEventListener("input", () => {
const s = q.value.trim().toLowerCase(); let n = 0;
etoilesVM.forEach(g => { const ok = !!s && g.dataset.k.includes(s); g.classList.toggle("touche", ok); if (ok) n++; });
svg.classList.toggle("cherche", !!s);
trouve.textContent = s ? (n ? `${n} étoile${n > 1 ? "s" : ""}` : "aucune étoile") : "";
});
q.addEventListener("keydown", e => {
if (e.key !== "Enter") return;
const h = etoilesVM.find(g => g.classList.contains("touche"));
if (h) centrer(+h.dataset.x, +h.dataset.y, 900);
});
// --- 6. registre, en-tête, pied ------------------------------------------------------------------
const reg = document.getElementById("registre");
function bloc(titre, meta, coul, lignes, note) {
const d = document.createElement("details");
d.open = true;
d.innerHTML = `<summary><span class="pastille" style="background:var(--${coul})"></span><h2>${esc(titre)}</h2><span class="meta">${esc(meta)}</span></summary>
<div class="defile"><table><thead><tr><th>Zone</th><th>Réseau</th><th>Sous-réseau</th><th>Passerelle</th><th>Machines</th></tr></thead>
<tbody>${lignes.map(l => `<tr><td class="z">${esc(l[0])}</td><td class="m">${esc(l[1])}</td><td class="m">${esc(l[2])}</td><td class="m">${esc(l[3])}</td>
<td>${l[4].map(v => `<span class="vmn">${esc(v.nom)} <code>${esc(v.ip)}</code></span>`).join("")}</td></tr>`).join("")}</tbody></table></div>
${note ? `<p class="note">${esc(note)}</p>` : ""}`;
reg.appendChild(d);
}
D.sites.forEach(s => {
const l = s.zones.map(z => [nomZone(z.nom), `VLAN ${z.vlan}`, z.sous_reseau, `${z.passerelle} ${s.frontiere}`, z.vms]);
s.fabric.forEach(f => l.push([f.nom, f.tunnel ? "WireGuard" : (f.vlan ? `VLAN ${f.vlan}` : "non étiqueté"), f.sous_reseau || "—", f.mtu ? `MTU ${f.mtu}` : "",
f.hotes.map(h => ({ nom: h.nom + (h.etat === "reserve" ? " (réserve)" : ""), ip: h.ip }))]));
s.liens.forEach(k => l.push(["inter-sites", "WireGuard", k.sous_reseau, k.mtu ? `MTU ${k.mtu}` : "",
[{ nom: k.local.nom, ip: k.local.ip }, { nom: `${k.pair.nom} (${k.pair.site})`, ip: k.pair.ip }]]));
if (s.relais) l.push([s.relais.nom, "WireGuard", s.relais.sous_reseau, s.relais.mtu ? `MTU ${s.relais.mtu}` : "",
[{ nom: s.relais.nom, ip: s.relais.ip }, { nom: s.frontiere, ip: s.relais.ip_frontiere }]]);
if (s.admins) l.push(["admins", `WireGuard :${s.admins.port}`, s.admins.reseau, s.admins.mtu ? `MTU ${s.admins.mtu}` : "",
[{ nom: s.frontiere, ip: s.admins.frontiere }, ...s.admins.pairs.map(p => ({ nom: p.nom, ip: p.adresse }))]]);
const pub = s.publiques.map(p => `${p.ip} (${p.pour})`).join(", ");
const note = [pub ? `Adresses publiques${s.relais ? `, relayées par ${s.relais.nom} (${s.relais.console})` : ""} : ${pub}.` : "",
s.sdn && s.sdn.controleur ? `SDN ${s.sdn.controleur}, ASN ${s.sdn.asn}, nœuds ${s.noeuds.join(", ")}.` : "",
s.reprises.length ? `Peut reprendre : ${s.reprises.map(t => `${t.nom} (${t.vrf}, ${t.supernet})`).join(", ")}.` : "",
s.absents.length ? `Déclarés sans dépôt frère : ${s.absents.join(", ")}.` : ""].filter(Boolean).join(" ");
bloc(`Site ${nomEtoile(s)} · ${s.nom}`, `index ${s.index} · ${s.domaine} · ${s.frontiere}`, "site", l, note);
s.locataires.forEach(t => bloc(`Locataire ${t.nom}`, `VRF ${t.vrf} · VNI ${t.vni} · ${t.supernet} · ${t.domaine}`, teinte(t.nom),
t.zones.map(z => [nomTZone(z.libelle), `${z.vnet} · ${z.tag}`, z.sous_reseau, `${z.passerelle} anycast`, z.vms]),
[`Hébergé par ${s.nom}.`, t.ip_publique ? `Face publique ${t.ip_publique}.` : "",
t.tunnel && t.tunnel.reseau ? `Tunnel d'administration ${t.tunnel.reseau}, port ${t.tunnel.port} : ${t.tunnel.pairs.map(p => `${p.nom} ${p.adresse}`).join(", ") || "aucun pair"}.` : "",
t.dns_public && t.dns_public.primaire ? `DNS public primaire ${t.dns_public.primaire}:${t.dns_public.port} (${(t.dns_public.zones || []).join(", ")}).` : ""].filter(Boolean).join(" ")));
});
const tous = D.sites.flatMap(s => [s, ...s.locataires]);
const nVM = tous.reduce((a, g) => a + g.zones.reduce((b, z) => b + z.vms.length, 0), 0);
const nZ = tous.reduce((a, g) => a + g.zones.length, 0);
const nLoc = D.sites.reduce((a, s) => a + s.locataires.length, 0);
const bordure = [...D.sites.map(s => s.frontiere), ...D.sites.filter(s => s.relais).map(s => s.relais.nom)];
const nHyp = D.sites.reduce((a, s) => a + s.hyperviseurs.length, 0);
const PORTEES = { site: p => `${p} et ses locataires`, locataire: p => `${p}, vu de son site` };
document.getElementById("sur").textContent = `Couche 3 · ${D.portee ? PORTEES[D.portee_nature || "site"](D.portee) : "tous les sites"} · plans du ${D.date}`;
document.getElementById("chapeau").textContent = "Chaque frontière y est un astre majeur, chaque zone une nébuleuse, chaque machine une étoile qui porte son adresse. "
+ (D.sites.length > 1 ? "Chaque site porte le nom de son étoile : " : "Le site porte le nom de son étoile : ")
+ D.sites.map(s => `${nomEtoile(s)} pour l'index ${s.index}`).join(", ") + ".";
const pl = (n, s, p) => `<span><b>${n}</b> ${n > 1 ? p : s}</span>`;
document.getElementById("compte").innerHTML = pl(D.sites.length, "site", "sites") + pl(nLoc, "locataire hébergé", "locataires hébergés")
+ pl(nZ, "zone", "zones") + pl(nVM, "machine virtuelle", "machines virtuelles")
+ `<span><b>${bordure.length}</b> routeurs de bordure : ${esc(bordure.join(", "))}</span>` + pl(nHyp, "hyperviseur", "hyperviseurs");
const transitsPartages = [...new Set(D.sites.map(s => s.transit.sous_reseau).filter((sr, i, t) => sr && t.indexOf(sr) !== i))];
const provenance = [...D.sites, ...D.sites.flatMap(s => s.locataires)].map(g => `<code>${esc(g.nom)}@${esc(g.commit || "?")}</code>`);
document.getElementById("pied").innerHTML = `
<div>Tiré des dépôts le ${esc(D.date)}, sans saisie à la main : ${provenance.join(", ")}. Un <code>+</code> signale un dépôt qui portait des modifications non commitées.</div>
<div>Cette carte dit ce que les plans déclarent ; elle ne mesure rien. Le réel se confronte par <code>make underlay-plan</code>, <code>make sdn-plan</code> et <code>make frontiere-plan</code>.</div>
${D.portee_nature === "site" ? `<div>Portée : ${esc(D.portee)}, ses locataires et ses reprises. Les autres sites n'y figurent pas.</div>` : ""}
${D.portee_nature === "locataire" ? `<div>Portée : ${esc(D.portee)}. De son site, la carte ne montre que ce que la fiche du site lui offre déjà : le reste appartient à l'hébergeur.</div>` : ""}
${(D.hors_carte || []).length ? `<div>Hors de la carte : ${D.hors_carte.map(h => `<code>${esc(h.nom)}</code> (index ${esc(h.index)}, ${esc(h.raison)})`).join(", ")}.</div>` : ""}
${transitsPartages.length ? `<div>${esc(transitsPartages.join(", "))} : même adresse de transit sur plusieurs sites. Chaque site a le sien ; ils ne se voient jamais, seuls les tunnels inter-sites relient les sites.</div>` : ""}
<div>Généré par <code>make carte</code> (Set-OPS). Elle porte des adresses internes : la remettre en main propre, ou la verser au dépôt privé du site.</div>`;
</script>
</body>
</html>