From 7f6101a6bcdfe12aebee5746e25e47e2b262a6d7 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Sat, 20 Aug 2016 19:37:31 +0200 Subject: [PATCH] Better Captcha message. --- .../CloudFlare/CloudFlareCaptchaException.cs | 5 ++++ .../CloudFlare/CloudFlareHttpInterceptor.cs | 2 +- src/NzbDrone.Core/Indexers/HttpIndexerBase.cs | 23 +++++++++++++++++-- src/UI/Form/CaptchaTemplate.hbs | 5 ++-- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/NzbDrone.Core/Http/CloudFlare/CloudFlareCaptchaException.cs b/src/NzbDrone.Core/Http/CloudFlare/CloudFlareCaptchaException.cs index 1654535a8..3368bd9ce 100644 --- a/src/NzbDrone.Core/Http/CloudFlare/CloudFlareCaptchaException.cs +++ b/src/NzbDrone.Core/Http/CloudFlare/CloudFlareCaptchaException.cs @@ -15,5 +15,10 @@ namespace NzbDrone.Core.Http.CloudFlare Response = response; CaptchaRequest = captchaRequest; } + + public bool IsExpired + { + get { return Response.Request.Cookies.ContainsKey("cf_clearance"); } + } } } diff --git a/src/NzbDrone.Core/Http/CloudFlare/CloudFlareHttpInterceptor.cs b/src/NzbDrone.Core/Http/CloudFlare/CloudFlareHttpInterceptor.cs index d4377d399..a35f7c0b8 100644 --- a/src/NzbDrone.Core/Http/CloudFlare/CloudFlareHttpInterceptor.cs +++ b/src/NzbDrone.Core/Http/CloudFlare/CloudFlareHttpInterceptor.cs @@ -27,7 +27,7 @@ namespace NzbDrone.Core.Http.CloudFlare { if (response.StatusCode == HttpStatusCode.Forbidden && response.Content.Contains(_cloudFlareChallengeScript)) { - _logger.Error("CloudFlare CAPTCHA block on {0}", response.Request.Url); + _logger.Debug("CloudFlare CAPTCHA block on {0}", response.Request.Url); throw new CloudFlareCaptchaException(response, CreateCaptchaRequest(response)); } diff --git a/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs b/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs index 94b0a1e00..c9cfff122 100644 --- a/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs +++ b/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs @@ -246,6 +246,18 @@ namespace NzbDrone.Core.Indexers _indexerStatusService.RecordFailure(Definition.Id); _logger.Warn("Invalid API Key for {0} {1}", this, url); } + catch (CloudFlareCaptchaException ex) + { + _indexerStatusService.RecordFailure(Definition.Id); + if (ex.IsExpired) + { + _logger.Error(ex, "Expired CAPTCHA token for {0}, please refresh in indexer settings.", this); + } + else + { + _logger.Error(ex, "CAPTCHA token required for {0}, check indexer settings.", this); + } + } catch (IndexerException ex) { _indexerStatusService.RecordFailure(Definition.Id); @@ -314,9 +326,16 @@ namespace NzbDrone.Core.Indexers { _logger.Warn("Request limit reached"); } - catch (CloudFlareCaptchaException) + catch (CloudFlareCaptchaException ex) { - return new ValidationFailure("CaptchaToken", "Site protected by CloudFlare CAPTCHA. Valid CAPTCHA token required."); + if (ex.IsExpired) + { + return new ValidationFailure("CaptchaToken", "CloudFlare CAPTCHA token expired, please Refresh."); + } + else + { + return new ValidationFailure("CaptchaToken", "Site protected by CloudFlare CAPTCHA. Valid CAPTCHA token required."); + } } catch (UnsupportedFeedException ex) { diff --git a/src/UI/Form/CaptchaTemplate.hbs b/src/UI/Form/CaptchaTemplate.hbs index 29ef3edcf..12e472df0 100644 --- a/src/UI/Form/CaptchaTemplate.hbs +++ b/src/UI/Form/CaptchaTemplate.hbs @@ -3,12 +3,13 @@
- +
- + +