fix migration logic

This commit is contained in:
kaso17
2018-06-26 17:47:19 +02:00
parent 28bbeec462
commit 6b44cc9b74
2 changed files with 26 additions and 6 deletions

View File

@@ -13,6 +13,7 @@ using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using static Jackett.Common.Models.IndexerConfig.ConfigurationData;
namespace Jackett.Common.Indexers namespace Jackett.Common.Indexers
{ {
@@ -194,17 +195,31 @@ namespace Jackett.Common.Indexers
LoadValuesFromJson(jsonConfig, false); LoadValuesFromJson(jsonConfig, false);
object passwordPropertyValue = null; StringItem passwordPropertyValue = null;
string passwordValue = ""; string passwordValue = "";
try try
{ {
passwordPropertyValue = configData.GetType().GetProperty("Password").GetValue(configData, null); // try dynamic items first (e.g. all cardigann indexers)
passwordValue = passwordPropertyValue.GetType().GetProperty("Value").GetValue(passwordPropertyValue, null).ToString(); 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) 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; return false;
} }
@@ -230,7 +245,7 @@ namespace Jackett.Common.Indexers
string unprotectedPassword = protectionService.LegacyUnProtect(passwordValue); string unprotectedPassword = protectionService.LegacyUnProtect(passwordValue);
//Password successfully unprotected using Windows/Mono DPAPI //Password successfully unprotected using Windows/Mono DPAPI
passwordPropertyValue.GetType().GetProperty("Value").SetValue(passwordPropertyValue, unprotectedPassword); passwordPropertyValue.Value = unprotectedPassword;
SaveConfig(); SaveConfig();
IsConfigured = true; IsConfigured = true;

View File

@@ -116,7 +116,7 @@ namespace Jackett.Common.Models.IndexerConfig
case ItemType.HiddenData: case ItemType.HiddenData:
case ItemType.DisplayInfo: case ItemType.DisplayInfo:
var value = ((StringItem)item).Value; 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)) if (string.IsNullOrEmpty(value))
value = string.Empty; 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 class Item
{ {
public ItemType ItemType { get; set; } public ItemType ItemType { get; set; }