using DotNetDDI.Data; using DotNetDDI.Integrations.Kea; using DotNetDDI.Integrations.PowerDns; using DotNetDDI.Options; using DotNetDDI.Services.Dhcp; using DotNetDDI.Services.Dns; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.AspNetCore.Connections; var builder = WebApplication.CreateBuilder(args); builder.Services.AddSystemd(); // Add services to the container. var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found."); builder.Services.AddDbContext(options => options.UseSqlite(connectionString)); builder.Services.AddDatabaseDeveloperPageExceptionFilter(); builder.Services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) .AddEntityFrameworkStores(); builder.Services.AddRazorPages(); builder.Services.Configure(builder.Configuration.GetRequiredSection("Dhcp")); builder.Services.Configure(builder.Configuration.GetRequiredSection("PowerDns")); builder.Services.AddHostedService(); builder.Services.AddHostedService(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddDhcpWatcherFactory(); builder.Services.AddKeaFactory(); builder.WebHost.ConfigureKestrel((context, options) => { options.UseSystemd(_ => throw new InvalidOperationException("SystemD Socket Activation is not supported by Kestrel.")); var pdnsOptions = context.Configuration.GetRequiredSection("PowerDns:Listener").Get(); ArgumentNullException.ThrowIfNull(pdnsOptions); var path = PathEx.ExpandPath(pdnsOptions.Socket); FileInfo file = new(path); file.Directory!.Create(); file.Delete(); options.ListenUnixSocket(path, options => { options.UseConnectionHandler(); }); }); var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseMigrationsEndPoint(); } else { app.UseExceptionHandler("/Error"); } app.UseRouting(); if (app.Configuration.GetValue("Admin:Authentication", true)) { app.UseAuthorization(); } app.UseStaticFiles(); app.MapRazorPages(); app.Run();