Cardigann: add support for text captcha

This commit is contained in:
kaso17 2018-01-10 18:20:11 +01:00
parent 26933d9286
commit 8a02403f83
20 changed files with 55 additions and 20 deletions

View File

@ -42,7 +42,7 @@
pwd: "{{ .Config.password }}"
captcha:
type: image
image: img.captcha
selector: img.captcha
input: private_key
error:
- selector: span.errormsg

View File

@ -65,7 +65,7 @@
form: form#login
captcha:
type: image
image: img[alt="Security code"]
selector: img[alt="Security code"]
input: code
inputs:
username: "{{ .Config.username }}"

View File

@ -50,7 +50,7 @@
form: form[action="takelogin.php"]
captcha:
type: image
image: img[src="visual.php"]
selector: img[src="visual.php"]
input: secimage
inputs:
username: "{{ .Config.username }}"

View File

@ -92,7 +92,7 @@
cookies: ["JAVA=OK"] # avoid jscheck redirect
captcha:
type: image
image: img[src^="cap/captcha_math.php"]
selector: img[src^="cap/captcha_math.php"]
input: stringCaptcha
inputs:
username: "{{ .Config.username }}"

View File

@ -29,7 +29,7 @@
form: form[action="takelogin.php"]
captcha:
type: image
image: img#captcha
selector: img#captcha
input: imagestring
inputs:
username: "{{ .Config.username }}"

View File

@ -46,7 +46,7 @@
form: form[action="login3.php?takelogin=1"]
captcha:
type: image
image: img#validationimage
selector: img#validationimage
input: validationcode
inputs:
username: "{{ .Config.username }}"

View File

@ -51,7 +51,7 @@
password: "{{ .Config.password }}"
captcha:
type: image
image: img[alt="CAPTCHA"]
selector: img[alt="CAPTCHA"]
input: imagestring
error:
- selector: td.embedded:has(h2:contains("failed"))

View File

@ -67,7 +67,7 @@
form: form[action="takelogin.php"]
captcha:
type: image
image: img[alt="CAPTCHA"]
selector: img[alt="CAPTCHA"]
input: imagestring
inputs:
logintype: "username"

View File

@ -32,7 +32,7 @@
form: form[action="takelogin.php"]
captcha:
type: image
image: img[alt="CAPTCHA"]
selector: img[alt="CAPTCHA"]
input: imagestring
inputs:
username: "{{ .Config.username }}"

View File

@ -23,7 +23,7 @@
password: "{{ .Config.password }}"
captcha:
type: image
image: img#captcha_img
selector: img#captcha_img
input: imagestring
error:
- selector: table:contains("Login failed!")

View File

@ -35,7 +35,7 @@
form: form[action="takelogin.php"]
captcha:
type: image
image: img[src="img.php"]
selector: img[src="img.php"]
input: vImageCodP
inputs:
username: "{{ .Config.username }}"

View File

@ -58,7 +58,7 @@
password: "{{ .Config.password }}"
captcha:
type: image
image: img#freecap
selector: img#freecap
input: word
error:
- selector: table:contains("Login failed!")

View File

@ -92,7 +92,7 @@
password: "{{ .Config.password }}"
captcha:
type: image
image: img#freecap
selector: img#freecap
input: word
error:
- selector: table:contains("Login failed!")

View File

@ -74,7 +74,7 @@
password: "{{ .Config.password }}"
captcha:
type: image
image: img#freecap
selector: img#freecap
input: word
error:
- selector: table:contains("Login failed!")

View File

@ -57,7 +57,7 @@
password: "{{ .Config.password }}"
captcha:
type: image
image: img#freecap
selector: img#freecap
input: word
error:
- selector: table:contains("Login failed!")

View File

@ -72,7 +72,7 @@
password: "{{ .Config.password }}"
captcha:
type: image
image: img#freecap
selector: img#freecap
input: word
error:
- selector: table:contains("Login failed!")

View File

@ -73,7 +73,7 @@
password: "{{ .Config.password }}"
captcha:
type: image
image: img#freecap
selector: img#freecap
input: word
error:
- selector: table:contains("Login failed!")

View File

@ -43,7 +43,7 @@
form: form[action="takelogin.php"]
captcha:
type: image
image: img[alt="CAPTCHA"]
selector: img[alt="CAPTCHA"]
input: imagestring
inputs:
username: "{{ .Config.username }}"

View File

@ -557,6 +557,22 @@ namespace Jackett.Indexers
pairs[input] = CaptchaText.Value;
}
}
if (Captcha.Type == "text")
{
var CaptchaAnswer = (StringItem)configData.GetDynamic("CaptchaAnswer");
if (CaptchaAnswer != null)
{
var input = Captcha.Input;
if (Login.Selectors)
{
var inputElement = landingResultDocument.QuerySelector(Captcha.Input);
if (inputElement == null)
throw new ExceptionWithConfigData(string.Format("Login failed: No captcha input found using {0}", Captcha.Input), configData);
input = inputElement.GetAttribute("name");
}
pairs[input] = CaptchaAnswer.Value;
}
}
}
// clear landingResults/Document, otherwise we might use an old version for a new relogin (if GetConfigurationForSetup() wasn't called before)
@ -716,7 +732,7 @@ namespace Jackett.Indexers
var Captcha = Login.Captcha;
if (Captcha.Type == "image")
{
var captchaElement = landingResultDocument.QuerySelector(Captcha.Image);
var captchaElement = landingResultDocument.QuerySelector(Captcha.Selector);
if (captchaElement != null)
{
hasCaptcha = true;
@ -736,6 +752,24 @@ namespace Jackett.Indexers
logger.Debug(string.Format("CardigannIndexer ({0}): No captcha image found", ID));
}
}
else if (Captcha.Type == "text")
{
var captchaElement = landingResultDocument.QuerySelector(Captcha.Selector);
if (captchaElement != null)
{
hasCaptcha = true;
var CaptchaChallenge = new DisplayItem(captchaElement.TextContent) { Name = "Captcha Challenge" };
var CaptchaAnswer = new StringItem { Name = "Captcha Answer" };
configData.AddDynamic("CaptchaChallenge", CaptchaChallenge);
configData.AddDynamic("CaptchaAnswer", CaptchaAnswer);
}
else
{
logger.Debug(string.Format("CardigannIndexer ({0}): No captcha image found", ID));
}
}
else
{
throw new NotImplementedException(string.Format("Captcha type \"{0}\" is not implemented", Captcha.Type));

View File

@ -102,7 +102,8 @@ namespace Jackett.Models
public class captchaBlock
{
public string Type { get; set; }
public string Image { get; set; }
public string Selector { get; set; }
public string Image { get { throw new Exception("Deprecated, please use Login.Captcha.Selector instead"); } set { throw new Exception("Deprecated, please use login/captcha/selector instead of image"); } }
public string Input { get; set; }
}