removed a bunch of validation, security, registration, premiere, whatever bs

pull/702/head
Claus Vium 6 years ago committed by Bond-009
parent 8ea0c72070
commit eca3c099d9

@ -41,7 +41,6 @@ using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net; using MediaBrowser.Common.Net;
using MediaBrowser.Common.Plugins; using MediaBrowser.Common.Plugins;
using MediaBrowser.Model.Extensions; using MediaBrowser.Model.Extensions;
using MediaBrowser.Common.Security;
using MediaBrowser.Common.Updates; using MediaBrowser.Common.Updates;
using MediaBrowser.Controller; using MediaBrowser.Controller;
using MediaBrowser.Controller.Channels; using MediaBrowser.Controller.Channels;
@ -340,11 +339,6 @@ namespace Emby.Server.Implementations
/// </summary> /// </summary>
/// <value>The installation manager.</value> /// <value>The installation manager.</value>
protected IInstallationManager InstallationManager { get; private set; } protected IInstallationManager InstallationManager { get; private set; }
/// <summary>
/// Gets the security manager.
/// </summary>
/// <value>The security manager.</value>
protected ISecurityManager SecurityManager { get; private set; }
/// <summary> /// <summary>
/// Gets or sets the zip client. /// Gets or sets the zip client.
@ -804,10 +798,7 @@ namespace Emby.Server.Implementations
SocketFactory = new SocketFactory(LoggerFactory.CreateLogger("SocketFactory")); SocketFactory = new SocketFactory(LoggerFactory.CreateLogger("SocketFactory"));
RegisterSingleInstance(SocketFactory); RegisterSingleInstance(SocketFactory);
SecurityManager = new PluginSecurityManager(this, HttpClient, JsonSerializer, ApplicationPaths, LoggerFactory, FileSystemManager, CryptographyProvider); InstallationManager = new InstallationManager(LoggerFactory.CreateLogger("InstallationManager"), this, ApplicationPaths, HttpClient, JsonSerializer, ServerConfigurationManager, FileSystemManager, CryptographyProvider, PackageRuntime);
RegisterSingleInstance(SecurityManager);
InstallationManager = new InstallationManager(LoggerFactory.CreateLogger("InstallationManager"), this, ApplicationPaths, HttpClient, JsonSerializer, SecurityManager, ServerConfigurationManager, FileSystemManager, CryptographyProvider, PackageRuntime);
RegisterSingleInstance(InstallationManager); RegisterSingleInstance(InstallationManager);
ZipClient = new ZipClient(FileSystemManager); ZipClient = new ZipClient(FileSystemManager);
@ -922,7 +913,7 @@ namespace Emby.Server.Implementations
PlaylistManager = new PlaylistManager(LibraryManager, FileSystemManager, LibraryMonitor, LoggerFactory.CreateLogger("PlaylistManager"), UserManager, ProviderManager); PlaylistManager = new PlaylistManager(LibraryManager, FileSystemManager, LibraryMonitor, LoggerFactory.CreateLogger("PlaylistManager"), UserManager, ProviderManager);
RegisterSingleInstance<IPlaylistManager>(PlaylistManager); RegisterSingleInstance<IPlaylistManager>(PlaylistManager);
LiveTvManager = new LiveTvManager(this, HttpClient, ServerConfigurationManager, Logger, ItemRepository, ImageProcessor, UserDataManager, DtoService, UserManager, LibraryManager, TaskManager, LocalizationManager, JsonSerializer, ProviderManager, FileSystemManager, SecurityManager, () => ChannelManager); LiveTvManager = new LiveTvManager(this, HttpClient, ServerConfigurationManager, Logger, ItemRepository, ImageProcessor, UserDataManager, DtoService, UserManager, LibraryManager, TaskManager, LocalizationManager, JsonSerializer, ProviderManager, FileSystemManager, () => ChannelManager);
RegisterSingleInstance(LiveTvManager); RegisterSingleInstance(LiveTvManager);
UserViewManager = new UserViewManager(LibraryManager, LocalizationManager, UserManager, ChannelManager, LiveTvManager, ServerConfigurationManager); UserViewManager = new UserViewManager(LibraryManager, LocalizationManager, UserManager, ChannelManager, LiveTvManager, ServerConfigurationManager);

@ -13,7 +13,6 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Emby.Server.Implementations.Services; using Emby.Server.Implementations.Services;
using MediaBrowser.Common.Net; using MediaBrowser.Common.Net;
using MediaBrowser.Common.Security;
using MediaBrowser.Controller; using MediaBrowser.Controller;
using MediaBrowser.Model.Extensions; using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Serialization;
@ -85,7 +84,6 @@ namespace Emby.Server.Implementations.HttpServer
{typeof (FileNotFoundException), 404}, {typeof (FileNotFoundException), 404},
//{typeof (DirectoryNotFoundException), 404}, //{typeof (DirectoryNotFoundException), 404},
{typeof (SecurityException), 401}, {typeof (SecurityException), 401},
{typeof (PaymentRequiredException), 402},
{typeof (ArgumentException), 400} {typeof (ArgumentException), 400}
}; };

