Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add recent usage statistics (#1037)

Leendert de Borst8e6d1257001a
diff --git a/apps/server/AliasVault.Admin/Main/Models/RecentUsageAliases.cs b/apps/server/AliasVault.Admin/Main/Models/RecentUsageAliases.cs
new file mode 100644
index 000000000..49c1338ad
--- /dev/null
+++ b/apps/server/AliasVault.Admin/Main/Models/RecentUsageAliases.cs
@@ -0,0 +1,39 @@
+//-----------------------------------------------------------------------
+// <copyright file="RecentUsageAliases.cs" company="lanedirt">
+// Copyright (c) lanedirt. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Admin.Main.Models;
+
+/// <summary>
+/// Model representing users with most aliases created in the last 72 hours.
+/// </summary>
+public class RecentUsageAliases
+{
+ /// <summary>
+ /// Gets or sets the user ID.
+ /// </summary>
+ public string UserId { get; set; } = string.Empty;
+
+ /// <summary>
+ /// Gets or sets the username.
+ /// </summary>
+ public string Username { get; set; } = string.Empty;
+
+ /// <summary>
+ /// Gets or sets the number of aliases created in the last 72 hours.
+ /// </summary>
+ public int AliasCount72h { get; set; }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether the account is disabled/blocked.
+ /// </summary>
+ public bool IsDisabled { get; set; }
+
+ /// <summary>
+ /// Gets or sets the date when the user registered their account.
+ /// </summary>
+ public DateTime RegistrationDate { get; set; }
+}
diff --git a/apps/server/AliasVault.Admin/Main/Models/RecentUsageEmails.cs b/apps/server/AliasVault.Admin/Main/Models/RecentUsageEmails.cs
new file mode 100644
index 000000000..a6d69c4ba
--- /dev/null
+++ b/apps/server/AliasVault.Admin/Main/Models/RecentUsageEmails.cs
@@ -0,0 +1,39 @@
+//-----------------------------------------------------------------------
+// <copyright file="RecentUsageEmails.cs" company="lanedirt">
+// Copyright (c) lanedirt. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Admin.Main.Models;
+
+/// <summary>
+/// Model representing users with most emails received in the last 72 hours.
+/// </summary>
+public class RecentUsageEmails
+{
+ /// <summary>
+ /// Gets or sets the user ID.
+ /// </summary>
+ public string UserId { get; set; } = string.Empty;
+
+ /// <summary>
+ /// Gets or sets the username.
+ /// </summary>
+ public string Username { get; set; } = string.Empty;
+
+ /// <summary>
+ /// Gets or sets the number of emails received in the last 72 hours.
+ /// </summary>
+ public int EmailCount72h { get; set; }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether the account is disabled/blocked.
+ /// </summary>
+ public bool IsDisabled { get; set; }
+
+ /// <summary>
+ /// Gets or sets the date when the user registered their account.
+ /// </summary>
+ public DateTime RegistrationDate { get; set; }
+}
diff --git a/apps/server/AliasVault.Admin/Main/Models/RecentUsageRegistrations.cs b/apps/server/AliasVault.Admin/Main/Models/RecentUsageRegistrations.cs
new file mode 100644
index 000000000..307f28df5
--- /dev/null
+++ b/apps/server/AliasVault.Admin/Main/Models/RecentUsageRegistrations.cs
@@ -0,0 +1,29 @@
+//-----------------------------------------------------------------------
+// <copyright file="RecentUsageRegistrations.cs" company="lanedirt">
+// Copyright (c) lanedirt. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Admin.Main.Models;
+
+/// <summary>
+/// Model representing IP addresses with most registrations in the last 72 hours.
+/// </summary>
+public class RecentUsageRegistrations
+{
+ /// <summary>
+ /// Gets or sets the original IP address (for linking purposes).
+ /// </summary>
+ public string OriginalIpAddress { get; set; } = string.Empty;
+
+ /// <summary>
+ /// Gets or sets the anonymized IP address.
+ /// </summary>
+ public string IpAddress { get; set; } = string.Empty;
+
+ /// <summary>
+ /// Gets or sets the number of registrations from this IP in the last 72 hours.
+ /// </summary>
+ public int RegistrationCount72h { get; set; }
+}
diff --git a/apps/server/AliasVault.Admin/Main/Models/RecentUsageStatistics.cs b/apps/server/AliasVault.Admin/Main/Models/RecentUsageStatistics.cs
new file mode 100644
index 000000000..805749e81
--- /dev/null
+++ b/apps/server/AliasVault.Admin/Main/Models/RecentUsageStatistics.cs
@@ -0,0 +1,29 @@
+//-----------------------------------------------------------------------
+// <copyright file="RecentUsageStatistics.cs" company="lanedirt">
+// Copyright (c) lanedirt. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Admin.Main.Models;
+
+/// <summary>
+/// Model representing comprehensive recent usage statistics for the last 72 hours.
+/// </summary>
+public class RecentUsageStatistics
+{
+ /// <summary>
+ /// Gets or sets the list of users with most aliases created in the last 72 hours.
+ /// </summary>
+ public List<RecentUsageAliases> TopUsersByAliases72h { get; set; } = new();
+
+ /// <summary>
+ /// Gets or sets the list of users with most emails received in the last 72 hours.
+ /// </summary>
+ public List<RecentUsageEmails> TopUsersByEmails72h { get; set; } = new();
+
+ /// <summary>
+ /// Gets or sets the list of IP addresses with most registrations in the last 72 hours.
+ /// </summary>
+ public List<RecentUsageRegistrations> TopIpsByRegistrations72h { get; set; } = new();
+}
diff --git a/apps/server/AliasVault.Admin/Main/Pages/Dashboard/Index.razor b/apps/server/AliasVault.Admin/Main/Pages/Dashboard/Index.razor
index 9ba1025d6..c0ff17556 100644
--- a/apps/server/AliasVault.Admin/Main/Pages/Dashboard/Index.razor
+++ b/apps/server/AliasVault.Admin/Main/Pages/Dashboard/Index.razor
@@ -9,6 +9,13 @@
Title="AliasVault Admin"
Description="Welcome to the AliasVault admin dashboard. Below you can find statistics about recent activity on this server.">
<CustomActions>
+ <a href="recent-usage-stats" class="inline-flex items-center px-3 py-2 text-sm font-medium text-gray-600 bg-gray-100 border border-gray-300 rounded-md hover:bg-gray-200 hover:text-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500 dark:bg-gray-700 dark:text-gray-300 dark:border-gray-600 dark:hover:bg-gray-600 dark:hover:text-gray-200 mr-3">
+ <svg class="w-4 h-4 mr-2" fill="currentColor" viewBox="0 0 20 20">
+ <path d="M10 12a2 2 0 100-4 2 2 0 000 4z"/>
+ <path fill-rule="evenodd" d="M.458 10C1.732 5.943 5.522 3 10 3s8.268 2.943 9.542 7c-1.274 4.057-5.064 7-9.542 7S1.732 14.057.458 10zM14 10a4 4 0 11-8 0 4 4 0 018 0z" clip-rule="evenodd"/>
+ </svg>
+ Recent Usage (72h)
+ </a>
<a href="all-time-stats" class="inline-flex items-center px-3 py-2 text-sm font-medium text-gray-600 bg-gray-100 border border-gray-300 rounded-md hover:bg-gray-200 hover:text-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500 dark:bg-gray-700 dark:text-gray-300 dark:border-gray-600 dark:hover:bg-gray-600 dark:hover:text-gray-200 mr-3">
<svg class="w-4 h-4 mr-2" fill="currentColor" viewBox="0 0 20 20">
<path d="M2 11a1 1 0 011-1h2a1 1 0 011 1v5a1 1 0 01-1 1H3a1 1 0 01-1-1v-5zM8 7a1 1 0 011-1h2a1 1 0 011 1v9a1 1 0 01-1 1H9a1 1 0 01-1-1V7zM14 4a1 1 0 011-1h2a1 1 0 011 1v12a1 1 0 01-1 1h-2a1 1 0 01-1-1V4z"/>
diff --git a/apps/server/AliasVault.Admin/Main/Pages/Dashboard/RecentUsage/Components/RecentUsageAliasesTable.razor b/apps/server/AliasVault.Admin/Main/Pages/Dashboard/RecentUsage/Components/RecentUsageAliasesTable.razor
new file mode 100644
index 000000000..e971d3a9c
--- /dev/null
+++ b/apps/server/AliasVault.Admin/Main/Pages/Dashboard/RecentUsage/Components/RecentUsageAliasesTable.razor
@@ -0,0 +1,80 @@
+@using AliasVault.Admin.Main.Models
+@using AliasVault.RazorComponents.Tables
+
+<div class="p-4 bg-white border border-gray-200 rounded-lg shadow-sm dark:border-gray-700 sm:p-6 dark:bg-gray-800">
+ <div class="flex items-center justify-between mb-4">
+ <div>
+ <h3 class="text-lg font-semibold text-gray-900 dark:text-white">Top Users by Aliases Created (Last 72h)</h3>
+ <p class="text-sm text-gray-500 dark:text-gray-400">Users who created the most email aliases in the last 72 hours</p>
+ </div>
+ </div>
+
+ @if (Data != null && Data.Any())
+ {
+ <div class="mb-3">
+ <Paginator CurrentPage="@CurrentPage" PageSize="@PageSize" TotalRecords="@Data.Count" OnPageChanged="@HandlePageChanged" />
+ </div>
+ <div class="overflow-x-auto">
+ <SortableTable Columns="@_tableColumns">
+ @foreach (var user in PagedData)
+ {
+ <SortableTableRow>
+ <SortableTableColumn IsPrimary="true">
+ <a href="users/@user.UserId" class="text-gray-900 dark:text-gray-100 hover:text-blue-600 dark:hover:text-blue-400 cursor-pointer">
+ @user.Username
+ </a>
+ @if (user.IsDisabled)
+ {
+ <span class="ml-2 inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200">
+ Blocked
+ </span>
+ }
+ </SortableTableColumn>
+ <SortableTableColumn>@user.AliasCount72h.ToString("N0")</SortableTableColumn>
+ <SortableTableColumn>@StatisticsService.GetAccountAge(user.RegistrationDate)</SortableTableColumn>
+ </SortableTableRow>
+ }
+ </SortableTable>
+ </div>
+ }
+ else if (Data != null && !Data.Any())
+ {
+ <div class="text-center text-gray-500 dark:text-gray-400">
+ <svg class="mx-auto h-12 w-12 text-gray-300 dark:text-gray-600" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"/>
+ </svg>
+ <h3 class="mt-2 text-sm font-medium text-gray-900 dark:text-white">No Recent Alias Activity</h3>
+ <p class="mt-1 text-sm text-gray-500 dark:text-gray-400">No aliases were created in the last 72 hours.</p>
+ </div>
+ }
+ else
+ {
+ <div class="px-6 py-8 flex justify-center">
+ <LoadingIndicator />
+ </div>
+ }
+</div>
+
+@code {
+ [Parameter]
+ public List<RecentUsageAliases>? Data { get; set; }
+
+ private int CurrentPage { get; set; } = 1;
+ private int PageSize { get; set; } = 20;
+
+ private IEnumerable<RecentUsageAliases> PagedData =>
+ Data?.Skip((CurrentPage - 1) * PageSize).Take(PageSize) ?? Enumerable.Empty<RecentUsageAliases>();
+
+ private readonly List<TableColumn> _tableColumns = new()
+ {
+ new() { Title = "User", PropertyName = "Username", Sortable = false },
+ new() { Title = "Aliases (72h)", PropertyName = "AliasCount72h", Sortable = false },
+ new() { Title = "Account Age", PropertyName = "RegistrationDate", Sortable = false }
+ };
+
+ private void HandlePageChanged(int page)
+ {
+ CurrentPage = page;
+ StateHasChanged();
+ }
+}
\ No newline at end of file
diff --git a/apps/server/AliasVault.Admin/Main/Pages/Dashboard/RecentUsage/Components/RecentUsageEmailsTable.razor b/apps/server/AliasVault.Admin/Main/Pages/Dashboard/RecentUsage/Components/RecentUsageEmailsTable.razor
new file mode 100644
index 000000000..d9ad3caec
--- /dev/null
+++ b/apps/server/AliasVault.Admin/Main/Pages/Dashboard/RecentUsage/Components/RecentUsageEmailsTable.razor
@@ -0,0 +1,102 @@
+@using AliasVault.Admin.Main.Models
+@using AliasVault.RazorComponents.Tables
+
+<div class="p-4 bg-white border border-gray-200 rounded-lg shadow-sm dark:border-gray-700 sm:p-6 dark:bg-gray-800">
+ <div class="flex items-center justify-between mb-4">
+ <div>
+ <h3 class="text-lg font-semibold text-gray-900 dark:text-white">Top Users by Emails Received (Last 72h)</h3>
+ <p class="text-sm text-gray-500 dark:text-gray-400">Users who received the most emails in the last 72 hours</p>
+ </div>
+ </div>
+
+ @if (Data != null && Data.Any())
+ {
+ <div class="mb-3">
+ <Paginator CurrentPage="@CurrentPage" PageSize="@PageSize" TotalRecords="@Data.Count" OnPageChanged="@HandlePageChanged" />
+ </div>
+ <div class="overflow-x-auto">
+ <SortableTable Columns="@_tableColumns">
+ @foreach (var user in PagedData)
+ {
+ <SortableTableRow>
+ <SortableTableColumn IsPrimary="true">
+ <a href="users/@user.UserId" class="text-gray-900 dark:text-gray-100 hover:text-blue-600 dark:hover:text-blue-400 cursor-pointer">
+ @user.Username
+ </a>
+ @if (user.IsDisabled)
+ {
+ <span class="ml-2 inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200">
+ Blocked
+ </span>
+ }
+ </SortableTableColumn>
+ <SortableTableColumn>@user.EmailCount72h.ToString("N0")</SortableTableColumn>
+ <SortableTableColumn>@GetAccountAge(user.RegistrationDate)</SortableTableColumn>
+ </SortableTableRow>
+ }
+ </SortableTable>
+ </div>
+ }
+ else if (Data != null && !Data.Any())
+ {
+ <div class="text-center text-gray-500 dark:text-gray-400">
+ <svg class="mx-auto h-12 w-12 text-gray-300 dark:text-gray-600" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 8l4 4 4-4m0 6l4 4 4-4"/>
+ </svg>
+ <h3 class="mt-2 text-sm font-medium text-gray-900 dark:text-white">No Recent Email Activity</h3>
+ <p class="mt-1 text-sm text-gray-500 dark:text-gray-400">No emails were received in the last 72 hours.</p>
+ </div>
+ }
+ else
+ {
+ <div class="px-6 py-8 flex justify-center">
+ <LoadingIndicator />
+ </div>
+ }
+</div>
+
+@code {
+ [Parameter]
+ public List<RecentUsageEmails>? Data { get; set; }
+
+ private int CurrentPage { get; set; } = 1;
+ private int PageSize { get; set; } = 20;
+
+ private IEnumerable<RecentUsageEmails> PagedData =>
+ Data?.Skip((CurrentPage - 1) * PageSize).Take(PageSize) ?? Enumerable.Empty<RecentUsageEmails>();
+
+ private readonly List<TableColumn> _tableColumns = new()
+ {
+ new() { Title = "User", PropertyName = "Username", Sortable = false },
+ new() { Title = "Emails (72h)", PropertyName = "EmailCount72h", Sortable = false },
+ new() { Title = "Account Age", PropertyName = "RegistrationDate", Sortable = false }
+ };
+
+ private void HandlePageChanged(int page)
+ {
+ CurrentPage = page;
+ StateHasChanged();
+ }
+
+ private string GetAccountAge(DateTime registrationDate)
+ {
+ var days = (DateTime.UtcNow - registrationDate).Days;
+
+ if (days == 0)
+ return "Today";
+ else if (days == 1)
+ return "1 day";
+ else if (days < 30)
+ return $"{days} days";
+ else if (days < 365)
+ {
+ var months = days / 30;
+ return months == 1 ? "1 month" : $"{months} months";
+ }
+ else
+ {
+ var years = days / 365;
+ return years == 1 ? "1 year" : $"{years} years";
+ }
+ }
+}
\ No newline at end of file
diff --git a/apps/server/AliasVault.Admin/Main/Pages/Dashboard/RecentUsage/Components/RecentUsageRegistrationsTable.razor b/apps/server/AliasVault.Admin/Main/Pages/Dashboard/RecentUsage/Components/RecentUsageRegistrationsTable.razor
new file mode 100644
index 000000000..c67c25279
--- /dev/null
+++ b/apps/server/AliasVault.Admin/Main/Pages/Dashboard/RecentUsage/Components/RecentUsageRegistrationsTable.razor
@@ -0,0 +1,72 @@
+@using AliasVault.Admin.Main.Models
+@using AliasVault.RazorComponents.Tables
+
+<div class="p-4 bg-white border border-gray-200 rounded-lg shadow-sm dark:border-gray-700 sm:p-6 dark:bg-gray-800">
+ <div class="flex items-center justify-between mb-4">
+ <div>
+ <h3 class="text-lg font-semibold text-gray-900 dark:text-white">Top IP Addresses by Registrations (Last 72h)</h3>
+ <p class="text-sm text-gray-500 dark:text-gray-400">IP addresses with the most account registrations in the last 72 hours (last octet anonymized)</p>
+ </div>
+ </div>
+
+ @if (Data != null && Data.Any())
+ {
+ <div class="mb-3">
+ <Paginator CurrentPage="@CurrentPage" PageSize="@PageSize" TotalRecords="@Data.Count" OnPageChanged="@HandlePageChanged" />
+ </div>
+ <div class="overflow-x-auto">
+ <SortableTable Columns="@_tableColumns">
+ @foreach (var ip in PagedData)
+ {
+ <SortableTableRow>
+ <SortableTableColumn IsPrimary="true">
+ <a href="logging/[email protected](ip.OriginalIpAddress)" class="font-mono text-gray-900 dark:text-gray-100 hover:text-blue-600 dark:hover:text-blue-400 cursor-pointer">
+ @ip.IpAddress
+ </a>
+ </SortableTableColumn>
+ <SortableTableColumn>@ip.RegistrationCount72h.ToString("N0")</SortableTableColumn>
+ </SortableTableRow>
+ }
+ </SortableTable>
+ </div>
+ }
+ else if (Data != null && !Data.Any())
+ {
+ <div class="text-center text-gray-500 dark:text-gray-400">
+ <svg class="mx-auto h-12 w-12 text-gray-300 dark:text-gray-600" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"/>
+ </svg>
+ <h3 class="mt-2 text-sm font-medium text-gray-900 dark:text-white">No Recent Registrations</h3>
+ <p class="mt-1 text-sm text-gray-500 dark:text-gray-400">No account registrations occurred in the last 72 hours.</p>
+ </div>
+ }
+ else
+ {
+ <div class="px-6 py-8 flex justify-center">
+ <LoadingIndicator />
+ </div>
+ }
+</div>
+
+@code {
+ [Parameter]
+ public List<RecentUsageRegistrations>? Data { get; set; }
+
+ private int CurrentPage { get; set; } = 1;
+ private int PageSize { get; set; } = 20;
+
+ private IEnumerable<RecentUsageRegistrations> PagedData =>
+ Data?.Skip((CurrentPage - 1) * PageSize).Take(PageSize) ?? Enumerable.Empty<RecentUsageRegistrations>();
+
+ private readonly List<TableColumn> _tableColumns = new()
+ {
+ new() { Title = "IP Range", PropertyName = "IpAddress", Sortable = false },
+ new() { Title = "Registrations (72h)", PropertyName = "RegistrationCount72h", Sortable = false }
+ };
+
+ private void HandlePageChanged(int page)
+ {
+ CurrentPage = page;
+ StateHasChanged();
+ }
+}
\ No newline at end of file
diff --git a/apps/server/AliasVault.Admin/Main/Pages/Dashboard/RecentUsageStats.razor b/apps/server/AliasVault.Admin/Main/Pages/Dashboard/RecentUsageStats.razor
new file mode 100644
index 000000000..3b610210b
--- /dev/null
+++ b/apps/server/AliasVault.Admin/Main/Pages/Dashboard/RecentUsageStats.razor
@@ -0,0 +1,90 @@
+@page "/recent-usage-stats"
+@using AliasVault.Admin.Main.Models
+@using AliasVault.Admin.Services
+@using AliasVault.Admin.Main.Pages.Dashboard.RecentUsage.Components
+@inherits MainBase
+@inject StatisticsService StatisticsService
+
+<LayoutPageTitle>Recent Usage Statistics</LayoutPageTitle>
+
+<PageHeader
+ BreadcrumbItems="@BreadcrumbItems"
+ Title="Recent Usage Statistics"
+ Description="View usage patterns from the last 72 hours.">
+ <CustomActions>
+ <RefreshButton OnClick="RefreshData" ButtonText="Refresh" />
+ </CustomActions>
+</PageHeader>
+
+<div class="px-4 space-y-6">
+ <!-- Recent Usage Analysis ---->
+ <div class="space-y-6">
+ <!-- Top Users by Aliases Created ---->
+ <RecentUsageAliasesTable Data="@_recentUsageStats?.TopUsersByAliases72h" />
+
+ <!-- Top Users by Emails Received ---->
+ <RecentUsageEmailsTable Data="@_recentUsageStats?.TopUsersByEmails72h" />
+
+ <!-- Top IP Addresses by Registrations ---->
+ <RecentUsageRegistrationsTable Data="@_recentUsageStats?.TopIpsByRegistrations72h" />
+ </div>
+
+ @if (_loadingError)
+ {
+ <div class="bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4">
+ <div class="flex">
+ <div class="flex-shrink-0">
+ <svg class="h-5 w-5 text-red-400" fill="currentColor" viewBox="0 0 20 20">
+ <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd"/>
+ </svg>
+ </div>
+ <div class="ml-3">
+ <h3 class="text-sm font-medium text-red-800 dark:text-red-200">Error Loading Statistics</h3>
+ <p class="text-sm text-red-700 dark:text-red-300 mt-1">Unable to retrieve recent usage statistics. Please try refreshing the page.</p>
+ </div>
+ </div>
+ </div>
+ }
+</div>
+
+@code {
+ private RecentUsageStatistics? _recentUsageStats;
+ private bool _loadingError = false;
+
+ protected override async Task OnInitializedAsync()
+ {
+ await base.OnInitializedAsync();
+
+ BreadcrumbItems.Add(new BreadcrumbItem { DisplayName = "Recent Usage Statistics" });
+
+ // Load statistics asynchronously
+ _ = LoadRecentUsageStatisticsAsync();
+ }
+
+ private void RefreshData()
+ {
+ // Reset data
+ _recentUsageStats = null;
+ _loadingError = false;
+
+ StateHasChanged();
+
+ // Reload statistics
+ _ = LoadRecentUsageStatisticsAsync();
+ }
+
+ private async Task LoadRecentUsageStatisticsAsync()
+ {
+ try
+ {
+ _recentUsageStats = await StatisticsService.GetRecentUsageStatisticsAsync();
+ StateHasChanged();
+ }
+ catch (Exception ex)
+ {
+ GlobalNotificationService.AddErrorMessage($"Error loading recent usage statistics: {ex.Message}");
+ _loadingError = true;
+ StateHasChanged();
+ }
+ }
+}
diff --git a/apps/server/AliasVault.Admin/Main/Pages/Users/View/Components/AuthLogTable.razor b/apps/server/AliasVault.Admin/Main/Pages/Users/View/Components/AuthLogTable.razor
index 78d24ec75..57fb356ab 100644
--- a/apps/server/AliasVault.Admin/Main/Pages/Users/View/Components/AuthLogTable.razor
+++ b/apps/server/AliasVault.Admin/Main/Pages/Users/View/Components/AuthLogTable.razor
@@ -15,7 +15,16 @@
<SortableTableColumn>@log.Timestamp.ToString("yyyy-MM-dd HH:mm")</SortableTableColumn>
<SortableTableColumn>@log.EventType</SortableTableColumn>
<SortableTableColumn><StatusPill Enabled="log.IsSuccess" TextTrue="Success" TextFalse="@log.FailureReason.ToString()" /></SortableTableColumn>
- <SortableTableColumn>@log.IpAddress</SortableTableColumn>
+ <SortableTableColumn>
+ @if (!string.IsNullOrEmpty(log.IpAddress))
+ {
+ <a href="logging/[email protected](log.IpAddress)" class="cursor-pointer">@log.IpAddress</a>
+ }
+ else
+ {
+ <span>-</span>
+ }
+ </SortableTableColumn>
<SortableTableColumn>@log.Client</SortableTableColumn>
</SortableTableRow>
}
diff --git a/apps/server/AliasVault.Admin/Services/StatisticsService.cs b/apps/server/AliasVault.Admin/Services/StatisticsService.cs
index 4ccf081d7..56aae3e89 100644
--- a/apps/server/AliasVault.Admin/Services/StatisticsService.cs
+++ b/apps/server/AliasVault.Admin/Services/StatisticsService.cs
@@ -9,6 +9,7 @@ namespace AliasVault.Admin.Services;
using AliasServerDb;
using AliasVault.Admin.Main.Models;
+using AliasVault.Shared.Models.Enums;
using Microsoft.EntityFrameworkCore;
/// <summary>
@@ -27,6 +28,39 @@ public class StatisticsService
_contextFactory = contextFactory;
}
+ /// <summary>
+ /// Formats the account age into a human-readable string.
+ /// </summary>
+ /// <param name="registrationDate">The registration date to format.</param>
+ /// <returns>Formatted account age string.</returns>
+ public static string GetAccountAge(DateTime registrationDate)
+ {
+ var days = (DateTime.UtcNow - registrationDate).Days;
+
+ if (days == 0)
+ {
+ return "Today";
+ }
+ else if (days == 1)
+ {
+ return "1 day";
+ }
+ else if (days < 30)
+ {
+ return $"{days} days";
+ }
+ else if (days < 365)
+ {
+ var months = days / 30;
+ return months == 1 ? "1 month" : $"{months} months";
+ }
+ else
+ {
+ var years = days / 365;
+ return years == 1 ? "1 year" : $"{years} years";
+ }
+ }
+
/// <summary>
/// Gets comprehensive server statistics including counts, storage metrics, and top users.
/// </summary>
@@ -59,6 +93,82 @@ public class StatisticsService
return stats;
}
+ /// <summary>
+ /// Gets recent usage statistics for the last 72 hours.
+ /// </summary>
+ /// <returns>Recent usage statistics object.</returns>
+ public async Task<RecentUsageStatistics> GetRecentUsageStatisticsAsync()
+ {
+ var stats = new RecentUsageStatistics();
+
+ // Get recent usage data in parallel
+ var tasks = new Task[]
+ {
+ GetTopUsersByAliases72hAsync().ContinueWith(t => stats.TopUsersByAliases72h = t.Result),
+ GetTopUsersByEmails72hAsync().ContinueWith(t => stats.TopUsersByEmails72h = t.Result),
+ GetTopIpsByRegistrations72hAsync().ContinueWith(t => stats.TopIpsByRegistrations72h = t.Result),
+ };
+
+ await Task.WhenAll(tasks);
+
+ return stats;
+ }
+
+ /// <summary>
+ /// Gets user-specific usage statistics for both all-time and recent periods.
+ /// </summary>
+ /// <param name="userId">The user ID to get statistics for.</param>
+ /// <returns>User usage statistics object.</returns>
+ public async Task<UserUsageStatistics> GetUserUsageStatisticsAsync(string userId)
+ {
+ await using var context = await _contextFactory.CreateDbContextAsync();
+
+ var stats = new UserUsageStatistics();
+ var cutoffDate = DateTime.UtcNow.AddHours(-72);
+
+ // Get latest vault for this user to get credential and email claim counts
+ var latestVault = await context.Vaults
+ .Where(v => v.UserId == userId)
+ .OrderByDescending(v => v.Version)
+ .FirstOrDefaultAsync();
+
+ if (latestVault != null)
+ {
+ stats.TotalCredentials = latestVault.CredentialsCount;
+ stats.TotalEmailClaims = latestVault.EmailClaimsCount;
+ }
+
+ // Get total received emails (all-time) - using UserEncryptionKey relationship
+ stats.TotalReceivedEmails = await context.Emails
+ .Where(e => e.EncryptionKey.UserId == userId)
+ .CountAsync();
+
+ // Get recent statistics (last 72 hours) - this is approximated since we don't have creation timestamps on individual credentials
+ // For recent credentials and email claims, we'll use vault versions created in the last 72h as a proxy
+ var recentVaultVersions = await context.Vaults
+ .Where(v => v.UserId == userId && v.CreatedAt >= cutoffDate)
+ .ToListAsync();
+
+ if (recentVaultVersions.Any())
+ {
+ var latestRecentVault = recentVaultVersions.OrderByDescending(v => v.Version).First();
+ var earliestRecentVault = recentVaultVersions.OrderBy(v => v.Version).FirstOrDefault();
+
+ if (earliestRecentVault != null)
+ {
+ stats.RecentCredentials72h = Math.Max(0, latestRecentVault.CredentialsCount - earliestRecentVault.CredentialsCount);
+ stats.RecentEmailClaims72h = Math.Max(0, latestRecentVault.EmailClaimsCount - earliestRecentVault.EmailClaimsCount);
+ }
+ }
+
+ // Get recent received emails (last 72 hours) - using DateSystem as created date
+ stats.RecentReceivedEmails72h = await context.Emails
+ .Where(e => e.EncryptionKey.UserId == userId && e.DateSystem >= cutoffDate)
+ .CountAsync();
+
+ return stats;
+ }
+
/// <summary>
/// Formats kilobytes into human-readable format.
/// </summary>
@@ -235,4 +345,106 @@ public class StatisticsService
LastActivity = ip.LastActivity,
}).ToList();
}
+
+ /// <summary>
+ /// Gets the top 20 users by number of aliases created in the last 72 hours.
+ /// </summary>
+ /// <returns>List of top users by recent aliases.</returns>
+ private async Task<List<RecentUsageAliases>> GetTopUsersByAliases72hAsync()
+ {
+ await using var context = await _contextFactory.CreateDbContextAsync();
+ var cutoffDate = DateTime.UtcNow.AddHours(-72);
+
+ var topUsers = await context.UserEmailClaims
+ .Where(uec => uec.UserId != null && uec.CreatedAt >= cutoffDate)
+ .GroupBy(uec => new { uec.UserId, uec.User!.UserName, uec.User.Blocked, uec.User.CreatedAt })
+ .Select(g => new
+ {
+ UserId = g.Key.UserId,
+ Username = g.Key.UserName,
+ IsDisabled = g.Key.Blocked,
+ RegistrationDate = g.Key.CreatedAt,
+ AliasCount72h = g.Count(),
+ })
+ .OrderByDescending(u => u.AliasCount72h)
+ .Take(20)
+ .ToListAsync();
+
+ return topUsers.Select(u => new RecentUsageAliases
+ {
+ UserId = u.UserId!,
+ Username = u.Username ?? "Unknown",
+ AliasCount72h = u.AliasCount72h,
+ IsDisabled = u.IsDisabled,
+ RegistrationDate = u.RegistrationDate,
+ }).ToList();
+ }
+
+ /// <summary>
+ /// Gets the top 20 users by number of emails received in the last 72 hours.
+ /// </summary>
+ /// <returns>List of top users by recent emails.</returns>
+ private async Task<List<RecentUsageEmails>> GetTopUsersByEmails72hAsync()
+ {
+ await using var context = await _contextFactory.CreateDbContextAsync();
+ var cutoffDate = DateTime.UtcNow.AddHours(-72);
+
+ var topUsers = await context.Emails
+ .Where(e => e.DateSystem >= cutoffDate)
+ .GroupBy(e => new { e.EncryptionKey.UserId, e.EncryptionKey.User!.UserName, e.EncryptionKey.User.Blocked, e.EncryptionKey.User.CreatedAt })
+ .Select(g => new
+ {
+ UserId = g.Key.UserId,
+ Username = g.Key.UserName,
+ IsDisabled = g.Key.Blocked,
+ RegistrationDate = g.Key.CreatedAt,
+ EmailCount72h = g.Count(),
+ })
+ .OrderByDescending(u => u.EmailCount72h)
+ .Take(20)
+ .ToListAsync();
+
+ return topUsers.Select(u => new RecentUsageEmails
+ {
+ UserId = u.UserId!,
+ Username = u.Username ?? "Unknown",
+ EmailCount72h = u.EmailCount72h,
+ IsDisabled = u.IsDisabled,
+ RegistrationDate = u.RegistrationDate,
+ }).ToList();
+ }
+
+ /// <summary>
+ /// Gets the top 20 IP addresses by number of registrations in the last 72 hours.
+ /// </summary>
+ /// <returns>List of top IP addresses by recent registrations.</returns>
+ private async Task<List<RecentUsageRegistrations>> GetTopIpsByRegistrations72hAsync()
+ {
+ await using var context = await _contextFactory.CreateDbContextAsync();
+ var cutoffDate = DateTime.UtcNow.AddHours(-72);
+
+ // Get registrations by IP from successful auth logs (using Register event type)
+ var topIps = await context.AuthLogs
+ .Where(al => al.Timestamp >= cutoffDate &&
+ al.IpAddress != null &&
+ al.IpAddress != "xxx.xxx.xxx.xxx" &&
+ al.IsSuccess &&
+ al.EventType == AuthEventType.Register)
+ .GroupBy(al => al.IpAddress)
+ .Select(g => new
+ {
+ IpAddress = g.Key,
+ RegistrationCount72h = g.Count(),
+ })
+ .OrderByDescending(ip => ip.RegistrationCount72h)
+ .Take(20)
+ .ToListAsync();
+
+ return topIps.Select(ip => new RecentUsageRegistrations
+ {
+ OriginalIpAddress = ip.IpAddress!,
+ IpAddress = AnonymizeIpAddress(ip.IpAddress!),
+ RegistrationCount72h = ip.RegistrationCount72h,
+ }).ToList();
+ }
}
diff --git a/apps/server/AliasVault.Admin/wwwroot/css/tailwind.css b/apps/server/AliasVault.Admin/wwwroot/css/tailwind.css
index 8b20ae92f..68b1651f4 100644
--- a/apps/server/AliasVault.Admin/wwwroot/css/tailwind.css
+++ b/apps/server/AliasVault.Admin/wwwroot/css/tailwind.css
@@ -1699,6 +1699,11 @@ video {
color: rgb(17 24 39 / var(--tw-text-opacity));
}
+.text-green-600 {
+ --tw-text-opacity: 1;
+ color: rgb(22 163 74 / var(--tw-text-opacity));
+}
+
.text-green-800 {
--tw-text-opacity: 1;
color: rgb(22 101 52 / var(--tw-text-opacity));
@@ -1714,6 +1719,11 @@ video {
color: rgb(184 112 47 / var(--tw-text-opacity));
}
+.text-purple-600 {
+ --tw-text-opacity: 1;
+ color: rgb(147 51 234 / var(--tw-text-opacity));
+}
+
.text-red-400 {
--tw-text-opacity: 1;
color: rgb(248 113 113 / var(--tw-text-opacity));
@@ -1749,6 +1759,11 @@ video {
color: rgb(133 77 14 / var(--tw-text-opacity));
}
+.text-green-500 {
+ --tw-text-opacity: 1;
+ color: rgb(34 197 94 / var(--tw-text-opacity));
+}
+
.underline {
text-decoration-line: underline;
}
@@ -2133,6 +2148,10 @@ video {
background-color: rgb(113 63 18 / var(--tw-bg-opacity));
}
+.dark\:bg-gray-900\/50:is(.dark *) {
+ background-color: rgb(17 24 39 / 0.5);
+}
+
.dark\:bg-opacity-80:is(.dark *) {
--tw-bg-opacity: 0.8;
}
@@ -2172,11 +2191,21 @@ video {
color: rgb(75 85 99 / var(--tw-text-opacity));
}
+.dark\:text-green-200:is(.dark *) {
+ --tw-text-opacity: 1;
+ color: rgb(187 247 208 / var(--tw-text-opacity));
+}
+
.dark\:text-green-300:is(.dark *) {
--tw-text-opacity: 1;
color: rgb(134 239 172 / var(--tw-text-opacity));
}
+.dark\:text-green-400:is(.dark *) {
+ --tw-text-opacity: 1;
+ color: rgb(74 222 128 / var(--tw-text-opacity));
+}
+
.dark\:text-primary-200:is(.dark *) {
--tw-text-opacity: 1;
color: rgb(251 203 116 / var(--tw-text-opacity));
@@ -2187,6 +2216,11 @@ video {
color: rgb(244 149 65 / var(--tw-text-opacity));
}
+.dark\:text-purple-400:is(.dark *) {
+ --tw-text-opacity: 1;
+ color: rgb(192 132 252 / var(--tw-text-opacity));
+}
+
.dark\:text-red-100:is(.dark *) {
--tw-text-opacity: 1;
color: rgb(254 226 226 / var(--tw-text-opacity));