2015-02-01 13:05:39 -07:00
|
|
|
|
using MediaBrowser.Common;
|
2015-05-26 08:31:50 -07:00
|
|
|
|
using MediaBrowser.Common.Net;
|
2013-03-03 22:43:06 -07:00
|
|
|
|
using MediaBrowser.Common.Security;
|
2013-06-30 19:27:50 -07:00
|
|
|
|
using MediaBrowser.Common.Updates;
|
2015-05-26 08:31:50 -07:00
|
|
|
|
using MediaBrowser.Controller.Devices;
|
2014-07-02 11:34:08 -07:00
|
|
|
|
using MediaBrowser.Controller.Net;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.Plugins;
|
2015-03-12 19:47:52 -07:00
|
|
|
|
using MediaBrowser.Model.Registration;
|
2013-02-24 14:53:54 -07:00
|
|
|
|
using MediaBrowser.Model.Serialization;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2015-02-01 13:05:39 -07:00
|
|
|
|
using System.Threading;
|
2015-01-09 22:53:35 -07:00
|
|
|
|
using System.Threading.Tasks;
|
2016-10-25 12:02:04 -07:00
|
|
|
|
using MediaBrowser.Model.Services;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class Plugins
|
|
|
|
|
/// </summary>
|
2014-03-23 13:07:02 -07:00
|
|
|
|
[Route("/Plugins", "GET", Summary = "Gets a list of currently installed plugins")]
|
2014-11-14 19:31:03 -07:00
|
|
|
|
[Authenticated]
|
2017-08-19 12:43:35 -07:00
|
|
|
|
public class GetPlugins : IReturn<PluginInfo[]>
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2015-05-16 12:09:02 -07:00
|
|
|
|
public bool? IsAppStoreEnabled { get; set; }
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class UninstallPlugin
|
|
|
|
|
/// </summary>
|
2014-03-23 13:07:02 -07:00
|
|
|
|
[Route("/Plugins/{Id}", "DELETE", Summary = "Uninstalls a plugin")]
|
2014-11-14 19:31:03 -07:00
|
|
|
|
[Authenticated(Roles = "Admin")]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public class UninstallPlugin : IReturnVoid
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
2013-03-08 12:14:09 -07:00
|
|
|
|
[ApiMember(Name = "Id", Description = "Plugin Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
|
2015-05-29 16:51:33 -07:00
|
|
|
|
public string Id { get; set; }
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class GetPluginConfiguration
|
|
|
|
|
/// </summary>
|
2014-03-23 13:07:02 -07:00
|
|
|
|
[Route("/Plugins/{Id}/Configuration", "GET", Summary = "Gets a plugin's configuration")]
|
2014-11-14 19:31:03 -07:00
|
|
|
|
[Authenticated]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public class GetPluginConfiguration
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
2013-03-08 12:14:09 -07:00
|
|
|
|
[ApiMember(Name = "Id", Description = "Plugin Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
2015-05-29 16:51:33 -07:00
|
|
|
|
public string Id { get; set; }
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class UpdatePluginConfiguration
|
|
|
|
|
/// </summary>
|
2014-03-23 13:07:02 -07:00
|
|
|
|
[Route("/Plugins/{Id}/Configuration", "POST", Summary = "Updates a plugin's configuration")]
|
2014-11-14 19:31:03 -07:00
|
|
|
|
[Authenticated]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public class UpdatePluginConfiguration : IRequiresRequestStream, IReturnVoid
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
2013-03-08 12:14:09 -07:00
|
|
|
|
[ApiMember(Name = "Id", Description = "Plugin Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
2015-05-29 16:51:33 -07:00
|
|
|
|
public string Id { get; set; }
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The raw Http Request Input Stream
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The request stream.</value>
|
|
|
|
|
public Stream RequestStream { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class GetPluginSecurityInfo
|
|
|
|
|
/// </summary>
|
2017-09-11 12:25:13 -07:00
|
|
|
|
[Route("/Plugins/SecurityInfo", "GET", Summary = "Gets plugin registration information", IsHidden = true)]
|
2014-11-14 19:31:03 -07:00
|
|
|
|
[Authenticated]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public class GetPluginSecurityInfo : IReturn<PluginSecurityInfo>
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class UpdatePluginSecurityInfo
|
|
|
|
|
/// </summary>
|
2017-09-11 12:25:13 -07:00
|
|
|
|
[Route("/Plugins/SecurityInfo", "POST", Summary = "Updates plugin registration information", IsHidden = true)]
|
2014-11-14 19:31:03 -07:00
|
|
|
|
[Authenticated(Roles = "Admin")]
|
2013-03-04 19:05:59 -07:00
|
|
|
|
public class UpdatePluginSecurityInfo : PluginSecurityInfo, IReturnVoid
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-11 12:25:13 -07:00
|
|
|
|
[Route("/Plugins/RegistrationRecords/{Name}", "GET", Summary = "Gets registration status for a feature", IsHidden = true)]
|
2014-11-14 19:31:03 -07:00
|
|
|
|
[Authenticated]
|
2013-04-07 17:26:31 -07:00
|
|
|
|
public class GetRegistrationStatus
|
|
|
|
|
{
|
|
|
|
|
[ApiMember(Name = "Name", Description = "Feature Name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
|
|
|
|
[ApiMember(Name = "Mb2Equivalent", Description = "Optional. The equivalent feature name in MB2", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
|
|
|
public string Mb2Equivalent { get; set; }
|
|
|
|
|
}
|
2014-11-14 19:31:03 -07:00
|
|
|
|
|
2017-09-11 12:25:13 -07:00
|
|
|
|
[Route("/Registrations/{Name}", "GET", Summary = "Gets registration status for a feature", IsHidden = true)]
|
2015-03-12 19:47:52 -07:00
|
|
|
|
[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; }
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-11 12:25:13 -07:00
|
|
|
|
[Route("/Appstore/Register", "POST", Summary = "Registers an appstore sale", IsHidden = true)]
|
2015-10-16 07:29:02 -07:00
|
|
|
|
[Authenticated]
|
|
|
|
|
public class RegisterAppstoreSale
|
|
|
|
|
{
|
2015-10-16 10:53:49 -07:00
|
|
|
|
[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; }
|
2015-10-16 07:29:02 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class PluginsService
|
|
|
|
|
/// </summary>
|
2013-03-15 22:52:33 -07:00
|
|
|
|
public class PluginService : BaseApiService
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2013-02-24 14:53:54 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _json serializer
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IJsonSerializer _jsonSerializer;
|
|
|
|
|
|
2013-03-02 19:47:04 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _app host
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IApplicationHost _appHost;
|
|
|
|
|
|
2013-03-03 22:43:06 -07:00
|
|
|
|
private readonly ISecurityManager _securityManager;
|
|
|
|
|
|
2013-03-04 21:25:27 -07:00
|
|
|
|
private readonly IInstallationManager _installationManager;
|
2015-05-26 08:31:50 -07:00
|
|
|
|
private readonly INetworkManager _network;
|
|
|
|
|
private readonly IDeviceManager _deviceManager;
|
2013-03-04 21:25:27 -07:00
|
|
|
|
|
2015-05-26 08:31:50 -07:00
|
|
|
|
public PluginService(IJsonSerializer jsonSerializer, IApplicationHost appHost, ISecurityManager securityManager, IInstallationManager installationManager, INetworkManager network, IDeviceManager deviceManager)
|
2013-02-24 14:53:54 -07:00
|
|
|
|
: base()
|
|
|
|
|
{
|
|
|
|
|
if (jsonSerializer == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("jsonSerializer");
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-02 19:47:04 -07:00
|
|
|
|
_appHost = appHost;
|
2013-03-03 22:43:06 -07:00
|
|
|
|
_securityManager = securityManager;
|
2013-03-04 21:25:27 -07:00
|
|
|
|
_installationManager = installationManager;
|
2015-05-26 08:31:50 -07:00
|
|
|
|
_network = network;
|
|
|
|
|
_deviceManager = deviceManager;
|
2013-02-24 14:53:54 -07:00
|
|
|
|
_jsonSerializer = jsonSerializer;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-07 17:26:31 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
/// <returns>System.Object.</returns>
|
2015-03-12 19:47:52 -07:00
|
|
|
|
public async Task<object> Get(GetRegistrationStatus request)
|
2013-04-07 17:26:31 -07:00
|
|
|
|
{
|
2015-03-12 19:47:52 -07:00
|
|
|
|
var result = await _securityManager.GetRegistrationStatus(request.Name, request.Mb2Equivalent).ConfigureAwait(false);
|
2013-04-07 17:26:31 -07:00
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(result);
|
|
|
|
|
}
|
2014-11-14 19:31:03 -07:00
|
|
|
|
|
2015-03-12 19:47:52 -07:00
|
|
|
|
public async Task<object> Get(GetRegistration request)
|
|
|
|
|
{
|
|
|
|
|
var result = await _securityManager.GetRegistrationStatus(request.Name).ConfigureAwait(false);
|
|
|
|
|
|
2015-05-26 08:31:50 -07:00
|
|
|
|
var info = new RegistrationInfo
|
2015-03-12 19:47:52 -07:00
|
|
|
|
{
|
|
|
|
|
ExpirationDate = result.ExpirationDate,
|
|
|
|
|
IsRegistered = result.IsRegistered,
|
|
|
|
|
IsTrial = result.TrialVersion,
|
|
|
|
|
Name = request.Name
|
2015-05-26 08:31:50 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(info);
|
2015-03-12 19:47:52 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
/// <returns>System.Object.</returns>
|
2015-01-09 22:53:35 -07:00
|
|
|
|
public async Task<object> Get(GetPlugins request)
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2017-08-19 12:43:35 -07:00
|
|
|
|
var result = _appHost.Plugins.OrderBy(p => p.Name).Select(p => p.GetPluginInfo()).ToArray();
|
2015-05-16 12:09:02 -07:00
|
|
|
|
var requireAppStoreEnabled = request.IsAppStoreEnabled.HasValue && request.IsAppStoreEnabled.Value;
|
2013-03-23 19:45:00 -07:00
|
|
|
|
|
2015-01-09 22:53:35 -07:00
|
|
|
|
// Don't fail just on account of image url's
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-08-19 12:43:35 -07:00
|
|
|
|
var packages = (await _installationManager.GetAvailablePackagesWithoutRegistrationInfo(CancellationToken.None));
|
2015-01-09 22:53:35 -07:00
|
|
|
|
|
|
|
|
|
foreach (var plugin in result)
|
|
|
|
|
{
|
2016-02-15 21:54:20 -07:00
|
|
|
|
var pkg = packages.FirstOrDefault(i => !string.IsNullOrWhiteSpace(i.guid) && string.Equals(i.guid.Replace("-", string.Empty), plugin.Id.Replace("-", string.Empty), StringComparison.OrdinalIgnoreCase));
|
2015-01-09 22:53:35 -07:00
|
|
|
|
|
|
|
|
|
if (pkg != null)
|
|
|
|
|
{
|
|
|
|
|
plugin.ImageUrl = pkg.thumbImage;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-05-16 12:09:02 -07:00
|
|
|
|
|
|
|
|
|
if (requireAppStoreEnabled)
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
})
|
2017-08-19 12:43:35 -07:00
|
|
|
|
.ToArray();
|
2015-05-16 12:09:02 -07:00
|
|
|
|
}
|
2015-01-09 22:53:35 -07:00
|
|
|
|
}
|
2016-08-05 14:15:48 -07:00
|
|
|
|
catch
|
2015-01-09 22:53:35 -07:00
|
|
|
|
{
|
2016-02-15 21:54:20 -07:00
|
|
|
|
//Logger.ErrorException("Error getting plugin list", ex);
|
2015-05-16 12:09:02 -07:00
|
|
|
|
// Play it safe here
|
|
|
|
|
if (requireAppStoreEnabled)
|
|
|
|
|
{
|
2017-08-19 12:43:35 -07:00
|
|
|
|
result = new PluginInfo[] { };
|
2015-05-16 12:09:02 -07:00
|
|
|
|
}
|
2015-01-09 22:53:35 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-03 21:04:19 -07:00
|
|
|
|
return ToOptimizedSerializedResultUsingCache(result);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
/// <returns>System.Object.</returns>
|
|
|
|
|
public object Get(GetPluginConfiguration request)
|
|
|
|
|
{
|
2015-05-29 16:51:33 -07:00
|
|
|
|
var guid = new Guid(request.Id);
|
|
|
|
|
var plugin = _appHost.Plugins.First(p => p.Id == guid);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2016-01-20 12:54:06 -07:00
|
|
|
|
return ToOptimizedResult(plugin.Configuration);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
/// <returns>System.Object.</returns>
|
|
|
|
|
public object Get(GetPluginSecurityInfo request)
|
|
|
|
|
{
|
|
|
|
|
var result = new PluginSecurityInfo
|
|
|
|
|
{
|
2013-03-03 22:43:06 -07:00
|
|
|
|
IsMBSupporter = _securityManager.IsMBSupporter,
|
2014-08-30 19:08:59 -07:00
|
|
|
|
SupporterKey = _securityManager.SupporterKey
|
2013-02-20 18:33:05 -07:00
|
|
|
|
};
|
|
|
|
|
|
2014-02-03 21:04:19 -07:00
|
|
|
|
return ToOptimizedSerializedResultUsingCache(result);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-16 07:29:02 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Post app store sale
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <returns></returns>
|
2015-10-29 06:28:05 -07:00
|
|
|
|
public void Post(RegisterAppstoreSale request)
|
2015-10-16 07:29:02 -07:00
|
|
|
|
{
|
2015-10-29 06:28:05 -07:00
|
|
|
|
var task = _securityManager.RegisterAppStoreSale(request.Parameters);
|
|
|
|
|
|
|
|
|
|
Task.WaitAll(task);
|
2015-10-16 07:29:02 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Posts the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
public void Post(UpdatePluginSecurityInfo request)
|
|
|
|
|
{
|
2013-03-04 19:05:59 -07:00
|
|
|
|
var info = request;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-03-03 22:43:06 -07:00
|
|
|
|
_securityManager.SupporterKey = info.SupporterKey;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Posts the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
public void Post(UpdatePluginConfiguration request)
|
|
|
|
|
{
|
|
|
|
|
// We need to parse this manually because we told service stack not to with IRequiresRequestStream
|
|
|
|
|
// https://code.google.com/p/servicestack/source/browse/trunk/Common/ServiceStack.Text/ServiceStack.Text/Controller/PathInfo.cs
|
2015-01-22 09:41:34 -07:00
|
|
|
|
var id = new Guid(GetPathValue(1));
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-03-02 19:47:04 -07:00
|
|
|
|
var plugin = _appHost.Plugins.First(p => p.Id == id);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-02-24 14:53:54 -07:00
|
|
|
|
var configuration = _jsonSerializer.DeserializeFromStream(request.RequestStream, plugin.ConfigurationType) as BasePluginConfiguration;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
plugin.UpdateConfiguration(configuration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Deletes the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
public void Delete(UninstallPlugin request)
|
|
|
|
|
{
|
2015-05-29 16:51:33 -07:00
|
|
|
|
var guid = new Guid(request.Id);
|
|
|
|
|
var plugin = _appHost.Plugins.First(p => p.Id == guid);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-03-04 21:25:27 -07:00
|
|
|
|
_installationManager.UninstallPlugin(plugin);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|