2017-03-13 18:57:45 +00:00
|
|
|
|
using MediaBrowser.Controller;
|
2014-11-15 02:31:03 +00:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
|
|
using MediaBrowser.Controller.Connect;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Controller.Net;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2016-06-23 17:04:18 +00:00
|
|
|
|
using MediaBrowser.Controller.MediaEncoding;
|
2016-10-25 19:02:04 +00:00
|
|
|
|
using MediaBrowser.Model.Services;
|
2017-11-08 20:23:39 +00:00
|
|
|
|
using MediaBrowser.Common.Net;
|
|
|
|
|
using System.Threading;
|
2014-11-15 02:31:03 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api
|
|
|
|
|
{
|
2018-09-12 17:26:21 +00:00
|
|
|
|
[Route("/Startup/Complete", "POST", Summary = "Reports that the startup wizard has been completed", IsHidden = true)]
|
2014-11-15 02:31:03 +00:00
|
|
|
|
public class ReportStartupWizardComplete : IReturnVoid
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
|
[Route("/Startup/Configuration", "GET", Summary = "Gets initial server configuration", IsHidden = true)]
|
|
|
|
|
public class GetStartupConfiguration : IReturn<StartupConfiguration>
|
2014-11-15 02:31:03 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
|
[Route("/Startup/Configuration", "POST", Summary = "Updates initial server configuration", IsHidden = true)]
|
|
|
|
|
public class UpdateStartupConfiguration : StartupConfiguration, IReturnVoid
|
2014-11-15 02:31:03 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
|
[Route("/Startup/RemoteAccess", "POST", Summary = "Updates initial server configuration", IsHidden = true)]
|
|
|
|
|
public class UpdateRemoteAccessConfiguration : IReturnVoid
|
2014-11-15 02:31:03 +00:00
|
|
|
|
{
|
2018-09-12 17:26:21 +00:00
|
|
|
|
public bool EnableRemoteAccess { get; set; }
|
|
|
|
|
public bool EnableAutomaticPortMapping { get; set; }
|
2014-11-15 02:31:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
|
[Route("/Startup/User", "GET", Summary = "Gets initial user info", IsHidden = true)]
|
2014-11-15 02:31:03 +00:00
|
|
|
|
public class GetStartupUser : IReturn<StartupUser>
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
|
[Route("/Startup/User", "POST", Summary = "Updates initial user info", IsHidden = true)]
|
2014-11-15 02:31:03 +00:00
|
|
|
|
public class UpdateStartupUser : StartupUser, IReturn<UpdateStartupUserResult>
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Authenticated(AllowBeforeStartupWizard = true, Roles = "Admin")]
|
|
|
|
|
public class StartupWizardService : BaseApiService
|
|
|
|
|
{
|
|
|
|
|
private readonly IServerConfigurationManager _config;
|
|
|
|
|
private readonly IServerApplicationHost _appHost;
|
|
|
|
|
private readonly IUserManager _userManager;
|
|
|
|
|
private readonly IConnectManager _connectManager;
|
2016-06-23 17:04:18 +00:00
|
|
|
|
private readonly IMediaEncoder _mediaEncoder;
|
2017-11-08 20:23:39 +00:00
|
|
|
|
private readonly IHttpClient _httpClient;
|
2014-11-15 02:31:03 +00:00
|
|
|
|
|
2017-11-08 20:23:39 +00:00
|
|
|
|
public StartupWizardService(IServerConfigurationManager config, IHttpClient httpClient, IServerApplicationHost appHost, IUserManager userManager, IConnectManager connectManager, IMediaEncoder mediaEncoder)
|
2014-11-15 02:31:03 +00:00
|
|
|
|
{
|
|
|
|
|
_config = config;
|
|
|
|
|
_appHost = appHost;
|
|
|
|
|
_userManager = userManager;
|
|
|
|
|
_connectManager = connectManager;
|
2016-06-23 17:04:18 +00:00
|
|
|
|
_mediaEncoder = mediaEncoder;
|
2017-11-08 20:23:39 +00:00
|
|
|
|
_httpClient = httpClient;
|
2014-11-15 02:31:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Post(ReportStartupWizardComplete request)
|
|
|
|
|
{
|
|
|
|
|
_config.Configuration.IsStartupWizardCompleted = true;
|
2017-11-01 19:50:16 +00:00
|
|
|
|
_config.SetOptimalValues();
|
2014-11-15 02:31:03 +00:00
|
|
|
|
_config.SaveConfiguration();
|
2017-11-08 20:23:39 +00:00
|
|
|
|
|
|
|
|
|
Task.Run(UpdateStats);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task UpdateStats()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2018-10-21 23:16:58 +00:00
|
|
|
|
var url = string.Format("http://www.mb3admin.local/admin/service/package/installed?mac={0}&product=MBServer&operation=Install&version={1}",
|
2017-11-08 20:23:39 +00:00
|
|
|
|
_appHost.SystemId,
|
|
|
|
|
_appHost.ApplicationVersion.ToString());
|
|
|
|
|
|
|
|
|
|
using (var response = await _httpClient.SendAsync(new HttpRequestOptions
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
Url = url,
|
|
|
|
|
CancellationToken = CancellationToken.None,
|
|
|
|
|
LogErrors = false,
|
|
|
|
|
LogRequest = false
|
|
|
|
|
|
|
|
|
|
}, "GET").ConfigureAwait(false))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2014-11-15 02:31:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object Get(GetStartupConfiguration request)
|
|
|
|
|
{
|
2015-08-20 20:57:29 +00:00
|
|
|
|
var result = new StartupConfiguration
|
2014-11-15 02:31:03 +00:00
|
|
|
|
{
|
|
|
|
|
UICulture = _config.Configuration.UICulture,
|
|
|
|
|
MetadataCountryCode = _config.Configuration.MetadataCountryCode,
|
|
|
|
|
PreferredMetadataLanguage = _config.Configuration.PreferredMetadataLanguage
|
|
|
|
|
};
|
2015-08-20 20:57:29 +00:00
|
|
|
|
|
|
|
|
|
return result;
|
2014-11-15 02:31:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Post(UpdateStartupConfiguration request)
|
|
|
|
|
{
|
|
|
|
|
_config.Configuration.UICulture = request.UICulture;
|
|
|
|
|
_config.Configuration.MetadataCountryCode = request.MetadataCountryCode;
|
|
|
|
|
_config.Configuration.PreferredMetadataLanguage = request.PreferredMetadataLanguage;
|
|
|
|
|
_config.SaveConfiguration();
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
|
public void Post(UpdateRemoteAccessConfiguration request)
|
|
|
|
|
{
|
|
|
|
|
_config.Configuration.EnableRemoteAccess = request.EnableRemoteAccess;
|
|
|
|
|
_config.Configuration.EnableUPnP = request.EnableAutomaticPortMapping;
|
|
|
|
|
_config.SaveConfiguration();
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-15 02:31:03 +00:00
|
|
|
|
public object Get(GetStartupUser request)
|
|
|
|
|
{
|
|
|
|
|
var user = _userManager.Users.First();
|
|
|
|
|
|
|
|
|
|
return new StartupUser
|
|
|
|
|
{
|
|
|
|
|
Name = user.Name,
|
|
|
|
|
ConnectUserName = user.ConnectUserName
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<object> Post(UpdateStartupUser request)
|
|
|
|
|
{
|
|
|
|
|
var user = _userManager.Users.First();
|
|
|
|
|
|
|
|
|
|
user.Name = request.Name;
|
2017-08-27 00:32:33 +00:00
|
|
|
|
_userManager.UpdateUser(user);
|
2014-11-15 02:31:03 +00:00
|
|
|
|
|
|
|
|
|
var result = new UpdateStartupUserResult();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(user.ConnectUserName) &&
|
|
|
|
|
string.IsNullOrWhiteSpace(request.ConnectUserName))
|
|
|
|
|
{
|
2018-09-12 17:26:21 +00:00
|
|
|
|
await _connectManager.RemoveConnect(user).ConfigureAwait(false);
|
2014-11-15 02:31:03 +00:00
|
|
|
|
}
|
|
|
|
|
else if (!string.Equals(user.ConnectUserName, request.ConnectUserName, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2018-09-12 17:26:21 +00:00
|
|
|
|
result.UserLinkResult = await _connectManager.LinkUser(user, request.ConnectUserName).ConfigureAwait(false);
|
2014-11-15 02:31:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class StartupConfiguration
|
|
|
|
|
{
|
|
|
|
|
public string UICulture { get; set; }
|
|
|
|
|
public string MetadataCountryCode { get; set; }
|
|
|
|
|
public string PreferredMetadataLanguage { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class StartupUser
|
|
|
|
|
{
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
public string ConnectUserName { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class UpdateStartupUserResult
|
|
|
|
|
{
|
|
|
|
|
public UserLinkResult UserLinkResult { get; set; }
|
|
|
|
|
}
|
|
|
|
|
}
|