feat(ui): gestion des sites façon Pangolin — édition + installation agent
- Édition de site : bouton Modifier + dialog (nom/adresse/fuseau) via
UpdateSiteAsync (nouvelle méthode client PUT api/sites/{id})
- Installation agent : nouveau SiteInstallPanel façon Pangolin avec onglets
Docker Compose (recommandé) / Script shell, génération du compose avec le
token du site et l'URL publique du serveur
- SitesPage : badges statut (StatusChip), boutons Modifier/Installer/Supprimer,
header descriptif ; le flux 'Installer un agent' génère token + compose
- SiteDetail : remplace l'ancien compose manuel par SiteInstallPanel
- Tests adaptés + nouveau test d'édition (PUT + reload + snackbar)
This commit is contained in:
1 parent
6606cf9dd5
commit
4da72ae6f3
6 files changed
+294
-62
No files matched your search
@@ -76,20 +76,8 @@ else
|
||||
|
||||
@if (!string.IsNullOrEmpty(_generatedToken))
|
||||
{
|
||||
<MudText Typo="Typo.subtitle1" Class="mt-6 mb-2">Docker Compose — Agent</MudText>
|
||||
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-2">
|
||||
Copiez ce bloc dans votre fichier <code>docker-compose.yml</code> pour connecter un agent à ce site :
|
||||
</MudText>
|
||||
|
||||
<MudPaper Class="pa-4" Style="background:#1a1a2e; border-radius:8px;" Elevation="0">
|
||||
<pre style="color:#e0e0e0; font-size:0.85rem; margin:0; white-space:pre-wrap;"><code>@_dockerComposeSnippet</code></pre>
|
||||
</MudPaper>
|
||||
|
||||
<MudButton Variant="Variant.Outlined" Size="Size.Small" Color="Color.Primary" Class="mt-2"
|
||||
OnClick="@CopyDockerCompose">
|
||||
<MudIcon Icon="@Icons.Material.Filled.ContentCopy" Class="mr-1" Size="Size.Small" />
|
||||
Copier le docker-compose
|
||||
</MudButton>
|
||||
<SiteInstallPanel SiteName="@_site.Name" SiteToken="@_generatedToken"
|
||||
CentralUrl="@CentralUrl" />
|
||||
}
|
||||
</MudPaper>
|
||||
|
||||
@@ -160,28 +148,8 @@ else
|
||||
finally { _generating = false; }
|
||||
}
|
||||
|
||||
private string GenerateDockerComposeSnippet(string token)
|
||||
{
|
||||
var hostname = $"agent-{_site?.Name?.ToLower().Replace(" ", "-") ?? "demo"}";
|
||||
return $$"""
|
||||
heimdall-agent:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: docker/Dockerfile.agent
|
||||
environment:
|
||||
HEIMDALL_CENTRAL_URL: "http://heimdall-central:8080"
|
||||
HEIMDALL_SITE_TOKEN: "{{token}}"
|
||||
HEIMDALL_AGENT_NAME: "{{hostname}}"
|
||||
restart: unless-stopped
|
||||
""";
|
||||
}
|
||||
private string GenerateDockerComposeSnippet(string token) => "";
|
||||
|
||||
private async Task CopyDockerCompose()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_dockerComposeSnippet))
|
||||
{
|
||||
await Js.InvokeVoidAsync("navigator.clipboard.writeText", _dockerComposeSnippet);
|
||||
Snackbar.Add("Docker-compose copié dans le presse-papier", Severity.Success);
|
||||
}
|
||||
}
|
||||
/// <summary>URL publique du serveur Heimdall (utilisée dans le compose généré).</summary>
|
||||
private string CentralUrl => "https://heimdall.tordais.cc";
|
||||
}
|
||||
@@ -4,14 +4,19 @@
|
||||
@inject HeimdallApiClient Api
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<MudText Typo="Typo.h4" Class="mb-6">
|
||||
<MudText Typo="Typo.h4" Class="mb-1">
|
||||
<i class="fas fa-video mr-2"></i>
|
||||
Sites
|
||||
</MudText>
|
||||
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-4">
|
||||
Créez et gérez les sites pour connecter vos agents de surveillance.
|
||||
</MudText>
|
||||
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@(() => _showCreate = true)" Class="mb-4">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Add" Class="mr-1" /> Nouveau site
|
||||
</MudButton>
|
||||
<div class="d-flex justify-space-between align-center mb-4">
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@(() => _showCreate = true)">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Add" Class="mr-1" /> Nouveau site
|
||||
</MudButton>
|
||||
</div>
|
||||
|
||||
@if (_loading)
|
||||
{
|
||||
@@ -41,14 +46,18 @@ else
|
||||
<MudTd DataLabel="Adresse">@context.Address</MudTd>
|
||||
<MudTd DataLabel="Fuseau">@context.Timezone</MudTd>
|
||||
<MudTd DataLabel="Statut">
|
||||
<MudText Color="@(context.Enabled ? Color.Success : Color.Default)" Typo="Typo.body2">
|
||||
@(context.Enabled ? "● Actif" : "○ Inactif")
|
||||
</MudText>
|
||||
<StatusChip Text="@(context.Enabled ? "Actif" : "Inactif")"
|
||||
Color="@(context.Enabled ? Color.Success : Color.Default)"
|
||||
Icon="@(context.Enabled ? Icons.Material.Filled.CheckCircle : Icons.Material.Filled.Cancel)" />
|
||||
</MudTd>
|
||||
<MudTd DataLabel="Actions">
|
||||
<MudTooltip Text="Générer un token d'enregistrement pour ce site">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.ContentCopy" Size="Size.Small"
|
||||
OnClick="@(() => CopyToken(context.Id))" />
|
||||
<MudTooltip Text="Modifier ce site">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Edit" Size="Size.Small"
|
||||
OnClick="@(() => OpenEdit(context))" />
|
||||
</MudTooltip>
|
||||
<MudTooltip Text="Installer un agent sur ce site">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Download" Size="Size.Small" Color="Color.Info"
|
||||
OnClick="@(() => CopyToken(context.Id, context.Name))" />
|
||||
</MudTooltip>
|
||||
<MudTooltip Text="Supprimer ce site">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Delete" Size="Size.Small" Color="Color.Error"
|
||||
@@ -117,7 +126,72 @@ else
|
||||
</MudDialog>
|
||||
}
|
||||
|
||||
@* ─── Token dialog ──────────────────────────────────────────── *@
|
||||
@* ─── Edit dialog ───────────────────────────────────────────── *@
|
||||
@if (_showEdit)
|
||||
{
|
||||
<MudOverlay Visible="@_showEdit" OnClick="@(() => _showEdit = false)" />
|
||||
<MudDialog @bind-Visible="_showEdit">
|
||||
<TitleContent><MudText Typo="Typo.h6">Modifier le site</MudText></TitleContent>
|
||||
<DialogContent>
|
||||
<MudTextField @bind-Value="_editName" Label="Nom du site *" Variant="Variant.Outlined"
|
||||
Class="mb-4" Required="true" Immediate="true" />
|
||||
<MudTextField @bind-Value="_editAddress" Label="Adresse" Variant="Variant.Outlined" Class="mb-4" />
|
||||
<MudTextField @bind-Value="_editTimezone" Label="Fuseau horaire" Variant="Variant.Outlined"
|
||||
Class="mb-4" HelperText="Ex: Europe/Paris (défaut: UTC)" />
|
||||
@if (!string.IsNullOrEmpty(_editError))
|
||||
{
|
||||
<MudAlert Severity="Severity.Error" Class="mb-4">@_editError</MudAlert>
|
||||
}
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton Variant="Variant.Text" OnClick="@(() => _showEdit = false)">Annuler</MudButton>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@SaveEdit" Disabled="@_editing">
|
||||
@if (_editing) { <MudProgressCircular Size="Size.Small" Class="mr-1" /> }
|
||||
Enregistrer
|
||||
</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
}
|
||||
|
||||
@* ─── Install agent dialog (façon Pangolin) ─────────────────── *@
|
||||
@if (_showInstall)
|
||||
{
|
||||
<MudOverlay Visible="@_showInstall" OnClick="@(() => _showInstall = false)" />
|
||||
<MudDialog @bind-Visible="_showInstall" Options="new DialogOptions { MaxWidth = MaxWidth.Large, FullWidth = true }">
|
||||
<TitleContent>
|
||||
<MudText Typo="Typo.h6">Installer un agent — @_installSiteName</MudText>
|
||||
</TitleContent>
|
||||
<DialogContent>
|
||||
@if (_tokenLoading)
|
||||
{
|
||||
<MudProgressCircular Indeterminate="true" Class="mb-4" />
|
||||
<MudText>Génération du token...</MudText>
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(_tokenError))
|
||||
{
|
||||
<MudAlert Severity="Severity.Error">@_tokenError</MudAlert>
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(_generatedToken))
|
||||
{
|
||||
<MudAlert Severity="Severity.Warning" Class="mb-4">
|
||||
<MudText Typo="Typo.body2" Class="mb-2">
|
||||
Ce token expire dans 24h et ne sera plus affiché.
|
||||
</MudText>
|
||||
<code class="d-block p-2" style="background:#f5f5f5;word-break:break-all;font-size:0.85rem;">
|
||||
@_generatedToken
|
||||
</code>
|
||||
</MudAlert>
|
||||
<SiteInstallPanel SiteName="@_installSiteName" SiteToken="@_generatedToken"
|
||||
CentralUrl="@CentralUrl" />
|
||||
}
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton Variant="Variant.Text" OnClick="@(() => _showInstall = false)">Fermer</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
}
|
||||
|
||||
@* ─── Token dialog (génération simple depuis le tableau) ─────── *@
|
||||
@if (_showTokenDialog)
|
||||
{
|
||||
<MudOverlay Visible="@_showTokenDialog" OnClick="@(() => _showTokenDialog = false)" />
|
||||
@@ -172,12 +246,36 @@ else
|
||||
private string _createdToken = "";
|
||||
private bool IsCreateDisabled => _saving || !string.IsNullOrEmpty(_createdToken);
|
||||
|
||||
// Token generation dialog
|
||||
// Token generation / install dialog
|
||||
private bool _showInstall;
|
||||
private bool _showTokenDialog;
|
||||
private bool _tokenLoading;
|
||||
private string _generatedToken = "";
|
||||
private string _tokenError = "";
|
||||
private Guid _tokenSiteId;
|
||||
private string _installSiteName = "";
|
||||
|
||||
// Edit dialog
|
||||
private bool _showEdit;
|
||||
private bool _editing;
|
||||
private Guid _editId;
|
||||
private string _editName = "";
|
||||
private string? _editAddress;
|
||||
private string? _editTimezone;
|
||||
private string _editError = "";
|
||||
|
||||
/// <summary>URL publique du serveur Heimdall (utilisée dans le compose généré).</summary>
|
||||
private string CentralUrl
|
||||
=> _centralUrl ??= ResolveCentralUrl();
|
||||
|
||||
private string? _centralUrl;
|
||||
|
||||
private static string ResolveCentralUrl()
|
||||
{
|
||||
// Défaut : URL du serveur local ; à remplacer par la config publique
|
||||
// (ex: https://heimdall.tordais.cc) quand elle sera exposée.
|
||||
return "https://heimdall.tordais.cc";
|
||||
}
|
||||
|
||||
protected override async Task OnInitializedAsync() => await LoadSites();
|
||||
|
||||
@@ -242,13 +340,14 @@ else
|
||||
finally { _saving = false; }
|
||||
}
|
||||
|
||||
private async Task CopyToken(Guid siteId)
|
||||
private async Task CopyToken(Guid siteId, string siteName)
|
||||
{
|
||||
_tokenSiteId = siteId;
|
||||
_installSiteName = siteName;
|
||||
_tokenLoading = true;
|
||||
_tokenError = "";
|
||||
_generatedToken = "";
|
||||
_showTokenDialog = true;
|
||||
_showInstall = true;
|
||||
StateHasChanged();
|
||||
|
||||
try
|
||||
@@ -274,6 +373,33 @@ else
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenEdit(SiteItem site)
|
||||
{
|
||||
_editId = site.Id;
|
||||
_editName = site.Name;
|
||||
_editAddress = site.Address;
|
||||
_editTimezone = site.Timezone;
|
||||
_editError = "";
|
||||
_showEdit = true;
|
||||
}
|
||||
|
||||
private async Task SaveEdit()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_editName)) { _editError = "Le nom est requis"; return; }
|
||||
_editing = true;
|
||||
_editError = "";
|
||||
try
|
||||
{
|
||||
var ok = await Api.UpdateSiteAsync(_editId, _editName, _editAddress, _editTimezone);
|
||||
if (!ok) { _editError = "Erreur lors de la mise à jour"; return; }
|
||||
Snackbar.Add("Site modifié avec succès", Severity.Success);
|
||||
_showEdit = false;
|
||||
await LoadSites();
|
||||
}
|
||||
catch (Exception ex) { _editError = $"Erreur : {ex.Message}"; }
|
||||
finally { _editing = false; }
|
||||
}
|
||||
|
||||
private async Task DeleteSite(Guid id, string name)
|
||||
{
|
||||
if (await Api.DeleteSiteAsync(id))
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
@* SiteInstallPanel.razor — génère les instructions d'installation d'un agent
|
||||
Heimdall sur un site, façon Pangolin (choix de la méthode + code à copier).
|
||||
Modes : Docker Compose (recommandé) ou script shell. *@
|
||||
@using MudBlazor
|
||||
|
||||
<MudText Typo="Typo.h6" Class="mb-1">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Download" Size="Size.Small" Class="mr-1" />
|
||||
Installer un agent sur ce site
|
||||
</MudText>
|
||||
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-4">
|
||||
Déployez le connecteur d'agent Heimdall sur la machine qui doit surveiller ce site.
|
||||
</MudText>
|
||||
|
||||
<MudTabs Class="mb-4" Elevation="0" Rounded="true">
|
||||
<MudTabPanel Text="Docker Compose" Icon="@Icons.Material.Filled.IntegrationInstructions">
|
||||
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-2">
|
||||
Copiez ce fichier <code>docker-compose.yml</code> sur la machine cible puis lancez
|
||||
<code>docker compose up -d</code>.
|
||||
</MudText>
|
||||
<MudPaper Class="pa-3" Style="border-radius: 8px; background: #0d1117; overflow-x: auto;">
|
||||
<pre class="mb-0" style="color:#c9d1d9;font-size:0.85rem;"><code>@ComposeYaml</code></pre>
|
||||
</MudPaper>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" Class="mt-3"
|
||||
OnClick="@(() => CopyCode(ComposeYaml))" StartIcon="@Icons.Material.Filled.ContentCopy">
|
||||
Copier le docker-compose.yml
|
||||
</MudButton>
|
||||
</MudTabPanel>
|
||||
<MudTabPanel Text="Script shell" Icon="@Icons.Material.Filled.Terminal">
|
||||
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-2">
|
||||
Exécutez cette commande sur la machine cible (Linux) :
|
||||
</MudText>
|
||||
<MudPaper Class="pa-3" Style="border-radius: 8px; background: #0d1117; overflow-x: auto;">
|
||||
<pre class="mb-0" style="color:#c9d1d9;font-size:0.85rem;"><code>@ShellCommand</code></pre>
|
||||
</MudPaper>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" Class="mt-3"
|
||||
OnClick="@(() => CopyCode(ShellCommand))" StartIcon="@Icons.Material.Filled.ContentCopy">
|
||||
Copier la commande
|
||||
</MudButton>
|
||||
</MudTabPanel>
|
||||
</MudTabs>
|
||||
|
||||
@code {
|
||||
/// <summary>Nom du site cible.</summary>
|
||||
[Parameter, EditorRequired] public string SiteName { get; set; } = "";
|
||||
|
||||
/// <summary>Token d'enregistrement du site (affiché dans le compose).</summary>
|
||||
[Parameter, EditorRequired] public string SiteToken { get; set; } = "";
|
||||
|
||||
/// <summary>URL publique du serveur Heimdall (ex: https://heimdall.tordais.cc).</summary>
|
||||
[Parameter, EditorRequired] public string CentralUrl { get; set; } = "";
|
||||
|
||||
[Inject] private ISnackbar Snackbar { get; set; } = default!;
|
||||
|
||||
private string ComposeYaml
|
||||
{
|
||||
get
|
||||
{
|
||||
var safeName = Slugify(SiteName);
|
||||
return $$"""
|
||||
services:
|
||||
heimdall-agent:
|
||||
image: eltruncho/heimdall-agent:latest
|
||||
container_name: heimdall-agent-{{safeName}}
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
Agent__CentralUrl: {{CentralUrl}}
|
||||
Agent__SiteToken: {{SiteToken}}
|
||||
Agent__AgentName: {{SiteName}}
|
||||
Agent__HeartbeatIntervalSeconds: "30"
|
||||
Agent__StateDirectory: /var/lib/heimdall
|
||||
volumes:
|
||||
- agent_state:/var/lib/heimdall
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8080/healthz"]
|
||||
interval: 30s
|
||||
timeout: 5s
|
||||
retries: 3
|
||||
start_period: 15s
|
||||
|
||||
volumes:
|
||||
agent_state:
|
||||
""";
|
||||
}
|
||||
}
|
||||
|
||||
private string ShellCommand
|
||||
=> $"curl -sSL {CentralUrl}/install-agent.sh -o install-agent.sh && bash install-agent.sh --site-token {SiteToken} --name \"{SiteName}\"";
|
||||
|
||||
private async Task CopyCode(string code)
|
||||
{
|
||||
await JsRuntime.InvokeVoidAsync("navigator.clipboard.writeText", code);
|
||||
Snackbar.Add("Code copié dans le presse-papiers", Severity.Success);
|
||||
}
|
||||
|
||||
[Inject] private IJSRuntime JsRuntime { get; set; } = default!;
|
||||
|
||||
private static string Slugify(string value)
|
||||
{
|
||||
var sb = new System.Text.StringBuilder();
|
||||
foreach (var ch in value.ToLowerInvariant())
|
||||
sb.Append(char.IsLetterOrDigit(ch) ? ch : '-');
|
||||
return sb.ToString().Trim('-');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user