2020-01-23 21:03:54 +01:00
|
|
|
using System;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.IO;
|
2020-01-25 01:36:53 +01:00
|
|
|
using System.Reflection;
|
2020-01-23 21:03:54 +01:00
|
|
|
using System.Runtime.InteropServices;
|
2020-01-29 16:32:23 +01:00
|
|
|
using Common;
|
2020-01-23 21:03:54 +01:00
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
2020-01-29 16:32:23 +01:00
|
|
|
using Microsoft.AspNetCore.Http.Features;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2020-01-23 21:03:54 +01:00
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Microsoft.Extensions.Hosting;
|
2020-01-27 13:23:00 +01:00
|
|
|
using WebInterface.Services;
|
2020-01-23 21:03:54 +01:00
|
|
|
|
|
|
|
namespace WebInterface
|
|
|
|
{
|
|
|
|
public class Startup
|
|
|
|
{
|
|
|
|
public Startup(IConfiguration configuration)
|
|
|
|
{
|
|
|
|
Configuration = configuration;
|
|
|
|
StartSupervisor();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void StartSupervisor()
|
|
|
|
{
|
|
|
|
bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
|
|
|
string supervisor = "Supervisor";
|
|
|
|
if (isWindows)
|
|
|
|
supervisor += ".exe";
|
2020-01-25 01:36:53 +01:00
|
|
|
string supervisorPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), supervisor);
|
|
|
|
if (!File.Exists(supervisorPath))
|
2020-01-29 16:32:23 +01:00
|
|
|
throw new Exception($"Couldn't find {supervisor} at {supervisorPath}.");
|
2020-01-25 01:55:46 +01:00
|
|
|
Process.Start(supervisorPath);
|
2020-01-23 21:03:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public IConfiguration Configuration { get; }
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
{
|
|
|
|
services.AddControllers();
|
2020-01-27 13:23:00 +01:00
|
|
|
services.AddControllersWithViews();
|
2020-01-27 14:48:53 +01:00
|
|
|
services.Add(new ServiceDescriptor(typeof(IStateService), typeof(StateService), ServiceLifetime.Singleton));
|
2020-01-27 23:37:28 +01:00
|
|
|
services.Add(new ServiceDescriptor(typeof(IPrivateServerService), typeof(PrivateServerService), ServiceLifetime.Transient));
|
|
|
|
services.Add(new ServiceDescriptor(typeof(IRateLimiterService), typeof(RateLimiterService), ServiceLifetime.Singleton));
|
2020-02-01 22:16:09 +01:00
|
|
|
services.Add(new ServiceDescriptor(typeof(ITorCheckService), typeof(TorCheckService), ServiceLifetime.Singleton));
|
2020-01-28 01:29:27 +01:00
|
|
|
services.Add(new ServiceDescriptor(typeof(ICustomMapService), typeof(CustomMapService), ServiceLifetime.Transient));
|
2020-01-29 16:32:23 +01:00
|
|
|
|
|
|
|
services.Configure<FormOptions>(options =>
|
|
|
|
{
|
|
|
|
// Set the limit to 1 MB
|
|
|
|
options.MultipartBodyLengthLimit = Constants.FileSizeLimit;
|
|
|
|
});
|
|
|
|
|
|
|
|
services.AddRazorPages()
|
|
|
|
.AddRazorPagesOptions(options =>
|
|
|
|
{
|
|
|
|
options.Conventions
|
|
|
|
.AddPageApplicationModelConvention("/nblood/private", model =>
|
|
|
|
{
|
|
|
|
model.Filters.Add(
|
|
|
|
new RequestFormLimitsAttribute()
|
|
|
|
{
|
|
|
|
// Set the limit to 1 MB
|
|
|
|
MultipartBodyLengthLimit = Constants.FileSizeLimit
|
|
|
|
});
|
|
|
|
model.Filters.Add(
|
|
|
|
new RequestSizeLimitAttribute(Constants.FileSizeLimit));
|
|
|
|
});
|
|
|
|
});
|
2020-01-23 21:03:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
|
|
{
|
|
|
|
if (env.IsDevelopment())
|
|
|
|
{
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
}
|
|
|
|
|
2020-02-01 02:33:53 +01:00
|
|
|
app.UseStaticFiles();
|
|
|
|
|
2020-01-23 21:03:54 +01:00
|
|
|
app.UseRouting();
|
|
|
|
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
|
|
{
|
|
|
|
endpoints.MapControllers();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|