site-web-alliance-boreale/atlas/carte-des-reseaux.js
Daniel Allaire 035cc36418 site web : l'atlas du moteur, dessine pour une federation d'exemple
Cinq planches (identite, autorite, noms, courriel, sauvegardes) et la carte celeste des
reseaux, produites par Set-OPS (make atlas-public) pour deux sites et une cooperative qui
n'existent pas. Liees depuis la formation, l'Atelier et la Constellation ; set-ops.html de
Chezlepro y renvoie pilier par pilier.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 22:23:55 -05:00

615 lines
46 KiB
JavaScript

/* Genere par scripts/atlas_public.py. Les attributs `data-style` deviennent des styles par le
CSSOM : la CSP du site refuse l'attribut `style`, pas le CSSOM. */
(function () {
function appliquer(racine) {
if (racine.nodeType !== 1 && racine !== document) return;
var liste = racine.querySelectorAll ? Array.prototype.slice.call(racine.querySelectorAll('[data-style]')) : [];
if (racine.hasAttribute && racine.hasAttribute('data-style')) liste.push(racine);
liste.forEach(function (e) { e.style.cssText += ';' + e.getAttribute('data-style'); e.removeAttribute('data-style'); });
}
new MutationObserver(function (lot) {
lot.forEach(function (m) { Array.prototype.forEach.call(m.addedNodes, appliquer); });
}).observe(document.documentElement, { childList: true, subtree: true });
appliquer(document);
})();
const D = {"date": "2026-11-14", "portee": null, "portee_nature": null, "sites": [{"nom": "SITE-Exemple", "commit": "", "index": 62, "etoile": "liesma62", "domaine": "liesma62", "organisation": "", "frontiere": "frontiere-62", "opnsense": true, "dns_public_nom": null, "transit": {"nom": "transit-frontiere", "vlan": 40, "sous_reseau": "10.9.62.0/24", "sortie": "10.9.62.1"}, "hyperviseurs": [{"nom": "noeud-62a", "adresses": {"transit-frontiere": "10.9.62.11"}}, {"nom": "noeud-62b", "adresses": {"transit-frontiere": "10.9.62.12"}}], "sdn": {"asn": 65062, "controleur": "EVPN0062", "noeuds_de_sortie": ["noeud-62a"], "sortie_primaire": "noeud-62a"}, "noeuds": ["noeud-62a", "noeud-62b"], "publiques": [{"ip": "203.0.113.62", "pour": "SITE-Exemple"}, {"ip": "203.0.113.60", "pour": "OPS-Exemple"}], "relais": null, "admins": {"reseau": "10.62.29.0/24", "port": 51821, "mtu": 1412, "frontiere": "10.62.29.1", "pairs": [{"nom": "anne-portable", "adresse": "10.62.29.2"}]}, "liens": [{"sous_reseau": "198.18.62.0/30", "mtu": 1412, "local": {"nom": "frontiere-62", "ip": "198.18.62.1"}, "pair": {"nom": "frontiere-63", "ip": "198.18.62.2", "site": "SITE-Voisin", "point_arrivee": null}, "dns_public": true}], "fabric": [{"nom": "management", "vlan": null, "sous_reseau": "10.62.0.0/24", "mtu": 1500, "tunnel": null, "fabric": "principal", "transit": false, "description": "", "hotes": [{"nom": "frontiere-62", "ip": "10.62.0.1", "role": "frontiere"}]}, {"nom": "transit-frontiere", "vlan": 40, "sous_reseau": "10.9.62.0/24", "mtu": 1500, "tunnel": null, "fabric": "principal", "transit": true, "description": "", "hotes": [{"nom": "frontiere-62", "ip": "10.9.62.1", "role": "frontiere"}, {"nom": "noeud-62a", "ip": "10.9.62.11", "role": "hyperviseur"}, {"nom": "noeud-62b", "ip": "10.9.62.12", "role": "hyperviseur"}]}], "zones": [{"nom": "site-pilotage", "vlan": 31, "sous_reseau": "10.62.31.0/24", "passerelle": "10.62.31.1", "description": "", "vms": [{"nom": "site-ops-01", "ip": "10.62.31.11", "noeud": "noeud-62a", "vmid": 9031}]}, {"nom": "site-genome", "vlan": 33, "sous_reseau": "10.62.33.0/24", "passerelle": "10.62.33.1", "description": "", "vms": [{"nom": "site-forge-01", "ip": "10.62.33.11", "noeud": "noeud-62a", "vmid": 9033}]}, {"nom": "site-sauvegarde", "vlan": 35, "sous_reseau": "10.62.35.0/24", "passerelle": "10.62.35.1", "description": "", "vms": [{"nom": "site-backup-01", "ip": "10.62.35.11", "noeud": "noeud-62a", "vmid": 9035}]}], "locataires": [{"nom": "OPS-Exemple", "commit": "", "index": 60, "domaine": "exemple.internal", "vrf": "t60", "vni": 60, "supernet": "10.60.0.0/16", "ip_publique": "203.0.113.60", "tunnel": {"reseau": "10.60.29.0/24", "port": 52060, "pairs": [{"nom": "anne-portable", "adresse": "10.60.29.2"}]}, "dns_public": {"zones": ["coop.example"], "primaire": "10.60.19.11", "port": 5300}, "zones": [{"libelle": "Frontiere", "sous_reseau": "10.60.16.0/24", "passerelle": "10.60.16.1", "vnet": "t60fron", "tag": 1601, "vms": [{"nom": "infra-edge-01", "ip": "10.60.16.11", "noeud": "noeud-62a", "vmid": 60016011}, {"nom": "edge-mta-01", "ip": "10.60.16.21", "noeud": "noeud-62a", "vmid": 60016021}]}, {"libelle": "Identite", "sous_reseau": "10.60.17.0/24", "passerelle": "10.60.17.1", "vnet": "t60iden", "tag": 1602, "vms": [{"nom": "idm-01", "ip": "10.60.17.11", "noeud": "noeud-62a", "vmid": 60017011}]}, {"libelle": "Donnees", "sous_reseau": "10.60.18.0/24", "passerelle": "10.60.18.1", "vnet": "t60donn", "tag": 1603, "vms": [{"nom": "data-sql-01", "ip": "10.60.18.11", "noeud": "noeud-62a", "vmid": 60018011}]}, {"libelle": "Services-infra", "sous_reseau": "10.60.19.0/24", "passerelle": "10.60.19.1", "vnet": "t60serv", "tag": 1604, "vms": [{"nom": "infra-dns-01", "ip": "10.60.19.11", "noeud": "noeud-62a", "vmid": 60019011}, {"nom": "infra-pki-01", "ip": "10.60.19.21", "noeud": "noeud-62a", "vmid": 60019021}, {"nom": "infra-mail-01", "ip": "10.60.19.31", "noeud": "noeud-62a", "vmid": 60019031}, {"nom": "ops-01", "ip": "10.60.19.41", "noeud": "noeud-62a", "vmid": 60019041}]}, {"libelle": "Observabilite", "sous_reseau": "10.60.20.0/24", "passerelle": "10.60.20.1", "vnet": "t60obse", "tag": 1605, "vms": [{"nom": "obs-01", "ip": "10.60.20.11", "noeud": "noeud-62a", "vmid": 60020011}, {"nom": "mon-01", "ip": "10.60.20.21", "noeud": "noeud-62a", "vmid": 60020021}]}, {"libelle": "Web", "sous_reseau": "10.60.21.0/24", "passerelle": "10.60.21.1", "vnet": "t60web", "tag": 1606, "vms": [{"nom": "web-frontal-01", "ip": "10.60.21.31", "noeud": "noeud-62a", "vmid": 60021031}]}]}], "reprises": [], "absents": []}, {"nom": "SITE-Voisin", "commit": "", "index": 63, "etoile": "nushagak63", "domaine": "nushagak63", "organisation": "", "frontiere": "frontiere-63", "opnsense": true, "dns_public_nom": null, "transit": {"nom": "transit-frontiere", "vlan": 40, "sous_reseau": "10.9.63.0/24", "sortie": "10.9.63.1"}, "hyperviseurs": [{"nom": "noeud-63a", "adresses": {"transit-frontiere": "10.9.63.11"}}, {"nom": "noeud-63b", "adresses": {"transit-frontiere": "10.9.63.12"}}], "sdn": {"asn": 65063, "controleur": "EVPN0063", "noeuds_de_sortie": ["noeud-63a"], "sortie_primaire": "noeud-63a"}, "noeuds": ["noeud-63a", "noeud-63b"], "publiques": [{"ip": "198.51.100.63", "pour": "SITE-Voisin"}], "relais": null, "admins": {"reseau": "10.63.29.0/24", "port": 51821, "mtu": 1412, "frontiere": "10.63.29.1", "pairs": [{"nom": "anne-portable", "adresse": "10.63.29.2"}]}, "liens": [{"sous_reseau": "198.18.62.0/30", "mtu": 1412, "local": {"nom": "frontiere-63", "ip": "198.18.62.2"}, "pair": {"nom": "frontiere-62", "ip": "198.18.62.1", "site": "SITE-Exemple", "point_arrivee": "203.0.113.62:51820"}, "dns_public": true}], "fabric": [{"nom": "management", "vlan": null, "sous_reseau": "10.63.0.0/24", "mtu": 1500, "tunnel": null, "fabric": "principal", "transit": false, "description": "", "hotes": [{"nom": "frontiere-63", "ip": "10.63.0.1", "role": "frontiere"}]}, {"nom": "transit-frontiere", "vlan": 40, "sous_reseau": "10.9.63.0/24", "mtu": 1500, "tunnel": null, "fabric": "principal", "transit": true, "description": "", "hotes": [{"nom": "frontiere-63", "ip": "10.9.63.1", "role": "frontiere"}, {"nom": "noeud-63a", "ip": "10.9.63.11", "role": "hyperviseur"}, {"nom": "noeud-63b", "ip": "10.9.63.12", "role": "hyperviseur"}]}], "zones": [{"nom": "site-pilotage", "vlan": 31, "sous_reseau": "10.63.31.0/24", "passerelle": "10.63.31.1", "description": "", "vms": [{"nom": "site-ops-01", "ip": "10.63.31.11", "noeud": "noeud-63a", "vmid": 9031}]}, {"nom": "site-genome", "vlan": 33, "sous_reseau": "10.63.33.0/24", "passerelle": "10.63.33.1", "description": "", "vms": [{"nom": "site-forge-01", "ip": "10.63.33.11", "noeud": "noeud-63a", "vmid": 9033}]}, {"nom": "site-sauvegarde", "vlan": 35, "sous_reseau": "10.63.35.0/24", "passerelle": "10.63.35.1", "description": "", "vms": [{"nom": "site-backup-01", "ip": "10.63.35.11", "noeud": "noeud-63a", "vmid": 9035}]}], "locataires": [], "reprises": [], "absents": []}], "hors_carte": []};
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" data-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>`;