82 lines
2.6 KiB
C#
82 lines
2.6 KiB
C#
using Flypaper.Core;
|
|
using Flypaper.GeoIp;
|
|
using Flypaper.Http;
|
|
using Flypaper.Storage;
|
|
using Flypaper.Web;
|
|
using Flypaper.Web.Auth;
|
|
using Flypaper.Web.Components;
|
|
using Flypaper.Web.Health;
|
|
using Flypaper.Web.Mcp;
|
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.DataProtection;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
var ports = builder.Configuration.GetSection(PortOptions.SectionName).Get<PortOptions>() ?? new PortOptions();
|
|
builder.WebHost.ConfigureKestrel(options =>
|
|
{
|
|
options.AddServerHeader = false;
|
|
options.ListenAnyIP(ports.Trap);
|
|
options.ListenAnyIP(ports.Dashboard);
|
|
});
|
|
|
|
builder.AddFlypaperStorage();
|
|
builder.Services.AddRazorComponents();
|
|
builder.Services.AddFlypaperCore(builder.Configuration);
|
|
builder.Services.AddFlypaperHttp(builder.Configuration);
|
|
builder.Services.AddFlypaperGeoIp(builder.Configuration);
|
|
|
|
var dataProtection = builder.Services.AddDataProtection().SetApplicationName("Flypaper");
|
|
if (builder.Configuration["Flypaper:DataProtection:KeysPath"] is { Length: > 0 } keysPath)
|
|
{
|
|
dataProtection.PersistKeysToFileSystem(new DirectoryInfo(keysPath));
|
|
}
|
|
|
|
builder.Services.AddFlypaperMcp(builder.Configuration);
|
|
|
|
builder.Services.Configure<AdminOptions>(builder.Configuration.GetSection(AdminOptions.SectionName));
|
|
builder.Services.AddSingleton<AdminAuthenticator>();
|
|
builder.Services
|
|
.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
|
|
.AddCookie(options =>
|
|
{
|
|
options.LoginPath = "/login";
|
|
options.AccessDeniedPath = "/login";
|
|
options.Cookie.Name = "flypaper.auth";
|
|
options.Cookie.HttpOnly = true;
|
|
options.Cookie.SameSite = SameSiteMode.Strict;
|
|
options.ExpireTimeSpan = TimeSpan.FromHours(8);
|
|
options.SlidingExpiration = true;
|
|
});
|
|
builder.Services.AddAuthorizationBuilder()
|
|
.SetFallbackPolicy(new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build());
|
|
|
|
var app = builder.Build();
|
|
|
|
app.Logger.LogInformation("Flypaper {Version} starting", AppVersion.Current);
|
|
FlypaperHttpExtensions.WarnAboutRemovedSettings(app.Configuration, app.Logger);
|
|
await app.Services.MigrateFlypaperDatabaseAsync();
|
|
|
|
app.UseFlypaper();
|
|
|
|
if (!app.Environment.IsDevelopment())
|
|
{
|
|
app.UseExceptionHandler("/Error", createScopeForErrors: true);
|
|
}
|
|
app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true);
|
|
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
app.UseAntiforgery();
|
|
|
|
app.MapStaticAssets().AllowAnonymous();
|
|
app.MapAuthEndpoints();
|
|
app.MapHealthEndpoint();
|
|
app.MapFlypaperMcp();
|
|
app.MapRazorComponents<App>();
|
|
|
|
await app.RunAsync();
|
|
|
|
public partial class Program;
|