Private GIT

Skip to content
Snippets Groups Projects
Commit e47cf660 authored by Kayomani's avatar Kayomani
Browse files

Fix SCC not saving and AlphaRatio

parent 073ddbe2
Branches
Tags
No related merge requests found
...@@ -48,6 +48,12 @@ namespace Jackett.Controllers ...@@ -48,6 +48,12 @@ namespace Jackett.Controllers
return Request.CreateResponse(HttpStatusCode.Forbidden, "Incorrect API key"); return Request.CreateResponse(HttpStatusCode.Forbidden, "Incorrect API key");
} }
if (!indexer.IsConfigured)
{
logger.Warn(string.Format("Rejected a request to {0} which is unconfigured.", indexer.DisplayName));
return Request.CreateResponse(HttpStatusCode.Forbidden, "This indexer is not configured.");
}
var releases = await indexer.PerformQuery(torznabQuery); var releases = await indexer.PerformQuery(torznabQuery);
if (string.IsNullOrWhiteSpace(torznabQuery.SanitizedSearchTerm)) if (string.IsNullOrWhiteSpace(torznabQuery.SanitizedSearchTerm))
......
...@@ -31,6 +31,13 @@ namespace Jackett.Controllers ...@@ -31,6 +31,13 @@ namespace Jackett.Controllers
try try
{ {
var indexer = indexerService.GetIndexer(indexerID); var indexer = indexerService.GetIndexer(indexerID);
if (!indexer.IsConfigured)
{
logger.Warn(string.Format("Rejected a request to {0} which is unconfigured.", indexer.DisplayName));
return Request.CreateResponse(HttpStatusCode.Forbidden, "This indexer is not configured.");
}
var remoteFile = Encoding.UTF8.GetString(HttpServerUtility.UrlTokenDecode(path)); var remoteFile = Encoding.UTF8.GetString(HttpServerUtility.UrlTokenDecode(path));
var downloadBytes = await indexer.Download(new Uri(remoteFile)); var downloadBytes = await indexer.Download(new Uri(remoteFile));
......
...@@ -13,6 +13,7 @@ using Jackett.Models; ...@@ -13,6 +13,7 @@ using Jackett.Models;
using Jackett.Utils; using Jackett.Utils;
using NLog; using NLog;
using Jackett.Services; using Jackett.Services;
using Jackett.Utils.Clients;
namespace Jackett.Indexers namespace Jackett.Indexers
{ {
...@@ -23,13 +24,10 @@ namespace Jackett.Indexers ...@@ -23,13 +24,10 @@ namespace Jackett.Indexers
private readonly string DownloadUrl = ""; private readonly string DownloadUrl = "";
private readonly string GuidUrl = ""; private readonly string GuidUrl = "";
CookieContainer cookies; private IWebClient webclient;
HttpClientHandler handler; private string cookieHeader = "";
HttpClient client;
string cookieHeader; public AlphaRatio(IIndexerManagerService i, IWebClient w, Logger l)
public AlphaRatio(IIndexerManagerService i, Logger l)
: base(name: "AlphaRatio", : base(name: "AlphaRatio",
description: "Legendary", description: "Legendary",
link: new Uri("https://alpharatio.cc"), link: new Uri("https://alpharatio.cc"),
...@@ -41,16 +39,7 @@ namespace Jackett.Indexers ...@@ -41,16 +39,7 @@ namespace Jackett.Indexers
SearchUrl = SiteLink + "ajax.php?action=browse&searchstr="; SearchUrl = SiteLink + "ajax.php?action=browse&searchstr=";
DownloadUrl = SiteLink + "torrents.php?action=download&id="; DownloadUrl = SiteLink + "torrents.php?action=download&id=";
GuidUrl = SiteLink + "torrents.php?torrentid="; GuidUrl = SiteLink + "torrents.php?torrentid=";
webclient = w;
cookies = new CookieContainer();
handler = new HttpClientHandler
{
CookieContainer = cookies,
AllowAutoRedirect = true,
UseCookies = true,
};
client = new HttpClient(handler);
} }
public Task<ConfigurationData> GetConfigurationForSetup() public Task<ConfigurationData> GetConfigurationForSetup()
...@@ -61,53 +50,48 @@ namespace Jackett.Indexers ...@@ -61,53 +50,48 @@ namespace Jackett.Indexers
public async Task ApplyConfiguration(JToken configJson) public async Task ApplyConfiguration(JToken configJson)
{ {
var configSaveData = new JObject(); var incomingConfig = new ConfigurationDataBasicLogin();
SaveConfig(configSaveData); incomingConfig.LoadValuesFromJson(configJson);
var config = new ConfigurationDataBasicLogin();
config.LoadValuesFromJson(configJson);
var pairs = new Dictionary<string, string> { var pairs = new Dictionary<string, string> {
{ "username", config.Username.Value }, { "username", incomingConfig.Username.Value },
{ "password", @config.Password.Value }, { "password", incomingConfig.Password.Value },
{ "login", "Login" }, { "login", "Login" },
{ "keeplogged", "1" } { "keeplogged", "1" }
}; };
var content = new FormUrlEncodedContent(pairs); // Do the login
var message = CreateHttpRequest(new Uri(LoginUrl)); var response = await webclient.GetString(new Utils.Clients.WebRequest()
message.Content = content; {
PostData = pairs,
//message.Headers.Referrer = new Uri(LoginUrl); Referer = LoginUrl,
string responseContent; Type = RequestType.POST,
Url = LoginUrl
});
configSaveData = new JObject(); cookieHeader = response.Cookies;
if (Engine.IsWindows) if (response.Status == HttpStatusCode.Found || response.Status == HttpStatusCode.Redirect || response.Status == HttpStatusCode.RedirectMethod)
{ {
// If Windows use .net http response = await webclient.GetString(new Utils.Clients.WebRequest()
var response = await client.SendAsync(message);
responseContent = await response.Content.ReadAsStringAsync();
cookies.DumpToJson(SiteLink, configSaveData);
}
else
{ {
// If UNIX system use curl, probably broken due to missing chromeUseragent record for CURL...cannot test Url = SiteLink.ToString(),
var response = await CurlHelper.PostAsync(LoginUrl, pairs); Referer = LoginUrl.ToString(),
responseContent = Encoding.UTF8.GetString(response.Content); Cookies = cookieHeader
cookieHeader = response.CookieHeader; });
configSaveData["cookie_header"] = cookieHeader;
} }
if (!responseContent.Contains("logout.php?")) if (!response.Content.Contains("logout.php?"))
{ {
CQ dom = responseContent; CQ dom = response.Content;
dom["#loginform > table"].Remove(); dom["#loginform > table"].Remove();
var errorMessage = dom["#loginform"].Text().Trim().Replace("\n\t", " "); var errorMessage = dom["#loginform"].Text().Trim().Replace("\n\t", " ");
throw new ExceptionWithConfigData(errorMessage, (ConfigurationData)config); throw new ExceptionWithConfigData(errorMessage, (ConfigurationData)incomingConfig);
} }
else else
{ {
var configSaveData = new JObject();
configSaveData["cookie_header"] = cookieHeader;
SaveConfig(configSaveData); SaveConfig(configSaveData);
IsConfigured = true; IsConfigured = true;
} }
...@@ -124,10 +108,12 @@ namespace Jackett.Indexers ...@@ -124,10 +108,12 @@ namespace Jackett.Indexers
public void LoadFromSavedConfiguration(JToken jsonConfig) public void LoadFromSavedConfiguration(JToken jsonConfig)
{ {
cookies.FillFromJson(SiteLink, jsonConfig, logger); cookieHeader = (string)jsonConfig["cookie_header"];
cookieHeader = cookies.GetCookieHeader(SiteLink); if (!string.IsNullOrEmpty(cookieHeader))
{
IsConfigured = true; IsConfigured = true;
} }
}
void FillReleaseInfoFromJson(ReleaseInfo release, JObject r) void FillReleaseInfoFromJson(ReleaseInfo release, JObject r)
{ {
...@@ -146,23 +132,18 @@ namespace Jackett.Indexers ...@@ -146,23 +132,18 @@ namespace Jackett.Indexers
var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString(); var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString();
var episodeSearchUrl = SearchUrl + HttpUtility.UrlEncode(searchString); var episodeSearchUrl = SearchUrl + HttpUtility.UrlEncode(searchString);
string results; var results = await webclient.GetString(new Utils.Clients.WebRequest()
if (Engine.IsWindows)
{
var request = CreateHttpRequest(new Uri(episodeSearchUrl));
request.Method = HttpMethod.Get;
var response = await client.SendAsync(request);
results = await response.Content.ReadAsStringAsync();
}
else
{ {
var response = await CurlHelper.GetAsync(episodeSearchUrl, cookieHeader); Cookies = cookieHeader,
results = Encoding.UTF8.GetString(response.Content); Type = RequestType.GET,
} Url = episodeSearchUrl
});
try try
{ {
var json = JObject.Parse(results); var json = JObject.Parse(results.Content);
foreach (JObject r in json["response"]["results"]) foreach (JObject r in json["response"]["results"])
{ {
DateTime pubDate = DateTime.MinValue; DateTime pubDate = DateTime.MinValue;
...@@ -198,7 +179,7 @@ namespace Jackett.Indexers ...@@ -198,7 +179,7 @@ namespace Jackett.Indexers
} }
catch (Exception ex) catch (Exception ex)
{ {
OnParseError(results, ex); OnParseError(results.Content, ex);
} }
return releases.ToArray(); return releases.ToArray();
...@@ -213,16 +194,13 @@ namespace Jackett.Indexers ...@@ -213,16 +194,13 @@ namespace Jackett.Indexers
public async Task<byte[]> Download(Uri link) public async Task<byte[]> Download(Uri link)
{ {
if (Engine.IsWindows) var response = await webclient.GetBytes(new Utils.Clients.WebRequest()
{
return await client.GetByteArrayAsync(link);
}
else
{ {
var response = await CurlHelper.GetAsync(link.ToString(), cookieHeader); Url = link.ToString(),
return response.Content; Cookies = cookieHeader
} });
return response.Content;
} }
} }
......
...@@ -86,6 +86,7 @@ namespace Jackett.Indexers ...@@ -86,6 +86,7 @@ namespace Jackett.Indexers
else else
{ {
var configSaveData = new JObject(); var configSaveData = new JObject();
configSaveData["cookie_header"] = cookieHeader;
SaveConfig(configSaveData); SaveConfig(configSaveData);
IsConfigured = true; IsConfigured = true;
} }
......
...@@ -24,17 +24,14 @@ namespace Jackett ...@@ -24,17 +24,14 @@ namespace Jackett
if (Startup.CurlSafe) if (Startup.CurlSafe)
{ {
builder.RegisterType<UnixSafeCurlWebClient>().As<IWebClient>(); builder.RegisterType<UnixSafeCurlWebClient>().As<IWebClient>();
Console.WriteLine("Using UnixSafeCurlWebClient");
} }
else if(System.Environment.OSVersion.Platform == PlatformID.Unix) else if(System.Environment.OSVersion.Platform == PlatformID.Unix)
{ {
builder.RegisterType<UnixLibCurlWebClient>().As<IWebClient>(); builder.RegisterType<UnixLibCurlWebClient>().As<IWebClient>();
Console.WriteLine("Using UnixLibCurlWebClient");
} }
else else
{ {
builder.RegisterType<WindowsWebClient>().As<IWebClient>(); builder.RegisterType<WindowsWebClient>().As<IWebClient>();
Console.WriteLine("Using WindowsWebClient");
} }
// Register indexers // Register indexers
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment