parent
e85ccd5808
commit
09ed132fe6
@ -1,21 +0,0 @@
|
||||
using NzbDrone.Common.Exceptions;
|
||||
using NzbDrone.Common.Http;
|
||||
|
||||
namespace NzbDrone.Core.Http.CloudFlare
|
||||
{
|
||||
public class CloudFlareCaptchaException : NzbDroneException
|
||||
{
|
||||
public HttpResponse Response { get; set; }
|
||||
|
||||
public CloudFlareCaptchaRequest CaptchaRequest { get; set; }
|
||||
|
||||
public CloudFlareCaptchaException(HttpResponse response, CloudFlareCaptchaRequest captchaRequest)
|
||||
: base("Unable to access {0}, blocked by CloudFlare CAPTCHA. Likely due to shared-IP VPN.", response.Request.Url.Host)
|
||||
{
|
||||
Response = response;
|
||||
CaptchaRequest = captchaRequest;
|
||||
}
|
||||
|
||||
public bool IsExpired => Response.Request.Cookies.ContainsKey("cf_clearance");
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
using NzbDrone.Common.Http;
|
||||
|
||||
namespace NzbDrone.Core.Http.CloudFlare
|
||||
{
|
||||
public class CloudFlareCaptchaRequest
|
||||
{
|
||||
public string Host { get; set; }
|
||||
public string SiteKey { get; set; }
|
||||
|
||||
public string Ray { get; set; }
|
||||
public string SecretToken { get; set; }
|
||||
|
||||
public HttpUri ResponseUrl { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Http;
|
||||
|
||||
namespace NzbDrone.Core.Http.CloudFlare
|
||||
{
|
||||
public class CloudFlareDetectionService
|
||||
{
|
||||
private static readonly HashSet<string> CloudflareServerNames = new HashSet<string> { "cloudflare", "cloudflare-nginx", "ddos-guard" };
|
||||
private readonly Logger _logger;
|
||||
|
||||
public CloudFlareDetectionService(Logger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public static bool IsCloudflareProtected(HttpResponse response)
|
||||
{
|
||||
if (!response.Headers.Any(i => i.Key != null && i.Key.ToLower() == "server" && CloudflareServerNames.Contains(i.Value.ToLower())))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// detect CloudFlare and DDoS-GUARD
|
||||
if (response.StatusCode.Equals(HttpStatusCode.ServiceUnavailable) ||
|
||||
response.StatusCode.Equals(HttpStatusCode.Forbidden))
|
||||
{
|
||||
return true; // Defected CloudFlare and DDoS-GUARD
|
||||
}
|
||||
|
||||
// detect Custom CloudFlare for EbookParadijs, Film-Paleis, MuziekFabriek and Puur-Hollands
|
||||
if (response.Headers.Vary.ToString() == "Accept-Encoding,User-Agent" &&
|
||||
response.Headers.ContentEncoding.ToString() == "" &&
|
||||
response.Content.ToLower().Contains("ddos"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using NzbDrone.Common.Exceptions;
|
||||
using NzbDrone.Common.Http;
|
||||
|
||||
namespace NzbDrone.Core.Http.CloudFlare
|
||||
{
|
||||
public class CloudFlareProtectionException : NzbDroneException
|
||||
{
|
||||
public HttpResponse Response { get; set; }
|
||||
|
||||
public CloudFlareProtectionException(HttpResponse response)
|
||||
: base("Unable to access {0}, blocked by CloudFlare Protection.", response.Request.Url.Host)
|
||||
{
|
||||
Response = response;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue