feat(server): web server, interface shell, demo mode and Docker image (refs #11 #12 #13 #14 #15 #16 #17)
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>
This commit is contained in:
1 parent
53ca01b7c3
commit
f9d71559e8
71 files changed
+5853
-80
No files matched your search
@@ -0,0 +1,117 @@
|
||||
@page "/servizio"
|
||||
@layout ServiceLayout
|
||||
@attribute [AllowAnonymous]
|
||||
@inject AnubisHost Host
|
||||
@inject IClock Clock
|
||||
|
||||
@* The error page of SPEC 15.1: what is wrong, what to do, and the engine stays off. Never another database. *@
|
||||
<PageTitle>@ServiceText.Title(_status.Mode) · Anubis</PageTitle>
|
||||
@if (_refresh)
|
||||
{
|
||||
<HeadContent><meta http-equiv="refresh" content="5" /></HeadContent>
|
||||
}
|
||||
|
||||
<h1>@ServiceText.Title(_status.Mode)</h1>
|
||||
|
||||
@switch (_status.Mode)
|
||||
{
|
||||
case HostMode.Starting:
|
||||
<p>Controllo configurazione e database. Questa pagina si aggiorna da sola.</p>
|
||||
break;
|
||||
|
||||
case HostMode.ConfigProblem:
|
||||
<p>Il motore resta spento finché la configurazione non è completa. Non uso nessun altro database al posto di quello indicato.</p>
|
||||
<table class="table problems">
|
||||
<thead><tr><th scope="col">Voce</th><th scope="col">Cosa non va</th><th scope="col">Come rimediare</th></tr></thead>
|
||||
<tbody>
|
||||
@foreach (var problem in Host.Config.Problems)
|
||||
{
|
||||
<tr><td><code>@problem.Setting</code></td><td>@problem.What</td><td>@problem.Remedy</td></tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
@if (Host.Config.Platform == PlatformKind.Docker)
|
||||
{
|
||||
<p class="hint">Le variabili si cambiano nella configurazione del container (su Unraid, nei campi del modello), poi si riavvia il container.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p class="hint">Il file è <code>@Host.Config.Data.ConfigFile</code>. Appena lo correggi riprovo da solo.</p>
|
||||
}
|
||||
break;
|
||||
|
||||
case HostMode.DatabaseUnavailable:
|
||||
<p>Il motore è fermo e aspetta il database. Non apro un altro database al suo posto: riprovo da solo ogni pochi secondi e riparto appena risponde.</p>
|
||||
<dl class="facts">
|
||||
<dt>Database</dt><dd>@Host.Config.Db?.Describe()</dd>
|
||||
<dt>Risposta</dt><dd>@(_status.Detail ?? "nessuna")</dd>
|
||||
<dt>Tentativi</dt><dd>@_status.Attempts, dal @Format.ShortDate(_status.Since, Clock.UtcNow, Host.Config.TimeZone)</dd>
|
||||
</dl>
|
||||
<h2>Cosa controllare</h2>
|
||||
<ul class="steps">
|
||||
@if (Host.Config.Db?.Engine == DbEngine.Postgres)
|
||||
{
|
||||
<li>Che il server PostgreSQL sia acceso e raggiungibile da qui (indirizzo e porta).</li>
|
||||
<li>Che nome del database, utente e password siano quelli giusti.</li>
|
||||
<li>Che il database esista: lo crei tu una volta, Anubis non crea e non cancella database.</li>
|
||||
}
|
||||
else
|
||||
{
|
||||
<li>Che il file del database sia al suo posto e leggibile. Se l'hai spostato, rimettilo dov'era.</li>
|
||||
<li>Che il disco della cartella dei dati sia collegato e abbia spazio libero.</li>
|
||||
}
|
||||
</ul>
|
||||
break;
|
||||
|
||||
case HostMode.SchemaProblem:
|
||||
<p>@_status.Detail</p>
|
||||
<p>Per non rovinare i dati il motore resta spento. Aggiorna Anubis alla versione che ha creato questo database, oppure ripristina un salvataggio in un database vuoto.</p>
|
||||
break;
|
||||
|
||||
case HostMode.IdentityProblem:
|
||||
<IdentityChoices Status="_status" Local="_local" />
|
||||
break;
|
||||
|
||||
case HostMode.FirstRun:
|
||||
<p><a href="/primo-avvio">Apri la procedura di primo avvio</a>.</p>
|
||||
break;
|
||||
}
|
||||
|
||||
@if (Errore is { } errore)
|
||||
{
|
||||
<p class="notice notice-loss" role="alert"><Icon Name="alert" Size="16" />@(errore switch
|
||||
{
|
||||
"password" => "Password della configurazione d'avvio sbagliata, oppure scelta fatta da un altro computer.",
|
||||
"importazione" => "Il ripristino non è riuscito e non ho cambiato nulla. Controlla l'archivio e riprova.",
|
||||
"attesa" => "Troppi tentativi sbagliati. Riprova tra 15 minuti.",
|
||||
_ => "Questa scelta non è disponibile adesso.",
|
||||
})</p>
|
||||
}
|
||||
|
||||
@code {
|
||||
private HostStatus _status = null!;
|
||||
private bool _refresh;
|
||||
private bool _local;
|
||||
|
||||
[CascadingParameter]
|
||||
public HttpContext? HttpContext { get; set; }
|
||||
|
||||
[SupplyParameterFromQuery(Name = "errore")]
|
||||
public string? Errore { get; set; }
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
_status = Host.Status;
|
||||
_refresh = _status.Mode is HostMode.Starting or HostMode.DatabaseUnavailable or HostMode.ConfigProblem;
|
||||
if (HttpContext is not null)
|
||||
{
|
||||
_local = CurrentUser.IsLocal(HttpContext);
|
||||
if (!HttpContext.Response.HasStarted)
|
||||
{
|
||||
HttpContext.Response.StatusCode = StatusCodes.Status503ServiceUnavailable;
|
||||
HttpContext.Response.Headers.CacheControl = "no-store";
|
||||
HttpContext.Response.Headers.RetryAfter = "5";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user