-
Notifications
You must be signed in to change notification settings - Fork 19
/
Program.cs
123 lines (103 loc) · 4.83 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using ISRORBilling;
using ISRORBilling.Database;
using ISRORBilling.Database.CommunityProvided.Nemo07;
using ISRORBilling.Models.Authentication;
using ISRORBilling.Models.Notification;
using ISRORBilling.Models.Options;
using ISRORBilling.Models.Ping;
using ISRORBilling.Services.Authentication;
using ISRORBilling.Services.Authentication.CommunityProvided.Nemo07;
using ISRORBilling.Services.Notification;
using ISRORBilling.Services.Notification.CommunityProvided;
using ISRORBilling.Services.Ping;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddLogging(loggingBuilder => {
var loggingSection = builder.Configuration.GetSection("Logging");
loggingBuilder.AddFile(loggingSection);
});
builder.Services.AddDbContext<AccountContext>(options =>
{
options.UseSqlServer(builder.Configuration.GetSection("DbConfig")["AccountDB"]);
options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
});
builder.Services.AddDbContext<JoymaxPortalContext>(options =>
{
options.UseSqlServer(builder.Configuration.GetSection("DbConfig")["JoymaxPortalDB"]);
options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
});
builder.Services.Configure<NationPingServiceOptions>(builder.Configuration.GetSection("NationPingService"));
builder.Services.AddHostedService<NationPingService>();
Enum.TryParse(builder.Configuration.GetSection("NotificationService:Type")?.Value, true, out NotificationServiceType notificationServiceType);
switch (notificationServiceType)
{
case NotificationServiceType.Email:
builder.Services.Configure<EmailOptions>(builder.Configuration.GetSection("EmailService"));
builder.Services.AddSingleton<INotificationService, EmailNotificationService>();
break;
case NotificationServiceType.Ferre:
builder.Services.AddSingleton<INotificationService, FerreNotificationService>();
break;
case NotificationServiceType.None:
default:
builder.Services.AddSingleton<INotificationService, NoneNotificationService>();
break;
}
Enum.TryParse(builder.Configuration.GetSection("AuthService")?.Value, true, out SupportedLoginServicesEnum loginService);
switch (loginService)
{
case SupportedLoginServicesEnum.Full:
builder.Services.AddScoped<IAuthService, FullAuthService>();
break;
case SupportedLoginServicesEnum.Bypass:
builder.Services.AddScoped<IAuthService, BypassAuthService>();
break;
case SupportedLoginServicesEnum.Nemo:
builder.Services.AddDbContext<NemoAccountContext>(options =>
{
options.UseSqlServer(builder.Configuration.GetSection("DbConfig")["AccountDB"]);
options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
});
builder.Services.AddScoped<IAuthService, NemoAuthService>();
break;
case SupportedLoginServicesEnum.Simple:
default:
builder.Services.AddScoped<IAuthService, SimpleAuthService>();
break;
}
var serviceCompany = int.Parse(builder.Configuration.GetSection("ServiceCompany").Value ?? "1");
var requestTimeoutSeconds = int.Parse(builder.Configuration.GetSection("RequestTimeoutSeconds").Value ?? "3600");
var saltKey = builder.Configuration.GetSection("SaltKey").Value ?? string.Empty;
var app = builder.Build();
app.MapGet("/Property/Silkroad-r/checkuser.aspx",
([FromQuery] string values, [FromServices] ILogger<Program> logger, [FromServices] IAuthService authService) =>
{
logger.LogDebug("Received in params: {Values}", values);
var request = new CheckUserRequest(values, saltKey, serviceCompany, requestTimeoutSeconds);
return authService.Login(request).ToString();
});
app.MapGet("/cgi/EmailPassword.asp",
async ([FromQuery] string values, [FromServices] ILogger<Program> logger, [FromServices] AccountContext accountContext,
[FromServices] INotificationService notificationService) =>
{
logger.LogDebug("Received in params: {Values}", values);
var request = new SendCodeRequest(values, saltKey);
if (await notificationService.SendSecondPassword(request))
return 0;
return -1;
});
app.MapGet("/cgi/Email_Certification.asp",
async ([FromQuery] string values, [FromServices] ILogger<Program> logger, [FromServices] AccountContext accountContext,
[FromServices] INotificationService notificationService) =>
{
logger.LogDebug("Received in params: {Values}", values);
var request = new SendCodeRequest(values, saltKey);
if (await notificationService.SendItemLockCode(request))
return 0;
return -1;
});
app.UseMiddleware<GenericHandlerMiddleware>(); //Useful to log incoming unknown requests
app.Run();