3 Commits
v0.6 ... v0.6.1

Author SHA1 Message Date
Jonas F
cf3a5ab68a Release 0.6.1 (#48)
* Fix typo

* Fix typos

* Fix typos

* Fix typo

* Clarify error message

* Fix reachable and ipleak test (#47)

* Fix reachable check

Fixes failing reachable checks when Basic Authentication is enabled in
Sonarr, Radarr, etc.

* Add option to disable IP leak test

---------

Co-authored-by: Jonas F <github@pcjones.de>

* Add IpLeakTest environment variable to docker compose

---------

Co-authored-by: akuntsch <github@akuntsch.de>
2024-10-21 17:28:31 +02:00
Jonas F
46e1baf53c Revert "Fix reachable and IP leak test (#44)" (#46)
This reverts commit 3f5d7bbef3.
2024-10-21 14:26:55 +02:00
akuntsch
3f5d7bbef3 Fix reachable and IP leak test (#44)
* Fix reachable check

Fixes failing reachable checks when Basic Authentication is enabled in
Sonarr, Radarr, etc.

* Add option to disable IP leak test
2024-10-21 14:26:35 +02:00
7 changed files with 54 additions and 53 deletions

View File

@@ -8,10 +8,12 @@ using UmlautAdaptarr.Utilities;
internal class Program internal class Program
{ {
private static void Main(string[] args) private static void Main(string[] args) {
MainAsync(args).Wait();
}
private static async Task MainAsync(string[] args)
{ {
Helper.ShowLogo();
Helper.ShowInformation();
// TODO: // TODO:
// add option to sort by nzb age // add option to sort by nzb age
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@@ -43,9 +45,9 @@ internal class Program
builder.AddTitleLookupService(); builder.AddTitleLookupService();
builder.Services.AddSingleton<SearchItemLookupService>(); builder.Services.AddSingleton<SearchItemLookupService>();
builder.Services.AddSingleton<TitleMatchingService>(); builder.Services.AddSingleton<TitleMatchingService>();
builder.AddSonarrSupport(); await builder.AddSonarrSupport();
builder.AddLidarrSupport(); await builder.AddLidarrSupport();
builder.AddReadarrSupport(); await builder.AddReadarrSupport();
builder.Services.AddSingleton<CacheService>(); builder.Services.AddSingleton<CacheService>();
builder.Services.AddSingleton<ProxyRequestService>(); builder.Services.AddSingleton<ProxyRequestService>();
builder.Services.AddSingleton<ArrApplicationFactory>(); builder.Services.AddSingleton<ArrApplicationFactory>();
@@ -54,6 +56,13 @@ internal class Program
var app = builder.Build(); var app = builder.Build();
Helper.ShowLogo();
if (app.Configuration.GetValue<bool>("IpLeakTest:Enabled"))
{
await Helper.ShowInformation();
}
GlobalStaticLogger.Initialize(app.Services.GetService<ILoggerFactory>()!); GlobalStaticLogger.Initialize(app.Services.GetService<ILoggerFactory>()!);
app.UseHttpsRedirection(); app.UseHttpsRedirection();
app.UseAuthorization(); app.UseAuthorization();
@@ -109,4 +118,4 @@ internal class Program
//.Enrich.With(new ApiKeyMaskingEnricher("appsettings.json")) // TODO - Not working currently //.Enrich.With(new ApiKeyMaskingEnricher("appsettings.json")) // TODO - Not working currently
.CreateLogger(); .CreateLogger();
} }
} }

View File

@@ -4,7 +4,7 @@ using UmlautAdaptarr.Providers;
namespace UmlautAdaptarr.Services.Factory namespace UmlautAdaptarr.Services.Factory
{ {
/// <summary> /// <summary>
/// Factory for creating RrApplication instances. /// Factory for creating ArrApplication instances.
/// </summary> /// </summary>
public class ArrApplicationFactory public class ArrApplicationFactory
{ {
@@ -33,21 +33,21 @@ namespace UmlautAdaptarr.Services.Factory
/// <summary> /// <summary>
/// Constructor for the ArrApplicationFactory. /// Constructor for the ArrApplicationFactory.
/// </summary> /// </summary>
/// <param name="rrArrApplications">A dictionary of IArrApplication instances.</param> /// <param name="arrApplications">A dictionary of IArrApplication instances.</param>
/// <param name="logger">Logger Instanz</param> /// <param name="logger">Logger Instanz</param>
public ArrApplicationFactory(IDictionary<string, IArrApplication> rrArrApplications, ILogger<ArrApplicationFactory> logger) public ArrApplicationFactory(IDictionary<string, IArrApplication> arrApplications, ILogger<ArrApplicationFactory> logger)
{ {
_logger = logger; _logger = logger;
try try
{ {
SonarrInstances = rrArrApplications.Values.OfType<SonarrClient>(); SonarrInstances = arrApplications.Values.OfType<SonarrClient>();
LidarrInstances = rrArrApplications.Values.OfType<LidarrClient>(); LidarrInstances = arrApplications.Values.OfType<LidarrClient>();
ReadarrInstances = rrArrApplications.Values.OfType<ReadarrClient>(); ReadarrInstances = arrApplications.Values.OfType<ReadarrClient>();
AllInstances = rrArrApplications; AllInstances = arrApplications;
if (!AllInstances.Values.Any()) if (AllInstances.Values.Count == 0)
{ {
throw new Exception("No RrApplication could be successfully initialized. This could be due to a faulty configuration"); throw new Exception("No ArrApplication could be successfully initialized. This could be due to a faulty configuration");
} }
} }
catch (Exception e) catch (Exception e)

View File

@@ -11,10 +11,10 @@ public static class Helper
"\r\n _ _ _ _ ___ _ _ \r\n| | | | | | | | / _ \\ | | | | \r\n| | | |_ __ ___ | | __ _ _ _| |_/ /_\\ \\ __| | __ _ _ __ | |_ __ _ _ __ _ __ \r\n| | | | '_ ` _ \\| |/ _` | | | | __| _ |/ _` |/ _` | '_ \\| __/ _` | '__| '__|\r\n| |_| | | | | | | | (_| | |_| | |_| | | | (_| | (_| | |_) | || (_| | | | | \r\n \\___/|_| |_| |_|_|\\__,_|\\__,_|\\__\\_| |_/\\__,_|\\__,_| .__/ \\__\\__,_|_| |_| \r\n | | \r\n |_| \r\n"); "\r\n _ _ _ _ ___ _ _ \r\n| | | | | | | | / _ \\ | | | | \r\n| | | |_ __ ___ | | __ _ _ _| |_/ /_\\ \\ __| | __ _ _ __ | |_ __ _ _ __ _ __ \r\n| | | | '_ ` _ \\| |/ _` | | | | __| _ |/ _` |/ _` | '_ \\| __/ _` | '__| '__|\r\n| |_| | | | | | | | (_| | |_| | |_| | | | (_| | (_| | |_) | || (_| | | | | \r\n \\___/|_| |_| |_|_|\\__,_|\\__,_|\\__\\_| |_/\\__,_|\\__,_| .__/ \\__\\__,_|_| |_| \r\n | | \r\n |_| \r\n");
} }
public static void ShowInformation() public static async Task ShowInformation()
{ {
Console.WriteLine("--------------------------[IP Leak Test]-----------------------------"); Console.WriteLine("--------------------------[IP Leak Test]-----------------------------");
var ipInfo = GetPublicIpAddressInfoAsync().GetAwaiter().GetResult(); var ipInfo = await GetPublicIpAddressInfoAsync();
if (ipInfo != null) if (ipInfo != null)
{ {

View File

@@ -29,7 +29,7 @@ public static class ServicesExtensions
/// <param name="builder">The <see cref="WebApplicationBuilder" /> to configure the service collection.</param> /// <param name="builder">The <see cref="WebApplicationBuilder" /> to configure the service collection.</param>
/// <param name="sectionName">The name of the configuration section containing service options.</param> /// <param name="sectionName">The name of the configuration section containing service options.</param>
/// <returns>The configured <see cref="WebApplicationBuilder" />.</returns> /// <returns>The configured <see cref="WebApplicationBuilder" />.</returns>
private static WebApplicationBuilder AddServicesWithOptions<TOptions, TService, TInterface>( private static async Task<WebApplicationBuilder> AddServicesWithOptions<TOptions, TService, TInterface>(
this WebApplicationBuilder builder, string sectionName) this WebApplicationBuilder builder, string sectionName)
where TOptions : class, new() where TOptions : class, new()
where TService : class, TInterface where TService : class, TInterface
@@ -57,9 +57,9 @@ public static class ServicesExtensions
foreach (var option in optionsArray) foreach (var option in optionsArray)
{ {
GlobalInstanceOptionsValidator validator = new GlobalInstanceOptionsValidator(); GlobalInstanceOptionsValidator validator = new();
var results = validator.Validate(option as GlobalInstanceOptions); var results = await validator.ValidateAsync(option as GlobalInstanceOptions);
if (!results.IsValid) if (!results.IsValid)
{ {
@@ -68,7 +68,7 @@ public static class ServicesExtensions
Console.WriteLine(($"Property {failure.PropertyName } failed validation. Error was: {failure.ErrorMessage}")); Console.WriteLine(($"Property {failure.PropertyName } failed validation. Error was: {failure.ErrorMessage}"));
} }
throw new Exception("Please fix first you config and then Start UmlautAdaptarr again"); throw new Exception("Please fix cour environment variables and then Start UmlautAdaptarr again");
} }
var instanceState = (bool)(typeof(TOptions).GetProperty("Enabled")?.GetValue(option, null) ?? false); var instanceState = (bool)(typeof(TOptions).GetProperty("Enabled")?.GetValue(option, null) ?? false);
@@ -143,7 +143,7 @@ public static class ServicesExtensions
/// </summary> /// </summary>
/// <param name="builder">The <see cref="WebApplicationBuilder" /> to configure the service collection.</param> /// <param name="builder">The <see cref="WebApplicationBuilder" /> to configure the service collection.</param>
/// <returns>The configured <see cref="WebApplicationBuilder" />.</returns> /// <returns>The configured <see cref="WebApplicationBuilder" />.</returns>
public static WebApplicationBuilder AddSonarrSupport(this WebApplicationBuilder builder) public static Task<WebApplicationBuilder> AddSonarrSupport(this WebApplicationBuilder builder)
{ {
// builder.Serviceses.AddSingleton<IOptionsMonitoSonarrInstanceOptionsns>, OptionsMonitoSonarrInstanceOptionsns>>(); // builder.Serviceses.AddSingleton<IOptionsMonitoSonarrInstanceOptionsns>, OptionsMonitoSonarrInstanceOptionsns>>();
return builder.AddServicesWithOptions<SonarrInstanceOptions, SonarrClient, IArrApplication>("Sonarr"); return builder.AddServicesWithOptions<SonarrInstanceOptions, SonarrClient, IArrApplication>("Sonarr");
@@ -154,7 +154,7 @@ public static class ServicesExtensions
/// </summary> /// </summary>
/// <param name="builder">The <see cref="WebApplicationBuilder" /> to configure the service collection.</param> /// <param name="builder">The <see cref="WebApplicationBuilder" /> to configure the service collection.</param>
/// <returns>The configured <see cref="WebApplicationBuilder" />.</returns> /// <returns>The configured <see cref="WebApplicationBuilder" />.</returns>
public static WebApplicationBuilder AddLidarrSupport(this WebApplicationBuilder builder) public static Task<WebApplicationBuilder> AddLidarrSupport(this WebApplicationBuilder builder)
{ {
return builder.AddServicesWithOptions<LidarrInstanceOptions, LidarrClient, IArrApplication>("Lidarr"); return builder.AddServicesWithOptions<LidarrInstanceOptions, LidarrClient, IArrApplication>("Lidarr");
} }
@@ -164,7 +164,7 @@ public static class ServicesExtensions
/// </summary> /// </summary>
/// <param name="builder">The <see cref="WebApplicationBuilder" /> to configure the service collection.</param> /// <param name="builder">The <see cref="WebApplicationBuilder" /> to configure the service collection.</param>
/// <returns>The configured <see cref="WebApplicationBuilder" />.</returns> /// <returns>The configured <see cref="WebApplicationBuilder" />.</returns>
public static WebApplicationBuilder AddReadarrSupport(this WebApplicationBuilder builder) public static Task<WebApplicationBuilder> AddReadarrSupport(this WebApplicationBuilder builder)
{ {
return builder.AddServicesWithOptions<ReadarrInstanceOptions, ReadarrClient, IArrApplication>("Readarr"); return builder.AddServicesWithOptions<ReadarrInstanceOptions, ReadarrClient, IArrApplication>("Readarr");
} }

View File

@@ -6,6 +6,10 @@ namespace UmlautAdaptarr.Validator;
public class GlobalInstanceOptionsValidator : AbstractValidator<GlobalInstanceOptions> public class GlobalInstanceOptionsValidator : AbstractValidator<GlobalInstanceOptions>
{ {
private readonly static HttpClient httpClient = new() {
Timeout = TimeSpan.FromSeconds(3)
};
public GlobalInstanceOptionsValidator() public GlobalInstanceOptionsValidator()
{ {
RuleFor(x => x.Enabled).NotNull(); RuleFor(x => x.Enabled).NotNull();
@@ -14,12 +18,14 @@ public class GlobalInstanceOptionsValidator : AbstractValidator<GlobalInstanceOp
{ {
RuleFor(x => x.Host) RuleFor(x => x.Host)
.NotEmpty().WithMessage("Host is required when Enabled is true.") .NotEmpty().WithMessage("Host is required when Enabled is true.")
.Must(BeAValidUrl).WithMessage("Host/Url must start with http:// or https:// and be a valid address.") .Must(BeAValidUrl).WithMessage("Host/Url must start with http:// or https:// and be a valid address.");
.Must(BeReachable)
.WithMessage("Host/Url is not reachable. Please check your Host or your UmlautAdaptrr Settings");
RuleFor(x => x.ApiKey) RuleFor(x => x.ApiKey)
.NotEmpty().WithMessage("ApiKey is required when Enabled is true."); .NotEmpty().WithMessage("ApiKey is required when Enabled is true.");
RuleFor(x => x)
.MustAsync(BeReachable)
.WithMessage("Host/Url is not reachable. Please check your Host or your UmlautAdaptrr Settings");
}); });
} }
@@ -29,42 +35,22 @@ public class GlobalInstanceOptionsValidator : AbstractValidator<GlobalInstanceOp
&& (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps); && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
} }
private static bool BeReachable(string url) private static async Task<bool> BeReachable(GlobalInstanceOptions opts, CancellationToken cancellationToken)
{ {
var endTime = DateTime.Now.AddMinutes(3); var endTime = DateTime.Now.AddMinutes(3);
var reachable = false; var reachable = false;
var url = $"{opts.Host}/api?apikey={opts.ApiKey}";
while (DateTime.Now < endTime) while (DateTime.Now < endTime)
{ {
try try
{ {
// TODO use HttpClient here using var response = await httpClient.GetAsync(url, cancellationToken);
var request = (HttpWebRequest)WebRequest.Create(url);
request.AllowAutoRedirect = false;
request.Timeout = 3000;
using var response = (HttpWebResponse)request.GetResponse();
reachable = response.StatusCode == HttpStatusCode.OK; reachable = response.StatusCode == HttpStatusCode.OK;
if (reachable) if (response.IsSuccessStatusCode)
{ {
break; break;
} }
// If status is 301/302 (Found), follow the redirect manually
else if (response.StatusCode == HttpStatusCode.MovedPermanently || response.StatusCode == HttpStatusCode.Found)
{
var redirectUrl = response.Headers["Location"]; // Get the redirect URL
if (!string.IsNullOrEmpty(redirectUrl))
{
// Create a new request for the redirected URL
var redirectRequest = (HttpWebRequest)WebRequest.Create(redirectUrl);
redirectRequest.Timeout = 3000;
using var redirectResponse = (HttpWebResponse)redirectRequest.GetResponse();
reachable = redirectResponse.StatusCode == HttpStatusCode.OK;
if (reachable)
{
break;
}
}
}
} }
catch catch
{ {
@@ -72,7 +58,7 @@ public class GlobalInstanceOptionsValidator : AbstractValidator<GlobalInstanceOp
} }
// Wait for 15 seconds for next try // Wait for 15 seconds for next try
Console.WriteLine($"The URL \"{url}\" is not reachable. Next attempt in 15 seconds..."); Console.WriteLine($"The URL \"{opts.Host}\" is not reachable. Next attempt in 15 seconds...");
Thread.Sleep(15000); Thread.Sleep(15000);
} }

View File

@@ -64,5 +64,10 @@
"Enabled": false, "Enabled": false,
"Host": "your_readarr_host_url", "Host": "your_readarr_host_url",
"ApiKey": "your_readarr_api_key" "ApiKey": "your_readarr_api_key"
},
"IpLeakTest": {
// Docker Environment Variables:
// - IpLeakTest: false (set to true to enable)
"Enabled": false
} }
} }

View File

@@ -23,6 +23,7 @@ services:
- LIDARR__ENABLED=false - LIDARR__ENABLED=false
- LIDARR__HOST=http://localhost:8686 - LIDARR__HOST=http://localhost:8686
- LIDARR__APIKEY=APIKEY - LIDARR__APIKEY=APIKEY
#- IpLeakTest=false # uncomment and set to true to enable IP leak test
### example for multiple instances of same type ### example for multiple instances of same type
#- SONARR__0__NAME=NAME 1 (optional) #- SONARR__0__NAME=NAME 1 (optional)
#- SONARR__0__ENABLED=false #- SONARR__0__ENABLED=false