Fixed: (GreatPosterWall) Use cookies for 2FA

Co-authored-by: ilike2burnthing <59480337+ilike2burnthing@users.noreply.github.com>
pull/1467/head
Bogdan 2 years ago committed by GitHub
parent 5f26287234
commit 26bea14137
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -106,8 +107,23 @@ public abstract class GazelleBase<TSettings> : TorrentIndexerBase<TSettings>
return response; 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) 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\"" }; var invalidResponses = new[] { "\"bad credentials\"", "\"groupName\":\"wrong-creds\"" };
return response.HasHttpRedirect || (response.Content != null && invalidResponses.Any(response.Content.Contains)); 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; namespace NzbDrone.Core.Indexers.Definitions.Gazelle;
public class GazelleSettingsValidator : UserPassBaseSettingsValidator<GazelleSettings> public class GazelleSettingsValidator<T> : UserPassBaseSettingsValidator<T>
where T : GazelleSettings
{ {
} }
public class GazelleSettings : UserPassTorrentBaseSettings public class GazelleSettings : UserPassTorrentBaseSettings
{ {
private static readonly GazelleSettingsValidator Validator = new (); private static readonly GazelleSettingsValidator<GazelleSettings> Validator = new ();
public string AuthKey { get; set; } public string AuthKey { get; set; }
public string PassKey { 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.Messaging.Events;
using NzbDrone.Core.Parser; using NzbDrone.Core.Parser;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Validation;
namespace NzbDrone.Core.Indexers.Definitions; 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")] [FieldDefinition(6, Label = "Freeleech Only", Type = FieldType.Checkbox, HelpText = "Search freeleech torrents only")]
public bool FreeleechOnly { get; set; } public bool FreeleechOnly { get; set; }
public override NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult(Validator.Validate(this));
}
} }
public class GreatPosterWallResponse public class GreatPosterWallResponse

@ -4,38 +4,28 @@ using NzbDrone.Core.Validation;
namespace NzbDrone.Core.Indexers.Settings namespace NzbDrone.Core.Indexers.Settings
{ {
public class CookieBaseSettingsValidator : AbstractValidator<CookieTorrentBaseSettings> public class CookieBaseSettingsValidator<T> : NoAuthSettingsValidator<T>
where T : CookieTorrentBaseSettings
{ {
public CookieBaseSettingsValidator() public CookieBaseSettingsValidator()
{ {
RuleFor(c => c.Cookie).NotEmpty(); 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() public CookieTorrentBaseSettings()
{ {
Cookie = ""; Cookie = "";
} }
[FieldDefinition(1, Label = "Base Url", HelpText = "Select which baseurl Prowlarr will use for requests to the site", Type = FieldType.Select, SelectOptionsProviderAction = "getUrls")] [FieldDefinition(2, Label = "Cookie", HelpText = "Site Cookie", Privacy = PrivacyLevel.Password)]
public string BaseUrl { get; set; }
[FieldDefinition(2, Label = "Cookie", HelpText = "Site Cookie", Privacy = PrivacyLevel.Password, Type = FieldType.Password)]
public string Cookie { get; set; } public string Cookie { get; set; }
[FieldDefinition(10)] public override NzbDroneValidationResult Validate()
public IndexerBaseSettings BaseSettings { get; set; } = new ();
[FieldDefinition(11)]
public IndexerTorrentBaseSettings TorrentBaseSettings { get; set; } = new ();
public virtual NzbDroneValidationResult Validate()
{ {
return new NzbDroneValidationResult(Validator.Validate(this)); return new NzbDroneValidationResult(Validator.Validate(this));
} }

@ -9,8 +9,8 @@ namespace NzbDrone.Core.Indexers.Settings
{ {
public NoAuthSettingsValidator() public NoAuthSettingsValidator()
{ {
RuleFor(x => x.BaseSettings).SetValidator(new IndexerCommonSettingsValidator()); RuleFor(c => c.BaseSettings).SetValidator(new IndexerCommonSettingsValidator());
RuleFor(x => x.TorrentBaseSettings).SetValidator(new IndexerTorrentSettingsValidator()); 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")] [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; } public string BaseUrl { get; set; }
[FieldDefinition(10)] [FieldDefinition(20)]
public IndexerBaseSettings BaseSettings { get; set; } = new (); public IndexerBaseSettings BaseSettings { get; set; } = new ();
[FieldDefinition(11)] [FieldDefinition(21)]
public IndexerTorrentBaseSettings TorrentBaseSettings { get; set; } = new (); public IndexerTorrentBaseSettings TorrentBaseSettings { get; set; } = new ();
public virtual NzbDroneValidationResult Validate() public virtual NzbDroneValidationResult Validate()

@ -4,19 +4,17 @@ using NzbDrone.Core.Validation;
namespace NzbDrone.Core.Indexers.Settings namespace NzbDrone.Core.Indexers.Settings
{ {
public class UserPassBaseSettingsValidator<T> : AbstractValidator<T> public class UserPassBaseSettingsValidator<T> : NoAuthSettingsValidator<T>
where T : UserPassTorrentBaseSettings where T : UserPassTorrentBaseSettings
{ {
public UserPassBaseSettingsValidator() public UserPassBaseSettingsValidator()
{ {
RuleFor(c => c.Username).NotEmpty(); RuleFor(c => c.Username).NotEmpty();
RuleFor(c => c.Password).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 (); private static readonly UserPassBaseSettingsValidator<UserPassTorrentBaseSettings> Validator = new ();
@ -26,22 +24,13 @@ namespace NzbDrone.Core.Indexers.Settings
Password = ""; 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)] [FieldDefinition(2, Label = "Username", HelpText = "Site Username", Privacy = PrivacyLevel.UserName)]
public string Username { get; set; } public string Username { get; set; }
[FieldDefinition(3, Label = "Password", HelpText = "Site Password", Privacy = PrivacyLevel.Password, Type = FieldType.Password)] [FieldDefinition(3, Label = "Password", HelpText = "Site Password", Privacy = PrivacyLevel.Password, Type = FieldType.Password)]
public string Password { get; set; } public string Password { get; set; }
[FieldDefinition(10)] public override NzbDroneValidationResult Validate()
public IndexerBaseSettings BaseSettings { get; set; } = new ();
[FieldDefinition(11)]
public IndexerTorrentBaseSettings TorrentBaseSettings { get; set; } = new ();
public virtual NzbDroneValidationResult Validate()
{ {
return new NzbDroneValidationResult(Validator.Validate(this)); return new NzbDroneValidationResult(Validator.Validate(this));
} }

Loading…
Cancel
Save