2025-06-21 11:52:29 +01:00
|
|
|
|
#pragma warning disable VSTHRD200
|
2024-05-05 02:20:43 +01:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
using Aaru.CommonTypes.Interop;
|
2025-04-27 12:48:13 +01:00
|
|
|
|
using Aaru.Server.Components;
|
|
|
|
|
|
using Aaru.Server.Components.Account;
|
2025-05-21 22:08:49 +01:00
|
|
|
|
using Aaru.Server.Services;
|
2024-05-03 03:24:40 +01:00
|
|
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2025-06-21 11:48:54 +01:00
|
|
|
|
using Serilog;
|
2025-06-21 11:52:29 +01:00
|
|
|
|
using Serilog.Events;
|
2024-05-04 02:27:56 +01:00
|
|
|
|
using DbContext = Aaru.Server.Database.DbContext;
|
2024-05-05 02:20:43 +01:00
|
|
|
|
using Version = System.Version;
|
|
|
|
|
|
|
|
|
|
|
|
Console.Clear();
|
|
|
|
|
|
|
2025-05-10 12:41:44 +01:00
|
|
|
|
// ReSharper disable once StringLiteralTypo
|
|
|
|
|
|
Console.Write("""
|
|
|
|
|
|
[32m . ,,
|
|
|
|
|
|
[32m ;,. '0d.
|
|
|
|
|
|
[32m oc oWd [31m ▄▄▄ ▄▄▄ ██▀███ █ ██
|
|
|
|
|
|
[0m[32m ;X. 'WN' [31m ▒████▄ ▒████▄ ▓██ ▒ ██▒ ██ ▓██▒
|
|
|
|
|
|
[0m[32m oMo cMM: [31m ▒██ ▀█▄ ▒██ ▀█▄ ▓██ ░▄█ ▒▓██ ▒██░
|
|
|
|
|
|
[0m[32m ;MM. .MMM; [31m ░██▄▄▄▄██░██▄▄▄▄██ ▒██▀▀█▄ ▓▓█ ░██░
|
|
|
|
|
|
[0m[32m NMM WMMW [31m ▓█ ▓██▒▓█ ▓██▒░██▓ ▒██▒▒▒█████▓
|
|
|
|
|
|
[0m[32m 'MMM MMMM; [31m ▒▒ ▓▒█░▒▒ ▓▒█░░ ▒▓ ░▒▓░░▒▓▒ ▒ ▒
|
|
|
|
|
|
[0m[32m ,MMM: dMMMM: [31m ▒ ▒▒ ░ ▒ ▒▒ ░ ░▒ ░ ▒░░░▒░ ░ ░
|
|
|
|
|
|
[0m[32m .MMMW. :MMMMM. [31m ░ ▒ ░ ▒ ░░ ░ ░░░ ░ ░
|
|
|
|
|
|
[0m[32m XMMMW: .:xKNMMMMMMN0d, lMMMMMd [31m ░ ░ ░ ░ ░ ░
|
|
|
|
|
|
[0m[32m :MMMMMK; cWMNkl:;;;:lxKMXc .0MMMMMO[0m
|
|
|
|
|
|
[32m ..KMMMMMMNo,. ,OMMMMMMW:,. [37;1m Aaru Website[0m
|
|
|
|
|
|
[32m .;d0NMMMMMMMMMMMMMMW0d:' .;lOWMMMMMMMMMMMMMXkl. [37;1m Version [0m[33m{0}[37;1m-[0m[31m{1}[0m
|
|
|
|
|
|
[32m :KMMMMMMMMMMMMMMMMMMMMMMMMc WMMMMMMMMMMMMMMMMMMMMMMWk'[0m
|
|
|
|
|
|
[32m ;NMMMMWX0kkkkO0XMMMMMMMMMMM0' dNMMMMMMMMMMW0xl:;,;:oOWMMX; [37;1m Running under [35;1m{2}[37;1m, [35m{3}-bit[37;1m in [35m{4}-bit[37;1m mode.[0m
|
|
|
|
|
|
[32m xMMWk:. .c0MMMMMW' OMMMMMM0c'.. .oNMO [37;1m Using [33;1m{5}[37;1m version [31;1m{6}[0m
|
|
|
|
|
|
[32m OMNc .MNc oWMMk 'WMMNl. .MMK ;KX.[0m
|
|
|
|
|
|
[32m xMO WMN ; ., , ': ,MMx lK[0m
|
|
|
|
|
|
[32m ,Md cMMl .XMMMWWMMMO XMW. :[0m
|
|
|
|
|
|
[32m Ok xMMl XMMMMMMMMc 0MW,[0m
|
|
|
|
|
|
[32m 0 oMM0' lMMMMMMMM. :NMN'[0m
|
|
|
|
|
|
[32m . .0MMKl ;MMMMMMMM oNMWd[0m
|
|
|
|
|
|
[32m .dNW cMMMMMMMM, XKl[0m
|
|
|
|
|
|
[32m 0MMMMMMMMK[0m
|
|
|
|
|
|
[32m ;MMMMMMMMMMO [37;1m Proudly presented to you by:[0m
|
|
|
|
|
|
[32m 'WMMMMKxMMMMM0 [34;1m Natalia Portillo[0m
|
|
|
|
|
|
[32m oMMMMNc :WMMMMN:[0m
|
|
|
|
|
|
[32m .dWMMM0; dWMMMMXl. [37;1m Thanks to all contributors, collaborators, translators, donators and friends.[0m
|
|
|
|
|
|
[32m .......,cd0WMMNk: c0MMMMMWKkolc:clodc'[0m
|
|
|
|
|
|
[32m .';loddol:'. ':oxkkOkkxoc,.[0m
|
|
|
|
|
|
[0m
|
|
|
|
|
|
|
|
|
|
|
|
""",
|
2024-05-05 02:20:43 +01:00
|
|
|
|
Aaru.CommonTypes.Interop.Version.GetVersion(),
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
|
"DEBUG",
|
|
|
|
|
|
#else
|
|
|
|
|
|
"RELEASE",
|
|
|
|
|
|
#endif
|
|
|
|
|
|
DetectOS.GetPlatformName(DetectOS.GetRealPlatformID()),
|
|
|
|
|
|
Environment.Is64BitOperatingSystem ? 64 : 32,
|
|
|
|
|
|
Environment.Is64BitProcess ? 64 : 32,
|
|
|
|
|
|
DetectOS.IsMono ? "Mono" : ".NET Core",
|
|
|
|
|
|
DetectOS.IsMono
|
|
|
|
|
|
? Aaru.CommonTypes.Interop.Version.GetMonoVersion()
|
|
|
|
|
|
: Aaru.CommonTypes.Interop.Version.GetNetCoreVersion());
|
|
|
|
|
|
|
2025-05-10 12:41:44 +01:00
|
|
|
|
Console.WriteLine("\e[31;1mBuilding web application...\e[0m");
|
2024-05-02 07:43:47 +01:00
|
|
|
|
|
2024-05-03 03:24:40 +01:00
|
|
|
|
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
2024-05-02 07:43:47 +01:00
|
|
|
|
|
2025-06-21 11:48:54 +01:00
|
|
|
|
#if DEBUG
|
|
|
|
|
|
builder.Logging.AddSerilog(new LoggerConfiguration().WriteTo.Console().CreateLogger());
|
|
|
|
|
|
#endif
|
2025-05-21 22:08:49 +01:00
|
|
|
|
|
2025-06-21 11:52:29 +01:00
|
|
|
|
builder.Logging.AddSerilog(new LoggerConfiguration().WriteTo
|
|
|
|
|
|
.LocalSyslog("aaru-server",
|
|
|
|
|
|
restrictedToMinimumLevel: LogEventLevel.Information)
|
|
|
|
|
|
.CreateLogger());
|
|
|
|
|
|
|
2024-05-02 07:43:47 +01:00
|
|
|
|
// Add services to the container.
|
|
|
|
|
|
builder.Services.AddRazorComponents().AddInteractiveServerComponents();
|
|
|
|
|
|
|
|
|
|
|
|
builder.Services.AddCascadingAuthenticationState();
|
|
|
|
|
|
builder.Services.AddScoped<IdentityUserAccessor>();
|
|
|
|
|
|
builder.Services.AddScoped<IdentityRedirectManager>();
|
|
|
|
|
|
builder.Services.AddScoped<AuthenticationStateProvider, IdentityRevalidatingAuthenticationStateProvider>();
|
|
|
|
|
|
|
2025-05-10 13:38:59 +01:00
|
|
|
|
builder.Services.AddAuthentication(static options =>
|
2024-05-02 07:43:47 +01:00
|
|
|
|
{
|
|
|
|
|
|
options.DefaultScheme = IdentityConstants.ApplicationScheme;
|
|
|
|
|
|
options.DefaultSignInScheme = IdentityConstants.ExternalScheme;
|
|
|
|
|
|
})
|
|
|
|
|
|
.AddIdentityCookies();
|
|
|
|
|
|
|
2024-05-03 03:24:40 +01:00
|
|
|
|
string connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ??
|
|
|
|
|
|
throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");
|
2024-05-02 07:43:47 +01:00
|
|
|
|
|
2024-05-04 02:27:56 +01:00
|
|
|
|
builder.Services.AddDbContextFactory<DbContext>(options => options
|
|
|
|
|
|
.UseMySql(connectionString,
|
|
|
|
|
|
new MariaDbServerVersion(new Version(10, 4, 0)))
|
|
|
|
|
|
.UseLazyLoadingProxies());
|
2024-05-03 22:54:50 +01:00
|
|
|
|
|
2024-05-02 07:43:47 +01:00
|
|
|
|
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
|
|
|
|
|
|
|
2024-05-05 02:20:43 +01:00
|
|
|
|
builder.Services.AddIdentityCore<IdentityUser>(static options =>
|
2024-05-03 22:54:50 +01:00
|
|
|
|
{
|
|
|
|
|
|
options.SignIn.RequireConfirmedAccount = true;
|
|
|
|
|
|
options.User.RequireUniqueEmail = true;
|
|
|
|
|
|
})
|
|
|
|
|
|
.AddEntityFrameworkStores<DbContext>()
|
2024-05-02 07:43:47 +01:00
|
|
|
|
.AddSignInManager()
|
|
|
|
|
|
.AddDefaultTokenProviders();
|
|
|
|
|
|
|
2024-05-03 22:54:50 +01:00
|
|
|
|
builder.Services.AddSingleton<IEmailSender<IdentityUser>, IdentityNoOpEmailSender>();
|
2024-05-02 07:43:47 +01:00
|
|
|
|
|
2025-05-20 20:48:57 +01:00
|
|
|
|
builder.Services.AddBlazorBootstrap();
|
|
|
|
|
|
|
2024-05-11 01:32:52 +01:00
|
|
|
|
// Add services to the container.
|
|
|
|
|
|
builder.Services.AddControllers();
|
|
|
|
|
|
|
2025-05-21 22:08:49 +01:00
|
|
|
|
builder.Services.AddHostedService<UpdateTask>();
|
|
|
|
|
|
|
2024-05-03 03:24:40 +01:00
|
|
|
|
WebApplication app = builder.Build();
|
2024-05-02 07:43:47 +01:00
|
|
|
|
|
|
|
|
|
|
// Configure the HTTP request pipeline.
|
|
|
|
|
|
if(app.Environment.IsDevelopment())
|
|
|
|
|
|
app.UseMigrationsEndPoint();
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-05-03 03:24:40 +01:00
|
|
|
|
app.UseExceptionHandler("/Error", true);
|
2024-05-02 07:43:47 +01:00
|
|
|
|
|
|
|
|
|
|
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
|
|
|
|
|
app.UseHsts();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
|
|
|
2024-05-11 01:32:52 +01:00
|
|
|
|
app.UseAuthorization();
|
2025-04-27 11:28:51 +01:00
|
|
|
|
app.MapStaticAssets();
|
2024-05-02 07:43:47 +01:00
|
|
|
|
app.UseAntiforgery();
|
|
|
|
|
|
|
|
|
|
|
|
app.MapRazorComponents<App>().AddInteractiveServerRenderMode();
|
|
|
|
|
|
|
|
|
|
|
|
// Add additional endpoints required by the Identity /Account Razor components.
|
|
|
|
|
|
app.MapAdditionalIdentityEndpoints();
|
2024-05-11 01:32:52 +01:00
|
|
|
|
app.MapControllers();
|
2024-05-02 07:43:47 +01:00
|
|
|
|
|
2024-05-05 02:21:04 +01:00
|
|
|
|
using(IServiceScope scope = app.Services.CreateScope())
|
|
|
|
|
|
{
|
|
|
|
|
|
IServiceProvider services = scope.ServiceProvider;
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
Stopwatch stopwatch = new();
|
|
|
|
|
|
|
|
|
|
|
|
stopwatch.Start();
|
2025-05-10 12:41:44 +01:00
|
|
|
|
Console.WriteLine("\e[31;1mUpdating database with Entity Framework...\e[0m");
|
2024-05-05 02:21:04 +01:00
|
|
|
|
DbContext context = services.GetRequiredService<DbContext>();
|
|
|
|
|
|
await context.Database.MigrateAsync();
|
|
|
|
|
|
stopwatch.Stop();
|
|
|
|
|
|
|
2025-05-10 12:41:44 +01:00
|
|
|
|
Console.WriteLine("\e[31;1mTook \e[32;1m{0} seconds\e[31;1m...\e[0m", stopwatch.Elapsed.TotalSeconds);
|
2024-05-05 02:25:34 +01:00
|
|
|
|
|
|
|
|
|
|
stopwatch.Restart();
|
2025-05-10 12:41:44 +01:00
|
|
|
|
Console.WriteLine("\e[31;1mSeeding Identity...\e[0m");
|
2024-05-05 02:25:34 +01:00
|
|
|
|
await Seeder.SeedAsync(context, services);
|
2025-04-27 13:13:56 +01:00
|
|
|
|
await context.Database.MigrateAsync();
|
2024-05-05 02:25:34 +01:00
|
|
|
|
stopwatch.Stop();
|
|
|
|
|
|
|
2025-05-10 12:41:44 +01:00
|
|
|
|
Console.WriteLine("\e[31;1mTook \e[32;1m{0} seconds\e[31;1m...\e[0m", stopwatch.Elapsed.TotalSeconds);
|
2024-05-05 02:21:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
catch(Exception ex)
|
|
|
|
|
|
{
|
2025-05-10 12:41:44 +01:00
|
|
|
|
Console.WriteLine("\e[31;1mCould not open database...\e[0m");
|
2024-05-05 02:21:04 +01:00
|
|
|
|
#if DEBUG
|
2025-05-10 13:38:59 +01:00
|
|
|
|
Console.WriteLine("\e[31;1mException: {0}\e[0m", ex);
|
2024-05-05 02:21:04 +01:00
|
|
|
|
#endif
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-10 12:41:44 +01:00
|
|
|
|
Console.WriteLine("\e[31;1mStarting web server...\e[0m");
|
2024-05-05 02:21:04 +01:00
|
|
|
|
|
2025-06-21 11:52:29 +01:00
|
|
|
|
await app.RunAsync();
|
|
|
|
|
|
#pragma warning restore VSTHRD200
|