1
0
Fork 0
mirror of https://github.com/Jackett/Jackett synced 2025-01-01 12:46:23 +00:00

speedcd: fix login. resolves #8151 (#8164)

This commit is contained in:
Diego Heras 2020-04-13 07:25:44 +02:00 committed by GitHub
parent f99589443b
commit 58aeabc164
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using AngleSharp.Html.Parser; using AngleSharp.Html.Parser;
using Jackett.Common.Models; using Jackett.Common.Models;
@ -16,7 +17,8 @@ namespace Jackett.Common.Indexers
{ {
public class SpeedCD : BaseWebIndexer public class SpeedCD : BaseWebIndexer
{ {
private string LoginUrl => SiteLink + "take_login.php"; private string LoginUrl1 => SiteLink + "checkpoint/API";
private string LoginUrl2 => SiteLink + "checkpoint/";
private string SearchUrl => SiteLink + "browse.php"; private string SearchUrl => SiteLink + "browse.php";
public override string[] AlternativeSiteLinks { get; protected set; } = { public override string[] AlternativeSiteLinks { get; protected set; } = {
@ -90,12 +92,23 @@ namespace Jackett.Common.Indexers
private async Task DoLogin() private async Task DoLogin()
{ {
// first request with username
var pairs = new Dictionary<string, string> { var pairs = new Dictionary<string, string> {
{ "username", configData.Username.Value }, { "username", configData.Username.Value }
{ "password", configData.Password.Value },
}; };
var result = await RequestLoginAndFollowRedirect(LoginUrl1, pairs, null, true, null, SiteLink);
var tokenRegex = new Regex(@"name=\\""a\\"" value=\\""([^""]+)\\""");
var matches = tokenRegex.Match(result.Content);
if (!matches.Success)
throw new ExceptionWithConfigData("Error parsing the login form", configData);
var token = matches.Groups[1].Value;
var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, null, true, null, SiteLink); // second request with token and password
pairs = new Dictionary<string, string> {
{ "a", token },
{ "b", configData.Password.Value },
};
result = await RequestLoginAndFollowRedirect(LoginUrl2, pairs, result.Cookies, true, null, SiteLink);
await ConfigureIfOK(result.Cookies, result.Content?.Contains("/browse.php") == true, () => await ConfigureIfOK(result.Cookies, result.Content?.Contains("/browse.php") == true, () =>
{ {
@ -103,7 +116,7 @@ namespace Jackett.Common.Indexers
var dom = parser.ParseDocument(result.Content); var dom = parser.ParseDocument(result.Content);
var errorMessage = dom.QuerySelector("h5")?.TextContent; var errorMessage = dom.QuerySelector("h5")?.TextContent;
if (result.Content.Contains("Wrong Captcha!")) if (result.Content.Contains("Wrong Captcha!"))
errorMessage = "Captcha requiered due to a failed login attempt. Login via a browser to whitelist your IP and then reconfigure jackett."; errorMessage = "Captcha requiered due to a failed login attempt. Login via a browser to whitelist your IP and then reconfigure Jackett.";
throw new ExceptionWithConfigData(errorMessage, configData); throw new ExceptionWithConfigData(errorMessage, configData);
}); });
} }