mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 11:34:57 +02:00
Add version and platform to stats and don't hit server on every reg check
This commit is contained in:
parent
d0485685de
commit
b78cdae321
6 changed files with 52 additions and 40 deletions
|
@ -383,7 +383,7 @@ namespace MediaBrowser.Common.Implementations
|
||||||
NetworkManager = CreateNetworkManager();
|
NetworkManager = CreateNetworkManager();
|
||||||
RegisterSingleInstance(NetworkManager);
|
RegisterSingleInstance(NetworkManager);
|
||||||
|
|
||||||
SecurityManager = new PluginSecurityManager(this, HttpClient, JsonSerializer, ApplicationPaths, NetworkManager);
|
SecurityManager = new PluginSecurityManager(this, HttpClient, JsonSerializer, ApplicationPaths, NetworkManager, LogManager);
|
||||||
RegisterSingleInstance(SecurityManager);
|
RegisterSingleInstance(SecurityManager);
|
||||||
|
|
||||||
InstallationManager = new InstallationManager(Logger, this, ApplicationPaths, HttpClient, JsonSerializer, SecurityManager, NetworkManager, ConfigurationManager);
|
InstallationManager = new InstallationManager(Logger, this, ApplicationPaths, HttpClient, JsonSerializer, SecurityManager, NetworkManager, ConfigurationManager);
|
||||||
|
|
|
@ -92,6 +92,7 @@
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="ScheduledTasks\ScheduledTaskWorker.cs" />
|
<Compile Include="ScheduledTasks\ScheduledTaskWorker.cs" />
|
||||||
<Compile Include="ScheduledTasks\TaskManager.cs" />
|
<Compile Include="ScheduledTasks\TaskManager.cs" />
|
||||||
|
<Compile Include="ScheduledTasks\Tasks\StatisticsTask.cs" />
|
||||||
<Compile Include="ScheduledTasks\Tasks\DeleteCacheFileTask.cs" />
|
<Compile Include="ScheduledTasks\Tasks\DeleteCacheFileTask.cs" />
|
||||||
<Compile Include="ScheduledTasks\Tasks\DeleteLogFileTask.cs" />
|
<Compile Include="ScheduledTasks\Tasks\DeleteLogFileTask.cs" />
|
||||||
<Compile Include="ScheduledTasks\Tasks\PluginUpdateTask.cs" />
|
<Compile Include="ScheduledTasks\Tasks\PluginUpdateTask.cs" />
|
||||||
|
|
|
@ -56,6 +56,16 @@ namespace MediaBrowser.Common.Implementations.Security
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void RemoveRegCheck(string featureId)
|
||||||
|
{
|
||||||
|
using (var provider = new MD5CryptoServiceProvider())
|
||||||
|
{
|
||||||
|
UpdateRecords.Remove(new Guid(provider.ComputeHash(Encoding.Unicode.GetBytes(featureId))));
|
||||||
|
Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public DateTime LastChecked(string featureId)
|
public DateTime LastChecked(string featureId)
|
||||||
{
|
{
|
||||||
using (var provider = new MD5CryptoServiceProvider())
|
using (var provider = new MD5CryptoServiceProvider())
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using MediaBrowser.Common.Configuration;
|
using MediaBrowser.Common.Configuration;
|
||||||
using MediaBrowser.Common.Net;
|
using MediaBrowser.Common.Net;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
|
using MediaBrowser.Model.Logging;
|
||||||
using MediaBrowser.Model.Serialization;
|
using MediaBrowser.Model.Serialization;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
@ -13,10 +14,11 @@ namespace MediaBrowser.Common.Implementations.Security
|
||||||
{
|
{
|
||||||
|
|
||||||
private static MBLicenseFile _licenseFile;
|
private static MBLicenseFile _licenseFile;
|
||||||
private const string MBValidateUrl = "http://mb3admin.com/admin/service/registration/validate";
|
private const string MBValidateUrl = Constants.Constants.MbAdminUrl+"service/registration/validate";
|
||||||
|
|
||||||
private static IApplicationPaths _appPaths;
|
private static IApplicationPaths _appPaths;
|
||||||
private static INetworkManager _networkManager;
|
private static INetworkManager _networkManager;
|
||||||
|
private static ILogger _logger;
|
||||||
|
|
||||||
private static MBLicenseFile LicenseFile
|
private static MBLicenseFile LicenseFile
|
||||||
{
|
{
|
||||||
|
@ -35,20 +37,25 @@ namespace MediaBrowser.Common.Implementations.Security
|
||||||
set { LicenseFile.LegacyKey = value; LicenseFile.Save(); }
|
set { LicenseFile.LegacyKey = value; LicenseFile.Save(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Init(IApplicationPaths appPaths, INetworkManager networkManager)
|
public static void Init(IApplicationPaths appPaths, INetworkManager networkManager, ILogManager logManager)
|
||||||
{
|
{
|
||||||
// Ugly alert (static init)
|
// Ugly alert (static init)
|
||||||
|
|
||||||
_appPaths = appPaths;
|
_appPaths = appPaths;
|
||||||
_networkManager = networkManager;
|
_networkManager = networkManager;
|
||||||
|
_logger = logManager.GetLogger("SecurityManager");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<MBRegistrationRecord> GetRegistrationStatus(IHttpClient httpClient, IJsonSerializer jsonSerializer, string feature, string mb2Equivalent = null)
|
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)*/};
|
||||||
|
|
||||||
|
if (!reg.registered)
|
||||||
{
|
{
|
||||||
var mac = _networkManager.GetMacAddress();
|
var mac = _networkManager.GetMacAddress();
|
||||||
var data = new Dictionary<string, string> {{"feature", feature}, {"key",SupporterKey}, {"mac",mac}, {"mb2equiv",mb2Equivalent}, {"legacykey", LegacyKey} };
|
var data = new Dictionary<string, string> { { "feature", feature }, { "key", SupporterKey }, { "mac", mac }, { "mb2equiv", mb2Equivalent }, { "legacykey", LegacyKey }, { "ver", version }, { "platform", Environment.OSVersion.VersionString } };
|
||||||
|
|
||||||
var reg = new RegRecord();
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var json = await httpClient.Post(MBValidateUrl, data, CancellationToken.None).ConfigureAwait(false))
|
using (var json = await httpClient.Post(MBValidateUrl, data, CancellationToken.None).ConfigureAwait(false))
|
||||||
|
@ -60,12 +67,16 @@ namespace MediaBrowser.Common.Implementations.Security
|
||||||
{
|
{
|
||||||
LicenseFile.AddRegCheck(feature);
|
LicenseFile.AddRegCheck(feature);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LicenseFile.RemoveRegCheck(feature);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
//if we have trouble obtaining from web - allow it if we've validated in the past 30 days
|
_logger.ErrorException("Error checking registration status of {0}", e, feature);
|
||||||
reg.registered = LicenseFile.LastChecked(feature) > DateTime.UtcNow.AddDays(-30);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new MBRegistrationRecord {IsRegistered = reg.registered, ExpirationDate = reg.expDate, RegChecked = true};
|
return new MBRegistrationRecord {IsRegistered = reg.registered, ExpirationDate = reg.expDate, RegChecked = true};
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
using MediaBrowser.Common.Net;
|
using MediaBrowser.Common.Net;
|
||||||
using MediaBrowser.Common.Security;
|
using MediaBrowser.Common.Security;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
|
using MediaBrowser.Model.Logging;
|
||||||
using MediaBrowser.Model.Serialization;
|
using MediaBrowser.Model.Serialization;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
@ -37,7 +38,7 @@ namespace MediaBrowser.Common.Implementations.Security
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
LazyInitializer.EnsureInitialized(ref _isMbSupporter, ref _isMbSupporterInitialized, ref _isMbSupporterSyncLock, () => GetRegistrationStatus("MBSupporter").Result.IsRegistered);
|
LazyInitializer.EnsureInitialized(ref _isMbSupporter, ref _isMbSupporterInitialized, ref _isMbSupporterSyncLock, () => GetRegistrationStatus("MBSupporter", null, _appHost.ApplicationVersion.ToString()).Result.IsRegistered);
|
||||||
return _isMbSupporter.Value;
|
return _isMbSupporter.Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +61,8 @@ namespace MediaBrowser.Common.Implementations.Security
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="PluginSecurityManager" /> class.
|
/// Initializes a new instance of the <see cref="PluginSecurityManager" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public PluginSecurityManager(IApplicationHost appHost, IHttpClient httpClient, IJsonSerializer jsonSerializer, IApplicationPaths appPaths, INetworkManager networkManager)
|
public PluginSecurityManager(IApplicationHost appHost, IHttpClient httpClient, IJsonSerializer jsonSerializer,
|
||||||
|
IApplicationPaths appPaths, INetworkManager networkManager, ILogManager logManager)
|
||||||
{
|
{
|
||||||
if (httpClient == null)
|
if (httpClient == null)
|
||||||
{
|
{
|
||||||
|
@ -72,6 +74,7 @@ namespace MediaBrowser.Common.Implementations.Security
|
||||||
_appHost = appHost;
|
_appHost = appHost;
|
||||||
_httpClient = httpClient;
|
_httpClient = httpClient;
|
||||||
_jsonSerializer = jsonSerializer;
|
_jsonSerializer = jsonSerializer;
|
||||||
|
MBRegistration.Init(_applciationPaths, _networkManager, logManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -92,13 +95,11 @@ namespace MediaBrowser.Common.Implementations.Security
|
||||||
/// </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 this feature</param>
|
||||||
/// <returns>Task{MBRegistrationRecord}.</returns>
|
/// <returns>Task{MBRegistrationRecord}.</returns>
|
||||||
public async Task<MBRegistrationRecord> GetRegistrationStatus(string feature, string mb2Equivalent = null)
|
public async Task<MBRegistrationRecord> GetRegistrationStatus(string feature, string mb2Equivalent = null, string version = null)
|
||||||
{
|
{
|
||||||
// Do this on demend instead of in the constructor to delay the external assembly load
|
return await MBRegistration.GetRegistrationStatus(_httpClient, _jsonSerializer, feature, mb2Equivalent, version).ConfigureAwait(false);
|
||||||
// Todo: Refactor external methods to take app paths as a param
|
|
||||||
MBRegistration.Init(_applciationPaths, _networkManager);
|
|
||||||
return await MBRegistration.GetRegistrationStatus(_httpClient, _jsonSerializer, feature, mb2Equivalent).ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -109,16 +110,10 @@ namespace MediaBrowser.Common.Implementations.Security
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
// Do this on demend instead of in the constructor to delay the external assembly load
|
|
||||||
// Todo: Refactor external methods to take app paths as a param
|
|
||||||
MBRegistration.Init(_applciationPaths, _networkManager);
|
|
||||||
return MBRegistration.SupporterKey;
|
return MBRegistration.SupporterKey;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
// Do this on demend instead of in the constructor to delay the external assembly load
|
|
||||||
// Todo: Refactor external methods to take app paths as a param
|
|
||||||
MBRegistration.Init(_applciationPaths, _networkManager);
|
|
||||||
if (value != MBRegistration.SupporterKey)
|
if (value != MBRegistration.SupporterKey)
|
||||||
{
|
{
|
||||||
MBRegistration.SupporterKey = value;
|
MBRegistration.SupporterKey = value;
|
||||||
|
@ -136,16 +131,10 @@ namespace MediaBrowser.Common.Implementations.Security
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
// Do this on demend instead of in the constructor to delay the external assembly load
|
|
||||||
// Todo: Refactor external methods to take app paths as a param
|
|
||||||
MBRegistration.Init(_applciationPaths, _networkManager);
|
|
||||||
return MBRegistration.LegacyKey;
|
return MBRegistration.LegacyKey;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
// Do this on demend instead of in the constructor to delay the external assembly load
|
|
||||||
// Todo: Refactor external methods to take app paths as a param
|
|
||||||
MBRegistration.Init(_applciationPaths, _networkManager);
|
|
||||||
if (value != MBRegistration.LegacyKey)
|
if (value != MBRegistration.LegacyKey)
|
||||||
{
|
{
|
||||||
MBRegistration.LegacyKey = value;
|
MBRegistration.LegacyKey = value;
|
||||||
|
|
|
@ -28,8 +28,9 @@ namespace MediaBrowser.Common.Security
|
||||||
/// </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, string version = null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Load all registration info for all entities that require registration
|
/// Load all registration info for all entities that require registration
|
||||||
|
|
Loading…
Reference in a new issue