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

This commit is contained in:
Claus Vium
2019-01-04 22:42:56 +01:00
committed by Bond-009
parent 8ea0c72070
commit eca3c099d9
14 changed files with 132 additions and 625 deletions

View File

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

View File

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

View File

@@ -1183,14 +1183,6 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
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
{
CancellationTokenSource = new CancellationTokenSource(),
@@ -2379,79 +2371,74 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
var allTimers = GetTimersForSeries(seriesTimer)
.ToList();
var registration = await _liveTvManager.GetRegistrationInfo("seriesrecordings").ConfigureAwait(false);
var enabledTimersForSeries = new List<TimerInfo>();
if (registration.IsValid)
foreach (var timer in allTimers)
{
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))
{
existingTimer = string.IsNullOrWhiteSpace(timer.ProgramId)
? null
: _timerProvider.GetTimerByProgramId(timer.ProgramId);
}
if (existingTimer == null)
{
if (ShouldCancelTimerForSeriesTimer(seriesTimer, timer))
{
timer.Status = RecordingStatus.Cancelled;
}
else
{
enabledTimersForSeries.Add(timer);
}
_timerProvider.Add(timer);
if (TimerCreated != null)
{
TimerCreated(this, new GenericEventArgs<TimerInfo>(timer));
}
timer.Status = RecordingStatus.Cancelled;
}
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))
enabledTimersForSeries.Add(timer);
}
_timerProvider.Add(timer);
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))
{
UpdateExistingTimerWithNewMetadata(existingTimer, timer);
// Needed by ShouldCancelTimerForSeriesTimer
timer.IsManual = existingTimer.IsManual;
if (ShouldCancelTimerForSeriesTimer(seriesTimer, timer))
{
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.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);
}
}
}

View File

@@ -22,7 +22,6 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.IO;
using MediaBrowser.Common.Security;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Model.Events;
@@ -51,7 +50,6 @@ namespace Emby.Server.Implementations.LiveTv
private readonly ITaskManager _taskManager;
private readonly IJsonSerializer _jsonSerializer;
private readonly IProviderManager _providerManager;
private readonly ISecurityManager _security;
private readonly Func<IChannelManager> _channelManager;
private readonly IDtoService _dtoService;
@@ -78,7 +76,23 @@ namespace Emby.Server.Implementations.LiveTv
private IServerApplicationHost _appHost;
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;
_config = config;
@@ -91,7 +105,6 @@ namespace Emby.Server.Implementations.LiveTv
_jsonSerializer = jsonSerializer;
_providerManager = providerManager;
_fileSystem = fileSystem;
_security = security;
_dtoService = dtoService;
_userDataManager = userDataManager;
_channelManager = channelManager;
@@ -2087,14 +2100,6 @@ namespace Emby.Server.Implementations.LiveTv
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 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)
{
var info = GetConfiguration().ListingProviders.First(i => string.Equals(i.Id, id, StringComparison.OrdinalIgnoreCase));

View File

@@ -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;
}
}
}

View File

@@ -10,7 +10,6 @@ using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Common.Progress;
using MediaBrowser.Common.Security;
using MediaBrowser.Common.Updates;
using MediaBrowser.Model.Cryptography;
using MediaBrowser.Model.Events;
@@ -107,7 +106,6 @@ namespace Emby.Server.Implementations.Updates
private readonly IApplicationPaths _appPaths;
private readonly IHttpClient _httpClient;
private readonly IJsonSerializer _jsonSerializer;
private readonly ISecurityManager _securityManager;
private readonly IServerConfigurationManager _config;
private readonly IFileSystem _fileSystem;
@@ -122,7 +120,16 @@ namespace Emby.Server.Implementations.Updates
// netframework or netcore
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)
{
@@ -136,7 +143,6 @@ namespace Emby.Server.Implementations.Updates
_appPaths = appPaths;
_httpClient = httpClient;
_jsonSerializer = jsonSerializer;
_securityManager = securityManager;
_config = config;
_fileSystem = fileSystem;
_cryptographyProvider = cryptographyProvider;
@@ -163,41 +169,10 @@ namespace Emby.Server.Implementations.Updates
string packageType = null,
Version applicationVersion = null)
{
if (withRegistration)
{
var data = new Dictionary<string, string>
{
{ "key", _securityManager.SupporterKey },
{ "mac", _applicationHost.SystemId },
{ "systemid", _applicationHost.SystemId }
};
// TODO cvium
// var packages = await GetAvailablePackagesWithoutRegistrationInfo(cancellationToken).ConfigureAwait(false);
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 FilterPackages(packages, packageType, applicationVersion);
}
}
}
else
{
var packages = await GetAvailablePackagesWithoutRegistrationInfo(cancellationToken).ConfigureAwait(false);
return FilterPackages(packages, packageType, applicationVersion);
}
return new List<PackageInfo>(); //FilterPackages(packages, packageType, applicationVersion);
}
/// <summary>