151 lines
6.8 KiB
Plaintext
151 lines
6.8 KiB
Plaintext
@namespace Heimdall.Web.Components.Settings
|
|||
|
|
@inject HeimdallApiClient Api
|
||
|
|
@inject ISnackbar Snackbar
|
||
|
|
|
||
|
|
<MudPaper Elevation="1" Class="pa-4 mb-4" Style="border-radius: var(--hmd-radius-lg);">
|
||
|
|
<div class="d-flex align-center mb-3">
|
||
|
|
<MudText Typo="Typo.h6" Class="flex-grow-1">
|
||
|
|
<i class="fas fa-bell mr-2"></i> Notifications
|
||
|
|
</MudText>
|
||
|
|
<MudChip T="string" Size="Size.Small" Variant="Variant.Outlined" Color="Color.Primary">ntfy + Email</MudChip>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-3">
|
||
|
|
Canaux de notification utilisés pour les alertes de détection, les digests et les événements système.
|
||
|
|
</MudText>
|
||
|
|
|
||
|
|
<MudText Typo="Typo.subtitle2" Class="mb-2">
|
||
|
|
<i class="fas fa-paper-plane mr-1" style="color: var(--mud-palette-primary);"></i> ntfy
|
||
|
|
</MudText>
|
||
|
|
<MudGrid>
|
||
|
|
<MudItem xs="12" md="6">
|
||
|
|
<MudTextField T="string" Label="Serveur ntfy" Variant="Variant.Outlined"
|
||
|
|
Value="@GetValue("ntfy.baseUrl")"
|
||
|
|
ValueChanged="OnBaseUrlChanged"
|
||
|
|
HelperText="URL de base du serveur ntfy (ex : https://ntfy.sh)." />
|
||
|
|
</MudItem>
|
||
|
|
<MudItem xs="12" md="6">
|
||
|
|
<MudTextField T="string" Label="Token d'accès" Variant="Variant.Outlined"
|
||
|
|
Type="InputType.Password"
|
||
|
|
Value="@SecretValue("ntfy.token")"
|
||
|
|
ValueChanged="OnTokenChanged"
|
||
|
|
Placeholder="•••••••• (déjà configuré)"
|
||
|
|
HelperText="Token optionnel pour les serveurs ntfy authentifiés." />
|
||
|
|
</MudItem>
|
||
|
|
</MudGrid>
|
||
|
|
|
||
|
|
<MudText Typo="Typo.subtitle2" Class="mb-2 mt-3">
|
||
|
|
<i class="fas fa-envelope mr-1" style="color: var(--mud-palette-primary);"></i> Email SMTP
|
||
|
|
</MudText>
|
||
|
|
<MudGrid>
|
||
|
|
<MudItem xs="12" md="6">
|
||
|
|
<MudTextField T="string" Label="Adresse expéditrice" Variant="Variant.Outlined"
|
||
|
|
Value="@GetValue("email.fromAddress")"
|
||
|
|
ValueChanged="OnFromAddressChanged"
|
||
|
|
HelperText="Adresse « De » des emails envoyés." />
|
||
|
|
</MudItem>
|
||
|
|
<MudItem xs="12" md="6">
|
||
|
|
<MudTextField T="string" Label="Nom expéditeur" Variant="Variant.Outlined"
|
||
|
|
Value="@GetValue("email.fromName")"
|
||
|
|
ValueChanged="OnFromNameChanged" />
|
||
|
|
</MudItem>
|
||
|
|
<MudItem xs="12" md="4">
|
||
|
|
<MudTextField T="string" Label="Serveur SMTP" Variant="Variant.Outlined"
|
||
|
|
Value="@GetValue("email.smtpHost")"
|
||
|
|
ValueChanged="OnSmtpHostChanged"
|
||
|
|
HelperText="Ex : smtp.gmail.com" />
|
||
|
|
</MudItem>
|
||
|
|
<MudItem xs="6" md="2">
|
||
|
|
<MudTextField T="string" Label="Port SMTP" Variant="Variant.Outlined"
|
||
|
|
Type="InputType.Number"
|
||
|
|
Value="@GetValue("email.smtpPort")"
|
||
|
|
ValueChanged="OnSmtpPortChanged" />
|
||
|
|
</MudItem>
|
||
|
|
<MudItem xs="12" md="3">
|
||
|
|
<MudTextField T="string" Label="Utilisateur SMTP" Variant="Variant.Outlined"
|
||
|
|
Value="@GetValue("email.username")"
|
||
|
|
ValueChanged="OnUsernameChanged" />
|
||
|
|
</MudItem>
|
||
|
|
<MudItem xs="12" md="3">
|
||
|
|
<MudTextField T="string" Label="Mot de passe SMTP" Variant="Variant.Outlined"
|
||
|
|
Type="InputType.Password"
|
||
|
|
Value="@SecretValue("email.password")"
|
||
|
|
ValueChanged="OnPasswordChanged"
|
||
|
|
Placeholder="•••••••• (déjà configuré)" />
|
||
|
|
</MudItem>
|
||
|
|
<MudItem xs="12">
|
||
|
|
<MudSwitch T="bool"
|
||
|
|
Value="@(GetValue("email.useSsl")?.Equals("true", StringComparison.OrdinalIgnoreCase) == true)"
|
||
|
|
ValueChanged="OnUseSslChanged"
|
||
|
|
Color="Color.Primary"
|
||
|
|
Label="Utiliser SSL/TLS"
|
||
|
|
HelperText="Active le chiffrement TLS lors de la connexion SMTP." />
|
||
|
|
</MudItem>
|
||
|
|
</MudGrid>
|
||
|
|
</MudPaper>
|
||
|
|
|
||
|
|
@code {
|
||
|
|
private List<AppSettingItem> _settings = [];
|
||
|
|
|
||
|
|
protected override async Task OnInitializedAsync()
|
||
|
|
{
|
||
|
|
try
|
||
|
|
{
|
||
|
|
_settings = await Api.GetSettingsAsync();
|
||
|
|
}
|
||
|
|
catch
|
||
|
|
{
|
||
|
|
// API indisponible (ex : test) — on reste sur les défauts.
|
||
|
|
_settings = [];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private string? GetValue(string key)
|
||
|
|
=> _settings.FirstOrDefault(s => s.Key == key)?.Value;
|
||
|
|
|
||
|
|
// Les secrets sont redactés par l'API (***REDACTED***) : afficher vide avec
|
||
|
|
// un placeholder pour ne pas laisser croire que la valeur est vide.
|
||
|
|
private string SecretValue(string key)
|
||
|
|
{
|
||
|
|
var v = GetValue(key);
|
||
|
|
return v is null or "" or "***REDACTED***" ? string.Empty : v;
|
||
|
|
}
|
||
|
|
|
||
|
|
private Task OnBaseUrlChanged(string v) => SaveValueAsync("ntfy.baseUrl", v);
|
||
|
|
private Task OnTokenChanged(string v) => SaveValueAsync("ntfy.token", v);
|
||
|
|
private Task OnFromAddressChanged(string v) => SaveValueAsync("email.fromAddress", v);
|
||
|
|
private Task OnFromNameChanged(string v) => SaveValueAsync("email.fromName", v);
|
||
|
|
private Task OnSmtpHostChanged(string v) => SaveValueAsync("email.smtpHost", v);
|
||
|
|
private Task OnSmtpPortChanged(string v) => SaveValueAsync("email.smtpPort", v);
|
||
|
|
private Task OnUsernameChanged(string v) => SaveValueAsync("email.username", v);
|
||
|
|
private Task OnPasswordChanged(string v) => SaveValueAsync("email.password", v);
|
||
|
|
private Task OnUseSslChanged(bool v) => SaveValueAsync("email.useSsl", v ? "true" : "false");
|
||
|
|
|
||
|
|
private async Task SaveValueAsync(string key, string? value)
|
||
|
|
{
|
||
|
|
value ??= string.Empty;
|
||
|
|
var existing = _settings.FirstOrDefault(s => s.Key == key);
|
||
|
|
try
|
||
|
|
{
|
||
|
|
if (existing is null)
|
||
|
|
{
|
||
|
|
await Api.CreateSettingAsync(new CreateAppSettingRequest(
|
||
|
|
Key: key, Value: value,
|
||
|
|
Category: "integrations",
|
||
|
|
Description: key, ValueType: "string", AllowedValues: null, AgentScoped: true));
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
await Api.UpdateSettingAsync(key, new UpdateAppSettingRequest(
|
||
|
|
Value: value, Description: existing.Description ?? key,
|
||
|
|
Category: "integrations", ValueType: "string", AllowedValues: null, AgentScoped: null));
|
||
|
|
}
|
||
|
|
_settings = await Api.GetSettingsAsync();
|
||
|
|
Snackbar.Add($"Paramètre {key} mis à jour", Severity.Success);
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
Snackbar.Add($"Échec de la mise à jour : {ex.Message}", Severity.Error);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|