2018-05-01 12:00:02 +00:00
|
|
|
|
using Autofac;
|
|
|
|
|
using Autofac.Extensions.DependencyInjection;
|
|
|
|
|
using Jackett.Common.Models.Config;
|
|
|
|
|
using Jackett.Common.Plumbing;
|
|
|
|
|
using Jackett.Common.Services.Interfaces;
|
2018-05-05 07:08:46 +00:00
|
|
|
|
using Jackett.Server.Middleware;
|
2018-05-01 12:00:02 +00:00
|
|
|
|
using Jackett.Server.Services;
|
2018-05-12 02:44:47 +00:00
|
|
|
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2018-05-01 11:13:20 +00:00
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
2018-05-12 02:44:47 +00:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2018-05-12 03:16:56 +00:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2018-05-12 02:44:47 +00:00
|
|
|
|
using Microsoft.AspNetCore.Mvc.Authorization;
|
2018-05-05 07:08:46 +00:00
|
|
|
|
using Microsoft.AspNetCore.Rewrite;
|
2018-05-01 11:13:20 +00:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2018-05-01 12:00:02 +00:00
|
|
|
|
using Microsoft.Extensions.FileProviders;
|
|
|
|
|
using Newtonsoft.Json.Serialization;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Text;
|
2018-05-01 11:13:20 +00:00
|
|
|
|
|
|
|
|
|
namespace Jackett.Server
|
|
|
|
|
{
|
|
|
|
|
public class Startup
|
|
|
|
|
{
|
|
|
|
|
public Startup(IConfiguration configuration)
|
|
|
|
|
{
|
|
|
|
|
Configuration = configuration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IConfiguration Configuration { get; }
|
|
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
2018-05-01 12:00:02 +00:00
|
|
|
|
public IServiceProvider ConfigureServices(IServiceCollection services)
|
2018-05-01 11:13:20 +00:00
|
|
|
|
{
|
2018-05-12 02:51:46 +00:00
|
|
|
|
services.AddResponseCompression();
|
|
|
|
|
|
2018-05-12 02:44:47 +00:00
|
|
|
|
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
|
|
|
|
|
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme,
|
|
|
|
|
options =>
|
|
|
|
|
{
|
|
|
|
|
options.LoginPath = new PathString("/UI/Login");
|
|
|
|
|
options.AccessDeniedPath = new PathString("/UI/Login");
|
|
|
|
|
options.LogoutPath = new PathString("/UI/Logout");
|
|
|
|
|
options.Cookie.Name = "Jackett";
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
services.AddMvc(config =>
|
|
|
|
|
{
|
|
|
|
|
var policy = new AuthorizationPolicyBuilder()
|
|
|
|
|
.RequireAuthenticatedUser()
|
|
|
|
|
.Build();
|
|
|
|
|
config.Filters.Add(new AuthorizeFilter(policy));
|
|
|
|
|
})
|
|
|
|
|
.AddJsonOptions(options =>
|
|
|
|
|
{
|
|
|
|
|
options.SerializerSettings.ContractResolver = new DefaultContractResolver(); //Web app uses Pascal Case JSON
|
2018-05-12 03:16:56 +00:00
|
|
|
|
})
|
|
|
|
|
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
|
2018-05-01 12:00:02 +00:00
|
|
|
|
|
|
|
|
|
RuntimeSettings runtimeSettings = new RuntimeSettings();
|
|
|
|
|
Configuration.GetSection("RuntimeSettings").Bind(runtimeSettings);
|
|
|
|
|
|
|
|
|
|
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
|
|
|
|
|
|
|
|
|
var builder = new ContainerBuilder();
|
|
|
|
|
|
|
|
|
|
Initialisation.SetupLogging(runtimeSettings, builder);
|
|
|
|
|
|
|
|
|
|
builder.Populate(services);
|
|
|
|
|
builder.RegisterModule(new JackettModule(runtimeSettings));
|
|
|
|
|
builder.RegisterType<SecuityService>().As<ISecuityService>();
|
|
|
|
|
builder.RegisterType<ServerService>().As<IServerService>();
|
|
|
|
|
builder.RegisterType<ProtectionService>().As<IProtectionService>();
|
|
|
|
|
|
|
|
|
|
IContainer container = builder.Build();
|
|
|
|
|
Initialisation.ApplicationContainer = container;
|
|
|
|
|
|
|
|
|
|
return new AutofacServiceProvider(container);
|
2018-05-01 11:13:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
|
|
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
|
|
|
|
{
|
2018-05-01 12:00:02 +00:00
|
|
|
|
Initialisation.Initialize();
|
|
|
|
|
|
2018-05-12 02:51:46 +00:00
|
|
|
|
app.UseResponseCompression();
|
|
|
|
|
|
2018-05-01 12:00:02 +00:00
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
|
|
2018-05-05 07:08:46 +00:00
|
|
|
|
app.UseCustomExceptionHandler();
|
|
|
|
|
|
|
|
|
|
var rewriteOptions = new RewriteOptions()
|
|
|
|
|
.Add(RewriteRules.RewriteBasePath)
|
|
|
|
|
.Add(RedirectRules.RedirectToDashboard);
|
|
|
|
|
|
|
|
|
|
app.UseRewriter(rewriteOptions);
|
|
|
|
|
|
2018-05-01 12:00:02 +00:00
|
|
|
|
app.UseFileServer(new FileServerOptions
|
2018-05-01 11:13:20 +00:00
|
|
|
|
{
|
2018-05-01 12:00:02 +00:00
|
|
|
|
FileProvider = new PhysicalFileProvider(Initialisation.ConfigService.GetContentFolder()),
|
|
|
|
|
RequestPath = "",
|
|
|
|
|
EnableDefaultFiles = true,
|
|
|
|
|
EnableDirectoryBrowsing = false
|
|
|
|
|
});
|
2018-05-01 11:13:20 +00:00
|
|
|
|
|
2018-05-12 02:44:47 +00:00
|
|
|
|
app.UseAuthentication();
|
|
|
|
|
|
2018-05-01 11:13:20 +00:00
|
|
|
|
app.UseMvc();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|