diff --git a/src/Jackett.Common/Indexers/BaseIndexer.cs b/src/Jackett.Common/Indexers/BaseIndexer.cs index c7d4f3cb9..195e0431f 100644 --- a/src/Jackett.Common/Indexers/BaseIndexer.cs +++ b/src/Jackett.Common/Indexers/BaseIndexer.cs @@ -13,6 +13,7 @@ using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; +using static Jackett.Common.Models.IndexerConfig.ConfigurationData; namespace Jackett.Common.Indexers { @@ -194,17 +195,31 @@ namespace Jackett.Common.Indexers LoadValuesFromJson(jsonConfig, false); - object passwordPropertyValue = null; + StringItem passwordPropertyValue = null; string passwordValue = ""; try { - passwordPropertyValue = configData.GetType().GetProperty("Password").GetValue(configData, null); - passwordValue = passwordPropertyValue.GetType().GetProperty("Value").GetValue(passwordPropertyValue, null).ToString(); + // try dynamic items first (e.g. all cardigann indexers) + passwordPropertyValue = (StringItem)configData.GetDynamicByName("password"); + + if (passwordPropertyValue == null) // if there's no dynamic password try the static property + { + passwordPropertyValue = (StringItem)configData.GetType().GetProperty("Password").GetValue(configData, null); + + // protection is based on the item.Name value (property name might be different, example: Abnormal), so check the Name again + if (!string.Equals(passwordPropertyValue.Name, "password", StringComparison.InvariantCultureIgnoreCase)) + { + logger.Debug($"Skipping non default password property (unencrpyted password) for [{ID}] while attempting migration"); + return false; + } + } + + passwordValue = passwordPropertyValue.Value; } catch (Exception) { - logger.Debug($"Unable to source password for [{ID}] while attempting migration, likely a public tracker"); + logger.Debug($"Unable to source password for [{ID}] while attempting migration, likely a tracker without a password setting"); return false; } @@ -230,7 +245,7 @@ namespace Jackett.Common.Indexers string unprotectedPassword = protectionService.LegacyUnProtect(passwordValue); //Password successfully unprotected using Windows/Mono DPAPI - passwordPropertyValue.GetType().GetProperty("Value").SetValue(passwordPropertyValue, unprotectedPassword); + passwordPropertyValue.Value = unprotectedPassword; SaveConfig(); IsConfigured = true; diff --git a/src/Jackett.Common/Models/IndexerConfig/ConfigurationData.cs b/src/Jackett.Common/Models/IndexerConfig/ConfigurationData.cs index 578b75862..f90319164 100644 --- a/src/Jackett.Common/Models/IndexerConfig/ConfigurationData.cs +++ b/src/Jackett.Common/Models/IndexerConfig/ConfigurationData.cs @@ -116,7 +116,7 @@ namespace Jackett.Common.Models.IndexerConfig case ItemType.HiddenData: case ItemType.DisplayInfo: var value = ((StringItem)item).Value; - if (string.Equals(item.Name, "password", StringComparison.InvariantCultureIgnoreCase)) + if (string.Equals(item.Name, "password", StringComparison.InvariantCultureIgnoreCase)) // if we chagne this logic we've to change the MigratedFromDPAPI() logic too, #2114 is realted { if (string.IsNullOrEmpty(value)) value = string.Empty; @@ -190,6 +190,11 @@ namespace Jackett.Common.Models.IndexerConfig } } + public Item GetDynamicByName(string Name) + { + return dynamics.Values.Where(i => string.Equals(i.Name, Name, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); + } + public class Item { public ItemType ItemType { get; set; }