redacted, orpheus: Add session cookie workaround for 2FA users (#7187) resolves #5912

This commit is contained in:
Anthony Snavely
2020-02-11 11:40:41 -08:00
committed by GitHub
parent afd9566388
commit cf06cd3541
3 changed files with 49 additions and 3 deletions

View File

@@ -26,6 +26,7 @@ namespace Jackett.Common.Indexers.Abstract
protected bool imdbInTags;
protected bool supportsCategories = true; // set to false if the tracker doesn't include the categories in the API search results
protected bool useTokens = false;
protected string cookie = "";
private new ConfigurationDataBasicLogin configData
{
@@ -33,7 +34,7 @@ namespace Jackett.Common.Indexers.Abstract
set { base.configData = value; }
}
public GazelleTracker(IIndexerConfigurationService configService, Utils.Clients.WebClient webClient, Logger logger, IProtectionService protectionService, string name, string desc, string link, bool supportsFreeleechTokens, bool imdbInTags = false)
public GazelleTracker(IIndexerConfigurationService configService, Utils.Clients.WebClient webClient, Logger logger, IProtectionService protectionService, string name, string desc, string link, bool supportsFreeleechTokens, bool imdbInTags = false, bool has2Fa = false)
: base(name: name,
description: desc,
link: link,
@@ -48,6 +49,19 @@ namespace Jackett.Common.Indexers.Abstract
this.supportsFreeleechTokens = supportsFreeleechTokens;
this.imdbInTags = imdbInTags;
if (has2Fa)
{
var cookieHint = new ConfigurationData.DisplayItem(
"<ol><li>(use this only if 2FA is enabled for your account)</li><li>Login to this tracker with your browser<li>Open the <b>DevTools</b> panel by pressing <b>F12</b><li>Select the <b>Network</b> tab<li>Click on the <b>Doc</b> button<li>Refresh the page by pressing <b>F5</b><li>Select the <b>Headers</b> tab<li>Find 'cookie:' in the <b>Request Headers</b> section<li>Copy & paste the whole cookie string to here.</ol>")
{
Name = "CookieHint"
};
configData.AddDynamic("cookieHint", cookieHint);
var cookieItem = new ConfigurationData.StringItem { Value = "" };
cookieItem.Name = "Cookie";
configData.AddDynamic("cookie", cookieItem);
}
if (supportsFreeleechTokens)
{
var useTokenItem = new ConfigurationData.BoolItem { Value = false };
@@ -60,11 +74,18 @@ namespace Jackett.Common.Indexers.Abstract
{
base.LoadValuesFromJson(jsonConfig, useProtectionService);
var cookieItem = (ConfigurationData.StringItem)configData.GetDynamic("cookie");
if (cookieItem != null)
{
cookie = cookieItem.Value;
}
var useTokenItem = (ConfigurationData.BoolItem)configData.GetDynamic("usetoken");
if (useTokenItem != null)
{
useTokens = useTokenItem.Value;
}
}
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
@@ -77,6 +98,29 @@ namespace Jackett.Common.Indexers.Abstract
{ "keeplogged", "1"},
};
if (!string.IsNullOrWhiteSpace(cookie))
{
// Cookie was manually supplied
CookieHeader = cookie;
try
{
var results = await PerformQuery(new TorznabQuery());
if (!results.Any())
{
throw new Exception("Your cookie did not work");
}
IsConfigured = true;
SaveConfig();
return IndexerConfigurationStatus.Completed;
}
catch (Exception e)
{
IsConfigured = false;
throw new Exception("Your cookie did not work: " + e.Message);
}
}
var response = await RequestLoginAndFollowRedirect(LoginUrl, pairs, string.Empty, true, SiteLink);
await ConfigureIfOK(response.Cookies, response.Content != null && response.Content.Contains("logout.php"), () =>
{

View File

@@ -17,7 +17,8 @@ namespace Jackett.Common.Indexers
logger: logger,
protectionService: protectionService,
webClient: webClient,
supportsFreeleechTokens: true
supportsFreeleechTokens: true,
has2Fa: true
)
{
Language = "en-us";

View File

@@ -17,7 +17,8 @@ namespace Jackett.Common.Indexers
logger: logger,
protectionService: protectionService,
webClient: webClient,
supportsFreeleechTokens: true
supportsFreeleechTokens: true,
has2Fa: true
)
{
Language = "en-us";