Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add server settings page to admin (#221)
Leendert de Borst9b8bbebb44d2
diff --git a/src/AliasVault.Admin/Main/Layout/TopMenu.razor b/src/AliasVault.Admin/Main/Layout/TopMenu.razorindex 9fda86b5f..85f30c712 100644--- a/src/AliasVault.Admin/Main/Layout/TopMenu.razor+++ b/src/AliasVault.Admin/Main/Layout/TopMenu.razor@@ -25,6 +25,9 @@<NavLink href="logging/auth" class="block text-gray-700 hover:text-primary-700 dark:text-gray-400 dark:hover:text-white" ActiveClass="text-primary-700 dark:text-primary-500" Match="NavLinkMatch.All">Auth logs</NavLink>+ <NavLink href="settings/server" class="block text-gray-700 hover:text-primary-700 dark:text-gray-400 dark:hover:text-white" ActiveClass="text-primary-700 dark:text-primary-500" Match="NavLinkMatch.All">+ Server settings+ </NavLink></ul></div></div>@@ -99,6 +102,11 @@Auth logs</NavLink></li>+ <li class="block border-b dark:border-gray-700">+ <NavLink href="settings/server" class="block py-3 px-4 text-gray-900 lg:py-0 dark:text-white lg:hover:underline lg:px-0" ActiveClass="text-primary-700 dark:text-primary-500" Match="NavLinkMatch.All">+ Server settings+ </NavLink>+ </li></ul></nav>}diff --git a/src/AliasVault.Admin/Main/Pages/Dashboard/Index.razor b/src/AliasVault.Admin/Main/Pages/Dashboard/Index.razorindex 9b2459abe..6516cd25b 100644--- a/src/AliasVault.Admin/Main/Pages/Dashboard/Index.razor+++ b/src/AliasVault.Admin/Main/Pages/Dashboard/Index.razor@@ -31,6 +31,12 @@{if (firstRender){+ // Check if 2FA is enabled. If not, show a one-time warning on the dashboard.+ if (!UserService.User().TwoFactorEnabled)+ {+ GlobalNotificationService.AddWarningMessage("Two-factor authentication is not enabled. It is recommended to enable it in Account Settings for better security.", true);+ }+await RefreshData();}}diff --git a/src/AliasVault.Admin/Main/Pages/MainBase.cs b/src/AliasVault.Admin/Main/Pages/MainBase.csindex dd4ef5de9..c72d559c4 100644--- a/src/AliasVault.Admin/Main/Pages/MainBase.cs+++ b/src/AliasVault.Admin/Main/Pages/MainBase.cs@@ -102,18 +102,6 @@ public abstract class MainBase : OwningComponentBaseBreadcrumbItems.Add(new BreadcrumbItem { DisplayName = "Home", Url = NavigationService.BaseUri });}- /// <inheritdoc />- protected override async Task OnAfterRenderAsync(bool firstRender)- {- await base.OnAfterRenderAsync(firstRender);-- // Check if 2FA is enabled. If not, show a persistent notification.- if (!UserService.User().TwoFactorEnabled)- {- GlobalNotificationService.AddWarningMessage("Two-factor authentication is not enabled. Please enable it in Account Settings for better security.");- }- }-/// <summary>/// Gets the username from the authentication state asynchronously./// </summary>diff --git a/src/AliasVault.Admin/Main/Pages/Settings/Server.razor b/src/AliasVault.Admin/Main/Pages/Settings/Server.razornew file mode 100644index 000000000..02dd9ca96--- /dev/null+++ b/src/AliasVault.Admin/Main/Pages/Settings/Server.razor@@ -0,0 +1,98 @@+@page "/settings/server"+@inject ServerSettingsService SettingsService+@using AliasVault.Admin.Models+@inherits MainBase++<LayoutPageTitle>Server settings</LayoutPageTitle>++<PageHeader+ BreadcrumbItems="@BreadcrumbItems"+ Title="Server settings"+ Description="Configure AliasVault server settings.">+ <CustomActions>+ <ConfirmButton OnClick="SaveSettings">Save changes</ConfirmButton>+ </CustomActions>+</PageHeader>++<div class="px-4">+ <div class="p-4 mb-4 mx-4 bg-white border border-gray-200 rounded-lg shadow-sm dark:border-gray-700 sm:p-6 dark:bg-gray-800">+ <h3 class="mb-4 text-lg font-medium text-gray-900 dark:text-white">Data Retention</h3>+ <div class="grid gap-4 mb-4 sm:grid-cols-2 sm:gap-6 sm:mb-5">+ <div>+ <label for="generalLogRetention" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">General Log Retention (days)</label>+ <input type="number" @bind="Settings.GeneralLogRetentionDays" id="generalLogRetention" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500">+ <p class="mt-1 text-sm text-gray-500 dark:text-gray-400">Set to 0 to disable automatic cleanup</p>+ </div>+ <div>+ <label for="authLogRetention" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Auth Log Retention (days)</label>+ <input type="number" @bind="Settings.AuthLogRetentionDays" id="authLogRetention" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500">+ <p class="mt-1 text-sm text-gray-500 dark:text-gray-400">Set to 0 to disable automatic cleanup</p>+ </div>+ <div>+ <label for="emailRetention" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Email Retention (days)</label>+ <input type="number" @bind="Settings.EmailRetentionDays" id="emailRetention" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500">+ <p class="mt-1 text-sm text-gray-500 dark:text-gray-400">Set to 0 to disable automatic cleanup</p>+ </div>+ <div>+ <label for="maxEmails" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Max Emails per User</label>+ <input type="number" @bind="Settings.MaxEmailsPerUser" id="maxEmails" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500">+ <p class="mt-1 text-sm text-gray-500 dark:text-gray-400">Set to 0 for unlimited emails</p>+ </div>+ </div>++ <h3 class="mb-4 text-lg font-medium text-gray-900 dark:text-white">Maintenance Schedule</h3>+ <div class="mb-4">+ <label for="schedule" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Time (24h format)</label>+ <input type="time" @bind="Settings.MaintenanceTime" id="schedule" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500">+ <p class="mt-1 text-sm text-gray-500 dark:text-gray-400">Time when maintenance tasks are run</p>+ </div>+ <div class="mb-4">+ <label class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Run on Days</label>+ <div class="flex flex-wrap gap-4">+ @foreach (var day in DaysOfWeek)+ {+ var isSelected = Settings.TaskRunnerDays.Contains(day.Key);+ <div class="flex items-center">+ <input type="checkbox" checked="@isSelected" @onchange="@(e => ToggleDay(day.Key))" id="@($"day_{day.Key}")" class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">+ <label for="@($"day_{day.Key}")" class="ml-2 text-sm font-medium text-gray-900 dark:text-gray-300">@day.Value</label>+ </div>+ }+ </div>+ </div>+ </div>+</div>++@code {+ private ServerSettingsModel Settings { get; set; } = new();++ private readonly Dictionary<int, string> DaysOfWeek = new()+ {+ { 1, "Monday" },+ { 2, "Tuesday" },+ { 3, "Wednesday" },+ { 4, "Thursday" },+ { 5, "Friday" },+ { 6, "Saturday" },+ { 7, "Sunday" }+ };++ /// <inheritdoc/>+ protected override async Task OnInitializedAsync()+ {+ Settings = await SettingsService.GetAllSettingsAsync();+ }++ private void ToggleDay(int day)+ {+ if (Settings.TaskRunnerDays.Contains(day))+ Settings.TaskRunnerDays.Remove(day);+ else+ Settings.TaskRunnerDays.Add(day);+ }++ private async Task SaveSettings()+ {+ await SettingsService.SaveSettingsAsync(Settings);+ GlobalNotificationService.AddSuccessMessage("Settings saved successfully", true);+ }+}diff --git a/src/AliasVault.Admin/Main/_Imports.razor b/src/AliasVault.Admin/Main/_Imports.razorindex 07ecb91bf..6fa56fbf3 100644--- a/src/AliasVault.Admin/Main/_Imports.razor+++ b/src/AliasVault.Admin/Main/_Imports.razor@@ -12,6 +12,7 @@@using AliasVault.Admin@using AliasVault.Admin.Auth.Components@using AliasVault.Admin.Main+@using AliasVault.Admin.Main.Layout@using AliasVault.Admin.Main.Components@using AliasVault.Admin.Main.Components.Alerts@using AliasVault.Admin.Main.Components.Layout@@ -27,4 +28,3 @@@using AliasVault.Admin.Services@using AliasServerDb@using Microsoft.AspNetCore.Authorization-diff --git a/src/AliasVault.Admin/Models/ServerSettingsModel.cs b/src/AliasVault.Admin/Models/ServerSettingsModel.csnew file mode 100644index 000000000..4ef9bf826--- /dev/null+++ b/src/AliasVault.Admin/Models/ServerSettingsModel.cs@@ -0,0 +1,44 @@+//-----------------------------------------------------------------------+// <copyright file="ServerSettingsModel.cs" company="lanedirt">+// Copyright (c) lanedirt. All rights reserved.+// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.+// </copyright>+//-----------------------------------------------------------------------++namespace AliasVault.Admin.Models;++/// <summary>+/// Server settings model.+/// </summary>+public class ServerSettingsModel+{+ /// <summary>+ /// Gets or sets the general log retention days.+ /// </summary>+ public int GeneralLogRetentionDays { get; set; } = 30;++ /// <summary>+ /// Gets or sets the auth log retention days.+ /// </summary>+ public int AuthLogRetentionDays { get; set; } = 90;++ /// <summary>+ /// Gets or sets the email retention days.+ /// </summary>+ public int EmailRetentionDays { get; set; } = 30;++ /// <summary>+ /// Gets or sets the max emails per user.+ /// </summary>+ public int MaxEmailsPerUser { get; set; } = 100;++ /// <summary>+ /// Gets or sets the time when maintenance tasks are run (24h format).+ /// </summary>+ public TimeOnly MaintenanceTime { get; set; } = new TimeOnly(0, 0);++ /// <summary>+ /// Gets or sets the task runner days.+ /// </summary>+ public List<int> TaskRunnerDays { get; set; } = new() { 1, 2, 3, 4, 5, 6, 7 };+}diff --git a/src/AliasVault.Admin/Program.cs b/src/AliasVault.Admin/Program.csindex 7ef3cbf5c..aca4e8c22 100644--- a/src/AliasVault.Admin/Program.cs+++ b/src/AliasVault.Admin/Program.cs@@ -53,6 +53,7 @@ builder.Services.AddScoped<AuthenticationStateProvider, RevalidatingAuthenticatibuilder.Services.AddHttpContextAccessor();builder.Services.AddScoped<AuthLoggingService>();builder.Services.AddScoped<ConfirmModalService>();+builder.Services.AddScoped<ServerSettingsService>();builder.Services.AddSingleton(new VersionedContentService(Directory.GetCurrentDirectory() + "/wwwroot"));builder.Services.AddAuthentication(options =>diff --git a/src/AliasVault.Admin/Services/GlobalNotificationService.cs b/src/AliasVault.Admin/Services/GlobalNotificationService.csindex f7f626b6f..dfaabf05f 100644--- a/src/AliasVault.Admin/Services/GlobalNotificationService.cs+++ b/src/AliasVault.Admin/Services/GlobalNotificationService.cs@@ -139,10 +139,7 @@ public class GlobalNotificationServicemessages.Add(new KeyValuePair<string, string>("error", message));}- // Clear messages- SuccessMessages.Clear();- InfoMessages.Clear();- ErrorMessages.Clear();+ ClearMessages();return messages;}diff --git a/src/AliasVault.Admin/Services/ServerSettingsService.cs b/src/AliasVault.Admin/Services/ServerSettingsService.csnew file mode 100644index 000000000..752fb6434--- /dev/null+++ b/src/AliasVault.Admin/Services/ServerSettingsService.cs@@ -0,0 +1,131 @@+//-----------------------------------------------------------------------+// <copyright file="ServerSettingsService.cs" company="lanedirt">+// Copyright (c) lanedirt. All rights reserved.+// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.+// </copyright>+//-----------------------------------------------------------------------++namespace AliasVault.Admin.Services;++using System;+using System.Collections.Generic;+using System.Linq;+using System.Threading.Tasks;+using AliasServerDb;+using AliasVault.Admin.Models;+using Microsoft.EntityFrameworkCore;++/// <summary>+/// Server settings service.+/// </summary>+public class ServerSettingsService+{+ private readonly AliasServerDbContext _dbContext;+ private readonly Dictionary<string, string?> _cache = new();++ /// <summary>+ /// Initializes a new instance of the <see cref="ServerSettingsService"/> class.+ /// </summary>+ /// <param name="dbContext">The database context.</param>+ public ServerSettingsService(AliasServerDbContext dbContext)+ {+ _dbContext = dbContext;+ }++ /// <summary>+ /// Gets the setting async.+ /// </summary>+ /// <param name="key">The key.</param>+ /// <returns>The setting.</returns>+ public async Task<string?> GetSettingAsync(string key)+ {+ if (_cache.TryGetValue(key, out var cachedValue))+ {+ return cachedValue;+ }++ var setting = await _dbContext.ServerSettings.FirstOrDefaultAsync(x => x.Key == key);+ _cache[key] = setting?.Value;+ return setting?.Value;+ }++ /// <summary>+ /// Sets the setting async.+ /// </summary>+ /// <param name="key">The key.</param>+ /// <param name="value">The value.</param>+ /// <returns>A task.</returns>+ public async Task SetSettingAsync(string key, string? value)+ {+ // First check if the value is already cached and matches+ if (_cache.TryGetValue(key, out var cachedValue) && cachedValue == value)+ {+ return;+ }++ var setting = await _dbContext.ServerSettings.FirstOrDefaultAsync(x => x.Key == key);+ var now = DateTime.UtcNow;++ // If setting exists and value hasn't changed, return early+ if (setting?.Value == value)+ {+ // Update cache to match database+ _cache[key] = value;+ return;+ }++ if (setting == null)+ {+ setting = new ServerSetting+ {+ Key = key,+ Value = value,+ CreatedAt = now,+ UpdatedAt = now,+ };+ _dbContext.ServerSettings.Add(setting);+ }+ else+ {+ setting.Value = value;+ setting.UpdatedAt = now;+ }++ await _dbContext.SaveChangesAsync();+ _cache[key] = value;+ }++ /// <summary>+ /// Gets all settings async.+ /// </summary>+ /// <returns>The settings.</returns>+ public async Task<ServerSettingsModel> GetAllSettingsAsync()+ {+ var settings = await _dbContext.ServerSettings.ToDictionaryAsync(x => x.Key, x => x.Value);++ return new ServerSettingsModel+ {+ GeneralLogRetentionDays = int.TryParse(settings.GetValueOrDefault("GeneralLogRetentionDays"), out var generalDays) ? generalDays : 30,+ AuthLogRetentionDays = int.TryParse(settings.GetValueOrDefault("AuthLogRetentionDays"), out var authDays) ? authDays : 90,+ EmailRetentionDays = int.TryParse(settings.GetValueOrDefault("EmailRetentionDays"), out var emailDays) ? emailDays : 30,+ MaxEmailsPerUser = int.TryParse(settings.GetValueOrDefault("MaxEmailsPerUser"), out var maxEmails) ? maxEmails : 100,+ MaintenanceTime = TimeOnly.TryParse(settings.GetValueOrDefault("MaintenanceTime") ?? "00:00", out var time) ? time : new TimeOnly(0, 0),+ TaskRunnerDays = settings.GetValueOrDefault("TaskRunnerDays")?.Split(',').Select(int.Parse).ToList() ?? new List<int> { 1, 2, 3, 4, 5, 6, 7 },+ };+ }++ /// <summary>+ /// Saves the settings async.+ /// </summary>+ /// <param name="model">The model.</param>+ /// <returns>A task.</returns>+ public async Task SaveSettingsAsync(ServerSettingsModel model)+ {+ await SetSettingAsync("GeneralLogRetentionDays", model.GeneralLogRetentionDays.ToString());+ await SetSettingAsync("AuthLogRetentionDays", model.AuthLogRetentionDays.ToString());+ await SetSettingAsync("EmailRetentionDays", model.EmailRetentionDays.ToString());+ await SetSettingAsync("MaxEmailsPerUser", model.MaxEmailsPerUser.ToString());+ await SetSettingAsync("MaintenanceTime", model.MaintenanceTime.ToString("HH:mm"));+ await SetSettingAsync("TaskRunnerDays", string.Join(",", model.TaskRunnerDays));+ }+}diff --git a/src/Databases/AliasServerDb/AliasServerDbContext.cs b/src/Databases/AliasServerDb/AliasServerDbContext.csindex cca5d0616..b2bc58a7a 100644--- a/src/Databases/AliasServerDb/AliasServerDbContext.cs+++ b/src/Databases/AliasServerDb/AliasServerDbContext.cs@@ -126,6 +126,11 @@ public class AliasServerDbContext : WorkerStatusDbContext, IDataProtectionKeyCon/// </summary>public DbSet<AuthLog> AuthLogs { get; set; }+ /// <summary>+ /// Gets or sets the ServerSettings DbSet.+ /// </summary>+ public DbSet<ServerSetting> ServerSettings { get; set; } = null!;+/// <summary>/// The OnModelCreating method./// </summary>@@ -237,38 +242,25 @@ public class AliasServerDbContext : WorkerStatusDbContext, IDataProtectionKeyCon/// <param name="optionsBuilder">DbContextOptionsBuilder instance.</param>protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder){- if (!optionsBuilder.IsConfigured)+ if (optionsBuilder.IsConfigured){- var configuration = new ConfigurationBuilder()+ return;+ }++ var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json").Build();- // Add SQLite connection with enhanced settings- var connectionString = configuration.GetConnectionString("AliasServerDbContext") +- ";Mode=ReadWriteCreate;Cache=Shared" +- ";Journal Mode=WAL" +- ";Synchronous=Normal" +- ";Busy Timeout=30000";-- optionsBuilder- .UseSqlite(connectionString, options => options.CommandTimeout(60))- .UseLazyLoadingProxies();+ // Add SQLite connection with enhanced settings+ var connectionString = configuration.GetConnectionString("AliasServerDbContext") ++ ";Mode=ReadWriteCreate;Cache=Shared" ++ ";Journal Mode=WAL" ++ ";Synchronous=Normal" ++ ";Busy Timeout=30000";- // Set additional PRAGMA settings- var connection = Database.GetDbConnection();- if (connection.State != System.Data.ConnectionState.Open)- {- connection.Open();- }-- using (var command = connection.CreateCommand())- {- command.CommandText = @"- PRAGMA temp_store = MEMORY;- PRAGMA mmap_size = 1073741824;";- command.ExecuteNonQuery();- }- }+ optionsBuilder+ .UseSqlite(connectionString, options => options.CommandTimeout(60))+ .UseLazyLoadingProxies();}}diff --git a/src/Databases/AliasServerDb/Migrations/20241204121218_AddServerSettingsTable.Designer.cs b/src/Databases/AliasServerDb/Migrations/20241204121218_AddServerSettingsTable.Designer.csnew file mode 100644index 000000000..ec8da63cf--- /dev/null+++ b/src/Databases/AliasServerDb/Migrations/20241204121218_AddServerSettingsTable.Designer.cs@@ -0,0 +1,848 @@+// <auto-generated />+using System;+using AliasServerDb;+using Microsoft.EntityFrameworkCore;+using Microsoft.EntityFrameworkCore.Infrastructure;+using Microsoft.EntityFrameworkCore.Migrations;+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;++#nullable disable++namespace AliasServerDb.Migrations+{+ [DbContext(typeof(AliasServerDbContext))]+ [Migration("20241204121218_AddServerSettingsTable")]+ partial class AddServerSettingsTable+ {+ /// <inheritdoc />+ protected override void BuildTargetModel(ModelBuilder modelBuilder)+ {+#pragma warning disable 612, 618+ modelBuilder+ .HasAnnotation("ProductVersion", "9.0.0")+ .HasAnnotation("Proxies:ChangeTracking", false)+ .HasAnnotation("Proxies:CheckEquality", false)+ .HasAnnotation("Proxies:LazyLoading", true);++ modelBuilder.Entity("AliasServerDb.AdminRole", b =>+ {+ b.Property<string>("Id")+ .HasColumnType("TEXT");++ b.Property<string>("ConcurrencyStamp")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.ToTable("AdminRoles");+ });++ modelBuilder.Entity("AliasServerDb.AdminUser", b =>+ {+ b.Property<string>("Id")+ .HasColumnType("TEXT");++ b.Property<int>("AccessFailedCount")+ .HasColumnType("INTEGER");++ b.Property<string>("ConcurrencyStamp")+ .HasColumnType("TEXT");++ b.Property<string>("Email")+ .HasColumnType("TEXT");++ b.Property<bool>("EmailConfirmed")+ .HasColumnType("INTEGER");++ b.Property<DateTime?>("LastPasswordChanged")+ .HasColumnType("TEXT");++ b.Property<bool>("LockoutEnabled")+ .HasColumnType("INTEGER");++ b.Property<DateTimeOffset?>("LockoutEnd")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedEmail")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedUserName")+ .HasColumnType("TEXT");++ b.Property<string>("PasswordHash")+ .HasColumnType("TEXT");++ b.Property<string>("PhoneNumber")+ .HasColumnType("TEXT");++ b.Property<bool>("PhoneNumberConfirmed")+ .HasColumnType("INTEGER");++ b.Property<string>("SecurityStamp")+ .HasColumnType("TEXT");++ b.Property<bool>("TwoFactorEnabled")+ .HasColumnType("INTEGER");++ b.Property<string>("UserName")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.ToTable("AdminUsers");+ });++ modelBuilder.Entity("AliasServerDb.AliasVaultRole", b =>+ {+ b.Property<string>("Id")+ .HasColumnType("TEXT");++ b.Property<string>("ConcurrencyStamp")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedName")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.ToTable("AliasVaultRoles");+ });++ modelBuilder.Entity("AliasServerDb.AliasVaultUser", b =>+ {+ b.Property<string>("Id")+ .HasColumnType("TEXT");++ b.Property<int>("AccessFailedCount")+ .HasColumnType("INTEGER");++ b.Property<string>("ConcurrencyStamp")+ .HasColumnType("TEXT");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("TEXT");++ b.Property<string>("Email")+ .HasColumnType("TEXT");++ b.Property<bool>("EmailConfirmed")+ .HasColumnType("INTEGER");++ b.Property<bool>("LockoutEnabled")+ .HasColumnType("INTEGER");++ b.Property<DateTimeOffset?>("LockoutEnd")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedEmail")+ .HasColumnType("TEXT");++ b.Property<string>("NormalizedUserName")+ .HasColumnType("TEXT");++ b.Property<DateTime>("PasswordChangedAt")+ .HasColumnType("TEXT");++ b.Property<string>("PasswordHash")+ .HasColumnType("TEXT");++ b.Property<string>("PhoneNumber")+ .HasColumnType("TEXT");++ b.Property<bool>("PhoneNumberConfirmed")+ .HasColumnType("INTEGER");++ b.Property<string>("SecurityStamp")+ .HasColumnType("TEXT");++ b.Property<bool>("TwoFactorEnabled")+ .HasColumnType("INTEGER");++ b.Property<DateTime>("UpdatedAt")+ .HasColumnType("TEXT");++ b.Property<string>("UserName")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.ToTable("AliasVaultUsers");+ });++ modelBuilder.Entity("AliasServerDb.AliasVaultUserRefreshToken", b =>+ {+ b.Property<Guid>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("TEXT");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("TEXT");++ b.Property<string>("DeviceIdentifier")+ .IsRequired()+ .HasMaxLength(255)+ .HasColumnType("TEXT");++ b.Property<DateTime>("ExpireDate")+ .HasMaxLength(255)+ .HasColumnType("TEXT");++ b.Property<string>("IpAddress")+ .HasMaxLength(45)+ .HasColumnType("TEXT");++ b.Property<string>("PreviousTokenValue")+ .HasMaxLength(255)+ .HasColumnType("TEXT");++ b.Property<string>("UserId")+ .IsRequired()+ .HasMaxLength(255)+ .HasColumnType("TEXT");++ b.Property<string>("Value")+ .IsRequired()+ .HasMaxLength(255)+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("UserId");++ b.ToTable("AliasVaultUserRefreshTokens");+ });++ modelBuilder.Entity("AliasServerDb.AuthLog", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("AdditionalInfo")+ .HasMaxLength(255)+ .HasColumnType("TEXT");++ b.Property<string>("Browser")+ .HasMaxLength(100)+ .HasColumnType("TEXT");++ b.Property<string>("Country")+ .HasMaxLength(50)+ .HasColumnType("TEXT");++ b.Property<string>("DeviceType")+ .HasMaxLength(100)+ .HasColumnType("TEXT");++ b.Property<int>("EventType")+ .HasColumnType("nvarchar(50)");++ b.Property<int?>("FailureReason")+ .HasColumnType("INTEGER");++ b.Property<string>("IpAddress")+ .HasMaxLength(50)+ .HasColumnType("TEXT");++ b.Property<bool>("IsSuccess")+ .HasColumnType("INTEGER");++ b.Property<bool>("IsSuspiciousActivity")+ .HasColumnType("INTEGER");++ b.Property<string>("OperatingSystem")+ .HasMaxLength(100)+ .HasColumnType("TEXT");++ b.Property<string>("RequestPath")+ .HasMaxLength(100)+ .HasColumnType("TEXT");++ b.Property<DateTime>("Timestamp")+ .HasColumnType("TEXT");++ b.Property<string>("UserAgent")+ .HasMaxLength(255)+ .HasColumnType("TEXT");++ b.Property<string>("Username")+ .IsRequired()+ .HasMaxLength(255)+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex(new[] { "EventType" }, "IX_EventType");++ b.HasIndex(new[] { "IpAddress" }, "IX_IpAddress");++ b.HasIndex(new[] { "Timestamp" }, "IX_Timestamp");++ b.HasIndex(new[] { "Username", "IsSuccess", "Timestamp" }, "IX_Username_IsSuccess_Timestamp")+ .IsDescending(false, false, true);++ b.HasIndex(new[] { "Username", "Timestamp" }, "IX_Username_Timestamp")+ .IsDescending(false, true);++ b.ToTable("AuthLogs");+ });++ modelBuilder.Entity("AliasServerDb.Email", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<DateTime>("Date")+ .HasColumnType("TEXT");++ b.Property<DateTime>("DateSystem")+ .HasColumnType("TEXT");++ b.Property<string>("EncryptedSymmetricKey")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<string>("From")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<string>("FromDomain")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<string>("FromLocal")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<string>("MessageHtml")+ .HasColumnType("TEXT");++ b.Property<string>("MessagePlain")+ .HasColumnType("TEXT");++ b.Property<string>("MessagePreview")+ .HasColumnType("TEXT");++ b.Property<string>("MessageSource")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<bool>("PushNotificationSent")+ .HasColumnType("INTEGER");++ b.Property<string>("Subject")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<string>("To")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<string>("ToDomain")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<string>("ToLocal")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<Guid>("UserEncryptionKeyId")+ .HasMaxLength(255)+ .HasColumnType("TEXT");++ b.Property<bool>("Visible")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("Date");++ b.HasIndex("DateSystem");++ b.HasIndex("PushNotificationSent");++ b.HasIndex("ToLocal");++ b.HasIndex("UserEncryptionKeyId");++ b.HasIndex("Visible");++ b.ToTable("Emails");+ });++ modelBuilder.Entity("AliasServerDb.EmailAttachment", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<byte[]>("Bytes")+ .IsRequired()+ .HasColumnType("BLOB");++ b.Property<DateTime>("Date")+ .HasColumnType("TEXT");++ b.Property<int>("EmailId")+ .HasColumnType("INTEGER");++ b.Property<string>("Filename")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<int>("Filesize")+ .HasColumnType("INTEGER");++ b.Property<string>("MimeType")+ .IsRequired()+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("EmailId");++ b.ToTable("EmailAttachments");+ });++ modelBuilder.Entity("AliasServerDb.Log", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("Application")+ .IsRequired()+ .HasMaxLength(50)+ .HasColumnType("TEXT");++ b.Property<string>("Exception")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<string>("Level")+ .IsRequired()+ .HasMaxLength(128)+ .HasColumnType("TEXT");++ b.Property<string>("LogEvent")+ .IsRequired()+ .HasColumnType("TEXT")+ .HasColumnName("LogEvent");++ b.Property<string>("Message")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<string>("MessageTemplate")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<string>("Properties")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<string>("SourceContext")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<DateTime>("TimeStamp")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("Application");++ b.HasIndex("TimeStamp");++ b.ToTable("Logs", (string)null);+ });++ modelBuilder.Entity("AliasServerDb.ServerSetting", b =>+ {+ b.Property<string>("Key")+ .HasMaxLength(255)+ .HasColumnType("TEXT");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("TEXT");++ b.Property<DateTime>("UpdatedAt")+ .HasColumnType("TEXT");++ b.Property<string>("Value")+ .HasColumnType("TEXT");++ b.HasKey("Key");++ b.ToTable("ServerSettings");+ });++ modelBuilder.Entity("AliasServerDb.UserEmailClaim", b =>+ {+ b.Property<Guid>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("TEXT");++ b.Property<string>("Address")+ .IsRequired()+ .HasMaxLength(255)+ .HasColumnType("TEXT");++ b.Property<string>("AddressDomain")+ .IsRequired()+ .HasMaxLength(255)+ .HasColumnType("TEXT");++ b.Property<string>("AddressLocal")+ .IsRequired()+ .HasMaxLength(255)+ .HasColumnType("TEXT");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("TEXT");++ b.Property<DateTime>("UpdatedAt")+ .HasColumnType("TEXT");++ b.Property<string>("UserId")+ .HasMaxLength(255)+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("Address")+ .IsUnique();++ b.HasIndex("UserId");++ b.ToTable("UserEmailClaims");+ });++ modelBuilder.Entity("AliasServerDb.UserEncryptionKey", b =>+ {+ b.Property<Guid>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("TEXT");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("TEXT");++ b.Property<bool>("IsPrimary")+ .HasColumnType("INTEGER");++ b.Property<string>("PublicKey")+ .IsRequired()+ .HasMaxLength(2000)+ .HasColumnType("TEXT");++ b.Property<DateTime>("UpdatedAt")+ .HasColumnType("TEXT");++ b.Property<string>("UserId")+ .IsRequired()+ .HasMaxLength(255)+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("UserId");++ b.ToTable("UserEncryptionKeys");+ });++ modelBuilder.Entity("AliasServerDb.Vault", b =>+ {+ b.Property<Guid>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("TEXT");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("TEXT");++ b.Property<int>("CredentialsCount")+ .HasColumnType("INTEGER");++ b.Property<int>("EmailClaimsCount")+ .HasColumnType("INTEGER");++ b.Property<string>("EncryptionSettings")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<string>("EncryptionType")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<int>("FileSize")+ .HasColumnType("INTEGER");++ b.Property<long>("RevisionNumber")+ .HasColumnType("INTEGER");++ b.Property<string>("Salt")+ .IsRequired()+ .HasMaxLength(100)+ .HasColumnType("TEXT");++ b.Property<DateTime>("UpdatedAt")+ .HasColumnType("TEXT");++ b.Property<string>("UserId")+ .IsRequired()+ .HasMaxLength(255)+ .HasColumnType("TEXT");++ b.Property<string>("VaultBlob")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<string>("Verifier")+ .IsRequired()+ .HasMaxLength(1000)+ .HasColumnType("TEXT");++ b.Property<string>("Version")+ .IsRequired()+ .HasMaxLength(255)+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.HasIndex("UserId");++ b.ToTable("Vaults");+ });++ modelBuilder.Entity("AliasVault.WorkerStatus.Database.WorkerServiceStatus", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("CurrentStatus")+ .IsRequired()+ .HasMaxLength(50)+ .HasColumnType("TEXT");++ b.Property<string>("DesiredStatus")+ .IsRequired()+ .HasMaxLength(50)+ .HasColumnType("TEXT");++ b.Property<DateTime>("Heartbeat")+ .HasColumnType("TEXT");++ b.Property<string>("ServiceName")+ .IsRequired()+ .HasMaxLength(255)+ .HasColumnType("varchar");++ b.HasKey("Id");++ b.ToTable("WorkerServiceStatuses");+ });++ modelBuilder.Entity("Microsoft.AspNetCore.DataProtection.EntityFrameworkCore.DataProtectionKey", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("FriendlyName")+ .HasColumnType("TEXT");++ b.Property<string>("Xml")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.ToTable("DataProtectionKeys");+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ClaimType")+ .HasColumnType("TEXT");++ b.Property<string>("ClaimValue")+ .HasColumnType("TEXT");++ b.Property<string>("RoleId")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.ToTable("RoleClaims", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>+ {+ b.Property<int>("Id")+ .ValueGeneratedOnAdd()+ .HasColumnType("INTEGER");++ b.Property<string>("ClaimType")+ .HasColumnType("TEXT");++ b.Property<string>("ClaimValue")+ .HasColumnType("TEXT");++ b.Property<string>("UserId")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.ToTable("UserClaims", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>+ {+ b.Property<string>("LoginProvider")+ .HasColumnType("TEXT");++ b.Property<string>("ProviderKey")+ .HasColumnType("TEXT");++ b.Property<string>("ProviderDisplayName")+ .HasColumnType("TEXT");++ b.Property<string>("UserId")+ .HasColumnType("TEXT");++ b.HasKey("LoginProvider", "ProviderKey");++ b.ToTable("UserLogins", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>+ {+ b.Property<string>("UserId")+ .HasColumnType("TEXT");++ b.Property<string>("RoleId")+ .HasColumnType("TEXT");++ b.HasKey("UserId", "RoleId");++ b.ToTable("UserRoles", (string)null);+ });++ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>+ {+ b.Property<string>("UserId")+ .HasColumnType("TEXT");++ b.Property<string>("LoginProvider")+ .HasColumnType("TEXT");++ b.Property<string>("Name")+ .HasColumnType("TEXT");++ b.Property<string>("Value")+ .HasColumnType("TEXT");++ b.HasKey("UserId", "LoginProvider", "Name");++ b.ToTable("UserTokens", (string)null);+ });++ modelBuilder.Entity("AliasServerDb.AliasVaultUserRefreshToken", b =>+ {+ b.HasOne("AliasServerDb.AliasVaultUser", "User")+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("User");+ });++ modelBuilder.Entity("AliasServerDb.Email", b =>+ {+ b.HasOne("AliasServerDb.UserEncryptionKey", "EncryptionKey")+ .WithMany("Emails")+ .HasForeignKey("UserEncryptionKeyId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("EncryptionKey");+ });++ modelBuilder.Entity("AliasServerDb.EmailAttachment", b =>+ {+ b.HasOne("AliasServerDb.Email", "Email")+ .WithMany("Attachments")+ .HasForeignKey("EmailId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Email");+ });++ modelBuilder.Entity("AliasServerDb.UserEmailClaim", b =>+ {+ b.HasOne("AliasServerDb.AliasVaultUser", "User")+ .WithMany("EmailClaims")+ .HasForeignKey("UserId");++ b.Navigation("User");+ });++ modelBuilder.Entity("AliasServerDb.UserEncryptionKey", b =>+ {+ b.HasOne("AliasServerDb.AliasVaultUser", "User")+ .WithMany("EncryptionKeys")+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("User");+ });++ modelBuilder.Entity("AliasServerDb.Vault", b =>+ {+ b.HasOne("AliasServerDb.AliasVaultUser", "User")+ .WithMany("Vaults")+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("User");+ });++ modelBuilder.Entity("AliasServerDb.AliasVaultUser", b =>+ {+ b.Navigation("EmailClaims");++ b.Navigation("EncryptionKeys");++ b.Navigation("Vaults");+ });++ modelBuilder.Entity("AliasServerDb.Email", b =>+ {+ b.Navigation("Attachments");+ });++ modelBuilder.Entity("AliasServerDb.UserEncryptionKey", b =>+ {+ b.Navigation("Emails");+ });+#pragma warning restore 612, 618+ }+ }+}diff --git a/src/Databases/AliasServerDb/Migrations/20241204121218_AddServerSettingsTable.cs b/src/Databases/AliasServerDb/Migrations/20241204121218_AddServerSettingsTable.csnew file mode 100644index 000000000..274846b3f--- /dev/null+++ b/src/Databases/AliasServerDb/Migrations/20241204121218_AddServerSettingsTable.cs@@ -0,0 +1,36 @@+using System;+using Microsoft.EntityFrameworkCore.Migrations;++#nullable disable++namespace AliasServerDb.Migrations+{+ /// <inheritdoc />+ public partial class AddServerSettingsTable : Migration+ {+ /// <inheritdoc />+ protected override void Up(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.CreateTable(+ name: "ServerSettings",+ columns: table => new+ {+ Key = table.Column<string>(type: "TEXT", maxLength: 255, nullable: false),+ Value = table.Column<string>(type: "TEXT", nullable: true),+ CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),+ UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: false)+ },+ constraints: table =>+ {+ table.PrimaryKey("PK_ServerSettings", x => x.Key);+ });+ }++ /// <inheritdoc />+ protected override void Down(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.DropTable(+ name: "ServerSettings");+ }+ }+}diff --git a/src/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs b/src/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.csindex 213b6b275..a12782aa1 100644--- a/src/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs+++ b/src/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs@@ -16,7 +16,7 @@ namespace AliasServerDb.Migrations{#pragma warning disable 612, 618modelBuilder- .HasAnnotation("ProductVersion", "8.0.10")+ .HasAnnotation("ProductVersion", "9.0.0").HasAnnotation("Proxies:ChangeTracking", false).HasAnnotation("Proxies:CheckEquality", false).HasAnnotation("Proxies:LazyLoading", true);@@ -464,6 +464,26 @@ namespace AliasServerDb.Migrationsb.ToTable("Logs", (string)null);});+ modelBuilder.Entity("AliasServerDb.ServerSetting", b =>+ {+ b.Property<string>("Key")+ .HasMaxLength(255)+ .HasColumnType("TEXT");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("TEXT");++ b.Property<DateTime>("UpdatedAt")+ .HasColumnType("TEXT");++ b.Property<string>("Value")+ .HasColumnType("TEXT");++ b.HasKey("Key");++ b.ToTable("ServerSettings");+ });+modelBuilder.Entity("AliasServerDb.UserEmailClaim", b =>{b.Property<Guid>("Id")diff --git a/src/Databases/AliasServerDb/ServerSetting.cs b/src/Databases/AliasServerDb/ServerSetting.csnew file mode 100644index 000000000..55a2175c3--- /dev/null+++ b/src/Databases/AliasServerDb/ServerSetting.cs@@ -0,0 +1,39 @@+//-----------------------------------------------------------------------+// <copyright file="ServerSetting.cs" company="lanedirt">+// Copyright (c) lanedirt. All rights reserved.+// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.+// </copyright>+//-----------------------------------------------------------------------++namespace AliasServerDb;++using System;+using System.ComponentModel.DataAnnotations;++/// <summary>+/// Represents a server setting in the AliasServerDb.+/// </summary>+public class ServerSetting+{+ /// <summary>+ /// Gets or sets the key of the server setting.+ /// </summary>+ [Key]+ [MaxLength(255)]+ public string Key { get; set; } = string.Empty;++ /// <summary>+ /// Gets or sets the value of the server setting.+ /// </summary>+ public string? Value { get; set; }++ /// <summary>+ /// Gets or sets the creation date of the server setting.+ /// </summary>+ public DateTime CreatedAt { get; set; }++ /// <summary>+ /// Gets or sets the update date of the server setting.+ /// </summary>+ public DateTime UpdatedAt { get; set; }+}