mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-10-01 07:55:22 +02:00
Fixed: (GreatPosterWall) Use cookies for 2FA
Co-authored-by: ilike2burnthing <59480337+ilike2burnthing@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
@@ -106,8 +107,23 @@ public abstract class GazelleBase<TSettings> : TorrentIndexerBase<TSettings>
|
||||
return response;
|
||||
}
|
||||
|
||||
protected override IDictionary<string, string> GetCookies()
|
||||
{
|
||||
if (Settings is GazelleUserPassOrCookieSettings cookieSettings && !string.IsNullOrWhiteSpace(cookieSettings.Cookie))
|
||||
{
|
||||
return CookieUtil.CookieHeaderToDictionary(cookieSettings.Cookie);
|
||||
}
|
||||
|
||||
return base.GetCookies();
|
||||
}
|
||||
|
||||
protected override bool CheckIfLoginNeeded(HttpResponse response)
|
||||
{
|
||||
if (Settings is GazelleUserPassOrCookieSettings cookieSettings && !string.IsNullOrWhiteSpace(cookieSettings.Cookie))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var invalidResponses = new[] { "\"bad credentials\"", "\"groupName\":\"wrong-creds\"" };
|
||||
|
||||
return response.HasHttpRedirect || (response.Content != null && invalidResponses.Any(response.Content.Contains));
|
||||
|
@@ -4,13 +4,14 @@ using NzbDrone.Core.Validation;
|
||||
|
||||
namespace NzbDrone.Core.Indexers.Definitions.Gazelle;
|
||||
|
||||
public class GazelleSettingsValidator : UserPassBaseSettingsValidator<GazelleSettings>
|
||||
public class GazelleSettingsValidator<T> : UserPassBaseSettingsValidator<T>
|
||||
where T : GazelleSettings
|
||||
{
|
||||
}
|
||||
|
||||
public class GazelleSettings : UserPassTorrentBaseSettings
|
||||
{
|
||||
private static readonly GazelleSettingsValidator Validator = new ();
|
||||
private static readonly GazelleSettingsValidator<GazelleSettings> Validator = new ();
|
||||
|
||||
public string AuthKey { get; set; }
|
||||
public string PassKey { get; set; }
|
||||
|
@@ -0,0 +1,31 @@
|
||||
using FluentValidation;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.Indexers.Settings;
|
||||
using NzbDrone.Core.Validation;
|
||||
|
||||
namespace NzbDrone.Core.Indexers.Definitions.Gazelle;
|
||||
|
||||
public class GazelleUserPassOrCookieValidator<T> : NoAuthSettingsValidator<T>
|
||||
where T : GazelleUserPassOrCookieSettings
|
||||
{
|
||||
public GazelleUserPassOrCookieValidator()
|
||||
{
|
||||
RuleFor(c => c.Username).NotEmpty().When(c => c.Cookie.IsNullOrWhiteSpace());
|
||||
RuleFor(c => c.Password).NotEmpty().When(c => c.Cookie.IsNullOrWhiteSpace());
|
||||
RuleFor(c => c.Cookie).NotEmpty().When(c => c.Username.IsNullOrWhiteSpace() && c.Password.IsNullOrWhiteSpace());
|
||||
}
|
||||
}
|
||||
|
||||
public class GazelleUserPassOrCookieSettings : GazelleSettings
|
||||
{
|
||||
private static readonly GazelleUserPassOrCookieValidator<GazelleUserPassOrCookieSettings> Validator = new ();
|
||||
|
||||
[FieldDefinition(4, Label = "Cookie", HelpText = "Use the Cookie field only if 2FA is enabled for your account, leave it empty otherwise.", Privacy = PrivacyLevel.Password)]
|
||||
public string Cookie { get; set; }
|
||||
|
||||
public override NzbDroneValidationResult Validate()
|
||||
{
|
||||
return new NzbDroneValidationResult(Validator.Validate(this));
|
||||
}
|
||||
}
|
@@ -15,6 +15,7 @@ using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Validation;
|
||||
|
||||
namespace NzbDrone.Core.Indexers.Definitions;
|
||||
|
||||
@@ -237,10 +238,17 @@ public class GreatPosterWallParser : GazelleParser
|
||||
}
|
||||
}
|
||||
|
||||
public class GreatPosterWallSettings : GazelleSettings
|
||||
public class GreatPosterWallSettings : GazelleUserPassOrCookieSettings
|
||||
{
|
||||
private static readonly GazelleUserPassOrCookieValidator<GreatPosterWallSettings> Validator = new ();
|
||||
|
||||
[FieldDefinition(6, Label = "Freeleech Only", Type = FieldType.Checkbox, HelpText = "Search freeleech torrents only")]
|
||||
public bool FreeleechOnly { get; set; }
|
||||
|
||||
public override NzbDroneValidationResult Validate()
|
||||
{
|
||||
return new NzbDroneValidationResult(Validator.Validate(this));
|
||||
}
|
||||
}
|
||||
|
||||
public class GreatPosterWallResponse
|
||||
|
@@ -4,38 +4,28 @@ using NzbDrone.Core.Validation;
|
||||
|
||||
namespace NzbDrone.Core.Indexers.Settings
|
||||
{
|
||||
public class CookieBaseSettingsValidator : AbstractValidator<CookieTorrentBaseSettings>
|
||||
public class CookieBaseSettingsValidator<T> : NoAuthSettingsValidator<T>
|
||||
where T : CookieTorrentBaseSettings
|
||||
{
|
||||
public CookieBaseSettingsValidator()
|
||||
{
|
||||
RuleFor(c => c.Cookie).NotEmpty();
|
||||
RuleFor(x => x.BaseSettings).SetValidator(new IndexerCommonSettingsValidator());
|
||||
RuleFor(x => x.TorrentBaseSettings).SetValidator(new IndexerTorrentSettingsValidator());
|
||||
}
|
||||
}
|
||||
|
||||
public class CookieTorrentBaseSettings : ITorrentIndexerSettings
|
||||
public class CookieTorrentBaseSettings : NoAuthTorrentBaseSettings
|
||||
{
|
||||
private static readonly CookieBaseSettingsValidator Validator = new ();
|
||||
private static readonly CookieBaseSettingsValidator<CookieTorrentBaseSettings> Validator = new ();
|
||||
|
||||
public CookieTorrentBaseSettings()
|
||||
{
|
||||
Cookie = "";
|
||||
}
|
||||
|
||||
[FieldDefinition(1, Label = "Base Url", HelpText = "Select which baseurl Prowlarr will use for requests to the site", Type = FieldType.Select, SelectOptionsProviderAction = "getUrls")]
|
||||
public string BaseUrl { get; set; }
|
||||
|
||||
[FieldDefinition(2, Label = "Cookie", HelpText = "Site Cookie", Privacy = PrivacyLevel.Password, Type = FieldType.Password)]
|
||||
[FieldDefinition(2, Label = "Cookie", HelpText = "Site Cookie", Privacy = PrivacyLevel.Password)]
|
||||
public string Cookie { get; set; }
|
||||
|
||||
[FieldDefinition(10)]
|
||||
public IndexerBaseSettings BaseSettings { get; set; } = new ();
|
||||
|
||||
[FieldDefinition(11)]
|
||||
public IndexerTorrentBaseSettings TorrentBaseSettings { get; set; } = new ();
|
||||
|
||||
public virtual NzbDroneValidationResult Validate()
|
||||
public override NzbDroneValidationResult Validate()
|
||||
{
|
||||
return new NzbDroneValidationResult(Validator.Validate(this));
|
||||
}
|
||||
|
@@ -9,8 +9,8 @@ namespace NzbDrone.Core.Indexers.Settings
|
||||
{
|
||||
public NoAuthSettingsValidator()
|
||||
{
|
||||
RuleFor(x => x.BaseSettings).SetValidator(new IndexerCommonSettingsValidator());
|
||||
RuleFor(x => x.TorrentBaseSettings).SetValidator(new IndexerTorrentSettingsValidator());
|
||||
RuleFor(c => c.BaseSettings).SetValidator(new IndexerCommonSettingsValidator());
|
||||
RuleFor(c => c.TorrentBaseSettings).SetValidator(new IndexerTorrentSettingsValidator());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,10 +21,10 @@ namespace NzbDrone.Core.Indexers.Settings
|
||||
[FieldDefinition(1, Label = "Base Url", Type = FieldType.Select, SelectOptionsProviderAction = "getUrls", HelpText = "Select which baseurl Prowlarr will use for requests to the site")]
|
||||
public string BaseUrl { get; set; }
|
||||
|
||||
[FieldDefinition(10)]
|
||||
[FieldDefinition(20)]
|
||||
public IndexerBaseSettings BaseSettings { get; set; } = new ();
|
||||
|
||||
[FieldDefinition(11)]
|
||||
[FieldDefinition(21)]
|
||||
public IndexerTorrentBaseSettings TorrentBaseSettings { get; set; } = new ();
|
||||
|
||||
public virtual NzbDroneValidationResult Validate()
|
||||
|
@@ -4,19 +4,17 @@ using NzbDrone.Core.Validation;
|
||||
|
||||
namespace NzbDrone.Core.Indexers.Settings
|
||||
{
|
||||
public class UserPassBaseSettingsValidator<T> : AbstractValidator<T>
|
||||
public class UserPassBaseSettingsValidator<T> : NoAuthSettingsValidator<T>
|
||||
where T : UserPassTorrentBaseSettings
|
||||
{
|
||||
public UserPassBaseSettingsValidator()
|
||||
{
|
||||
RuleFor(c => c.Username).NotEmpty();
|
||||
RuleFor(c => c.Password).NotEmpty();
|
||||
RuleFor(x => x.BaseSettings).SetValidator(new IndexerCommonSettingsValidator());
|
||||
RuleFor(x => x.TorrentBaseSettings).SetValidator(new IndexerTorrentSettingsValidator());
|
||||
}
|
||||
}
|
||||
|
||||
public class UserPassTorrentBaseSettings : ITorrentIndexerSettings
|
||||
public class UserPassTorrentBaseSettings : NoAuthTorrentBaseSettings
|
||||
{
|
||||
private static readonly UserPassBaseSettingsValidator<UserPassTorrentBaseSettings> Validator = new ();
|
||||
|
||||
@@ -26,22 +24,13 @@ namespace NzbDrone.Core.Indexers.Settings
|
||||
Password = "";
|
||||
}
|
||||
|
||||
[FieldDefinition(1, Label = "Base Url", HelpText = "Select which baseurl Prowlarr will use for requests to the site", Type = FieldType.Select, SelectOptionsProviderAction = "getUrls")]
|
||||
public string BaseUrl { get; set; }
|
||||
|
||||
[FieldDefinition(2, Label = "Username", HelpText = "Site Username", Privacy = PrivacyLevel.UserName)]
|
||||
public string Username { get; set; }
|
||||
|
||||
[FieldDefinition(3, Label = "Password", HelpText = "Site Password", Privacy = PrivacyLevel.Password, Type = FieldType.Password)]
|
||||
public string Password { get; set; }
|
||||
|
||||
[FieldDefinition(10)]
|
||||
public IndexerBaseSettings BaseSettings { get; set; } = new ();
|
||||
|
||||
[FieldDefinition(11)]
|
||||
public IndexerTorrentBaseSettings TorrentBaseSettings { get; set; } = new ();
|
||||
|
||||
public virtual NzbDroneValidationResult Validate()
|
||||
public override NzbDroneValidationResult Validate()
|
||||
{
|
||||
return new NzbDroneValidationResult(Validator.Validate(this));
|
||||
}
|
||||
|
Reference in New Issue
Block a user