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-07-02 11:05:24 +00:00
|
|
|
|
using Jackett.Common.Utils.Clients;
|
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;
|
2018-05-30 11:43:58 +00:00
|
|
|
|
using Microsoft.AspNetCore.DataProtection;
|
2018-05-01 11:13:20 +00:00
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
2018-05-12 02:44:47 +00:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2018-07-13 12:15:09 +00:00
|
|
|
|
using Microsoft.AspNetCore.HttpOverrides;
|
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;
|
2018-05-30 11:43:58 +00:00
|
|
|
|
using System.IO;
|
2018-05-01 12:00:02 +00:00
|
|
|
|
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);
|
|
|
|
|
|
2018-05-30 11:43:58 +00:00
|
|
|
|
DirectoryInfo dataProtectionFolder = new DirectoryInfo(Path.Combine(runtimeSettings.DataFolder, "DataProtection"));
|
|
|
|
|
|
|
|
|
|
services.AddDataProtection()
|
|
|
|
|
.PersistKeysToFileSystem(dataProtectionFolder)
|
|
|
|
|
.SetApplicationName("Jackett");
|
|
|
|
|
|
2018-05-01 12:00:02 +00:00
|
|
|
|
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
|
|
|
|
|
|
|
|
|
var builder = new ContainerBuilder();
|
|
|
|
|
|
2018-06-18 11:50:09 +00:00
|
|
|
|
Helper.SetupLogging(builder);
|
2018-05-01 12:00:02 +00:00
|
|
|
|
|
|
|
|
|
builder.Populate(services);
|
|
|
|
|
builder.RegisterModule(new JackettModule(runtimeSettings));
|
|
|
|
|
builder.RegisterType<SecuityService>().As<ISecuityService>();
|
|
|
|
|
builder.RegisterType<ServerService>().As<IServerService>();
|
|
|
|
|
builder.RegisterType<ProtectionService>().As<IProtectionService>();
|
2018-06-10 02:33:16 +00:00
|
|
|
|
builder.RegisterType<ServiceConfigService>().As<IServiceConfigService>();
|
2018-07-02 11:05:24 +00:00
|
|
|
|
if (runtimeSettings.ClientOverride == "httpclientnetcore")
|
|
|
|
|
builder.RegisterType<HttpWebClientNetCore>().As<WebClient>();
|
2018-05-01 12:00:02 +00:00
|
|
|
|
|
|
|
|
|
IContainer container = builder.Build();
|
2018-06-03 11:11:18 +00:00
|
|
|
|
Helper.ApplicationContainer = container;
|
|
|
|
|
|
2018-07-10 12:22:02 +00:00
|
|
|
|
Helper.Logger.Debug("Autofac container built");
|
|
|
|
|
|
2018-06-03 11:11:18 +00:00
|
|
|
|
Helper.Initialize();
|
2018-05-01 12:00:02 +00:00
|
|
|
|
|
|
|
|
|
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.
|
2018-06-03 11:11:18 +00:00
|
|
|
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime applicationLifetime)
|
2018-05-01 11:13:20 +00:00
|
|
|
|
{
|
2018-06-03 11:11:18 +00:00
|
|
|
|
applicationLifetime.ApplicationStopping.Register(OnShutdown);
|
2018-06-10 02:33:16 +00:00
|
|
|
|
Helper.applicationLifetime = applicationLifetime;
|
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();
|
|
|
|
|
|
2018-07-13 12:15:09 +00:00
|
|
|
|
string serverBasePath = Helper.ServerService.BasePath() ?? string.Empty;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(serverBasePath))
|
|
|
|
|
{
|
|
|
|
|
app.UsePathBase(serverBasePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.UseForwardedHeaders(new ForwardedHeadersOptions
|
|
|
|
|
{
|
|
|
|
|
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
|
|
|
|
|
});
|
|
|
|
|
|
2018-05-05 07:08:46 +00:00
|
|
|
|
var rewriteOptions = new RewriteOptions()
|
2018-06-18 11:48:45 +00:00
|
|
|
|
.AddRewrite(@"^torznab\/([\w-]*)", "api/v2.0/indexers/$1/results/torznab", skipRemainingRules: true) //legacy torznab route
|
|
|
|
|
.AddRewrite(@"^potato\/([\w-]*)", "api/v2.0/indexers/$1/results/potato", skipRemainingRules: true) //legacy potato route
|
2018-05-05 07:08:46 +00:00
|
|
|
|
.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-06-03 11:11:18 +00:00
|
|
|
|
FileProvider = new PhysicalFileProvider(Helper.ConfigService.GetContentFolder()),
|
2018-05-01 12:00:02 +00:00
|
|
|
|
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();
|
|
|
|
|
}
|
2018-06-03 11:11:18 +00:00
|
|
|
|
|
|
|
|
|
private void OnShutdown()
|
|
|
|
|
{
|
|
|
|
|
//this code is called when the application stops
|
|
|
|
|
}
|
2018-05-01 11:13:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|