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>
231 lines
9.9 KiB
Plaintext
231 lines
9.9 KiB
Plaintext
@inherits LoadedComponent
|
|
@page "/impostazioni"
|
|
@inject AnubisHost Host
|
|
@inject ShellData Shell
|
|
@inject SecondFactorDrafts Drafts
|
|
|
|
<PageTitle>Impostazioni · Anubis</PageTitle>
|
|
|
|
@* First part of SPEC 13.5: appearance, security, system. The other sections arrive with their phases. *@
|
|
@if (Ok is { } ok)
|
|
{
|
|
<p class="notice notice-gain" role="status"><Icon Name="check" Size="16" />@(ok switch
|
|
{
|
|
"password" => "Password cambiata. Le altre sessioni sono state chiuse.",
|
|
"due-fattori" => "Secondo fattore attivato.",
|
|
"due-fattori-tolti" => "Secondo fattore disattivato.",
|
|
"salvataggio" => "Salvataggio fatto.",
|
|
_ => "Fatto.",
|
|
})</p>
|
|
}
|
|
@if (ErrorText is { } error)
|
|
{
|
|
<p class="notice notice-loss" role="alert"><Icon Name="alert" Size="16" />@error</p>
|
|
}
|
|
|
|
<nav class="tabs" aria-label="Sezioni delle impostazioni">
|
|
<a href="#aspetto">Aspetto</a><a href="#sicurezza">Sicurezza</a><a href="#sistema">Sistema</a><a href="#modifiche">Modifiche</a>
|
|
</nav>
|
|
|
|
<section class="panel" id="aspetto">
|
|
<h2>Aspetto</h2>
|
|
@foreach (var setting in _appearance)
|
|
{
|
|
var definition = SettingsStore.Definition(setting.Key);
|
|
<form method="post" action="/azioni/impostazioni/@setting.Key" class="form-inline">
|
|
<AntiforgeryToken />
|
|
<input type="hidden" name="ritorno" value="/impostazioni#aspetto" />
|
|
<label for="@setting.Key">@definition.Label</label>
|
|
<select id="@setting.Key" name="valore" disabled="@setting.ReadOnly" data-autosubmit>
|
|
@foreach (var value in definition.Allowed!)
|
|
{
|
|
<option value="@value" selected="@(value == setting.Value)">@Label(value)</option>
|
|
}
|
|
</select>
|
|
@if (setting.ReadOnly)
|
|
{
|
|
<span class="hint">Fissato da @setting.Source: si cambia lì.</span>
|
|
}
|
|
else
|
|
{
|
|
<button class="btn btn-small" type="submit">Salva</button>
|
|
}
|
|
</form>
|
|
}
|
|
<p class="hint">Gli importi in dollari usano il cambio del giorno, che arriva con i dati di mercato. Fino ad allora restano in euro.</p>
|
|
</section>
|
|
|
|
<section class="panel" id="sicurezza">
|
|
<h2>Sicurezza</h2>
|
|
@if (Shell.IsDemo)
|
|
{
|
|
<p class="hint">Nella modalità dimostrativa password e secondo fattore non si cambiano.</p>
|
|
}
|
|
else
|
|
{
|
|
<h3>Password</h3>
|
|
<form method="post" action="/azioni/password" class="form">
|
|
<AntiforgeryToken />
|
|
<label for="attuale">Password attuale</label>
|
|
<input id="attuale" name="attuale" type="password" autocomplete="current-password" required />
|
|
<label for="nuova">Nuova password</label>
|
|
<input id="nuova" name="nuova" type="password" autocomplete="new-password" minlength="@Passwords.MinimumLength" required />
|
|
<label for="conferma">Scrivila di nuovo</label>
|
|
<input id="conferma" name="conferma" type="password" autocomplete="new-password" minlength="@Passwords.MinimumLength" required />
|
|
<button class="btn" type="submit">Cambia password</button>
|
|
</form>
|
|
|
|
<h3>Secondo fattore</h3>
|
|
@if (_hasSecondFactor)
|
|
{
|
|
<p>Attivo: all'accesso chiedo anche il codice dell'app. Servirà anche per attivare i soldi veri.</p>
|
|
<form method="post" action="/azioni/due-fattori/disattiva" class="form">
|
|
<AntiforgeryToken />
|
|
<label for="password-2fa">Per disattivarlo: password</label>
|
|
<input id="password-2fa" name="password" type="password" autocomplete="current-password" required />
|
|
<label for="codice-2fa">Codice dell'app</label>
|
|
<input id="codice-2fa" name="codice" inputmode="numeric" autocomplete="one-time-code" pattern="[0-9]{6}" maxlength="6" required />
|
|
<button class="btn" type="submit">Disattiva il secondo fattore</button>
|
|
</form>
|
|
}
|
|
else
|
|
{
|
|
<p>Facoltativo: un codice di sei cifre da un'app di autenticazione (per esempio quella del tuo gestore di password), oltre alla password.</p>
|
|
<ol class="steps">
|
|
<li>Nell'app scegli "aggiungi con chiave" e scrivi questa chiave: <code class="secret">@_draft</code></li>
|
|
<li>Oppure, se l'app accetta un indirizzo, usa: <code class="secret">@_draftUri</code></li>
|
|
<li>Scrivi qui il codice che l'app mostra.</li>
|
|
</ol>
|
|
<form method="post" action="/azioni/due-fattori/attiva" class="form">
|
|
<AntiforgeryToken />
|
|
<label for="codice">Codice</label>
|
|
<input id="codice" name="codice" inputmode="numeric" autocomplete="one-time-code" pattern="[0-9]{6}" maxlength="6" required />
|
|
<button class="btn" type="submit">Attiva il secondo fattore</button>
|
|
</form>
|
|
}
|
|
<form method="post" action="/azioni/esci" class="form-inline"><AntiforgeryToken /><button class="btn" type="submit"><Icon Name="logout" Size="18" />Esci</button></form>
|
|
}
|
|
</section>
|
|
|
|
<section class="panel" id="sistema">
|
|
<h2>Sistema</h2>
|
|
<dl class="facts">
|
|
<dt>Piattaforma</dt><dd>@(Host.Config.Platform == PlatformKind.Docker ? "Docker" : "Desktop (Windows)")</dd>
|
|
<dt>Database</dt><dd>@Host.Config.Db?.Describe()</dd>
|
|
<dt>Cartella dei dati</dt><dd>@Host.Config.Data.Root</dd>
|
|
<dt>Chiave dei segreti</dt><dd>@Host.Config.SecretKey.Description</dd>
|
|
<dt>Fuso orario</dt><dd>@Host.Config.TimeZone.Id</dd>
|
|
<dt>Versione</dt><dd>@AnubisInfo.Version</dd>
|
|
</dl>
|
|
<p class="hint">
|
|
@if (Host.Config.Platform == PlatformKind.Docker)
|
|
{
|
|
@:Motore e connessione del database si cambiano solo nella configurazione del container.
|
|
}
|
|
else
|
|
{
|
|
@:Motore e connessione del database stanno in config.toml, nella cartella dei dati. Lo spostamento su un altro database arriva con l'applicazione desktop.
|
|
}
|
|
</p>
|
|
|
|
<h3>Salvataggi</h3>
|
|
<p class="hint">Ogni notte alle 03:30 e prima di ogni aggiornamento dello schema. Tengo gli ultimi @Backups.Keep.</p>
|
|
<form method="post" action="/azioni/salvataggio" class="form-inline"><AntiforgeryToken /><button class="btn" type="submit"><Icon Name="database" Size="18" />Salva adesso</button></form>
|
|
@if (_backups.Count > 0)
|
|
{
|
|
<div class="table-wrap">
|
|
<table class="table">
|
|
<thead><tr><th scope="col">Quando</th><th scope="col">Perché</th><th scope="col">Cartella</th></tr></thead>
|
|
<tbody>
|
|
@foreach (var b in _backups)
|
|
{
|
|
<tr><td class="nowrap">@Format.ShortDate(b.TakenAt, Shell.Now, Shell.Zone)</td><td>@b.Reason</td><td><code>@b.Name</code></td></tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
}
|
|
</section>
|
|
|
|
<section class="panel" id="modifiche">
|
|
<h2>Registro delle modifiche</h2>
|
|
@if (_history.Count == 0)
|
|
{
|
|
<p class="note">Nessuna modifica finora.</p>
|
|
}
|
|
else
|
|
{
|
|
<div class="table-wrap">
|
|
<table class="table">
|
|
<thead><tr><th scope="col">Quando</th><th scope="col">Voce</th><th scope="col">Prima</th><th scope="col">Dopo</th><th scope="col">Chi</th></tr></thead>
|
|
<tbody>
|
|
@foreach (var h in _history)
|
|
{
|
|
<tr><td class="nowrap">@Format.ShortDate(h.At, Shell.Now, Shell.Zone)</td><td>@h.Key</td><td>@Label(h.OldValue)</td><td>@Label(h.NewValue)</td><td>@h.ChangedBy</td></tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
}
|
|
</section>
|
|
|
|
@code {
|
|
private readonly List<SettingValue> _appearance = [];
|
|
private List<SettingChange> _history = [];
|
|
private IReadOnlyList<BackupInfo> _backups = [];
|
|
private bool _hasSecondFactor;
|
|
private string? _draft;
|
|
private string? _draftUri;
|
|
|
|
[CascadingParameter]
|
|
public HttpContext? HttpContext { get; set; }
|
|
|
|
[SupplyParameterFromQuery(Name = "ok")]
|
|
public string? Ok { get; set; }
|
|
|
|
[SupplyParameterFromQuery(Name = "errore")]
|
|
public string? Errore { get; set; }
|
|
|
|
protected override async Task LoadAsync()
|
|
{
|
|
var ct = HttpContext?.RequestAborted ?? CancellationToken.None;
|
|
var services = Host.Services!;
|
|
_appearance.Add(await services.Settings.GetAsync(SettingsStore.Theme.Key, ct));
|
|
_appearance.Add(await services.Settings.GetAsync(SettingsStore.Currency.Key, ct));
|
|
_history = await services.Settings.HistoryAsync(null, 50, ct);
|
|
_backups = services.Backups.List();
|
|
var user = HttpContext!.User;
|
|
_hasSecondFactor = CurrentUser.HasSecondFactor(user);
|
|
if (!_hasSecondFactor && !Shell.IsDemo)
|
|
{
|
|
var secret = Drafts.For(CurrentUser.Session(user));
|
|
_draft = Base32.Encode(secret);
|
|
_draftUri = Totp.Uri("Anubis", AccessStore.AdminName, secret);
|
|
}
|
|
}
|
|
|
|
private string? ErrorText => Errore switch
|
|
{
|
|
"codice" => "Il codice non è giusto. Controlla l'ora del telefono e riprova con il codice che vedi adesso.",
|
|
"segreto" => "La chiave è scaduta: ricarica la pagina e aggiungi di nuovo Anubis nell'app.",
|
|
"salvataggio" => "Il salvataggio non è riuscito. Controlla lo spazio libero nella cartella dei dati.",
|
|
"impostazione" => "Questa impostazione non si può cambiare così.",
|
|
"bot" => "Comando non ammesso nello stato attuale del bot.",
|
|
_ => PasswordMessages.For(Errore),
|
|
};
|
|
|
|
private static string Label(string? value) => value switch
|
|
{
|
|
null => "—",
|
|
"auto" => "Come il sistema",
|
|
"light" => "Chiaro",
|
|
"dark" => "Scuro",
|
|
"EUR" => "Euro (EUR)",
|
|
"USD" => "Dollaro (USD)",
|
|
"active" => "Attivo",
|
|
"paused" => "In pausa",
|
|
"stopped" => "Fermo",
|
|
_ => value.Trim('"'),
|
|
};
|
|
}
|