Readiness, Electrum status, audit browsing and logs (B-92, API-37, API-46, API-47, AUD-34, AUD-41, ARC-02, ARC-09, ARC-61, ELC-29, SEC-48)
- GET /health/ready (Electrum connected, header < 1800s, scheduler heartbeat < 30s) is the container healthcheck; the scheduler beats on every tick and draw-wait iteration - GET /admin/electrum and an Electrum indicator in /admin (server, header age, last rotation) - GET /admin/audit-log: before_id, event_type, round_id, user_id, from, to; the panel gets filters - registration writes user_registered in its transaction - the app's own logs also go to stdout; uvicorn trusts X-Forwarded-For from Caddy's fixed address only, so the access log shows the client's IP Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9520c80dcf
commit
575f1a5354
23 files changed
+478
-91
No files matched your search
+13
-1
@@ -37,6 +37,7 @@
|
||||
<span id="chain-status-label">Connessione…</span>
|
||||
</span>
|
||||
<span class="chain-block mono" id="chain-block">Blocco —</span>
|
||||
<span class="chain-block mono" id="electrum-status">Electrum —</span>
|
||||
<button class="secondary" style="margin:8px 0 8px 14px" onclick="adminLogout()">Esci</button>
|
||||
</nav>
|
||||
|
||||
@@ -153,7 +154,17 @@
|
||||
|
||||
<div class="view" id="view-audit">
|
||||
<h2 class="section-title">Audit log</h2>
|
||||
<p class="hint">Ultimi eventi registrati dal sistema (config, bet, payout, accessi a chiavi private, ecc.).</p>
|
||||
<p class="hint">Eventi registrati dal sistema (config, bet, payout, accessi a chiavi private, ecc.), dal più recente. I filtri si combinano; "Carica altri" prosegue dall'ultimo evento mostrato.</p>
|
||||
<div class="card">
|
||||
<div class="row-between" style="flex-wrap:wrap;gap:8px">
|
||||
<input id="audit-f-type" placeholder="Tipo (es. payout_failed)" style="width:200px" />
|
||||
<input id="audit-f-round" placeholder="Round" inputmode="numeric" style="width:90px" />
|
||||
<input id="audit-f-user" placeholder="Utente" inputmode="numeric" style="width:90px" />
|
||||
<input id="audit-f-from" type="datetime-local" title="Da" />
|
||||
<input id="audit-f-to" type="datetime-local" title="A" />
|
||||
<button class="secondary" style="width:auto;margin-top:0" onclick="loadAuditLog()">Filtra</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="table-wrap">
|
||||
@@ -164,6 +175,7 @@
|
||||
<tbody id="audit-tbody"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
<button id="audit-more" class="secondary hidden" style="width:auto" onclick="loadAuditLog(true)">Carica altri</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
+45
-5
@@ -76,6 +76,26 @@ async function refreshChainStatus() {
|
||||
} catch (e) {
|
||||
// leave the last-known status on screen rather than blanking it out
|
||||
}
|
||||
refreshElectrumStatus();
|
||||
}
|
||||
|
||||
// B-92 (API-47): which server the platform is talking to and how fresh its last block is.
|
||||
async function refreshElectrumStatus() {
|
||||
const el = document.getElementById('electrum-status');
|
||||
if (!adminToken) return;
|
||||
try {
|
||||
const s = await callAdmin('GET', '/admin/electrum');
|
||||
const age = s.last_header_age_seconds;
|
||||
el.textContent = s.connected
|
||||
? `Electrum ${s.endpoint}${age != null ? ' · ultimo blocco ' + age + 's fa' : ''}`
|
||||
: 'Electrum non connesso';
|
||||
el.title = s.last_rotation
|
||||
? `Ultimo cambio server: ${s.last_rotation.from} (${s.last_rotation.reason}) alle ${fmtDate(s.last_rotation.at)}`
|
||||
: '';
|
||||
if (!s.quorum_enforced) el.title += ' · quorum non imposto (ALLOW_NO_QUORUM)';
|
||||
} catch (e) {
|
||||
// keep the last text
|
||||
}
|
||||
}
|
||||
|
||||
function startChainStatusPolling() {
|
||||
@@ -90,7 +110,7 @@ function stopChainStatusPolling() {
|
||||
}
|
||||
|
||||
const VIEWS = ['parametri', 'utenti', 'round', 'pending', 'audit', 'bugreports'];
|
||||
const VIEW_LOADERS = { utenti: loadUsers, round: loadRounds, pending: loadPending, audit: loadAuditLog, bugreports: loadBugReports };
|
||||
const VIEW_LOADERS = { utenti: loadUsers, round: loadRounds, pending: loadPending, audit: () => loadAuditLog(), bugreports: loadBugReports };
|
||||
let currentAdminView = 'parametri';
|
||||
|
||||
function switchView(name) {
|
||||
@@ -345,11 +365,29 @@ async function loadPending() {
|
||||
}
|
||||
}
|
||||
|
||||
async function loadAuditLog() {
|
||||
let auditLastId = null;
|
||||
const AUDIT_PAGE = 200;
|
||||
|
||||
async function loadAuditLog(more = false) {
|
||||
try {
|
||||
const entries = await callAdmin('GET', '/admin/audit-log');
|
||||
// B-92 (API-37): filters combine; "more" continues from the last id shown.
|
||||
const params = new URLSearchParams({ limit: String(AUDIT_PAGE) });
|
||||
const type = document.getElementById('audit-f-type').value.trim();
|
||||
if (type) params.append('event_type', type);
|
||||
for (const [id, key] of [['audit-f-round', 'round_id'], ['audit-f-user', 'user_id']]) {
|
||||
const v = document.getElementById(id).value.trim();
|
||||
if (v) params.append(key, v);
|
||||
}
|
||||
for (const [id, key] of [['audit-f-from', 'from'], ['audit-f-to', 'to']]) {
|
||||
const v = document.getElementById(id).value;
|
||||
if (v) params.append(key, new Date(v).toISOString());
|
||||
}
|
||||
if (more === true && auditLastId !== null) params.append('before_id', String(auditLastId));
|
||||
const entries = await callAdmin('GET', '/admin/audit-log?' + params);
|
||||
auditLastId = entries.length ? entries[entries.length - 1].id : auditLastId;
|
||||
document.getElementById('audit-more').classList.toggle('hidden', entries.length < AUDIT_PAGE);
|
||||
const tbody = document.getElementById('audit-tbody');
|
||||
tbody.innerHTML = entries.map((e) => `
|
||||
const rows = entries.map((e) => `
|
||||
<tr>
|
||||
<td>${e.id}</td>
|
||||
<td>${escapeHtml(e.event_type)}</td>
|
||||
@@ -358,7 +396,9 @@ async function loadAuditLog() {
|
||||
<td>${e.round_id ?? '—'}</td>
|
||||
<td>${fmtDate(e.created_at)}</td>
|
||||
</tr>
|
||||
`).join('') || '<tr><td colspan="6" class="hint">Nessun evento registrato.</td></tr>';
|
||||
`).join('');
|
||||
if (more === true) tbody.insertAdjacentHTML('beforeend', rows);
|
||||
else tbody.innerHTML = rows || '<tr><td colspan="6" class="hint">Nessun evento registrato.</td></tr>';
|
||||
} catch (e) {
|
||||
toast('Errore nel caricamento audit log: ' + e.message, 'error');
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user