4NK_web_status/status/index.html

431 lines
19 KiB
HTML

<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LeCoffre Node - Status</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: #333;
min-height: 100vh;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.header {
text-align: center;
color: white;
margin-bottom: 30px;
}
.header h1 {
font-size: 2.5em;
margin-bottom: 10px;
text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}
.header p {
font-size: 1.2em;
opacity: 0.9;
}
.services-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 20px;
margin-bottom: 30px;
}
.service-card {
background: white;
border-radius: 10px;
padding: 20px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
transition: transform 0.3s ease;
}
.service-card:hover {
transform: translateY(-5px);
}
.service-header {
display: flex;
align-items: center;
margin-bottom: 15px;
}
.status-indicator {
width: 12px;
height: 12px;
border-radius: 50%;
margin-right: 10px;
}
.status-up { background-color: #4CAF50; }
.status-down { background-color: #f44336; }
.status-warning { background-color: #ff9800; }
.service-title {
font-size: 1.3em;
font-weight: bold;
color: #2c3e50;
}
.service-description {
color: #7f8c8d;
margin-bottom: 15px;
}
.service-url {
color: #3498db;
text-decoration: none;
font-weight: 500;
}
.service-url:hover {
text-decoration: underline;
}
.footer {
text-align: center;
color: white;
margin-top: 30px;
opacity: 0.8;
}
.refresh-btn {
background: #3498db;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
margin: 20px 0;
font-size: 1em;
}
.refresh-btn:hover {
background: #2980b9;
}
.timestamp {
color: #95a5a6;
font-size: 0.9em;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🚀 LeCoffre Node</h1>
<p>Architecture Autonome - Tableau de Bord des Services</p>
</div>
<div id="summary" style="display:none; background:#eef6ff; color:#0b4f82; border:1px solid #cfe6ff; padding:10px 14px; border-radius:6px; margin: 8px 0;">
<!-- résumé dynamique -->
</div>
<div id="deploy-banner" style="display:none; background:#fff3cd; color:#856404; border:1px solid #ffeeba; padding:10px 14px; border-radius:6px; margin-bottom:16px;">
Déploiement en cours… <span id="deploy-percent">0</span>%
</div>
<div style="text-align: center;">
<button class="refresh-btn" id="refresh-btn">🔄 Actualiser</button>
<div class="timestamp" id="timestamp"></div>
</div>
<div class="services-grid" id="services-grid">
<!-- Les services seront chargés dynamiquement -->
</div>
<div class="services-grid" id="external-grid">
<!-- Les services externes seront chargés dynamiquement -->
</div>
<div class="services-grid" id="runner-grid">
<!-- Informations du runner -->
</div>
<div class="services-grid" id="integrations-grid">
<!-- Intégrations (OVH/Stripe/Mailchimp) -->
</div>
<div class="services-grid" id="indexeddb-grid">
<!-- IndexedDB 4NK (wallets) -->
</div>
<div class="footer">
<p>LeCoffre Node - Architecture Autonome Complète</p>
<p>Monitoring et logs disponibles via Grafana</p>
</div>
</div>
<script>
function formatBytes(bytes) {
if (!bytes || bytes <= 0) return '0 B';
const units = ['B','KB','MB','GB','TB'];
const i = Math.floor(Math.log(bytes) / Math.log(1024));
return `${(bytes / Math.pow(1024, i)).toFixed(2)} ${units[i]}`;
}
function createServiceCard(service) {
const statusClass = service.status === 'running' || service.health === 'healthy' ? 'status-up' : 'status-down';
const statusText = service.status === 'running' ? 'En ligne' : (service.status || 'Inconnu');
const description = `${service.protocol || ''}${service.port ? ` · Port ${service.port}` : ''}`.trim();
return `
<div class="service-card">
<div class="service-header">
<div class="status-indicator ${statusClass}"></div>
<div class="service-title">${service.name}</div>
</div>
<div class="service-description">${description}</div>
<div style="margin-top: 10px; font-size: 0.9em; color: #7f8c8d;">
Statut: ${statusText}${service.uptime ? ` · Uptime: ${service.uptime}` : ''}
</div>
${service.health_text ? `<div style="margin-top: 6px; font-size: 0.9em; color: #7f8c8d;">Détails: ${service.health_text}</div>` : ''}
${service.name === 'SDK Storage' && (service.data_size_bytes !== undefined) ? `<div style="margin-top: 6px; font-size: 0.9em; color: #7f8c8d;">Taille: ${formatBytes(service.data_size_bytes)}</div>` : ''}
${service.image ? `<div style="margin-top: 6px; font-size: 0.85em; color: #95a5a6;">Image: ${service.image}</div>` : ''}
</div>
`;
}
function createExternalCard(ext) {
const statusClass = ext.status === 'running' ? 'status-up' : 'status-warning';
const url = ext.url || '';
return `
<div class="service-card">
<div class="service-header">
<div class="status-indicator ${statusClass}"></div>
<div class="service-title">${ext.name}</div>
</div>
<div class="service-description">${ext.protocol || ''}${url ? ` · ${url}` : ''}</div>
<div style="margin-top: 10px; font-size: 0.9em; color: #7f8c8d;">
Statut: ${ext.status}${ext.response_time ? ` · ${ext.response_time}` : ''}
</div>
</div>
`;
}
function createRunnerCard(runner) {
const statusClass = runner.status === 'running' ? 'status-up' : 'status-warning';
return `
<div class="service-card">
<div class="service-header">
<div class="status-indicator ${statusClass}"></div>
<div class="service-title">Dernière action du runner</div>
</div>
<div class="service-description">Watchtower</div>
<div style="margin-top: 10px; font-size: 0.9em; color: #7f8c8d;">
Statut: ${runner.status || 'inconnu'}${runner.uptime ? ` · Uptime: ${runner.uptime}` : ''}
</div>
${runner.started_at ? `<div style="margin-top: 6px; font-size: 0.85em; color: #95a5a6;">Démarré: ${new Date(runner.started_at).toLocaleString('fr-FR')}</div>` : ''}
</div>
`;
}
function createIntegrationsCards(flags) {
const entries = [
{ name: 'OVH SMS', key: 'OVH' },
{ name: 'Stripe Paiement', key: 'Stripe' },
{ name: 'Mailchimp Emails', key: 'Mailchimp' },
];
return entries.map(e => {
const ok = !!flags?.[e.key];
const statusClass = ok ? 'status-up' : 'status-warning';
return `
<div class="service-card">
<div class="service-header">
<div class="status-indicator ${statusClass}"></div>
<div class="service-title">${e.name}</div>
</div>
<div class="service-description">${ok ? 'Clés configurées' : 'Non configuré'}</div>
${e.key === 'Mailchimp' && window.__integrations?.mailchimp ? `<div style="margin-top:6px;color:#7f8c8d;">Statut: ${window.__integrations.mailchimp.status}</div>` : ''}
${e.key === 'Stripe' && window.__integrations?.stripe ? `<div style="margin-top:6px;color:#7f8c8d;">Abonnements: STD ${window.__integrations.stripe.STANDARD||0} · UNL ${window.__integrations.stripe.UNLIMITED||0}</div>` : ''}
${e.key === 'OVH' && window.__integrations?.ovh ? `<div style="margin-top:6px;color:#7f8c8d;">${window.__integrations.ovh.status}</div>` : ''}
</div>
`;
});
}
async function refreshStatus() {
const grid = document.getElementById('services-grid');
const extGrid = document.getElementById('external-grid');
const runnerGrid = document.getElementById('runner-grid');
const integrationsGrid = document.getElementById('integrations-grid');
const idbGrid = document.getElementById('indexeddb-grid');
grid.innerHTML = '<div style="text-align: center; color: white;">Chargement...</div>';
extGrid.innerHTML = '';
runnerGrid.innerHTML = '';
integrationsGrid.innerHTML = '';
idbGrid.innerHTML = '';
try {
const res = await fetch('/status/api');
if (!res.ok) throw new Error('API status indisponible');
const data = await res.json();
// Summary banner
try {
const svcCount = (data.services || []).length;
const it = data.integrations_test || {};
const iMail = it.mailchimp?.status || '—';
const iStripeStd = (it.stripe_subscriptions_by_offer?.STANDARD) || 0;
const iStripeUnl = (it.stripe_subscriptions_by_offer?.UNLIMITED) || 0;
const iOvh = it.ovh?.status || '—';
// wallets count (approx)
const wallets = data.wallets || {};
let walletCount = 0;
Object.values(wallets).forEach((grp) => {
if (grp && typeof grp === 'object' && !Array.isArray(grp)) {
if ('confirmed_sat' in grp || 'immature_sat' in grp) {
walletCount += 1;
} else {
walletCount += Object.keys(grp).length;
}
}
});
const summary = document.getElementById('summary');
summary.innerHTML = `Services: ${svcCount} · Wallets: ${walletCount} · Mailchimp: ${iMail} · Stripe: STD ${iStripeStd} / UNL ${iStripeUnl} · OVH: ${iOvh}`;
summary.style.display = 'block';
} catch(e) {
// ignore summary errors
}
const cards = (data.services || []).map(createServiceCard);
grid.innerHTML = cards.join('');
const extCards = (data.external || []).map(createExternalCard);
extGrid.innerHTML = extCards.join('');
if (data.runner) {
runnerGrid.innerHTML = createRunnerCard(data.runner);
}
// Intégrations (config + résultats API)
if (data.integrations_configured) {
window.__integrations = {
mailchimp: data.integrations_test?.mailchimp,
stripe: data.integrations_test?.stripe_subscriptions_by_offer,
stripe_prices: data.integrations_test?.stripe_prices || {},
ovh: data.integrations_test?.ovh,
};
const integCards = createIntegrationsCards(data.integrations_configured);
integrationsGrid.innerHTML = integCards.join('');
}
// IndexedDB scan (same-origin, best-effort)
try {
const idbInfo = await scanIndexedDbWallets();
const cards = renderIndexedDbCards(idbInfo);
idbGrid.innerHTML = cards.join('');
} catch (e) {
idbGrid.innerHTML = '<div class="service-card"><div class="service-header"><div class="status-indicator status-warning"></div><div class="service-title">IndexedDB 4NK</div></div><div class="service-description">Impossible de lire IndexedDB (permissions navigateur ?)</div></div>';
}
// Deployment banner
if (data.deployment && typeof data.deployment.percent === 'number') {
const banner = document.getElementById('deploy-banner');
const dp = document.getElementById('deploy-percent');
dp.textContent = data.deployment.percent;
banner.style.display = data.deployment.percent < 100 ? 'block' : 'none';
}
document.getElementById('timestamp').textContent =
`Dernière mise à jour: ${new Date().toLocaleString('fr-FR')}`;
} catch (e) {
grid.innerHTML = '<div style="text-align: center; color: white;">Impossible de joindre /status/api</div>';
document.getElementById('timestamp').textContent =
`Dernière tentative: ${new Date().toLocaleString('fr-FR')}`;
}
}
// Wire button (avoid inline handler for CSP)
document.getElementById('refresh-btn').addEventListener('click', () => {
refreshStatus();
});
refreshStatus();
// ---- IndexedDB helpers ----
function openDb(name, version) {
return new Promise((resolve, reject) => {
const req = indexedDB.open(name, version);
req.onsuccess = () => resolve(req.result);
req.onerror = () => reject(req.error || new Error('IndexedDB open failed'));
req.onupgradeneeded = () => {
// do nothing; we are read-only here
};
});
}
function readAllFromStore(db, storeName) {
return new Promise((resolve, reject) => {
const tx = db.transaction(storeName, 'readonly');
const store = tx.objectStore(storeName);
const out = [];
const cursorReq = store.openCursor();
cursorReq.onsuccess = (e) => {
const cursor = e.target.result;
if (cursor) {
out.push({ key: cursor.key, value: cursor.value });
cursor.continue();
} else {
resolve(out);
}
};
cursorReq.onerror = () => reject(cursorReq.error);
});
}
async function scanIndexedDbWallets() {
if (!('indexedDB' in window)) throw new Error('No IndexedDB');
const db = await openDb('4nk', 1);
const wallets = await readAllFromStore(db, 'wallet');
// Approx size: JSON length
let totalBytes = 0;
const details = wallets.map(w => {
const val = w.value || {};
const json = JSON.stringify(val);
totalBytes += json ? json.length : 0;
const paired = (val.device?.paired_member?.spaddresses) || [];
const lastscan = val.device?.sp_wallet?.lastscan || '';
const outputs = (val.device?.sp_wallet?.outputs) || [];
// Sum outputs amounts if present (assume property 'amount' in sats or tokens)
let sumTokens = 0;
try {
for (const o of outputs) {
const amt = Number(o?.amount || 0);
if (!Number.isNaN(amt)) sumTokens += amt;
}
} catch {}
return {
key: String(w.key),
paired,
lastscan,
outputsCount: outputs.length || 0,
outputsTokens: sumTokens,
};
});
return { totalBytes, count: wallets.length, details };
}
function renderIndexedDbCards(info) {
const cards = [];
const size = formatBytes(info.totalBytes || 0);
cards.push(`
<div class="service-card">
<div class="service-header">
<div class="status-indicator status-up"></div>
<div class="service-title">IndexedDB 4NK</div>
</div>
<div class="service-description">Taille totale: ${size} · Wallets: ${info.count}</div>
</div>
`);
for (const w of info.details || []) {
cards.push(`
<div class="service-card">
<div class="service-header">
<div class="status-indicator status-up"></div>
<div class="service-title">Wallet ${w.key}</div>
</div>
<div class="service-description">lastscan: ${w.lastscan || '—'}</div>
<div style="margin-top:6px;color:#7f8c8d;">paired spaddresses:</div>
<div style="font-size:0.85em;color:#95a5a6;">${(w.paired||[]).map(a=>`<div>${a}</div>`).join('') || '—'}</div>
<div style="margin-top:6px;color:#7f8c8d;">outputs: ${w.outputsCount} · jetons: ${w.outputsTokens}</div>
</div>
`);
}
return cards;
}
</script>
</body>
</html>