removed dead code
This commit is contained in:
parent
402e80dac3
commit
6e25c572fa
|
@ -7,12 +7,12 @@ using MediaBrowser.Model.Entities;
|
||||||
using MediaBrowser.Model.Plugins;
|
using MediaBrowser.Model.Plugins;
|
||||||
using MediaBrowser.Model.Serialization;
|
using MediaBrowser.Model.Serialization;
|
||||||
using ServiceStack;
|
using ServiceStack;
|
||||||
|
using ServiceStack.Text.Controller;
|
||||||
|
using ServiceStack.Web;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using ServiceStack.Text.Controller;
|
|
||||||
using ServiceStack.Web;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Api
|
namespace MediaBrowser.Api
|
||||||
{
|
{
|
||||||
|
@ -190,8 +190,7 @@ namespace MediaBrowser.Api
|
||||||
var result = new PluginSecurityInfo
|
var result = new PluginSecurityInfo
|
||||||
{
|
{
|
||||||
IsMBSupporter = _securityManager.IsMBSupporter,
|
IsMBSupporter = _securityManager.IsMBSupporter,
|
||||||
SupporterKey = _securityManager.SupporterKey,
|
SupporterKey = _securityManager.SupporterKey
|
||||||
LegacyKey = _securityManager.LegacyKey
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return ToOptimizedSerializedResultUsingCache(result);
|
return ToOptimizedSerializedResultUsingCache(result);
|
||||||
|
@ -206,7 +205,6 @@ namespace MediaBrowser.Api
|
||||||
var info = request;
|
var info = request;
|
||||||
|
|
||||||
_securityManager.SupporterKey = info.SupporterKey;
|
_securityManager.SupporterKey = info.SupporterKey;
|
||||||
_securityManager.LegacyKey = info.LegacyKey;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -99,7 +99,6 @@
|
||||||
<Compile Include="ScheduledTasks\Tasks\ReloadLoggerFileTask.cs" />
|
<Compile Include="ScheduledTasks\Tasks\ReloadLoggerFileTask.cs" />
|
||||||
<Compile Include="ScheduledTasks\Tasks\SystemUpdateTask.cs" />
|
<Compile Include="ScheduledTasks\Tasks\SystemUpdateTask.cs" />
|
||||||
<Compile Include="Security\MBLicenseFile.cs" />
|
<Compile Include="Security\MBLicenseFile.cs" />
|
||||||
<Compile Include="Security\MBRegistration.cs" />
|
|
||||||
<Compile Include="Security\PluginSecurityManager.cs" />
|
<Compile Include="Security\PluginSecurityManager.cs" />
|
||||||
<Compile Include="Security\RegRecord.cs" />
|
<Compile Include="Security\RegRecord.cs" />
|
||||||
<Compile Include="Serialization\JsonSerializer.cs" />
|
<Compile Include="Serialization\JsonSerializer.cs" />
|
||||||
|
|
|
@ -1,99 +0,0 @@
|
||||||
using MediaBrowser.Common.Configuration;
|
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Model.Entities;
|
|
||||||
using MediaBrowser.Model.Logging;
|
|
||||||
using MediaBrowser.Model.Serialization;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Common.Implementations.Security
|
|
||||||
{
|
|
||||||
public static class MBRegistration
|
|
||||||
{
|
|
||||||
|
|
||||||
private static MBLicenseFile _licenseFile;
|
|
||||||
private const string MBValidateUrl = Constants.Constants.MbAdminUrl + "service/registration/validate";
|
|
||||||
|
|
||||||
private static IApplicationPaths _appPaths;
|
|
||||||
private static INetworkManager _networkManager;
|
|
||||||
private static ILogger _logger;
|
|
||||||
private static IApplicationHost _applicationHost;
|
|
||||||
|
|
||||||
private static MBLicenseFile LicenseFile
|
|
||||||
{
|
|
||||||
get { return _licenseFile ?? (_licenseFile = new MBLicenseFile(_appPaths)); }
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string SupporterKey
|
|
||||||
{
|
|
||||||
get { return LicenseFile.RegKey; }
|
|
||||||
set { LicenseFile.RegKey = value; LicenseFile.Save(); }
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string LegacyKey
|
|
||||||
{
|
|
||||||
get { return LicenseFile.LegacyKey; }
|
|
||||||
set { LicenseFile.LegacyKey = value; LicenseFile.Save(); }
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Init(IApplicationPaths appPaths, INetworkManager networkManager, ILogManager logManager, IApplicationHost appHost)
|
|
||||||
{
|
|
||||||
// Ugly alert (static init)
|
|
||||||
|
|
||||||
_appPaths = appPaths;
|
|
||||||
_networkManager = networkManager;
|
|
||||||
_logger = logManager.GetLogger("SecurityManager");
|
|
||||||
_applicationHost = appHost;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async Task<MBRegistrationRecord> GetRegistrationStatus(IHttpClient httpClient, IJsonSerializer jsonSerializer, string feature, string mb2Equivalent = null, string version = null)
|
|
||||||
{
|
|
||||||
//check the reg file first to alleviate strain on the MB admin server - must actually check in every 30 days tho
|
|
||||||
var reg = new RegRecord { registered = LicenseFile.LastChecked(feature) > DateTime.UtcNow.AddDays(-30) };
|
|
||||||
var success = reg.registered;
|
|
||||||
|
|
||||||
if (!reg.registered)
|
|
||||||
{
|
|
||||||
var mac = _networkManager.GetMacAddress();
|
|
||||||
var data = new Dictionary<string, string>
|
|
||||||
{
|
|
||||||
{ "feature", feature },
|
|
||||||
{ "key", SupporterKey },
|
|
||||||
{ "mac", mac },
|
|
||||||
{ "mb2equiv", mb2Equivalent },
|
|
||||||
{ "legacykey", LegacyKey },
|
|
||||||
{ "ver", version },
|
|
||||||
{ "platform", Environment.OSVersion.VersionString },
|
|
||||||
{ "isservice", _applicationHost.IsRunningAsService.ToString().ToLower() }
|
|
||||||
};
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (var json = await httpClient.Post(MBValidateUrl, data, CancellationToken.None).ConfigureAwait(false))
|
|
||||||
{
|
|
||||||
reg = jsonSerializer.DeserializeFromStream<RegRecord>(json);
|
|
||||||
success = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (reg.registered)
|
|
||||||
{
|
|
||||||
LicenseFile.AddRegCheck(feature);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LicenseFile.RemoveRegCheck(feature);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
_logger.ErrorException("Error checking registration status of {0}", e, feature);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new MBRegistrationRecord { IsRegistered = reg.registered, ExpirationDate = reg.expDate, RegChecked = true, RegError = !success};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -17,6 +17,8 @@ namespace MediaBrowser.Common.Implementations.Security
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class PluginSecurityManager : ISecurityManager
|
public class PluginSecurityManager : ISecurityManager
|
||||||
{
|
{
|
||||||
|
private const string MBValidateUrl = Constants.Constants.MbAdminUrl + "service/registration/validate";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The _is MB supporter
|
/// The _is MB supporter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -38,16 +40,23 @@ namespace MediaBrowser.Common.Implementations.Security
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
LazyInitializer.EnsureInitialized(ref _isMbSupporter, ref _isMbSupporterInitialized, ref _isMbSupporterSyncLock, () => GetRegistrationStatus("MBSupporter", null, _appHost.ApplicationVersion.ToString()).Result.IsRegistered);
|
LazyInitializer.EnsureInitialized(ref _isMbSupporter, ref _isMbSupporterInitialized, ref _isMbSupporterSyncLock, () => GetSupporterRegistrationStatus().Result.IsRegistered);
|
||||||
return _isMbSupporter.Value;
|
return _isMbSupporter.Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private MBLicenseFile _licenseFile;
|
||||||
|
private MBLicenseFile LicenseFile
|
||||||
|
{
|
||||||
|
get { return _licenseFile ?? (_licenseFile = new MBLicenseFile(_appPaths)); }
|
||||||
|
}
|
||||||
|
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClient _httpClient;
|
||||||
private readonly IJsonSerializer _jsonSerializer;
|
private readonly IJsonSerializer _jsonSerializer;
|
||||||
private readonly IApplicationHost _appHost;
|
private readonly IApplicationHost _appHost;
|
||||||
private readonly IApplicationPaths _applciationPaths;
|
private readonly ILogger _logger;
|
||||||
private readonly INetworkManager _networkManager;
|
private readonly INetworkManager _networkManager;
|
||||||
|
private readonly IApplicationPaths _appPaths;
|
||||||
|
|
||||||
private IEnumerable<IRequiresRegistration> _registeredEntities;
|
private IEnumerable<IRequiresRegistration> _registeredEntities;
|
||||||
protected IEnumerable<IRequiresRegistration> RegisteredEntities
|
protected IEnumerable<IRequiresRegistration> RegisteredEntities
|
||||||
|
@ -69,12 +78,12 @@ namespace MediaBrowser.Common.Implementations.Security
|
||||||
throw new ArgumentNullException("httpClient");
|
throw new ArgumentNullException("httpClient");
|
||||||
}
|
}
|
||||||
|
|
||||||
_applciationPaths = appPaths;
|
|
||||||
_networkManager = networkManager;
|
|
||||||
_appHost = appHost;
|
_appHost = appHost;
|
||||||
_httpClient = httpClient;
|
_httpClient = httpClient;
|
||||||
_jsonSerializer = jsonSerializer;
|
_jsonSerializer = jsonSerializer;
|
||||||
MBRegistration.Init(_applciationPaths, _networkManager, logManager, _appHost);
|
_networkManager = networkManager;
|
||||||
|
_appPaths = appPaths;
|
||||||
|
_logger = logManager.GetLogger("SecurityManager");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -97,9 +106,9 @@ namespace MediaBrowser.Common.Implementations.Security
|
||||||
/// <param name="feature">The feature.</param>
|
/// <param name="feature">The feature.</param>
|
||||||
/// <param name="mb2Equivalent">The MB2 equivalent.</param>
|
/// <param name="mb2Equivalent">The MB2 equivalent.</param>
|
||||||
/// <returns>Task{MBRegistrationRecord}.</returns>
|
/// <returns>Task{MBRegistrationRecord}.</returns>
|
||||||
public async Task<MBRegistrationRecord> GetRegistrationStatus(string feature, string mb2Equivalent = null)
|
public Task<MBRegistrationRecord> GetRegistrationStatus(string feature, string mb2Equivalent = null)
|
||||||
{
|
{
|
||||||
return await MBRegistration.GetRegistrationStatus(_httpClient, _jsonSerializer, feature, mb2Equivalent).ConfigureAwait(false);
|
return GetRegistrationStatusInternal(feature, mb2Equivalent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -109,9 +118,14 @@ namespace MediaBrowser.Common.Implementations.Security
|
||||||
/// <param name="mb2Equivalent">The MB2 equivalent.</param>
|
/// <param name="mb2Equivalent">The MB2 equivalent.</param>
|
||||||
/// <param name="version">The version of this feature</param>
|
/// <param name="version">The version of this feature</param>
|
||||||
/// <returns>Task{MBRegistrationRecord}.</returns>
|
/// <returns>Task{MBRegistrationRecord}.</returns>
|
||||||
public async Task<MBRegistrationRecord> GetRegistrationStatus(string feature, string mb2Equivalent, string version)
|
public Task<MBRegistrationRecord> GetRegistrationStatus(string feature, string mb2Equivalent, string version)
|
||||||
{
|
{
|
||||||
return await MBRegistration.GetRegistrationStatus(_httpClient, _jsonSerializer, feature, mb2Equivalent, version).ConfigureAwait(false);
|
return GetRegistrationStatusInternal(feature, mb2Equivalent, version);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<MBRegistrationRecord> GetSupporterRegistrationStatus()
|
||||||
|
{
|
||||||
|
return GetRegistrationStatusInternal("MBSupporter", null, _appHost.ApplicationVersion.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -122,38 +136,78 @@ namespace MediaBrowser.Common.Implementations.Security
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return MBRegistration.SupporterKey;
|
return LicenseFile.RegKey;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value != MBRegistration.SupporterKey)
|
if (value != LicenseFile.RegKey)
|
||||||
{
|
{
|
||||||
MBRegistration.SupporterKey = value;
|
LicenseFile.RegKey = value;
|
||||||
|
LicenseFile.Save();
|
||||||
|
|
||||||
// re-load registration info
|
// re-load registration info
|
||||||
Task.Run(() => LoadAllRegistrationInfo());
|
Task.Run(() => LoadAllRegistrationInfo());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
private async Task<MBRegistrationRecord> GetRegistrationStatusInternal(string feature,
|
||||||
/// Gets or sets the legacy key.
|
string mb2Equivalent = null,
|
||||||
/// </summary>
|
string version = null)
|
||||||
/// <value>The legacy key.</value>
|
|
||||||
public string LegacyKey
|
|
||||||
{
|
{
|
||||||
get
|
//check the reg file first to alleviate strain on the MB admin server - must actually check in every 30 days tho
|
||||||
|
var reg = new RegRecord
|
||||||
{
|
{
|
||||||
return MBRegistration.LegacyKey;
|
registered = LicenseFile.LastChecked(feature) > DateTime.UtcNow.AddDays(-15)
|
||||||
|
};
|
||||||
|
|
||||||
|
var success = reg.registered;
|
||||||
|
|
||||||
|
if (!reg.registered)
|
||||||
|
{
|
||||||
|
var mac = _networkManager.GetMacAddress();
|
||||||
|
var data = new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "feature", feature },
|
||||||
|
{ "key", SupporterKey },
|
||||||
|
{ "mac", mac },
|
||||||
|
{ "mb2equiv", mb2Equivalent },
|
||||||
|
{ "ver", version },
|
||||||
|
{ "platform", Environment.OSVersion.VersionString },
|
||||||
|
{ "isservice", _appHost.IsRunningAsService.ToString().ToLower() }
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var json = await _httpClient.Post(MBValidateUrl, data, CancellationToken.None).ConfigureAwait(false))
|
||||||
|
{
|
||||||
|
reg = _jsonSerializer.DeserializeFromStream<RegRecord>(json);
|
||||||
|
success = true;
|
||||||
}
|
}
|
||||||
set
|
|
||||||
|
if (reg.registered)
|
||||||
{
|
{
|
||||||
if (value != MBRegistration.LegacyKey)
|
LicenseFile.AddRegCheck(feature);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
MBRegistration.LegacyKey = value;
|
LicenseFile.RemoveRegCheck(feature);
|
||||||
// re-load registration info
|
}
|
||||||
Task.Run(() => LoadAllRegistrationInfo());
|
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.ErrorException("Error checking registration status of {0}", e, feature);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new MBRegistrationRecord
|
||||||
|
{
|
||||||
|
IsRegistered = reg.registered,
|
||||||
|
ExpirationDate = reg.expDate,
|
||||||
|
RegChecked = true,
|
||||||
|
RegError = !success
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
using System.Threading.Tasks;
|
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace MediaBrowser.Common.Security
|
namespace MediaBrowser.Common.Security
|
||||||
{
|
{
|
||||||
|
@ -17,18 +17,11 @@ namespace MediaBrowser.Common.Security
|
||||||
/// <value>The supporter key.</value>
|
/// <value>The supporter key.</value>
|
||||||
string SupporterKey { get; set; }
|
string SupporterKey { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the legacy key.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The legacy key.</value>
|
|
||||||
string LegacyKey { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the registration status. Overload to support existing plug-ins.
|
/// Gets the registration status. Overload to support existing plug-ins.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="feature">The feature.</param>
|
/// <param name="feature">The feature.</param>
|
||||||
/// <param name="mb2Equivalent">The MB2 equivalent.</param>
|
/// <param name="mb2Equivalent">The MB2 equivalent.</param>
|
||||||
/// <param name="version">The version of the feature</param>
|
|
||||||
/// <returns>Task{MBRegistrationRecord}.</returns>
|
/// <returns>Task{MBRegistrationRecord}.</returns>
|
||||||
Task<MBRegistrationRecord> GetRegistrationStatus(string feature, string mb2Equivalent = null);
|
Task<MBRegistrationRecord> GetRegistrationStatus(string feature, string mb2Equivalent = null);
|
||||||
|
|
||||||
|
@ -40,6 +33,7 @@ namespace MediaBrowser.Common.Security
|
||||||
/// <param name="version">The version of the feature</param>
|
/// <param name="version">The version of the feature</param>
|
||||||
/// <returns>Task{MBRegistrationRecord}.</returns>
|
/// <returns>Task{MBRegistrationRecord}.</returns>
|
||||||
Task<MBRegistrationRecord> GetRegistrationStatus(string feature, string mb2Equivalent, string version);
|
Task<MBRegistrationRecord> GetRegistrationStatus(string feature, string mb2Equivalent, string version);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Load all registration info for all entities that require registration
|
/// Load all registration info for all entities that require registration
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -12,12 +12,6 @@ namespace MediaBrowser.Model.Entities
|
||||||
/// <value>The supporter key.</value>
|
/// <value>The supporter key.</value>
|
||||||
public string SupporterKey { get; set; }
|
public string SupporterKey { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the legacy supporter key.
|
|
||||||
/// </summary>
|
|
||||||
/// <value><c>The legacy supporter key</value>
|
|
||||||
public string LegacyKey { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating whether this instance is MB supporter.
|
/// Gets or sets a value indicating whether this instance is MB supporter.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user