Phase 1 completed on top of the library foundations: - Server: startup state machine (config, first run, database down, schema, identity, ready) with an error page that retries by itself; the configured database is the only one ever opened, and a vanished SQLite file is never recreated. REST API and status WebSocket; session cookie auth, CSRF on every form and write call; desktop and demo answer only the computer itself. - Interface: static Blazor rendering with plain forms (no interactive runtime), menu, top bar and phone bottom bar as in the mockups, light and dark themes with appendix C tokens and a contrast test, Panoramica, Diario, Rischio, Impostazioni; service pages for sign-in, first access, desktop first run and the database error page with its choices. - Demo mode (tasks seed-demo): appendix F in a database of its own under the temp folder, frozen clock, never touches the configured installation. - Docker: entrypoint gives /data to PUID:PGID and drops root with setpriv, HEALTHCHECK through bash /dev/tcp; proven with SQLite, PostgreSQL, a wrong configuration and a database that goes away and comes back. - tasks screenshots drives the installed Edge/Chrome through DevTools for exact 1440 and 390 pixel shots; anubis db export|import on the command line. Fixes from the independent review: return paths without control characters, Host check against DNS rebinding, attempt limit counted before the check and also on the error-page password, one-use TOTP codes and a code to switch the second factor off, error-page choices serialized with the startup loop, identity checked before migrating, restore restarts with "Ferma tutto" on, damaged archives reported instead of crashing. Running the server tests on PostgreSQL exposed pages rendered before their data arrived; data-loading components now load first (LoadedComponent). Decisions in ADR 0007. Tests: 100 on SQLite and on PostgreSQL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
126 lines
5.8 KiB
Plaintext
126 lines
5.8 KiB
Plaintext
@inject AnubisHost Host
|
|
@inject IClock Clock
|
|
|
|
@* SPEC 15.1: database and data folder disagree. The user chooses; Docker asks the startup password because users
|
|
and sessions live in the database that is missing, desktop accepts choices only from the computer itself. *@
|
|
@{
|
|
var verdict = Status.Identity!.Verdict;
|
|
var data = Host.Config.Data;
|
|
var docker = Host.Config.Platform == PlatformKind.Docker;
|
|
var canChoose = docker || Local;
|
|
}
|
|
|
|
@switch (verdict)
|
|
{
|
|
case IdentityVerdict.EmptyDatabase:
|
|
<p>Il database è vuoto, ma la cartella dei dati appartiene a un'installazione che esiste già. Il motore resta spento: se partisse, comincerebbe da zero e i conti risulterebbero diversi dal registro.</p>
|
|
break;
|
|
case IdentityVerdict.DifferentInstallation:
|
|
<p>Il database appartiene a un'altra installazione di Anubis. Il motore resta spento: due registri sugli stessi conti produrrebbero ordini doppi.</p>
|
|
break;
|
|
case IdentityVerdict.StaleDatabase:
|
|
<p>È il database di questa installazione, ma una copia più vecchia: dopo l'ultimo ripristino o spostamento ne è nata una più recente. Il motore resta spento per non lavorare su dati superati.</p>
|
|
break;
|
|
}
|
|
|
|
<dl class="facts">
|
|
<dt>Database</dt><dd>@Host.Config.Db?.Describe()</dd>
|
|
<dt>Cartella dei dati</dt><dd>@data.Root</dd>
|
|
@if (Status.Identity.File is { } file)
|
|
{
|
|
<dt>Installazione della cartella</dt><dd>@file.InstallationId.ToString("D")[..8], nata il @Format.ShortDate(file.CreatedAt, Clock.UtcNow, Host.Config.TimeZone, withTime: false)</dd>
|
|
}
|
|
@if (Status.Identity.Row is { } row)
|
|
{
|
|
<dt>Installazione del database</dt><dd>@row.Id.ToString("D")[..8], nata il @Format.ShortDate(row.CreatedAt, Clock.UtcNow, Host.Config.TimeZone, withTime: false)</dd>
|
|
}
|
|
</dl>
|
|
|
|
<p class="hint">La soluzione più sicura spesso è correggere la configurazione perché punti al database giusto. Altrimenti scegli qui sotto. Dopo un ripristino o un'importazione il bot riparte protetto: "Ferma tutto" acceso finché non confermi.</p>
|
|
|
|
@if (!canChoose)
|
|
{
|
|
<p class="notice notice-attention" role="status"><Icon Name="lock" Size="16" />Queste scelte si fanno solo dal computer su cui gira Anubis.</p>
|
|
}
|
|
else
|
|
{
|
|
@if (verdict == IdentityVerdict.EmptyDatabase)
|
|
{
|
|
var backups = new Backups(data, Clock).List();
|
|
var imports = ServiceChoices.ImportFolders(data);
|
|
<section class="service-section">
|
|
<h2>Ripristina un salvataggio</h2>
|
|
@if (backups.Count == 0)
|
|
{
|
|
<p class="hint">Nessun salvataggio nella cartella <code>@data.Backups</code>.</p>
|
|
}
|
|
else
|
|
{
|
|
<form method="post" action="/azioni/servizio/ripristina" class="form">
|
|
<AntiforgeryToken />
|
|
<label for="salvataggio">Salvataggio</label>
|
|
<select id="salvataggio" name="salvataggio">
|
|
@foreach (var backup in backups)
|
|
{
|
|
<option value="@backup.Name">@Format.ShortDate(backup.TakenAt, Clock.UtcNow, Host.Config.TimeZone) · @backup.Reason</option>
|
|
}
|
|
</select>
|
|
<AdminPassword Docker="docker" />
|
|
<button class="btn btn-primary" type="submit">Ripristina</button>
|
|
</form>
|
|
}
|
|
</section>
|
|
<section class="service-section">
|
|
<h2>Importa un archivio</h2>
|
|
@if (imports.Count == 0)
|
|
{
|
|
<p class="hint">Metti la cartella di un archivio esportato (con il suo <code>index.json</code>) dentro <code>@data.Import</code> e ricarica la pagina.</p>
|
|
}
|
|
else
|
|
{
|
|
<form method="post" action="/azioni/servizio/importa" class="form">
|
|
<AntiforgeryToken />
|
|
<label for="archivio">Archivio</label>
|
|
<select id="archivio" name="archivio">
|
|
@foreach (var folder in imports)
|
|
{
|
|
<option value="@Path.GetFileName(folder)">@Path.GetFileName(folder)</option>
|
|
}
|
|
</select>
|
|
<AdminPassword Docker="docker" />
|
|
<button class="btn btn-primary" type="submit">Importa</button>
|
|
</form>
|
|
}
|
|
</section>
|
|
<section class="service-section">
|
|
<h2>Comincia da capo</h2>
|
|
<p class="hint">Una nuova installazione in questo database vuoto. Il file d'identità della cartella viene messo da parte, non cancellato.</p>
|
|
<form method="post" action="/azioni/servizio/da-capo" class="form">
|
|
<AntiforgeryToken />
|
|
<AdminPassword Docker="docker" />
|
|
<button class="btn btn-danger" type="submit" data-confirm="Cominciare da capo con un database vuoto? Lo storico precedente resta nei salvataggi.">Comincia da capo</button>
|
|
</form>
|
|
</section>
|
|
}
|
|
else
|
|
{
|
|
<section class="service-section">
|
|
<h2>Usa comunque questo database</h2>
|
|
<p class="hint">Diventa il database di questa installazione con una nuova impronta. Ogni altra copia non verrà più accettata. Il bot riparte protetto.</p>
|
|
<form method="post" action="/azioni/servizio/usa-questo" class="form">
|
|
<AntiforgeryToken />
|
|
<AdminPassword Docker="docker" />
|
|
<button class="btn btn-danger" type="submit" data-confirm="Usare questo database da ora in poi? Le altre copie non saranno più accettate.">Usa questo database</button>
|
|
</form>
|
|
</section>
|
|
}
|
|
}
|
|
|
|
@code {
|
|
[Parameter, EditorRequired]
|
|
public HostStatus Status { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public bool Local { get; set; }
|
|
}
|