From d1ff05ac13eea86619fb91d60d28ccbbc43cfc34 Mon Sep 17 00:00:00 2001 From: KZ Date: Sat, 8 Aug 2015 00:15:42 +0100 Subject: [PATCH] Implement recaptcha for torrentday (This will only work for localhost) --- src/Jackett/Content/custom.js | 27 ++- src/Jackett/Content/index.html | 170 ++++++++++-------- src/Jackett/Content/libs/handlebarsmoment.js | 3 +- src/Jackett/Indexers/TorrentDay.cs | 25 ++- src/Jackett/Jackett.csproj | 1 + .../Models/IndexerConfig/ConfigurationData.cs | 21 ++- .../ConfigurationDataRecaptchaLogin.cs | 25 +++ 7 files changed, 172 insertions(+), 100 deletions(-) create mode 100644 src/Jackett/Models/IndexerConfig/ConfigurationDataRecaptchaLogin.cs diff --git a/src/Jackett/Content/custom.js b/src/Jackett/Content/custom.js index 7ed47288c..0f50fee4a 100644 --- a/src/Jackett/Content/custom.js +++ b/src/Jackett/Content/custom.js @@ -197,8 +197,8 @@ function reloadIndexers() { } function displayIndexers(items) { - var indexerTemplate = Handlebars.compile($("#templates > .configured-indexer")[0].outerHTML); - var unconfiguredIndexerTemplate = Handlebars.compile($("#templates > .unconfigured-indexer")[0].outerHTML); + var indexerTemplate = Handlebars.compile($("#configured-indexer").html()); + var unconfiguredIndexerTemplate = Handlebars.compile($("#unconfigured-indexer").html()); for (var i = 0; i < items.length; i++) { var item = items[i]; item.torznab_host = resolveUrl("/torznab/" + item.id); @@ -209,7 +209,7 @@ function displayIndexers(items) { $('#unconfigured-indexers').append($(unconfiguredIndexerTemplate(item))); } - var addIndexerButton = $("#templates > .add-indexer")[0].outerHTML; + var addIndexerButton = $('#add-indexer').html(); $('#indexers').append(addIndexerButton); $('#indexers').fadeIn(); @@ -293,12 +293,22 @@ function populateConfigItems(configForm, config) { } var $formItemContainer = configForm.find(".config-setup-form"); $formItemContainer.empty(); - var setupItemTemplate = Handlebars.compile($("#templates > .setup-item")[0].outerHTML); + var setupItemTemplate = Handlebars.compile($("#setup-item").html()); for (var i = 0; i < config.length; i++) { var item = config[i]; - var setupValueTemplate = Handlebars.compile($("#templates > .setup-item-" + item.type)[0].outerHTML); + var setupValueTemplate = Handlebars.compile($("#setup-item-" + item.type).html()); + + item.value_element = setupValueTemplate(item); - $formItemContainer.append(setupItemTemplate(item)); + var template = setupItemTemplate(item); + + $formItemContainer.append(template); + + if (item.type === 'recaptcha') { + grecaptcha.render($('.jackettrecaptcha')[0], { + 'sitekey': item.sitekey + }); + } } } @@ -327,6 +337,9 @@ function getConfigModalJson(configForm) { case "inputbool": itemEntry.value = $el.find(".setup-item-inputbool input").is(":checked"); break; + case "recaptcha": + itemEntry.value = $('.g-recaptcha-response').val(); + break; } configJson.push(itemEntry) }); @@ -342,7 +355,7 @@ function populateSetupForm(indexerId, name, config, caps) { var originalBtnText = $goButton.html(); $goButton.prop('disabled', true); - $goButton.html($('#templates > .spinner')[0].outerHTML); + $goButton.html($('#spinner').html()); var jqxhr = $.post("/admin/configure_indexer", JSON.stringify(data), function (data) { if (data.result == "error") { diff --git a/src/Jackett/Content/index.html b/src/Jackett/Content/index.html index 6f03dc8c3..967ec8715 100644 --- a/src/Jackett/Content/index.html +++ b/src/Jackett/Content/index.html @@ -13,6 +13,7 @@ + @@ -20,6 +21,85 @@ + + + + + + + + + + + + Jackett @@ -248,85 +339,6 @@
- -
- - -
- -
- - - - - - -
-
- Torznab Host: - - CouchPotato Host: - {{#if potatoenabled}} - - - {{else}} - - {{/if}} -
-
- -
- -
- Visit - -
-
- - -
-
{{name}}
-
{{{value_element}}}
-
-
- {{#if ispassword}} - - {{else}} - - {{/if}} -
- -
- {{#if value}} - - {{else}} - - {{/if}} -
- - -
- -
- - - - -
- - - \ No newline at end of file diff --git a/src/Jackett/Content/libs/handlebarsmoment.js b/src/Jackett/Content/libs/handlebarsmoment.js index 55062fd16..0bf9f5fd1 100644 --- a/src/Jackett/Content/libs/handlebarsmoment.js +++ b/src/Jackett/Content/libs/handlebarsmoment.js @@ -30,5 +30,4 @@ Handlebars.registerHelper('jacketTimespan', function (context, block) { var years = timeSpan.asYears(); return Math.round(years) + 'y ago'; -}); - +}); \ No newline at end of file diff --git a/src/Jackett/Indexers/TorrentDay.cs b/src/Jackett/Indexers/TorrentDay.cs index ce74a39f9..6100aa6a4 100644 --- a/src/Jackett/Indexers/TorrentDay.cs +++ b/src/Jackett/Indexers/TorrentDay.cs @@ -25,9 +25,9 @@ namespace Jackett.Indexers private string LoginUrl { get { return SiteLink + "tak3login.php"; } } private string SearchUrl { get { return SiteLink + "browse.php"; } } - new ConfigurationDataBasicLogin configData + new ConfigurationDataRecaptchaLogin configData { - get { return (ConfigurationDataBasicLogin)base.configData; } + get { return (ConfigurationDataRecaptchaLogin)base.configData; } set { base.configData = value; } } @@ -40,7 +40,7 @@ namespace Jackett.Indexers client: wc, logger: l, p: ps, - configData: new ConfigurationDataBasicLogin()) + configData: new ConfigurationDataRecaptchaLogin()) { AddCategoryMapping(29, TorznabCatType.Anime); @@ -84,19 +84,26 @@ namespace Jackett.Indexers AddCategoryMapping(15, TorznabCatType.XXX); } + public override async Task GetConfigurationForSetup() + { + var loginPage = await RequestStringWithCookies(StartPageUrl, string.Empty); + CQ cq = loginPage.Content; + var result = new ConfigurationDataRecaptchaLogin(); + result.CookieHeader.Value = loginPage.Cookies; + result.Captcha.SiteKey = cq.Find(".g-recaptcha").Attr("data-sitekey"); + return result; + } + public async Task ApplyConfiguration(JToken configJson) { configData.LoadValuesFromJson(configJson); - - var startMessage = await RequestStringWithCookies(StartPageUrl, string.Empty); - - var pairs = new Dictionary { { "username", configData.Username.Value }, - { "password", configData.Password.Value } + { "password", configData.Password.Value }, + { "g-recaptcha-response", configData.Captcha.Value } }; - var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, null, true, SiteLink, LoginUrl); + var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, configData.CookieHeader.Value, true, SiteLink, LoginUrl); await ConfigureIfOK(result.Cookies, result.Content != null && result.Content.Contains("logout.php"), () => { CQ dom = result.Content; diff --git a/src/Jackett/Jackett.csproj b/src/Jackett/Jackett.csproj index 85f6c83d4..f109239cd 100644 --- a/src/Jackett/Jackett.csproj +++ b/src/Jackett/Jackett.csproj @@ -213,6 +213,7 @@ + diff --git a/src/Jackett/Models/IndexerConfig/ConfigurationData.cs b/src/Jackett/Models/IndexerConfig/ConfigurationData.cs index 360909642..e5ccab601 100644 --- a/src/Jackett/Models/IndexerConfig/ConfigurationData.cs +++ b/src/Jackett/Models/IndexerConfig/ConfigurationData.cs @@ -20,7 +20,8 @@ namespace Jackett.Models.IndexerConfig InputBool, DisplayImage, DisplayInfo, - HiddenData + HiddenData, + Recaptcha } public HiddenItem CookieHeader { get; private set; } = new HiddenItem { Name = "CookieHeader" }; @@ -69,6 +70,9 @@ namespace Jackett.Models.IndexerConfig case ItemType.InputBool: ((BoolItem)item).Value = arrItem.Value("value"); break; + case ItemType.Recaptcha: + ((RecaptchaItem)item).Value = arrItem.Value("value"); + break; } } } @@ -85,6 +89,9 @@ namespace Jackett.Models.IndexerConfig jObject["name"] = item.Name; switch (item.ItemType) { + case ItemType.Recaptcha: + jObject["sitekey"] = ((RecaptchaItem)item).SiteKey; + break; case ItemType.InputString: case ItemType.HiddenData: case ItemType.DisplayInfo: @@ -98,7 +105,6 @@ namespace Jackett.Models.IndexerConfig else if (ps != null) value = ps.Protect(value); } - jObject["value"] = value; break; case ItemType.InputBool: @@ -125,7 +131,7 @@ namespace Jackett.Models.IndexerConfig if (!forDisplay) { properties = properties - .Where(p => p.ItemType == ItemType.HiddenData || p.ItemType == ItemType.InputBool || p.ItemType == ItemType.InputString) + .Where(p => p.ItemType == ItemType.HiddenData || p.ItemType == ItemType.InputBool || p.ItemType == ItemType.InputString || p.ItemType == ItemType.Recaptcha) .ToArray(); } @@ -159,6 +165,7 @@ namespace Jackett.Models.IndexerConfig public class StringItem : Item { + public string SiteKey { get; set; } public string Value { get; set; } public StringItem() { @@ -166,6 +173,14 @@ namespace Jackett.Models.IndexerConfig } } + public class RecaptchaItem : StringItem + { + public RecaptchaItem() + { + ItemType = ConfigurationData.ItemType.Recaptcha; + } + } + public class BoolItem : Item { public bool Value { get; set; } diff --git a/src/Jackett/Models/IndexerConfig/ConfigurationDataRecaptchaLogin.cs b/src/Jackett/Models/IndexerConfig/ConfigurationDataRecaptchaLogin.cs new file mode 100644 index 000000000..94991c02d --- /dev/null +++ b/src/Jackett/Models/IndexerConfig/ConfigurationDataRecaptchaLogin.cs @@ -0,0 +1,25 @@ +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Jackett.Models.IndexerConfig +{ + public class ConfigurationDataRecaptchaLogin : ConfigurationData + { + public StringItem Username { get; private set; } + public StringItem Password { get; private set; } + public RecaptchaItem Captcha { get; private set; } + + public ConfigurationDataRecaptchaLogin() + { + Username = new StringItem { Name = "Username" }; + Password = new StringItem { Name = "Password" }; + Captcha = new RecaptchaItem() { Name = "Recaptcha" }; + } + + + } +}