mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
Feature/netcore preparation (#2072)
* Use platform detection that works on mono 4.6+ * Move to use package reference for restoring nuget packages. * DateTimeRoutines does not have Nuget packages that support .NET Standard (and therefore .NET Core). We will have to include them for now until we can get rid of this dependency. * Start spliting some interfaces into their own files - this will help by allowing us to split them out in the future into a seperate project so the actual implementations can stay within their respective architectures when required * Move out common libraries * Few more tidy up tasks to get things working with .NET Standard * Restructure the solution layout * Encoding work to reduce rework later on platforms without Windows codepages (or require compliance with RFC1345) * Move folder structure around to have more natural layout of the solutions * DI server configuration to get rid of "temporary" hack and dependency circle for serverservice * Make all encoding consistent to match the expected encoding casing for earlier versions of mono.
This commit is contained in:

committed by
flightlevel

parent
47a2ffa313
commit
571c52a0f2
58
src/Jackett.Common/Utils/BrowserUtil.cs
Normal file
58
src/Jackett.Common/Utils/BrowserUtil.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Jackett.Utils
|
||||
{
|
||||
public static class BrowserUtil
|
||||
{
|
||||
public static string ChromeUserAgent
|
||||
{
|
||||
get {
|
||||
if (System.Environment.OSVersion.Platform == PlatformID.Unix)
|
||||
{
|
||||
return "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chrome/47.0.2526.73 Safari/537.36";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 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);
|
||||
string 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)
|
||||
{
|
||||
Regex 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)
|
||||
{
|
||||
string all = CFEMailRegexMatches.Groups[0].Value;
|
||||
string cfemail = CFEMailRegexMatches.Groups[1].Value;
|
||||
var decoded = DecodeCloudFlareProtectedEmail(cfemail);
|
||||
html = html.Replace(all, decoded);
|
||||
CFEMailRegexMatches = CFEMailRegexMatches.NextMatch();
|
||||
}
|
||||
return html;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user