@ -1183,14 +1183,6 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
return; return;
} }
var registration = await _liveTvManager.GetRegistrationInfo("dvr").ConfigureAwait(false);
if (!registration.IsValid)
{
_logger.LogWarning("Emby Premiere required to use Emby DVR.");
OnTimerOutOfDate(timer);
return;
}
var activeRecordingInfo = new ActiveRecordingInfo var activeRecordingInfo = new ActiveRecordingInfo
{ {
CancellationTokenSource = new CancellationTokenSource(), CancellationTokenSource = new CancellationTokenSource(),
@ -2379,79 +2371,74 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
var allTimers = GetTimersForSeries(seriesTimer) var allTimers = GetTimersForSeries(seriesTimer)
.ToList(); .ToList();
var registration = await _liveTvManager.GetRegistrationInfo("seriesrecordings").ConfigureAwait(false);
var enabledTimersForSeries = new List<TimerInfo>(); var enabledTimersForSeries = new List<TimerInfo>();
foreach (var timer in allTimers)
if (registration.IsValid)
{ {
foreach (var timer in allTimers) var existingTimer = _timerProvider.GetTimer(timer.Id);
if (existingTimer == null)
{ {
var existingTimer = _timerProvider.GetTimer(timer.Id); existingTimer = string.IsNullOrWhiteSpace(timer.ProgramId)
? null
: _timerProvider.GetTimerByProgramId(timer.ProgramId);
}
if (existingTimer == null) if (existingTimer == null)
{
if (ShouldCancelTimerForSeriesTimer(seriesTimer, timer))
{
timer.Status = RecordingStatus.Cancelled;
}
else
{ {
existingTimer = string.IsNullOrWhiteSpace(timer.ProgramId) enabledTimersForSeries.Add(timer);
? null
: _timerProvider.GetTimerByProgramId(timer.ProgramId);
} }
_timerProvider.Add(timer);
if (existingTimer == null) if (TimerCreated != null)
{ {
TimerCreated(this, new GenericEventArgs<TimerInfo>(timer));
}
}
else
{
// Only update if not currently active - test both new timer and existing in case Id's are different
// Id's could be different if the timer was created manually prior to series timer creation
ActiveRecordingInfo activeRecordingInfo;
if (!_activeRecordings.TryGetValue(timer.Id, out activeRecordingInfo) && !_activeRecordings.TryGetValue(existingTimer.Id, out activeRecordingInfo))
{
UpdateExistingTimerWithNewMetadata(existingTimer, timer);
// Needed by ShouldCancelTimerForSeriesTimer
timer.IsManual = existingTimer.IsManual;
if (ShouldCancelTimerForSeriesTimer(seriesTimer, timer)) if (ShouldCancelTimerForSeriesTimer(seriesTimer, timer))
{ {
timer.Status = RecordingStatus.Cancelled; existingTimer.Status = RecordingStatus.Cancelled;
} }
else else if (!existingTimer.IsManual)
{ {
enabledTimersForSeries.Add(timer); existingTimer.Status = RecordingStatus.New;
} }
_timerProvider.Add(timer);
if (TimerCreated != null) if (existingTimer.Status != RecordingStatus.Cancelled)
{ {
TimerCreated(this, new GenericEventArgs<TimerInfo>(timer)); enabledTimersForSeries.Add(existingTimer);
} }
}
else if (updateTimerSettings)
{
// Only update if not currently active - test both new timer and existing in case Id's are different
// Id's could be different if the timer was created manually prior to series timer creation
ActiveRecordingInfo activeRecordingInfo;
if (!_activeRecordings.TryGetValue(timer.Id, out activeRecordingInfo) && !_activeRecordings.TryGetValue(existingTimer.Id, out activeRecordingInfo))
{ {
UpdateExistingTimerWithNewMetadata(existingTimer, timer); existingTimer.KeepUntil = seriesTimer.KeepUntil;
existingTimer.IsPostPaddingRequired = seriesTimer.IsPostPaddingRequired;
// Needed by ShouldCancelTimerForSeriesTimer existingTimer.IsPrePaddingRequired = seriesTimer.IsPrePaddingRequired;
timer.IsManual = existingTimer.IsManual; existingTimer.PostPaddingSeconds = seriesTimer.PostPaddingSeconds;
existingTimer.PrePaddingSeconds = seriesTimer.PrePaddingSeconds;
if (ShouldCancelTimerForSeriesTimer(seriesTimer, timer)) existingTimer.Priority = seriesTimer.Priority;
{
existingTimer.Status = RecordingStatus.Cancelled;
}
else if (!existingTimer.IsManual)
{
existingTimer.Status = RecordingStatus.New;
}
if (existingTimer.Status != RecordingStatus.Cancelled)
{
enabledTimersForSeries.Add(existingTimer);
}
if (updateTimerSettings)
{
existingTimer.KeepUntil = seriesTimer.KeepUntil;
existingTimer.IsPostPaddingRequired = seriesTimer.IsPostPaddingRequired;
existingTimer.IsPrePaddingRequired = seriesTimer.IsPrePaddingRequired;
existingTimer.PostPaddingSeconds = seriesTimer.PostPaddingSeconds;
existingTimer.PrePaddingSeconds = seriesTimer.PrePaddingSeconds;
existingTimer.Priority = seriesTimer.Priority;
}
existingTimer.SeriesTimerId = seriesTimer.Id;
_timerProvider.Update(existingTimer);
} }
existingTimer.SeriesTimerId = seriesTimer.Id;
_timerProvider.Update(existingTimer);
} }
} }
} }

@ -22,7 +22,6 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using MediaBrowser.Common.Security;
using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Model.Events; using MediaBrowser.Model.Events;
@ -51,7 +50,6 @@ namespace Emby.Server.Implementations.LiveTv
private readonly ITaskManager _taskManager; private readonly ITaskManager _taskManager;
private readonly IJsonSerializer _jsonSerializer; private readonly IJsonSerializer _jsonSerializer;
private readonly IProviderManager _providerManager; private readonly IProviderManager _providerManager;
private readonly ISecurityManager _security;
private readonly Func<IChannelManager> _channelManager; private readonly Func<IChannelManager> _channelManager;
private readonly IDtoService _dtoService; private readonly IDtoService _dtoService;
@ -78,7 +76,23 @@ namespace Emby.Server.Implementations.LiveTv
private IServerApplicationHost _appHost; private IServerApplicationHost _appHost;
private IHttpClient _httpClient; private IHttpClient _httpClient;
public LiveTvManager(IServerApplicationHost appHost, IHttpClient httpClient, IServerConfigurationManager config, ILogger logger, IItemRepository itemRepo, IImageProcessor imageProcessor, IUserDataManager userDataManager, IDtoService dtoService, IUserManager userManager, ILibraryManager libraryManager, ITaskManager taskManager, ILocalizationManager localization, IJsonSerializer jsonSerializer, IProviderManager providerManager, IFileSystem fileSystem, ISecurityManager security, Func<IChannelManager> channelManager) public LiveTvManager(
IServerApplicationHost appHost,
IHttpClient httpClient,
IServerConfigurationManager config,
ILogger logger,
IItemRepository itemRepo,
IImageProcessor imageProcessor,
IUserDataManager userDataManager,
IDtoService dtoService,
IUserManager userManager,
ILibraryManager libraryManager,
ITaskManager taskManager,
ILocalizationManager localization,
IJsonSerializer jsonSerializer,
IProviderManager providerManager,
IFileSystem fileSystem,
Func<IChannelManager> channelManager)
{ {
_appHost = appHost; _appHost = appHost;
_config = config; _config = config;
@ -91,7 +105,6 @@ namespace Emby.Server.Implementations.LiveTv
_jsonSerializer = jsonSerializer; _jsonSerializer = jsonSerializer;
_providerManager = providerManager; _providerManager = providerManager;
_fileSystem = fileSystem; _fileSystem = fileSystem;
_security = security;
_dtoService = dtoService; _dtoService = dtoService;
_userDataManager = userDataManager; _userDataManager = userDataManager;
_channelManager = channelManager; _channelManager = channelManager;
@ -2087,14 +2100,6 @@ namespace Emby.Server.Implementations.LiveTv
public async Task CreateSeriesTimer(SeriesTimerInfoDto timer, CancellationToken cancellationToken) public async Task CreateSeriesTimer(SeriesTimerInfoDto timer, CancellationToken cancellationToken)
{ {
var registration = await GetRegistrationInfo("seriesrecordings").ConfigureAwait(false);
if (!registration.IsValid)
{
_logger.LogInformation("Creating series recordings requires an active Emby Premiere subscription.");
return;
}
var service = GetService(timer.ServiceName); var service = GetService(timer.ServiceName);
var info = await _tvDtoService.GetSeriesTimerInfo(timer, true, this, cancellationToken).ConfigureAwait(false); var info = await _tvDtoService.GetSeriesTimerInfo(timer, true, this, cancellationToken).ConfigureAwait(false);
@ -2436,30 +2441,6 @@ namespace Emby.Server.Implementations.LiveTv
} }
} }
public Task<MBRegistrationRecord> GetRegistrationInfo(string feature)
{
if (string.Equals(feature, "seriesrecordings", StringComparison.OrdinalIgnoreCase))
{
feature = "embytvseriesrecordings";
}
if (string.Equals(feature, "dvr-l", StringComparison.OrdinalIgnoreCase))
{
var config = GetConfiguration();
if (config.TunerHosts.Length > 0 &&
config.ListingProviders.Count(i => (i.EnableAllTuners || i.EnabledTuners.Length > 0) && string.Equals(i.Type, SchedulesDirect.TypeName, StringComparison.OrdinalIgnoreCase)) > 0)
{
return Task.FromResult(new MBRegistrationRecord
{
IsRegistered = true,
IsValid = true
});
}
}
return _security.GetRegistrationStatus(feature);
}
public Task<List<ChannelInfo>> GetChannelsForListingsProvider(string id, CancellationToken cancellationToken) public Task<List<ChannelInfo>> GetChannelsForListingsProvider(string id, CancellationToken cancellationToken)
{ {
var info = GetConfiguration().ListingProviders.First(i => string.Equals(i.Id, id, StringComparison.OrdinalIgnoreCase)); var info = GetConfiguration().ListingProviders.First(i => string.Equals(i.Id, id, StringComparison.OrdinalIgnoreCase));

@ -1,212 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Security;
using MediaBrowser.Controller;
using MediaBrowser.Model.Cryptography;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.Serialization;
namespace Emby.Server.Implementations.Security
{
/// <summary>
/// Class PluginSecurityManager
/// </summary>
public class PluginSecurityManager : ISecurityManager
{
private const string MBValidateUrl = "https://mb3admin.local/admin/service/registration/validate";
private const string AppstoreRegUrl = /*MbAdmin.HttpsUrl*/ "https://mb3admin.local/admin/service/appstore/register";
public async Task<bool> IsSupporter()
{
var result = await GetRegistrationStatusInternal("MBSupporter", false, _appHost.ApplicationVersion.ToString(), CancellationToken.None).ConfigureAwait(false);
return result.IsRegistered;
}
private MBLicenseFile _licenseFile;
private MBLicenseFile LicenseFile => _licenseFile ?? (_licenseFile = new MBLicenseFile(_appPaths, _fileSystem, _cryptographyProvider));
private readonly IHttpClient _httpClient;
private readonly IJsonSerializer _jsonSerializer;
private readonly IServerApplicationHost _appHost;
private readonly ILogger _logger;
private readonly IApplicationPaths _appPaths;
private readonly IFileSystem _fileSystem;
private readonly ICryptoProvider _cryptographyProvider;
/// <summary>
/// Initializes a new instance of the <see cref="PluginSecurityManager" /> class.
/// </summary>
public PluginSecurityManager(IServerApplicationHost appHost, IHttpClient httpClient, IJsonSerializer jsonSerializer,
IApplicationPaths appPaths, ILoggerFactory loggerFactory, IFileSystem fileSystem, ICryptoProvider cryptographyProvider)
{
if (httpClient == null)
{
throw new ArgumentNullException(nameof(httpClient));
}
_appHost = appHost;
_httpClient = httpClient;
_jsonSerializer = jsonSerializer;
_appPaths = appPaths;
_fileSystem = fileSystem;
_cryptographyProvider = cryptographyProvider;
_logger = loggerFactory.CreateLogger("SecurityManager");
}
/// <summary>
/// Gets the registration status.
/// This overload supports existing plug-ins.
/// </summary>
public Task<MBRegistrationRecord> GetRegistrationStatus(string feature)
{
return GetRegistrationStatusInternal(feature, false, null, CancellationToken.None);
}
/// <summary>
/// Gets or sets the supporter key.
/// </summary>
/// <value>The supporter key.</value>
public string SupporterKey
{
get => LicenseFile.RegKey;
set => throw new Exception("Please call UpdateSupporterKey");
}
public async Task UpdateSupporterKey(string newValue)
{
if (newValue != null)
{
newValue = newValue.Trim();
}
if (!string.Equals(newValue, LicenseFile.RegKey, StringComparison.Ordinal))
{
LicenseFile.RegKey = newValue;
LicenseFile.Save();
// Reset this
await GetRegistrationStatusInternal("MBSupporter", true, _appHost.ApplicationVersion.ToString(), CancellationToken.None).ConfigureAwait(false);
}
}
/// <summary>
/// Register an app store sale with our back-end. It will validate the transaction with the store
/// and then register the proper feature and then fill in the supporter key on success.
/// </summary>
/// <param name="parameters">Json parameters to send to admin server</param>
public async Task RegisterAppStoreSale(string parameters)
{
var options = new HttpRequestOptions()
{
Url = AppstoreRegUrl,
CancellationToken = CancellationToken.None,
BufferContent = false
};
options.RequestHeaders.Add("X-Emby-Token", _appHost.SystemId);
options.RequestContent = parameters;
options.RequestContentType = "application/json";
try
{
using (var response = await _httpClient.Post(options).ConfigureAwait(false))
{
var reg = await _jsonSerializer.DeserializeFromStreamAsync<RegRecord>(response.Content).ConfigureAwait(false);
if (reg == null)
{
var msg = "Result from appstore registration was null.";
_logger.LogError(msg);
throw new ArgumentException(msg);
}
if (!string.IsNullOrEmpty(reg.key))
{
await UpdateSupporterKey(reg.key).ConfigureAwait(false);
}
}
}
catch (ArgumentException)
{
SaveAppStoreInfo(parameters);
throw;
}
catch (HttpException ex)
{
_logger.LogError(ex, "Error registering appstore purchase {parameters}", parameters ?? "NO PARMS SENT");
throw new Exception("Error registering store sale");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error registering appstore purchase {parameters}", parameters ?? "NO PARMS SENT");
SaveAppStoreInfo(parameters);
//TODO - could create a re-try routine on start-up if this file is there. For now we can handle manually.
throw new Exception("Error registering store sale");
}
}
private void SaveAppStoreInfo(string info)
{
// Save all transaction information to a file
try
{
_fileSystem.WriteAllText(Path.Combine(_appPaths.ProgramDataPath, "apptrans-error.txt"), info);
}
catch (IOException)
{
}
}
private SemaphoreSlim _regCheckLock = new SemaphoreSlim(1, 1);
private async Task<MBRegistrationRecord> GetRegistrationStatusInternal(string feature, bool forceCallToServer, string version, CancellationToken cancellationToken)
{
await _regCheckLock.WaitAsync(cancellationToken).ConfigureAwait(false);
try
{
var record = new MBRegistrationRecord
{
IsRegistered = true,
RegChecked = true,
TrialVersion = false,
IsValid = true,
RegError = false
};
return record;
}
finally
{
_regCheckLock.Release();
}
}
private bool IsInTrial(DateTime expirationDate, bool regChecked, bool isRegistered)
{
//don't set this until we've successfully obtained exp date
if (!regChecked)
{
return false;
}
var isInTrial = expirationDate > DateTime.UtcNow;
return isInTrial && !isRegistered;
}
}
}

@ -10,7 +10,6 @@ using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Net; using MediaBrowser.Common.Net;
using MediaBrowser.Common.Plugins; using MediaBrowser.Common.Plugins;
using MediaBrowser.Common.Progress; using MediaBrowser.Common.Progress;
using MediaBrowser.Common.Security;
using MediaBrowser.Common.Updates; using MediaBrowser.Common.Updates;
using MediaBrowser.Model.Cryptography; using MediaBrowser.Model.Cryptography;
using MediaBrowser.Model.Events; using MediaBrowser.Model.Events;
@ -107,7 +106,6 @@ namespace Emby.Server.Implementations.Updates
private readonly IApplicationPaths _appPaths; private readonly IApplicationPaths _appPaths;
private readonly IHttpClient _httpClient; private readonly IHttpClient _httpClient;
private readonly IJsonSerializer _jsonSerializer; private readonly IJsonSerializer _jsonSerializer;
private readonly ISecurityManager _securityManager;
private readonly IServerConfigurationManager _config; private readonly IServerConfigurationManager _config;
private readonly IFileSystem _fileSystem; private readonly IFileSystem _fileSystem;
@ -122,7 +120,16 @@ namespace Emby.Server.Implementations.Updates
// netframework or netcore // netframework or netcore
private readonly string _packageRuntime; private readonly string _packageRuntime;
public InstallationManager(ILogger logger, IApplicationHost appHost, IApplicationPaths appPaths, IHttpClient httpClient, IJsonSerializer jsonSerializer, ISecurityManager securityManager, IServerConfigurationManager config, IFileSystem fileSystem, ICryptoProvider cryptographyProvider, string packageRuntime) public InstallationManager(
ILogger logger,
IApplicationHost appHost,
IApplicationPaths appPaths,
IHttpClient httpClient,
IJsonSerializer jsonSerializer,
IServerConfigurationManager config,
IFileSystem fileSystem,
ICryptoProvider cryptographyProvider,
string packageRuntime)
{ {
if (logger == null) if (logger == null)
{ {
@ -136,7 +143,6 @@ namespace Emby.Server.Implementations.Updates
_appPaths = appPaths; _appPaths = appPaths;
_httpClient = httpClient; _httpClient = httpClient;
_jsonSerializer = jsonSerializer; _jsonSerializer = jsonSerializer;
_securityManager = securityManager;
_config = config; _config = config;
_fileSystem = fileSystem; _fileSystem = fileSystem;
_cryptographyProvider = cryptographyProvider; _cryptographyProvider = cryptographyProvider;
@ -163,41 +169,10 @@ namespace Emby.Server.Implementations.Updates
string packageType = null, string packageType = null,
Version applicationVersion = null) Version applicationVersion = null)
{ {
if (withRegistration) // TODO cvium
{ // var packages = await GetAvailablePackagesWithoutRegistrationInfo(cancellationToken).ConfigureAwait(false);
var data = new Dictionary<string, string>
{
{ "key", _securityManager.SupporterKey },
{ "mac", _applicationHost.SystemId },
{ "systemid", _applicationHost.SystemId }
};
var options = new HttpRequestOptions
{
Url = "https://www.mb3admin.local/admin/service/package/retrieveall?includeAllRuntimes=true",
CancellationToken = cancellationToken
};
options.SetPostData(data);
using (var response = await _httpClient.SendAsync(options, "POST").ConfigureAwait(false))
{
using (var json = response.Content)
{
cancellationToken.ThrowIfCancellationRequested();
var packages = await _jsonSerializer.DeserializeFromStreamAsync<PackageInfo[]>(json).ConfigureAwait(false); return new List<PackageInfo>(); //FilterPackages(packages, packageType, applicationVersion);
return FilterPackages(packages, packageType, applicationVersion);
}
}
}
else
{
var packages = await GetAvailablePackagesWithoutRegistrationInfo(cancellationToken).ConfigureAwait(false);
return FilterPackages(packages, packageType, applicationVersion);
}
} }
/// <summary> /// <summary>

@ -1,16 +1,13 @@
using MediaBrowser.Common; using MediaBrowser.Common;
using MediaBrowser.Common.Net; using MediaBrowser.Common.Net;
using MediaBrowser.Common.Security;
using MediaBrowser.Common.Updates; using MediaBrowser.Common.Updates;
using MediaBrowser.Controller.Devices; using MediaBrowser.Controller.Devices;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Plugins; using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Serialization;
using System; using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using MediaBrowser.Common.Plugins; using MediaBrowser.Common.Plugins;
@ -79,55 +76,6 @@ namespace MediaBrowser.Api
public Stream RequestStream { get; set; } public Stream RequestStream { get; set; }
} }
/// <summary>
/// Class GetPluginSecurityInfo
/// </summary>
[Route("/Plugins/SecurityInfo", "GET", Summary = "Gets plugin registration information", IsHidden = true)]
[Authenticated]
public class GetPluginSecurityInfo : IReturn<PluginSecurityInfo>
{
}
/// <summary>
/// Class UpdatePluginSecurityInfo
/// </summary>
[Route("/Plugins/SecurityInfo", "POST", Summary = "Updates plugin registration information", IsHidden = true)]
[Authenticated(Roles = "Admin")]
public class UpdatePluginSecurityInfo : PluginSecurityInfo, IReturnVoid
{
}
[Route("/Plugins/RegistrationRecords/{Name}", "GET", Summary = "Gets registration status for a feature", IsHidden = true)]
[Authenticated]
public class GetRegistrationStatus
{
[ApiMember(Name = "Name", Description = "Feature Name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Name { get; set; }
}
[Route("/Registrations/{Name}", "GET", Summary = "Gets registration status for a feature", IsHidden = true)]
[Authenticated]
public class GetRegistration : IReturn<RegistrationInfo>
{
[ApiMember(Name = "Name", Description = "Feature Name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Name { get; set; }
}
public class RegistrationInfo
{
public string Name { get; set; }
public DateTime ExpirationDate { get; set; }
public bool IsTrial { get; set; }
public bool IsRegistered { get; set; }
}
[Route("/Appstore/Register", "POST", Summary = "Registers an appstore sale", IsHidden = true)]
[Authenticated]
public class RegisterAppstoreSale
{
[ApiMember(Name = "Parameters", Description = "Java representation of parameters to pass through to admin server", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
public string Parameters { get; set; }
}
/// <summary> /// <summary>
/// Class PluginsService /// Class PluginsService
@ -143,14 +91,11 @@ namespace MediaBrowser.Api
/// The _app host /// The _app host
/// </summary> /// </summary>
private readonly IApplicationHost _appHost; private readonly IApplicationHost _appHost;
private readonly ISecurityManager _securityManager;
private readonly IInstallationManager _installationManager; private readonly IInstallationManager _installationManager;
private readonly INetworkManager _network; private readonly INetworkManager _network;
private readonly IDeviceManager _deviceManager; private readonly IDeviceManager _deviceManager;
public PluginService(IJsonSerializer jsonSerializer, IApplicationHost appHost, ISecurityManager securityManager, IInstallationManager installationManager, INetworkManager network, IDeviceManager deviceManager) public PluginService(IJsonSerializer jsonSerializer, IApplicationHost appHost, IInstallationManager installationManager, INetworkManager network, IDeviceManager deviceManager)
: base() : base()
{ {
if (jsonSerializer == null) if (jsonSerializer == null)
@ -159,39 +104,12 @@ namespace MediaBrowser.Api
} }
_appHost = appHost; _appHost = appHost;
_securityManager = securityManager;
_installationManager = installationManager; _installationManager = installationManager;
_network = network; _network = network;
_deviceManager = deviceManager; _deviceManager = deviceManager;
_jsonSerializer = jsonSerializer; _jsonSerializer = jsonSerializer;
} }
/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
public async Task<object> Get(GetRegistrationStatus request)
{
var result = await _securityManager.GetRegistrationStatus(request.Name).ConfigureAwait(false);
return ToOptimizedResult(result);
}
public async Task<object> Get(GetRegistration request)
{
var result = await _securityManager.GetRegistrationStatus(request.Name).ConfigureAwait(false);
var info = new RegistrationInfo
{
ExpirationDate = result.ExpirationDate,
IsRegistered = result.IsRegistered,
IsTrial = result.TrialVersion,
Name = request.Name
};
return ToOptimizedResult(info);
}
/// <summary> /// <summary>
/// Gets the specified request. /// Gets the specified request.
@ -200,46 +118,46 @@ namespace MediaBrowser.Api
/// <returns>System.Object.</returns> /// <returns>System.Object.</returns>
public async Task<object> Get(GetPlugins request) public async Task<object> Get(GetPlugins request)
{ {
var result = _appHost.Plugins.OrderBy(p => p.Name).Select(p => p.GetPluginInfo()).ToArray(); // TODO cvium
var requireAppStoreEnabled = request.IsAppStoreEnabled.HasValue && request.IsAppStoreEnabled.Value; var result = _appHost.Plugins.OrderBy(p => p.Name).Select(p => p.GetPluginInfo()).ToArray();
// var requireAppStoreEnabled = request.IsAppStoreEnabled.HasValue && request.IsAppStoreEnabled.Value;
// Don't fail just on account of image url's //
try // // Don't fail just on account of image url's
{ // try
var packages = (await _installationManager.GetAvailablePackagesWithoutRegistrationInfo(CancellationToken.None)); // {
// var packages = (await _installationManager.GetAvailablePackagesWithoutRegistrationInfo(CancellationToken.None));
foreach (var plugin in result) //
{ // foreach (var plugin in result)
var pkg = packages.FirstOrDefault(i => !string.IsNullOrWhiteSpace(i.guid) && string.Equals(i.guid.Replace("-", string.Empty), plugin.Id.Replace("-", string.Empty), StringComparison.OrdinalIgnoreCase)); // {
// var pkg = packages.FirstOrDefault(i => !string.IsNullOrWhiteSpace(i.guid) && string.Equals(i.guid.Replace("-", string.Empty), plugin.Id.Replace("-", string.Empty), StringComparison.OrdinalIgnoreCase));
if (pkg != null) //
{ // if (pkg != null)
plugin.ImageUrl = pkg.thumbImage; // {
} // plugin.ImageUrl = pkg.thumbImage;
} // }
// }
if (requireAppStoreEnabled) //
{ // if (requireAppStoreEnabled)
result = result // {
.Where(plugin => // result = result
{ // .Where(plugin =>
var pkg = packages.FirstOrDefault(i => !string.IsNullOrWhiteSpace(i.guid) && new Guid(plugin.Id).Equals(new Guid(i.guid))); // {
return pkg != null && pkg.enableInAppStore; // var pkg = packages.FirstOrDefault(i => !string.IsNullOrWhiteSpace(i.guid) && new Guid(plugin.Id).Equals(new Guid(i.guid)));
// return pkg != null && pkg.enableInAppStore;
}) //
.ToArray(); // })
} // .ToArray();
} // }
catch (Exception ex) // }
{ // catch (Exception ex)
Logger.LogError(ex, "Error getting plugin list"); // {
// Play it safe here // Logger.LogError(ex, "Error getting plugin list");
if (requireAppStoreEnabled) // // Play it safe here
{ // if (requireAppStoreEnabled)
result = new PluginInfo[] { }; // {
} // result = new PluginInfo[] { };
} // }
// }
return ToOptimizedResult(result); return ToOptimizedResult(result);
} }
@ -256,41 +174,6 @@ namespace MediaBrowser.Api
return ToOptimizedResult(plugin.Configuration); return ToOptimizedResult(plugin.Configuration);
} }
/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
public async Task<object> Get(GetPluginSecurityInfo request)
{
var result = new PluginSecurityInfo
{
IsMBSupporter = await _securityManager.IsSupporter().ConfigureAwait(false),
SupporterKey = _securityManager.SupporterKey
};
return ToOptimizedResult(result);
}
/// <summary>
/// Post app store sale
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public Task Post(RegisterAppstoreSale request)
{
return _securityManager.RegisterAppStoreSale(request.Parameters);
}
/// <summary>
/// Posts the specified request.
/// </summary>
/// <param name="request">The request.</param>
public Task Post(UpdatePluginSecurityInfo request)
{
return _securityManager.UpdateSupporterKey(request.SupporterKey);
}
/// <summary> /// <summary>
/// Posts the specified request. /// Posts the specified request.
/// </summary> /// </summary>

@ -1,6 +1,5 @@
using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Net; using MediaBrowser.Common.Net;
using MediaBrowser.Common.Security;
using MediaBrowser.Controller; using MediaBrowser.Controller;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Model.System; using MediaBrowser.Model.System;
@ -100,8 +99,6 @@ namespace MediaBrowser.Api.System
private readonly INetworkManager _network; private readonly INetworkManager _network;
private readonly ISecurityManager _security;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="SystemService" /> class. /// Initializes a new instance of the <see cref="SystemService" /> class.
/// </summary> /// </summary>
@ -109,13 +106,12 @@ namespace MediaBrowser.Api.System
/// <param name="appPaths">The application paths.</param> /// <param name="appPaths">The application paths.</param>
/// <param name="fileSystem">The file system.</param> /// <param name="fileSystem">The file system.</param>
/// <exception cref="ArgumentNullException">jsonSerializer</exception> /// <exception cref="ArgumentNullException">jsonSerializer</exception>
public SystemService(IServerApplicationHost appHost, IApplicationPaths appPaths, IFileSystem fileSystem, INetworkManager network, ISecurityManager security) public SystemService(IServerApplicationHost appHost, IApplicationPaths appPaths, IFileSystem fileSystem, INetworkManager network)
{ {
_appHost = appHost; _appHost = appHost;
_appPaths = appPaths; _appPaths = appPaths;
_fileSystem = fileSystem; _fileSystem = fileSystem;
_network = network; _network = network;
_security = security;
} }
public object Post(PingSystem request) public object Post(PingSystem request)

@ -1,15 +0,0 @@
using System.Threading.Tasks;
namespace MediaBrowser.Common.Security
{
public interface IRequiresRegistration
{
/// <summary>
/// Load all registration information required for this entity.
/// Your class should re-load all MBRegistrationRecords when this is called even if they were
/// previously loaded.
/// </summary>
/// <returns></returns>
Task LoadRegistrationInfoAsync();
}
}

@ -1,32 +0,0 @@
using MediaBrowser.Model.Entities;
using System.Threading.Tasks;
namespace MediaBrowser.Common.Security
{
public interface ISecurityManager
{
/// <summary>
/// Gets a value indicating whether this instance is MB supporter.
/// </summary>
/// <value><c>true</c> if this instance is MB supporter; otherwise, <c>false</c>.</value>
Task<bool> IsSupporter();
/// <summary>
/// Gets or sets the supporter key.
/// </summary>
/// <value>The supporter key.</value>
string SupporterKey { get; }
/// <summary>
/// Gets the registration status. Overload to support existing plug-ins.
/// </summary>
Task<MBRegistrationRecord> GetRegistrationStatus(string feature);
/// <summary>
/// Register and app store sale with our back-end
/// </summary>
/// <param name="parameters">Json parameters to pass to admin server</param>
Task RegisterAppStoreSale(string parameters);
Task UpdateSupporterKey(string newValue);
}
}

@ -1,8 +0,0 @@
using System;
namespace MediaBrowser.Common.Security
{
public class PaymentRequiredException : Exception
{
}
}

@ -49,9 +49,7 @@ namespace MediaBrowser.Common.Updates
/// <param name="applicationVersion">The application version.</param> /// <param name="applicationVersion">The application version.</param>
/// <returns>Task{List{PackageInfo}}.</returns> /// <returns>Task{List{PackageInfo}}.</returns>
Task<List<PackageInfo>> GetAvailablePackages(CancellationToken cancellationToken, Task<List<PackageInfo>> GetAvailablePackages(CancellationToken cancellationToken,
bool withRegistration = true, bool withRegistration = true, string packageType = null, Version applicationVersion = null);
string packageType = null,
Version applicationVersion = null);
/// <summary> /// <summary>
/// Gets all available packages from a static resource. /// Gets all available packages from a static resource.

@ -1,14 +0,0 @@
using System;
namespace MediaBrowser.Model.Entities
{
public class MBRegistrationRecord
{
public DateTime ExpirationDate { get; set; }
public bool IsRegistered { get; set; }
public bool RegChecked { get; set; }
public bool RegError { get; set; }
public bool TrialVersion { get; set; }
public bool IsValid { get; set; }
}
}

@ -1,21 +0,0 @@

namespace MediaBrowser.Model.Entities
{
/// <summary>
/// Class PluginSecurityInfo
/// </summary>
public class PluginSecurityInfo
{
/// <summary>
/// Gets or sets the supporter key.
/// </summary>
/// <value>The supporter key.</value>
public string SupporterKey { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this instance is MB supporter.
/// </summary>
/// <value><c>true</c> if this instance is MB supporter; otherwise, <c>false</c>.</value>
public bool IsMBSupporter { get; set; }
}
}
Loading…
Cancel
Save