|
| 1 | +using Immense.RemoteControl.Server.Extensions; |
| 2 | +using Immense.SimpleMessenger; |
1 | 3 | using Microsoft.AspNetCore.Authorization; |
2 | 4 | using Microsoft.AspNetCore.Components.Authorization; |
3 | 5 | using Microsoft.AspNetCore.Components.Server.Circuits; |
4 | 6 | using Microsoft.AspNetCore.HttpOverrides; |
5 | 7 | using Microsoft.AspNetCore.Identity; |
6 | 8 | using Microsoft.AspNetCore.Identity.UI.Services; |
| 9 | +using Microsoft.AspNetCore.RateLimiting; |
7 | 10 | using Microsoft.AspNetCore.StaticFiles; |
8 | 11 | using Microsoft.EntityFrameworkCore; |
9 | 12 | using Microsoft.Extensions.FileProviders; |
10 | 13 | using Remotely.Server.Auth; |
| 14 | +using Remotely.Server.Components; |
| 15 | +using Remotely.Server.Components.Account; |
11 | 16 | using Remotely.Server.Data; |
| 17 | +using Remotely.Server.Extensions; |
12 | 18 | using Remotely.Server.Hubs; |
| 19 | +using Remotely.Server.Models; |
| 20 | +using Remotely.Server.Options; |
13 | 21 | using Remotely.Server.Services; |
14 | | -using System.Net; |
15 | | -using Immense.RemoteControl.Server.Extensions; |
16 | 22 | using Remotely.Server.Services.RcImplementations; |
| 23 | +using Remotely.Server.Services.Stores; |
| 24 | +using Remotely.Shared.Entities; |
17 | 25 | using Remotely.Shared.Services; |
18 | 26 | using Serilog; |
19 | | -using Microsoft.AspNetCore.RateLimiting; |
| 27 | +using System.Net; |
20 | 28 | using RatePolicyNames = Remotely.Server.RateLimiting.PolicyNames; |
21 | | -using Remotely.Shared.Entities; |
22 | | -using Immense.SimpleMessenger; |
23 | | -using Remotely.Server.Services.Stores; |
24 | | -using Remotely.Server.Components.Account; |
25 | | -using Remotely.Server.Components; |
26 | | -using Remotely.Server.Options; |
27 | | -using Remotely.Server.Extensions; |
28 | | -using Remotely.Server.Models; |
29 | 29 |
|
30 | 30 | var builder = WebApplication.CreateBuilder(args); |
31 | 31 | var configuration = builder.Configuration; |
|
57 | 57 | { |
58 | 58 | case "sqlite": |
59 | 59 | services.AddDbContext<AppDb, SqliteDbContext>( |
60 | | - contextLifetime: ServiceLifetime.Transient, |
| 60 | + contextLifetime: ServiceLifetime.Transient, |
61 | 61 | optionsLifetime: ServiceLifetime.Transient); |
62 | 62 | break; |
| 63 | + |
63 | 64 | case "sqlserver": |
64 | 65 | services.AddDbContext<AppDb, SqlServerDbContext>( |
65 | 66 | contextLifetime: ServiceLifetime.Transient, |
66 | 67 | optionsLifetime: ServiceLifetime.Transient); |
67 | 68 | break; |
| 69 | + |
68 | 70 | case "postgresql": |
69 | 71 | services.AddDbContext<AppDb, PostgreSqlDbContext>( |
70 | 72 | contextLifetime: ServiceLifetime.Transient, |
71 | 73 | optionsLifetime: ServiceLifetime.Transient); |
72 | 74 | break; |
| 75 | + |
73 | 76 | default: |
74 | 77 | throw new InvalidOperationException( |
75 | 78 | $"Invalid DBProvider: {dbProvider}. Ensure a valid value " + |
|
112 | 115 | .AddSignInManager() |
113 | 116 | .AddDefaultTokenProviders(); |
114 | 117 |
|
115 | | - |
116 | 118 | services.AddScoped<IAuthorizationHandler, TwoFactorRequiredHandler>(); |
117 | 119 | services.AddScoped<IAuthorizationHandler, OrganizationAdminRequirementHandler>(); |
118 | 120 | services.AddScoped<IAuthorizationHandler, ServerAdminRequirementHandler>(); |
|
154 | 156 |
|
155 | 157 | services.AddCors(options => |
156 | 158 | { |
157 | | - if (settings.TrustedCorsOrigins is { Count: > 0} trustedOrigins) |
| 159 | + if (settings.TrustedCorsOrigins is { Count: > 0 } trustedOrigins) |
158 | 160 | { |
159 | 161 | options.AddPolicy("TrustedOriginPolicy", builder => builder |
160 | 162 | .WithOrigins(trustedOrigins.ToArray()) |
|
165 | 167 | } |
166 | 168 | }); |
167 | 169 |
|
168 | | - |
169 | 170 | services.Configure<ForwardedHeadersOptions>(options => |
170 | 171 | { |
171 | 172 | options.ForwardedHeaders = ForwardedHeaders.All; |
|
177 | 178 | options.KnownProxies.Add(dockerGatewayIp); |
178 | 179 | } |
179 | 180 |
|
180 | | - if (settings.KnownProxies is { Count: >0 } knownProxies) |
| 181 | + if (settings.KnownProxies is { Count: > 0 } knownProxies) |
181 | 182 | { |
182 | 183 | foreach (var proxy in knownProxies) |
183 | 184 | { |
|
207 | 208 | { |
208 | 209 | clOptions.QueueLimit = int.MaxValue; |
209 | 210 |
|
210 | | - clOptions.PermitLimit = |
| 211 | + clOptions.PermitLimit = |
211 | 212 | settings.MaxConcurrentUpdates <= 0 ? |
212 | 213 | 10 : |
213 | 214 | settings.MaxConcurrentUpdates; |
|
222 | 223 | } |
223 | 224 | else |
224 | 225 | { |
| 226 | + services.AddScoped<IEmailSender<RemotelyUser>, EmailSenderEx>(); |
225 | 227 | services.AddScoped<IEmailSenderEx, EmailSenderEx>(); |
226 | 228 | } |
227 | 229 | services.AddSingleton<IAppDbFactory, AppDbFactory>(); |
@@ -367,13 +369,12 @@ void ConfigureSerilog(WebApplicationBuilder webAppBuilder, SettingsModel setting |
367 | 369 | { |
368 | 370 | try |
369 | 371 | { |
370 | | - |
371 | 372 | var dataRetentionDays = settings.DataRetentionInDays; |
372 | 373 | if (dataRetentionDays <= 0) |
373 | 374 | { |
374 | 375 | dataRetentionDays = 7; |
375 | 376 | } |
376 | | - |
| 377 | + |
377 | 378 | var logPath = LogsManager.DefaultLogsDirectory; |
378 | 379 |
|
379 | 380 | void ApplySharedLoggerConfig(LoggerConfiguration loggerConfiguration) |
|
0 commit comments