Separate dashboard port, first-run password setup and default trusted proxies
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a34ff96490
commit
c22d452720
25 files changed
+654
-109
No files matched your search
@@ -3,35 +3,34 @@
|
||||
@attribute [AllowAnonymous]
|
||||
@using Flypaper.Web.Auth
|
||||
@inject AdminAuthenticator Admin
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
<PageTitle>Flypaper · Anmelden</PageTitle>
|
||||
|
||||
<h1 class="login-title">Flypaper</h1>
|
||||
|
||||
@if (!Admin.IsConfigured)
|
||||
{
|
||||
<div class="banner bad">
|
||||
<strong>Zugang gesperrt.</strong>
|
||||
Es ist kein Admin-Passwort gesetzt. Setze die Umgebungsvariable <code>Flypaper__Admin__Password</code> und starte den Container neu.
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<form method="post" action="/auth/login" class="card form">
|
||||
<AntiforgeryToken />
|
||||
<input type="hidden" name="returnUrl" value="@ReturnUrl" />
|
||||
<label for="password">Passwort</label>
|
||||
<input id="password" name="password" type="password" autocomplete="current-password" autofocus required />
|
||||
@if (Error is not null)
|
||||
{
|
||||
<p class="error">Passwort falsch.</p>
|
||||
}
|
||||
<button type="submit">Anmelden</button>
|
||||
</form>
|
||||
}
|
||||
<form method="post" action="/auth/login" class="card form">
|
||||
<AntiforgeryToken />
|
||||
<input type="hidden" name="returnUrl" value="@ReturnUrl" />
|
||||
<label for="password">Passwort</label>
|
||||
<input id="password" name="password" type="password" autocomplete="current-password" autofocus required />
|
||||
@if (Error is not null)
|
||||
{
|
||||
<p class="error">Passwort falsch.</p>
|
||||
}
|
||||
<button type="submit">Anmelden</button>
|
||||
</form>
|
||||
|
||||
@code {
|
||||
[SupplyParameterFromQuery(Name = "error")] private string? Error { get; set; }
|
||||
|
||||
[SupplyParameterFromQuery(Name = "returnUrl")] private string? ReturnUrl { get; set; }
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (!await Admin.IsConfiguredAsync())
|
||||
{
|
||||
Navigation.NavigateTo("/setup");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace Flypaper.Web.Components.Pages.Settings;
|
||||
|
||||
public sealed class PasswordModel
|
||||
{
|
||||
public string? Current { get; set; }
|
||||
|
||||
public string? New { get; set; }
|
||||
|
||||
public string? Confirmation { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
@using Flypaper.Web.Auth
|
||||
@inject AdminAuthenticator Admin
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
<section class="card form">
|
||||
<h2>Admin-Passwort</h2>
|
||||
|
||||
@if (Changed == "changed")
|
||||
{
|
||||
<div class="banner ok">Passwort geändert.</div>
|
||||
}
|
||||
|
||||
@if (Admin.UsesEnvironmentPassword)
|
||||
{
|
||||
<p class="muted">Das Passwort kommt aus der Umgebungsvariable <code>Flypaper__Admin__Password</code> und lässt sich nur dort ändern.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<EditForm Model="Model" FormName="password" OnSubmit="ChangeAsync" action="/settings" class="form">
|
||||
<label for="current-password">Aktuelles Passwort</label>
|
||||
<InputText id="current-password" type="password" autocomplete="current-password" @bind-Value="Model!.Current" />
|
||||
<FieldError Errors="_errors" Field="@nameof(PasswordModel.Current)" />
|
||||
|
||||
<label for="new-password">Neues Passwort <span class="muted">(mindestens @AdminAuthenticator.MinimumPasswordLength Zeichen)</span></label>
|
||||
<InputText id="new-password" type="password" autocomplete="new-password" @bind-Value="Model!.New" />
|
||||
|
||||
<label for="confirm-password">Neues Passwort wiederholen</label>
|
||||
<InputText id="confirm-password" type="password" autocomplete="new-password" @bind-Value="Model!.Confirmation" />
|
||||
<FieldError Errors="_errors" Field="@nameof(PasswordModel.New)" />
|
||||
|
||||
<div class="actions">
|
||||
<button type="submit">Passwort ändern</button>
|
||||
</div>
|
||||
</EditForm>
|
||||
}
|
||||
</section>
|
||||
|
||||
@code {
|
||||
private readonly Dictionary<string, string> _errors = [];
|
||||
|
||||
[SupplyParameterFromForm(FormName = "password")] private PasswordModel? Model { get; set; }
|
||||
|
||||
[SupplyParameterFromQuery(Name = "password")] private string? Changed { get; set; }
|
||||
|
||||
protected override void OnInitialized() => Model ??= new PasswordModel();
|
||||
|
||||
private async Task ChangeAsync()
|
||||
{
|
||||
if (AdminAuthenticator.ValidateNewPassword(Model!.New, Model.Confirmation) is { } error)
|
||||
{
|
||||
_errors[nameof(PasswordModel.New)] = error;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!await Admin.TryChangePasswordAsync(Model.Current ?? "", Model.New!))
|
||||
{
|
||||
_errors[nameof(PasswordModel.Current)] = "Aktuelles Passwort falsch.";
|
||||
return;
|
||||
}
|
||||
|
||||
Navigation.NavigateTo("/settings?password=changed");
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@
|
||||
@inject IConfiguration Configuration
|
||||
@inject RuntimeSettingsStore Store
|
||||
@inject AdminAuthenticator Admin
|
||||
@inject IOptions<PortOptions> Ports
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
<PageTitle>Flypaper · Einstellungen</PageTitle>
|
||||
@@ -42,7 +43,7 @@ else if (Saved == "reset")
|
||||
<InputTextArea id="trap-paths" @bind-Value="Model!.TrapPaths" rows="10" class="mono" />
|
||||
<FieldError Errors="_errors" Field="@nameof(SettingsModel.TrapPaths)" />
|
||||
|
||||
<label for="hosts">Zusätzliche bekannte Hosts <span class="muted">(einer pro Zeile, z. B. beispiel.de oder *.beispiel.de)</span></label>
|
||||
<label for="hosts">Bekannte Hosts <span class="muted">(einer pro Zeile, z. B. beispiel.de oder *.beispiel.de; werden auf dem Fallen-Port nur bei Fallenpfaden gefangen, sonst 404)</span></label>
|
||||
<InputTextArea id="hosts" @bind-Value="Model!.ExtraKnownHosts" rows="4" class="mono" />
|
||||
<FieldError Errors="_errors" Field="@nameof(SettingsModel.ExtraKnownHosts)" />
|
||||
|
||||
@@ -89,6 +90,8 @@ else if (Saved == "reset")
|
||||
|
||||
<TrapDataSection />
|
||||
|
||||
<PasswordSection />
|
||||
|
||||
<section class="card">
|
||||
<h2>Nur per Umgebungsvariable</h2>
|
||||
<p class="muted">Gelten ab Containerstart und lassen sich hier nicht ändern.</p>
|
||||
@@ -97,7 +100,8 @@ else if (Saved == "reset")
|
||||
<tr><th>Datenbank</th><td class="mono">@DatabasePath</td></tr>
|
||||
<tr><th>Bekannte Hosts</th><td class="mono">@Format(Configuration.GetSection("Flypaper:Http:KnownHosts").Get<string[]>())</td></tr>
|
||||
<tr><th>Vertrauenswürdige Proxies</th><td class="mono">@Format(Configuration.GetSection("Flypaper:Http:TrustedProxies").Get<string[]>())</td></tr>
|
||||
<tr><th>Admin-Passwort</th><td>@(Admin.IsConfigured ? "gesetzt" : "nicht gesetzt")</td></tr>
|
||||
<tr><th>Admin-Passwort</th><td>@(Admin.UsesEnvironmentPassword ? "per Umgebungsvariable" : "im Dashboard festgelegt")</td></tr>
|
||||
<tr><th>Ports</th><td class="mono">Falle @Ports.Value.Trap, Dashboard @Ports.Value.Dashboard</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
@page "/setup"
|
||||
@layout EmptyLayout
|
||||
@attribute [AllowAnonymous]
|
||||
@using Flypaper.Web.Auth
|
||||
@inject AdminAuthenticator Admin
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
<PageTitle>Flypaper · Einrichten</PageTitle>
|
||||
|
||||
<h1 class="login-title">Flypaper einrichten</h1>
|
||||
|
||||
<form method="post" action="/auth/setup" class="card form">
|
||||
<AntiforgeryToken />
|
||||
<p class="muted">Lege das Admin-Passwort für das Dashboard fest. Diese Seite ist nur erreichbar, solange noch kein Passwort existiert.</p>
|
||||
<label for="password">Passwort <span class="muted">(mindestens @AdminAuthenticator.MinimumPasswordLength Zeichen)</span></label>
|
||||
<input id="password" name="password" type="password" autocomplete="new-password" minlength="@AdminAuthenticator.MinimumPasswordLength" autofocus required />
|
||||
<label for="confirmation">Passwort wiederholen</label>
|
||||
<input id="confirmation" name="confirmation" type="password" autocomplete="new-password" required />
|
||||
@if (Error is not null)
|
||||
{
|
||||
<p class="error">@Error</p>
|
||||
}
|
||||
<button type="submit">Passwort festlegen</button>
|
||||
</form>
|
||||
|
||||
@code {
|
||||
[SupplyParameterFromQuery(Name = "error")] private string? Error { get; set; }
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (await Admin.IsConfiguredAsync())
|
||||
{
|
||||
Navigation.NavigateTo("/login");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user