From c92caf18c57d9461a8edb7a209630eed0cf01d91 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 19 Jul 2015 11:37:08 -0600 Subject: [PATCH 1/4] Fix indexer class lookup by string when name has non-alphanumeric chars --- src/Jackett/Indexers/Freshon.cs | 2 +- src/Jackett/Jackett.csproj | 1 + src/Jackett/Services/IndexerManagerService.cs | 3 ++- src/Jackett/Utils/StringUtil.cs | 20 +++++++++++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 src/Jackett/Utils/StringUtil.cs diff --git a/src/Jackett/Indexers/Freshon.cs b/src/Jackett/Indexers/Freshon.cs index 41522d2be..4b62bcff8 100644 --- a/src/Jackett/Indexers/Freshon.cs +++ b/src/Jackett/Indexers/Freshon.cs @@ -17,7 +17,7 @@ using System.Threading.Tasks; using System.Web; using System.Web.UI.WebControls; -namespace Jackett +namespace Jackett.Indexers { public class Freshon : BaseIndexer, IIndexer { diff --git a/src/Jackett/Jackett.csproj b/src/Jackett/Jackett.csproj index e83170226..18be84d2d 100644 --- a/src/Jackett/Jackett.csproj +++ b/src/Jackett/Jackett.csproj @@ -197,6 +197,7 @@ + diff --git a/src/Jackett/Services/IndexerManagerService.cs b/src/Jackett/Services/IndexerManagerService.cs index 55fd7b9aa..0f1aacb87 100644 --- a/src/Jackett/Services/IndexerManagerService.cs +++ b/src/Jackett/Services/IndexerManagerService.cs @@ -1,6 +1,7 @@ using Autofac; using Jackett.Indexers; using Jackett.Models; +using Jackett.Utils; using Newtonsoft.Json.Linq; using NLog; using System; @@ -52,7 +53,7 @@ namespace Jackett.Services public IIndexer GetIndexer(string name) { - var indexer = indexers.Values.Where(i => string.Equals(i.DisplayName, name, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); + var indexer = indexers.Values.Where(i => string.Equals(StringUtil.StripNonAlphaNumeric(i.DisplayName), name, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); if (indexer != null) { return indexer; diff --git a/src/Jackett/Utils/StringUtil.cs b/src/Jackett/Utils/StringUtil.cs new file mode 100644 index 000000000..c6fa12e55 --- /dev/null +++ b/src/Jackett/Utils/StringUtil.cs @@ -0,0 +1,20 @@ +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 StringUtil + { + public static string StripNonAlphaNumeric(string str) + { + Regex rgx = new Regex("[^a-zA-Z0-9 -]"); + str = rgx.Replace(str, ""); + return str; + } + + } +} From c39feb7997a88e7a34adfcc01dbc912521357e80 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 19 Jul 2015 12:25:47 -0600 Subject: [PATCH 2/4] Fixed TestIndexer async Task --- src/Jackett/Controllers/AdminController.cs | 10 +++++----- src/Jackett/Services/IndexerManagerService.cs | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Jackett/Controllers/AdminController.cs b/src/Jackett/Controllers/AdminController.cs index 2120bc504..254f855c7 100644 --- a/src/Jackett/Controllers/AdminController.cs +++ b/src/Jackett/Controllers/AdminController.cs @@ -20,7 +20,7 @@ namespace Jackett.Controllers private IIndexerManagerService indexerService; private IServerService serverService; - public AdminController(IConfigurationService config, IIndexerManagerService i, IServerService ss) + public AdminController(IConfigurationService config, IIndexerManagerService i, IServerService ss) { this.config = config; indexerService = i; @@ -67,7 +67,7 @@ namespace Jackett.Controllers var indexer = indexerService.GetIndexer((string)postData["indexer"]); jsonReply["name"] = indexer.DisplayName; await indexer.ApplyConfiguration(postData["config"]); - indexerService.TestIndexer((string)postData["indexer"]); + await indexerService.TestIndexer((string)postData["indexer"]); jsonReply["result"] = "success"; } catch (Exception ex) @@ -125,7 +125,7 @@ namespace Jackett.Controllers { var postData = await ReadPostDataJson(); string indexerString = (string)postData["indexer"]; - indexerService.TestIndexer(indexerString); + await indexerService.TestIndexer(indexerString); jsonReply["name"] = indexerService.GetIndexer(indexerString).DisplayName; jsonReply["result"] = "success"; } @@ -187,9 +187,9 @@ namespace Jackett.Controllers try { var postData = await ReadPostDataJson(); - // int port = await WebServer.ApplyPortConfiguration(postData); + // int port = await WebServer.ApplyPortConfiguration(postData); jsonReply["result"] = "success"; - // jsonReply["port"] = port; + // jsonReply["port"] = port; } catch (Exception ex) { diff --git a/src/Jackett/Services/IndexerManagerService.cs b/src/Jackett/Services/IndexerManagerService.cs index 0f1aacb87..1a358073a 100644 --- a/src/Jackett/Services/IndexerManagerService.cs +++ b/src/Jackett/Services/IndexerManagerService.cs @@ -15,7 +15,7 @@ namespace Jackett.Services { public interface IIndexerManagerService { - void TestIndexer(string name); + Task TestIndexer(string name); void DeleteIndexer(string name); IIndexer GetIndexer(string name); IEnumerable GetAllIndexers(); @@ -70,7 +70,7 @@ namespace Jackett.Services return indexers.Values; } - public async void TestIndexer(string name) + public async Task TestIndexer(string name) { var indexer = GetIndexer(name); var browseQuery = new TorznabQuery(); From 195ec0a94cb83a503d8d70fe94e4482eef32c5bf Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 19 Jul 2015 13:28:08 -0600 Subject: [PATCH 3/4] Indexer ID rather than class name --- src/Jackett/Controllers/AdminController.cs | 2 +- src/Jackett/Indexers/BaseIndexer.cs | 2 ++ src/Jackett/Indexers/IIndexer.cs | 2 ++ src/Jackett/Services/IndexerManagerService.cs | 4 ++-- src/Jackett/Utils/StringUtil.cs | 5 +++++ 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Jackett/Controllers/AdminController.cs b/src/Jackett/Controllers/AdminController.cs index 254f855c7..b0097fbdf 100644 --- a/src/Jackett/Controllers/AdminController.cs +++ b/src/Jackett/Controllers/AdminController.cs @@ -99,7 +99,7 @@ namespace Jackett.Controllers foreach (var indexer in indexerService.GetAllIndexers()) { var item = new JObject(); - item["id"] = indexer.GetType().Name; + item["id"] = indexer.ID; item["name"] = indexer.DisplayName; item["description"] = indexer.DisplayDescription; item["configured"] = indexer.IsConfigured; diff --git a/src/Jackett/Indexers/BaseIndexer.cs b/src/Jackett/Indexers/BaseIndexer.cs index 106633a91..0e7e4170a 100644 --- a/src/Jackett/Indexers/BaseIndexer.cs +++ b/src/Jackett/Indexers/BaseIndexer.cs @@ -7,6 +7,7 @@ using Jackett.Models; using Newtonsoft.Json.Linq; using NLog; using Jackett.Services; +using Jackett.Utils; namespace Jackett.Indexers { @@ -14,6 +15,7 @@ namespace Jackett.Indexers { public string DisplayDescription { get; private set; } public string DisplayName { get; private set; } + public string ID { get { return StringUtil.StripNonAlphaNumeric(GetType().Name.ToLowerInvariant()); } } public bool IsConfigured { get; protected set; } public Uri SiteLink { get; private set; } public bool RequiresRageIDLookupDisabled { get; private set; } diff --git a/src/Jackett/Indexers/IIndexer.cs b/src/Jackett/Indexers/IIndexer.cs index ab5e1840a..ea2844b3e 100644 --- a/src/Jackett/Indexers/IIndexer.cs +++ b/src/Jackett/Indexers/IIndexer.cs @@ -13,6 +13,8 @@ namespace Jackett.Indexers { string DisplayName { get; } string DisplayDescription { get; } + string ID { get; } + Uri SiteLink { get; } bool RequiresRageIDLookupDisabled { get; } diff --git a/src/Jackett/Services/IndexerManagerService.cs b/src/Jackett/Services/IndexerManagerService.cs index 1a358073a..8f2f8ff74 100644 --- a/src/Jackett/Services/IndexerManagerService.cs +++ b/src/Jackett/Services/IndexerManagerService.cs @@ -41,7 +41,7 @@ namespace Jackett.Services { foreach (var idx in container.Resolve>().OrderBy(_ => _.DisplayName)) { - indexers.Add(idx.DisplayName, idx); + indexers.Add(idx.ID, idx); var configFilePath = GetIndexerConfigFilePath(idx); if (File.Exists(configFilePath)) { @@ -90,7 +90,7 @@ namespace Jackett.Services private string GetIndexerConfigFilePath(IIndexer indexer) { - return Path.Combine(configService.GetIndexerConfigDir(), indexer.GetType().Name.ToLower() + ".json"); + return Path.Combine(configService.GetIndexerConfigDir(), indexer.ID + ".json"); } public void SaveConfig(IIndexer indexer, JToken obj) diff --git a/src/Jackett/Utils/StringUtil.cs b/src/Jackett/Utils/StringUtil.cs index c6fa12e55..6a40ca5f9 100644 --- a/src/Jackett/Utils/StringUtil.cs +++ b/src/Jackett/Utils/StringUtil.cs @@ -16,5 +16,10 @@ namespace Jackett.Utils return str; } + public static string FromBase64(string str) + { + return Encoding.UTF8.GetString(Convert.FromBase64String(str)); + } + } } From 63ba324281eeaafbc0be061f782e5a6ca1438b46 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 19 Jul 2015 13:38:41 -0600 Subject: [PATCH 4/4] Fixed indexer register by name --- src/Jackett/Indexers/BaseIndexer.cs | 6 +++++- src/Jackett/JackettModule.cs | 10 +++++----- src/Jackett/Services/IndexerManagerService.cs | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Jackett/Indexers/BaseIndexer.cs b/src/Jackett/Indexers/BaseIndexer.cs index 0e7e4170a..25a5874fe 100644 --- a/src/Jackett/Indexers/BaseIndexer.cs +++ b/src/Jackett/Indexers/BaseIndexer.cs @@ -15,7 +15,7 @@ namespace Jackett.Indexers { public string DisplayDescription { get; private set; } public string DisplayName { get; private set; } - public string ID { get { return StringUtil.StripNonAlphaNumeric(GetType().Name.ToLowerInvariant()); } } + public string ID { get { return GetIndexerID(GetType()); } } public bool IsConfigured { get; protected set; } public Uri SiteLink { get; private set; } public bool RequiresRageIDLookupDisabled { get; private set; } @@ -26,6 +26,10 @@ namespace Jackett.Indexers protected static List cache = new List(); protected static readonly TimeSpan cacheTime = new TimeSpan(0, 9, 0); + public static string GetIndexerID(Type type) + { + return StringUtil.StripNonAlphaNumeric(type.Name.ToLowerInvariant()); + } public BaseIndexer(string name, string description, bool rageid, Uri link, IIndexerManagerService manager, Logger logger) { diff --git a/src/Jackett/JackettModule.cs b/src/Jackett/JackettModule.cs index 2b68ce122..e4b1c2daf 100644 --- a/src/Jackett/JackettModule.cs +++ b/src/Jackett/JackettModule.cs @@ -9,7 +9,7 @@ using Jackett.Indexers; namespace Jackett { - public class JackettModule: Module + public class JackettModule : Module { protected override void Load(ContainerBuilder builder) { @@ -19,11 +19,11 @@ namespace Jackett builder.RegisterApiControllers(thisAssembly).InstancePerRequest(); // Register indexers - foreach(var indexer in thisAssembly.GetTypes() - .Where(p => typeof(IIndexer).IsAssignableFrom(p) && !p.IsInterface) - .ToArray()) + foreach (var indexer in thisAssembly.GetTypes() + .Where(p => typeof(IIndexer).IsAssignableFrom(p) && !p.IsInterface) + .ToArray()) { - builder.RegisterType(indexer).Named(indexer.Name); + builder.RegisterType(indexer).Named(BaseIndexer.GetIndexerID(indexer)); } } } diff --git a/src/Jackett/Services/IndexerManagerService.cs b/src/Jackett/Services/IndexerManagerService.cs index 8f2f8ff74..b6491fa78 100644 --- a/src/Jackett/Services/IndexerManagerService.cs +++ b/src/Jackett/Services/IndexerManagerService.cs @@ -85,7 +85,7 @@ namespace Jackett.Services var indexer = GetIndexer(name); var configPath = GetIndexerConfigFilePath(indexer); File.Delete(configPath); - indexers[name] = container.ResolveNamed(name); + indexers[name] = container.ResolveNamed(indexer.ID); } private string GetIndexerConfigFilePath(IIndexer indexer)