mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
core: remove legacy cloudflare code (#10110)
This commit is contained in:
@@ -1,45 +1,14 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
|
|
||||||
namespace Jackett.Common.Utils
|
namespace Jackett.Common.Utils
|
||||||
{
|
{
|
||||||
public static class BrowserUtil
|
public static class BrowserUtil
|
||||||
{
|
{
|
||||||
// When updating these make sure they are not detected by the incapsula bot detection engine (e.g. kickasstorrent indexer)
|
// When updating these make sure they are not detected by the incapsula bot detection engine
|
||||||
|
// (e.g. kickasstorrent indexer)
|
||||||
public static string ChromeUserAgent => Environment.OSVersion.Platform == PlatformID.Unix ?
|
public static string ChromeUserAgent => Environment.OSVersion.Platform == PlatformID.Unix ?
|
||||||
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36" :
|
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36" :
|
||||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36";
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36";
|
||||||
|
|
||||||
// This can be used to decode e-mail addresses protected by cloudflare
|
|
||||||
public static string DecodeCloudFlareProtectedEmail(string input)
|
|
||||||
{
|
|
||||||
var key = Convert.ToInt32(input.Substring(0, 2), 16);
|
|
||||||
var result = "";
|
|
||||||
for (var i = 2; i < input.Length - 1; i += 2)
|
|
||||||
{
|
|
||||||
var hexChar = input.Substring(i, 2);
|
|
||||||
var intChar = Convert.ToInt32(hexChar, 16) ^ key;
|
|
||||||
var strChar = Convert.ToChar(intChar);
|
|
||||||
result += strChar;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// decode cloudflare protected emails in a HTML document
|
|
||||||
public static string DecodeCloudFlareProtectedEmailFromHTML(string html)
|
|
||||||
{
|
|
||||||
var CFEMailRegex = new Regex("<span class=\"__cf_email__\" data-cfemail=\"(\\w+)\">\\[email protected\\]<\\/span><script data-cfhash='[\\w]+' type=\"text\\/javascript\">.*?<\\/script>", RegexOptions.Compiled);
|
|
||||||
var CFEMailRegexMatches = CFEMailRegex.Match(html);
|
|
||||||
|
|
||||||
while (CFEMailRegexMatches.Success)
|
|
||||||
{
|
|
||||||
var all = CFEMailRegexMatches.Groups[0].Value;
|
|
||||||
var cfemail = CFEMailRegexMatches.Groups[1].Value;
|
|
||||||
var decoded = DecodeCloudFlareProtectedEmail(cfemail);
|
|
||||||
html = html.Replace(all, decoded);
|
|
||||||
CFEMailRegexMatches = CFEMailRegexMatches.NextMatch();
|
|
||||||
}
|
|
||||||
return html;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -193,8 +193,6 @@ namespace Jackett.Common.Utils.Clients
|
|||||||
}{bodySize} bytes{body}");
|
}{bodySize} bytes{body}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.Headers.TryGetValue("server", out var server) && server[0] == "cloudflare-nginx")
|
|
||||||
result.ContentString = BrowserUtil.DecodeCloudFlareProtectedEmailFromHTML(result.ContentString);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user