rework hosting options

This commit is contained in:
Luke Pulverenti 2015-01-18 23:29:57 -05:00
parent 1316994324
commit de76156391
23 changed files with 231 additions and 163 deletions

View File

@ -858,7 +858,7 @@ namespace MediaBrowser.Api.Playback
if (SupportsThrottleWithStream) if (SupportsThrottleWithStream)
{ {
var url = "http://localhost:" + ServerConfigurationManager.Configuration.HttpServerPortNumber.ToString(UsCulture) + "/videos/" + state.Request.Id + "/stream?static=true&Throttle=true&mediaSourceId=" + state.Request.MediaSourceId; var url = "http://localhost:" + ServerConfigurationManager.Configuration.HttpServerPortNumber.ToString(UsCulture) + "/videos/" + state.Request.Id + "/stream?static=true&Throttle=true&mediaSourceId=" + state.Request.MediaSourceId;
url += "&transcodingJobId=" + transcodingJobId; url += "&transcodingJobId=" + transcodingJobId;
return string.Format("\"{0}\"", url); return string.Format("\"{0}\"", url);

View File

@ -1,4 +1,5 @@
using MediaBrowser.Common.Progress; using MediaBrowser.Common.Progress;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
@ -93,6 +94,31 @@ namespace MediaBrowser.Controller.Entities.Movies
return list; return list;
} }
/// <summary>
/// Updates the official rating based on content and returns true or false indicating if it changed.
/// </summary>
/// <returns></returns>
public bool UpdateRatingToContent()
{
var currentOfficialRating = OfficialRating;
// Gather all possible ratings
var ratings = RecursiveChildren
.Concat(GetLinkedChildren())
.Where(i => i is Movie || i is Series)
.Select(i => i.OfficialRating)
.Where(i => !string.IsNullOrEmpty(i))
.Distinct(StringComparer.OrdinalIgnoreCase)
.Select(i => new Tuple<string, int?>(i, LocalizationManager.GetRatingLevel(i)))
.OrderBy(i => i.Item2 ?? 1000)
.Select(i => i.Item1);
OfficialRating = ratings.FirstOrDefault() ?? currentOfficialRating;
return !string.Equals(currentOfficialRating ?? string.Empty, OfficialRating ?? string.Empty,
StringComparison.OrdinalIgnoreCase);
}
public override IEnumerable<BaseItem> GetChildren(User user, bool includeLinkedChildren) public override IEnumerable<BaseItem> GetChildren(User user, bool includeLinkedChildren)
{ {
var children = base.GetChildren(user, includeLinkedChildren); var children = base.GetChildren(user, includeLinkedChildren);

View File

@ -28,7 +28,19 @@ namespace MediaBrowser.Controller
/// Gets the HTTP server port. /// Gets the HTTP server port.
/// </summary> /// </summary>
/// <value>The HTTP server port.</value> /// <value>The HTTP server port.</value>
int HttpServerPort { get; } int HttpPort { get; }
/// <summary>
/// Gets the HTTPS port.
/// </summary>
/// <value>The HTTPS port.</value>
int HttpsPort { get; }
/// <summary>
/// Gets a value indicating whether [supports HTTPS].
/// </summary>
/// <value><c>true</c> if [supports HTTPS]; otherwise, <c>false</c>.</value>
bool EnableHttps { get; }
/// <summary> /// <summary>
/// Gets a value indicating whether this instance has update available. /// Gets a value indicating whether this instance has update available.

View File

@ -1,4 +1,3 @@
using MediaBrowser.Common.Net;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -15,6 +14,12 @@ namespace MediaBrowser.Controller.Net
/// <value>The URL prefix.</value> /// <value>The URL prefix.</value>
IEnumerable<string> UrlPrefixes { get; } IEnumerable<string> UrlPrefixes { get; }
/// <summary>
/// Gets the certificate path.
/// </summary>
/// <value>The certificate path.</value>
string CertificatePath { get; }
/// <summary> /// <summary>
/// Starts the specified server name. /// Starts the specified server name.
/// </summary> /// </summary>

View File

@ -167,7 +167,7 @@ namespace MediaBrowser.Dlna.Main
var descriptorURI = "/dlna/" + guid.ToString("N") + "/description.xml"; var descriptorURI = "/dlna/" + guid.ToString("N") + "/description.xml";
var uri = new Uri(string.Format("http://{0}:{1}{2}", address, _config.Configuration.HttpServerPortNumber, descriptorURI)); var uri = new Uri(string.Format("http://{0}:{1}{2}", address, _appHost.HttpPort, descriptorURI));
var services = new List<string> var services = new List<string>
{ {

View File

@ -152,7 +152,7 @@ namespace MediaBrowser.Dlna.PlayTo
"http", "http",
localIp, localIp,
_appHost.HttpServerPort _appHost.HttpPort
); );
} }

View File

@ -36,7 +36,7 @@ namespace MediaBrowser.Model.Configuration
/// Gets or sets a value indicating whether [use HTTPS]. /// Gets or sets a value indicating whether [use HTTPS].
/// </summary> /// </summary>
/// <value><c>true</c> if [use HTTPS]; otherwise, <c>false</c>.</value> /// <value><c>true</c> if [use HTTPS]; otherwise, <c>false</c>.</value>
public bool UseHttps { get; set; } public bool EnableHttps { get; set; }
/// <summary> /// <summary>
/// Gets or sets the value pointing to the file system where the ssl certiifcate is located.. /// Gets or sets the value pointing to the file system where the ssl certiifcate is located..
@ -206,7 +206,7 @@ namespace MediaBrowser.Model.Configuration
PublicPort = 8096; PublicPort = 8096;
HttpServerPortNumber = 8096; HttpServerPortNumber = 8096;
HttpsPortNumber = 8920; HttpsPortNumber = 8920;
UseHttps = false; EnableHttps = false;
CertificatePath = null; CertificatePath = null;
EnableDashboardResponseCaching = true; EnableDashboardResponseCaching = true;
EnableDashboardResourceMinification = true; EnableDashboardResourceMinification = true;

View File

@ -122,11 +122,11 @@ namespace MediaBrowser.Model.System
/// <value>The HTTP server port number.</value> /// <value>The HTTP server port number.</value>
public int HttpServerPortNumber { get; set; } public int HttpServerPortNumber { get; set; }
/// <summary> /// <summary>
/// Gets or sets the value pointing to the file system where the ssl certiifcate is located. /// Gets or sets a value indicating whether [enable HTTPS].
/// </summary> /// </summary>
/// <value>The value pointing to the file system where the ssl certiifcate is located.</value> /// <value><c>true</c> if [enable HTTPS]; otherwise, <c>false</c>.</value>
public bool UseHttps { get; set; } public bool EnableHttps { get; set; }
/// <summary> /// <summary>
/// Gets or sets the HTTPS server port number. /// Gets or sets the HTTPS server port number.

View File

@ -60,23 +60,7 @@ namespace MediaBrowser.Providers.BoxSets
{ {
if (!item.LockedFields.Contains(MetadataFields.OfficialRating)) if (!item.LockedFields.Contains(MetadataFields.OfficialRating))
{ {
var currentOfficialRating = item.OfficialRating; if (item.UpdateRatingToContent())
// Gather all possible ratings
var ratings = item.RecursiveChildren
.Concat(item.GetLinkedChildren())
.Where(i => i is Movie || i is Series)
.Select(i => i.OfficialRating)
.Where(i => !string.IsNullOrEmpty(i))
.Distinct(StringComparer.OrdinalIgnoreCase)
.Select(i => new Tuple<string, int?>(i, _iLocalizationManager.GetRatingLevel(i)))
.OrderBy(i => i.Item2 ?? 1000)
.Select(i => i.Item1);
item.OfficialRating = ratings.FirstOrDefault() ?? item.OfficialRating;
if (!string.Equals(currentOfficialRating ?? string.Empty, item.OfficialRating ?? string.Empty,
StringComparison.OrdinalIgnoreCase))
{ {
updateType = updateType | ItemUpdateType.MetadataEdit; updateType = updateType | ItemUpdateType.MetadataEdit;
} }

View File

@ -8,8 +8,6 @@ using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging; using MediaBrowser.Model.Logging;
using MediaBrowser.Providers.Manager; using MediaBrowser.Providers.Manager;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Providers.TV namespace MediaBrowser.Providers.TV
{ {
@ -61,16 +59,5 @@ namespace MediaBrowser.Providers.TV
target.DisplaySpecialsWithSeasons = source.DisplaySpecialsWithSeasons; target.DisplaySpecialsWithSeasons = source.DisplaySpecialsWithSeasons;
} }
} }
protected override async Task<ItemUpdateType> BeforeSave(Series item, bool isFullRefresh, ItemUpdateType currentUpdateType)
{
var updateType = await base.BeforeSave(item, isFullRefresh, currentUpdateType).ConfigureAwait(false);
//var provider = new DummySeasonProvider(ServerConfigurationManager, Logger, _localization, _libraryManager);
//await provider.Run(item, CancellationToken.None).ConfigureAwait(false);
return updateType;
}
} }
} }

View File

@ -184,8 +184,9 @@ namespace MediaBrowser.Server.Implementations.Collections
collection.LinkedChildren.AddRange(list); collection.LinkedChildren.AddRange(list);
await collection.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false); collection.UpdateRatingToContent();
await collection.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false);
await collection.RefreshMetadata(CancellationToken.None).ConfigureAwait(false); await collection.RefreshMetadata(CancellationToken.None).ConfigureAwait(false);
if (fireEvent) if (fireEvent)
@ -274,8 +275,9 @@ namespace MediaBrowser.Server.Implementations.Collections
} }
} }
await collection.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false); collection.UpdateRatingToContent();
await collection.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false);
await collection.RefreshMetadata(CancellationToken.None).ConfigureAwait(false); await collection.RefreshMetadata(CancellationToken.None).ConfigureAwait(false);
EventHelper.FireEventIfNotNull(ItemsRemovedFromCollection, this, new CollectionModifiedEventArgs EventHelper.FireEventIfNotNull(ItemsRemovedFromCollection, this, new CollectionModifiedEventArgs

View File

@ -78,7 +78,7 @@ namespace MediaBrowser.Server.Implementations.Connect
if (!ip.StartsWith("http://", StringComparison.OrdinalIgnoreCase) && if (!ip.StartsWith("http://", StringComparison.OrdinalIgnoreCase) &&
!ip.StartsWith("https://", StringComparison.OrdinalIgnoreCase)) !ip.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
{ {
ip = (_config.Configuration.UseHttps ? "https://" : "http://") + ip; ip = (_appHost.EnableHttps ? "https://" : "http://") + ip;
} }
return ip + ":" + _config.Configuration.PublicPort.ToString(CultureInfo.InvariantCulture); return ip + ":" + _config.Configuration.PublicPort.ToString(CultureInfo.InvariantCulture);
@ -90,7 +90,7 @@ namespace MediaBrowser.Server.Implementations.Connect
private string XApplicationValue private string XApplicationValue
{ {
get { return "Media Browser Server/" + _appHost.ApplicationVersion; } get { return _appHost.Name + "/" + _appHost.ApplicationVersion; }
} }
public ConnectManager(ILogger logger, public ConnectManager(ILogger logger,
@ -112,6 +112,7 @@ namespace MediaBrowser.Server.Implementations.Connect
_providerManager = providerManager; _providerManager = providerManager;
_userManager.UserConfigurationUpdated += _userManager_UserConfigurationUpdated; _userManager.UserConfigurationUpdated += _userManager_UserConfigurationUpdated;
_config.ConfigurationUpdated += _config_ConfigurationUpdated;
LoadCachedData(); LoadCachedData();
} }
@ -164,8 +165,7 @@ namespace MediaBrowser.Server.Implementations.Connect
} }
catch (HttpException ex) catch (HttpException ex)
{ {
if (!ex.StatusCode.HasValue || if (!ex.StatusCode.HasValue || !new[] { HttpStatusCode.NotFound, HttpStatusCode.Unauthorized }.Contains(ex.StatusCode.Value))
!new[] { HttpStatusCode.NotFound, HttpStatusCode.Unauthorized }.Contains(ex.StatusCode.Value))
{ {
throw; throw;
} }
@ -179,6 +179,8 @@ namespace MediaBrowser.Server.Implementations.Connect
await CreateServerRegistration(wanApiAddress, localAddress).ConfigureAwait(false); await CreateServerRegistration(wanApiAddress, localAddress).ConfigureAwait(false);
} }
_lastReportedIdentifier = GetConnectReportingIdentifier(localAddress, wanApiAddress);
await RefreshAuthorizationsInternal(true, CancellationToken.None).ConfigureAwait(false); await RefreshAuthorizationsInternal(true, CancellationToken.None).ConfigureAwait(false);
} }
catch (Exception ex) catch (Exception ex)
@ -187,6 +189,27 @@ namespace MediaBrowser.Server.Implementations.Connect
} }
} }
private string _lastReportedIdentifier;
private string GetConnectReportingIdentifier()
{
return GetConnectReportingIdentifier(_appHost.GetSystemInfo().LocalAddress, WanApiAddress);
}
private string GetConnectReportingIdentifier(string localAddress, string remoteAddress)
{
return (remoteAddress ?? string.Empty) + (localAddress ?? string.Empty);
}
void _config_ConfigurationUpdated(object sender, EventArgs e)
{
// If info hasn't changed, don't report anything
if (string.Equals(_lastReportedIdentifier, GetConnectReportingIdentifier(), StringComparison.OrdinalIgnoreCase))
{
return;
}
UpdateConnectInfo();
}
private async Task CreateServerRegistration(string wanApiAddress, string localAddress) private async Task CreateServerRegistration(string wanApiAddress, string localAddress)
{ {
if (string.IsNullOrWhiteSpace(wanApiAddress)) if (string.IsNullOrWhiteSpace(wanApiAddress))

View File

@ -5,6 +5,7 @@ using MediaBrowser.Model.Logging;
using Mono.Nat; using Mono.Nat;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.IO; using System.IO;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
@ -17,30 +18,44 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IServerConfigurationManager _config; private readonly IServerConfigurationManager _config;
private bool _isStarted;
private Timer _timer; private Timer _timer;
private bool _isStarted;
public ExternalPortForwarding(ILogManager logmanager, IServerApplicationHost appHost, IServerConfigurationManager config) public ExternalPortForwarding(ILogManager logmanager, IServerApplicationHost appHost, IServerConfigurationManager config)
{ {
_logger = logmanager.GetLogger("PortMapper"); _logger = logmanager.GetLogger("PortMapper");
_appHost = appHost; _appHost = appHost;
_config = config; _config = config;
}
_config.ConfigurationUpdated += _config_ConfigurationUpdated; private string _lastConfigIdentifier;
private string GetConfigIdentifier()
{
var values = new List<string>();
var config = _config.Configuration;
values.Add(config.EnableUPnP.ToString());
values.Add(config.PublicPort.ToString(CultureInfo.InvariantCulture));
values.Add(_appHost.HttpPort.ToString(CultureInfo.InvariantCulture));
values.Add(_appHost.HttpsPort.ToString(CultureInfo.InvariantCulture));
values.Add(config.EnableHttps.ToString());
values.Add(_appHost.EnableHttps.ToString());
return string.Join("|", values.ToArray());
} }
void _config_ConfigurationUpdated(object sender, EventArgs e) void _config_ConfigurationUpdated(object sender, EventArgs e)
{ {
var enable = _config.Configuration.EnableUPnP; _config.ConfigurationUpdated -= _config_ConfigurationUpdated;
if (!string.Equals(_lastConfigIdentifier, GetConfigIdentifier(), StringComparison.OrdinalIgnoreCase))
{
if (_isStarted)
{
DisposeNat();
}
if (enable && !_isStarted) Run();
{
Reload();
}
else if (!enable && _isStarted)
{
DisposeNat();
} }
} }
@ -48,31 +63,36 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
{ {
//NatUtility.Logger = new LogWriter(_logger); //NatUtility.Logger = new LogWriter(_logger);
Reload();
}
private void Reload()
{
if (_config.Configuration.EnableUPnP) if (_config.Configuration.EnableUPnP)
{ {
_logger.Debug("Starting NAT discovery"); Start();
NatUtility.DeviceFound += NatUtility_DeviceFound;
// Mono.Nat does never rise this event. The event is there however it is useless.
// You could remove it with no risk.
NatUtility.DeviceLost += NatUtility_DeviceLost;
// it is hard to say what one should do when an unhandled exception is raised
// because there isn't anything one can do about it. Probably save a log or ignored it.
NatUtility.UnhandledException += NatUtility_UnhandledException;
NatUtility.StartDiscovery();
_isStarted = true;
_timer = new Timer(s => _createdRules = new List<string>(), null, TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(10));
} }
_config.ConfigurationUpdated -= _config_ConfigurationUpdated;
_config.ConfigurationUpdated += _config_ConfigurationUpdated;
}
private void Start()
{
_logger.Debug("Starting NAT discovery");
NatUtility.DeviceFound += NatUtility_DeviceFound;
// Mono.Nat does never rise this event. The event is there however it is useless.
// You could remove it with no risk.
NatUtility.DeviceLost += NatUtility_DeviceLost;
// it is hard to say what one should do when an unhandled exception is raised
// because there isn't anything one can do about it. Probably save a log or ignored it.
NatUtility.UnhandledException += NatUtility_UnhandledException;
NatUtility.StartDiscovery();
_timer = new Timer(s => _createdRules = new List<string>(), null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5));
_lastConfigIdentifier = GetConfigIdentifier();
_isStarted = true;
} }
void NatUtility_UnhandledException(object sender, UnhandledExceptionEventArgs e) void NatUtility_UnhandledException(object sender, UnhandledExceptionEventArgs e)
@ -124,9 +144,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
{ {
_createdRules.Add(address); _createdRules.Add(address);
var info = _appHost.GetSystemInfo(); CreatePortMap(device, _appHost.HttpPort, _config.Configuration.PublicPort);
CreatePortMap(device, info.HttpServerPortNumber, _config.Configuration.PublicPort);
} }
} }
@ -136,7 +154,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
device.CreatePortMap(new Mapping(Protocol.Tcp, privatePort, publicPort) device.CreatePortMap(new Mapping(Protocol.Tcp, privatePort, publicPort)
{ {
Description = "Media Browser Server" Description = _appHost.Name
}); });
} }

View File

@ -3,7 +3,6 @@ using MediaBrowser.Common;
using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Logging; using MediaBrowser.Model.Logging;
using MediaBrowser.Server.Implementations.HttpServer.NetListener;
using MediaBrowser.Server.Implementations.HttpServer.SocketSharp; using MediaBrowser.Server.Implementations.HttpServer.SocketSharp;
using ServiceStack; using ServiceStack;
using ServiceStack.Api.Swagger; using ServiceStack.Api.Swagger;
@ -41,7 +40,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
private readonly ReaderWriterLockSlim _localEndpointLock = new ReaderWriterLockSlim(); private readonly ReaderWriterLockSlim _localEndpointLock = new ReaderWriterLockSlim();
private string _certificatePath; public string CertificatePath { get; private set; }
/// <summary> /// <summary>
/// Gets the local end points. /// Gets the local end points.
@ -206,7 +205,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
private IHttpListener GetListener() private IHttpListener GetListener()
{ {
return new WebSocketSharpListener(_logger, OnRequestReceived, _certificatePath); return new WebSocketSharpListener(_logger, OnRequestReceived, CertificatePath);
} }
private void WebSocketHandler(WebSocketConnectEventArgs args) private void WebSocketHandler(WebSocketConnectEventArgs args)
@ -434,7 +433,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
public void StartServer(IEnumerable<string> urlPrefixes, string certificatePath) public void StartServer(IEnumerable<string> urlPrefixes, string certificatePath)
{ {
_certificatePath = certificatePath; CertificatePath = certificatePath;
UrlPrefixes = urlPrefixes.ToList(); UrlPrefixes = urlPrefixes.ToList();
Start(UrlPrefixes.First()); Start(UrlPrefixes.First());
} }

View File

@ -3,12 +3,12 @@ using MediaBrowser.Model.Logging;
using MediaBrowser.Server.Implementations.Logging; using MediaBrowser.Server.Implementations.Logging;
using ServiceStack; using ServiceStack;
using ServiceStack.Web; using ServiceStack.Web;
using SocketHttpListener.Net;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using SocketHttpListener.Net;
namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
{ {

View File

@ -192,9 +192,10 @@
"LabelPlayMethodDirectPlay": "Direct Playing", "LabelPlayMethodDirectPlay": "Direct Playing",
"LabelAudioCodec": "Audio: {0}", "LabelAudioCodec": "Audio: {0}",
"LabelVideoCodec": "Video: {0}", "LabelVideoCodec": "Video: {0}",
"LabelLocalAccessUrl": "Local access: {0}",
"LabelRemoteAccessUrl": "Remote access: {0}", "LabelRemoteAccessUrl": "Remote access: {0}",
"LabelRunningOnPort": "Running on port {0}.", "LabelRunningOnPort": "Running on http port {0}.",
"LabelRunningOnHttpsPort": "Running on SSL port {0}.", "LabelRunningOnPorts": "Running on http port {0}, and https port {1}.",
"HeaderLatestFromChannel": "Latest from {0}", "HeaderLatestFromChannel": "Latest from {0}",
"ButtonDownload": "Download", "ButtonDownload": "Download",
"LabelUnknownLanaguage": "Unknown language", "LabelUnknownLanaguage": "Unknown language",

View File

@ -519,19 +519,17 @@
"LabelLocalHttpServerPortNumberHelp": "The tcp port number that Media Browser's http server should bind to.", "LabelLocalHttpServerPortNumberHelp": "The tcp port number that Media Browser's http server should bind to.",
"LabelPublicPort": "Public port number:", "LabelPublicPort": "Public port number:",
"LabelPublicPortHelp": "The public port number that should be mapped to the local port.", "LabelPublicPortHelp": "The public port number that should be mapped to the local port.",
"LabelEnableHttps": "Enable https for remote connections",
"LabelUseHttps": "Enable SSL", "LabelEnableHttpsHelp": "If enabled, the server will report an https url as it's external address.",
"LabelUseHttpsHelp": "Check to enable SSL hosting.", "LabelHttpsPort": "Local https port:",
"LabelHttpsPort": "Local http port:",
"LabelHttpsPortHelp": "The tcp port number that Media Browser's https server should bind to.", "LabelHttpsPortHelp": "The tcp port number that Media Browser's https server should bind to.",
"LabelCertificatePath": "SSL Certificate path:", "LabelCertificatePath": "SSL Certificate path:",
"LabelCertificatePathHelp": "The path on the filesystem to the ssl certificate pfx file.", "LabelCertificatePathHelp": "The path on the file system to the ssl certificate .pfx file.",
"LabelWebSocketPortNumber": "Web socket port number:", "LabelWebSocketPortNumber": "Web socket port number:",
"LabelEnableAutomaticPortMap": "Enable automatic port mapping", "LabelEnableAutomaticPortMap": "Enable automatic port mapping",
"LabelEnableAutomaticPortMapHelp": "Attempt to automatically map the public port to the local port via UPnP. This may not work with some router models.", "LabelEnableAutomaticPortMapHelp": "Attempt to automatically map the public port to the local port via UPnP. This may not work with some router models.",
"LabelExternalDDNS": "External DDNS:", "LabelExternalDDNS": "External WAN Address:",
"LabelExternalDDNSHelp": "If you have a dynamic DNS enter it here. Media Browser apps will use it when connecting remotely.", "LabelExternalDDNSHelp": "If you have a dynamic DNS enter it here. Media Browser apps will use it when connecting remotely. Leave empty for automatic detection.",
"TabResume": "Resume", "TabResume": "Resume",
"TabWeather": "Weather", "TabWeather": "Weather",
"TitleAppSettings": "App Settings", "TitleAppSettings": "App Settings",
@ -600,6 +598,7 @@
"ButtonRestart": "Restart", "ButtonRestart": "Restart",
"ButtonShutdown": "Shutdown", "ButtonShutdown": "Shutdown",
"ButtonUpdateNow": "Update Now", "ButtonUpdateNow": "Update Now",
"TabHosting": "Hosting",
"PleaseUpdateManually": "Please shutdown the server and update manually.", "PleaseUpdateManually": "Please shutdown the server and update manually.",
"NewServerVersionAvailable": "A new version of Media Browser Server is available!", "NewServerVersionAvailable": "A new version of Media Browser Server is available!",
"ServerUpToDate": "Media Browser Server is up to date", "ServerUpToDate": "Media Browser Server is up to date",

View File

@ -78,7 +78,7 @@ namespace MediaBrowser.Server.Mono
var nativeApp = new NativeApp(); var nativeApp = new NativeApp();
_appHost = new ApplicationHost(appPaths, logManager, options, fileSystem, "MBServer.Mono", false, nativeApp); _appHost = new ApplicationHost(appPaths, logManager, options, fileSystem, "MBServer.Mono", nativeApp);
if (options.ContainsOption("-v")) { if (options.ContainsOption("-v")) {
Console.WriteLine (_appHost.ApplicationVersion.ToString()); Console.WriteLine (_appHost.ApplicationVersion.ToString());

View File

@ -110,38 +110,6 @@ namespace MediaBrowser.Server.Startup.Common
get { return (IServerConfigurationManager)ConfigurationManager; } get { return (IServerConfigurationManager)ConfigurationManager; }
} }
/// <summary>
/// Gets the name of the web application that can be used for url building.
/// All api urls will be of the form {protocol}://{host}:{port}/{appname}/...
/// </summary>
/// <value>The name of the web application.</value>
public string WebApplicationName
{
get { return "mediabrowser"; }
}
/// <summary>
/// Gets the HTTP server URL prefix.
/// </summary>
/// <value>The HTTP server URL prefix.</value>
private IEnumerable<string> HttpServerUrlPrefixes
{
get
{
var list = new List<string>
{
"http://+:" + ServerConfigurationManager.Configuration.HttpServerPortNumber + "/"
};
if (ServerConfigurationManager.Configuration.UseHttps)
{
list.Add("https://+:" + ServerConfigurationManager.Configuration.HttpsPortNumber + "/");
}
return list;
}
}
/// <summary> /// <summary>
/// Gets the configuration manager. /// Gets the configuration manager.
/// </summary> /// </summary>
@ -230,8 +198,6 @@ namespace MediaBrowser.Server.Startup.Common
private readonly StartupOptions _startupOptions; private readonly StartupOptions _startupOptions;
private readonly string _remotePackageName; private readonly string _remotePackageName;
private bool _supportsNativeWebSocket;
internal INativeApp NativeApp { get; set; } internal INativeApp NativeApp { get; set; }
/// <summary> /// <summary>
@ -242,20 +208,17 @@ namespace MediaBrowser.Server.Startup.Common
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="fileSystem">The file system.</param> /// <param name="fileSystem">The file system.</param>
/// <param name="remotePackageName">Name of the remote package.</param> /// <param name="remotePackageName">Name of the remote package.</param>
/// <param name="supportsNativeWebSocket">if set to <c>true</c> [supports native web socket].</param>
/// <param name="nativeApp">The native application.</param> /// <param name="nativeApp">The native application.</param>
public ApplicationHost(ServerApplicationPaths applicationPaths, public ApplicationHost(ServerApplicationPaths applicationPaths,
ILogManager logManager, ILogManager logManager,
StartupOptions options, StartupOptions options,
IFileSystem fileSystem, IFileSystem fileSystem,
string remotePackageName, string remotePackageName,
bool supportsNativeWebSocket,
INativeApp nativeApp) INativeApp nativeApp)
: base(applicationPaths, logManager, fileSystem) : base(applicationPaths, logManager, fileSystem)
{ {
_startupOptions = options; _startupOptions = options;
_remotePackageName = remotePackageName; _remotePackageName = remotePackageName;
_supportsNativeWebSocket = supportsNativeWebSocket;
NativeApp = nativeApp; NativeApp = nativeApp;
SetBaseExceptionMessage(); SetBaseExceptionMessage();
@ -359,6 +322,9 @@ namespace MediaBrowser.Server.Startup.Common
public override async Task Init(IProgress<double> progress) public override async Task Init(IProgress<double> progress)
{ {
HttpPort = ServerConfigurationManager.Configuration.HttpServerPortNumber;
HttpsPort = ServerConfigurationManager.Configuration.HttpsPortNumber;
PerformPreInitMigrations(); PerformPreInitMigrations();
await base.Init(progress).ConfigureAwait(false); await base.Init(progress).ConfigureAwait(false);
@ -586,10 +552,10 @@ namespace MediaBrowser.Server.Startup.Common
new FFmpegValidator(Logger, ApplicationPaths).Validate(info); new FFmpegValidator(Logger, ApplicationPaths).Validate(info);
MediaEncoder = new MediaEncoder(LogManager.GetLogger("MediaEncoder"), MediaEncoder = new MediaEncoder(LogManager.GetLogger("MediaEncoder"),
JsonSerializer, JsonSerializer,
info.EncoderPath, info.EncoderPath,
info.ProbePath, info.ProbePath,
info.Version, info.Version,
ServerConfigurationManager, ServerConfigurationManager,
FileSystemManager, FileSystemManager,
@ -791,6 +757,21 @@ namespace MediaBrowser.Server.Startup.Common
SyncManager.AddParts(GetExports<ISyncProvider>()); SyncManager.AddParts(GetExports<ISyncProvider>());
} }
private IEnumerable<string> GetUrlPrefixes()
{
var prefixes = new List<string>
{
"http://+:" + ServerConfigurationManager.Configuration.HttpServerPortNumber + "/"
};
if (!string.IsNullOrWhiteSpace(ServerConfigurationManager.Configuration.CertificatePath))
{
prefixes.Add("https://+:" + ServerConfigurationManager.Configuration.HttpsPortNumber + "/");
}
return prefixes;
}
/// <summary> /// <summary>
/// Starts the server. /// Starts the server.
/// </summary> /// </summary>
@ -798,7 +779,7 @@ namespace MediaBrowser.Server.Startup.Common
{ {
try try
{ {
ServerManager.Start(HttpServerUrlPrefixes, ServerConfigurationManager.Configuration.CertificatePath); ServerManager.Start(GetUrlPrefixes(), ServerConfigurationManager.Configuration.CertificatePath);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -817,11 +798,29 @@ namespace MediaBrowser.Server.Startup.Common
{ {
base.OnConfigurationUpdated(sender, e); base.OnConfigurationUpdated(sender, e);
if (!HttpServer.UrlPrefixes.SequenceEqual(HttpServerUrlPrefixes, StringComparer.OrdinalIgnoreCase)) var requiresRestart = false;
{
ServerConfigurationManager.Configuration.IsPortAuthorized = false;
ServerConfigurationManager.SaveConfiguration();
// Don't do anything if these haven't been set yet
if (HttpPort != 0 && HttpsPort != 0)
{
// Need to restart if ports have changed
if (ServerConfigurationManager.Configuration.HttpServerPortNumber != HttpPort ||
ServerConfigurationManager.Configuration.HttpsPortNumber != HttpsPort)
{
ServerConfigurationManager.Configuration.IsPortAuthorized = false;
ServerConfigurationManager.SaveConfiguration();
requiresRestart = true;
}
}
if (!HttpServer.UrlPrefixes.SequenceEqual(GetUrlPrefixes(), StringComparer.OrdinalIgnoreCase))
{
requiresRestart = true;
}
if (requiresRestart)
{
NotifyPendingRestart(); NotifyPendingRestart();
} }
} }
@ -953,7 +952,7 @@ namespace MediaBrowser.Server.Startup.Common
HasPendingRestart = HasPendingRestart, HasPendingRestart = HasPendingRestart,
Version = ApplicationVersion.ToString(), Version = ApplicationVersion.ToString(),
IsNetworkDeployed = CanSelfUpdate, IsNetworkDeployed = CanSelfUpdate,
WebSocketPortNumber = HttpServerPort, WebSocketPortNumber = HttpPort,
FailedPluginAssemblies = FailedAssemblies.ToList(), FailedPluginAssemblies = FailedAssemblies.ToList(),
InProgressInstallations = InstallationManager.CurrentInstallations.Select(i => i.Item1).ToList(), InProgressInstallations = InstallationManager.CurrentInstallations.Select(i => i.Item1).ToList(),
CompletedInstallations = InstallationManager.CompletedInstallations.ToList(), CompletedInstallations = InstallationManager.CompletedInstallations.ToList(),
@ -964,9 +963,9 @@ namespace MediaBrowser.Server.Startup.Common
InternalMetadataPath = ApplicationPaths.InternalMetadataPath, InternalMetadataPath = ApplicationPaths.InternalMetadataPath,
CachePath = ApplicationPaths.CachePath, CachePath = ApplicationPaths.CachePath,
MacAddress = GetMacAddress(), MacAddress = GetMacAddress(),
HttpServerPortNumber = HttpServerPort, HttpServerPortNumber = HttpPort,
UseHttps = this.ServerConfigurationManager.Configuration.UseHttps, EnableHttps = EnableHttps,
HttpsPortNumber = HttpsServerPort, HttpsPortNumber = HttpsPort,
OperatingSystem = OperatingSystemDisplayName, OperatingSystem = OperatingSystemDisplayName,
CanSelfRestart = CanSelfRestart, CanSelfRestart = CanSelfRestart,
CanSelfUpdate = CanSelfUpdate, CanSelfUpdate = CanSelfUpdate,
@ -981,6 +980,19 @@ namespace MediaBrowser.Server.Startup.Common
}; };
} }
public bool EnableHttps
{
get
{
return SupportsHttps && ServerConfigurationManager.Configuration.EnableHttps;
}
}
public bool SupportsHttps
{
get { return !string.IsNullOrWhiteSpace(HttpServer.CertificatePath); }
}
/// <summary> /// <summary>
/// Gets the local ip address. /// Gets the local ip address.
/// </summary> /// </summary>
@ -994,7 +1006,7 @@ namespace MediaBrowser.Server.Startup.Common
{ {
address = string.Format("http://{0}:{1}", address = string.Format("http://{0}:{1}",
address, address,
ServerConfigurationManager.Configuration.HttpServerPortNumber.ToString(CultureInfo.InvariantCulture)); HttpPort.ToString(CultureInfo.InvariantCulture));
} }
return address; return address;
@ -1036,15 +1048,9 @@ namespace MediaBrowser.Server.Startup.Common
} }
} }
public int HttpServerPort public int HttpPort { get; private set; }
{
get { return ServerConfigurationManager.Configuration.HttpServerPortNumber; }
}
public int HttpsServerPort public int HttpsPort { get; private set; }
{
get { return ServerConfigurationManager.Configuration.HttpsPortNumber; }
}
/// <summary> /// <summary>
/// Gets the mac address. /// Gets the mac address.

View File

@ -18,7 +18,7 @@ namespace MediaBrowser.Server.Startup.Common.Browser
/// <param name="logger">The logger.</param> /// <param name="logger">The logger.</param>
public static void OpenDashboardPage(string page, IServerApplicationHost appHost, ILogger logger) public static void OpenDashboardPage(string page, IServerApplicationHost appHost, ILogger logger)
{ {
var url = "http://localhost:" + appHost.HttpServerPort + "/web/" + page; var url = "http://localhost:" + appHost.HttpPort + "/web/" + page;
OpenUrl(url, logger); OpenUrl(url, logger);
} }
@ -68,7 +68,7 @@ namespace MediaBrowser.Server.Startup.Common.Browser
/// <param name="logger">The logger.</param> /// <param name="logger">The logger.</param>
public static void OpenSwagger(IServerApplicationHost appHost, ILogger logger) public static void OpenSwagger(IServerApplicationHost appHost, ILogger logger)
{ {
OpenUrl("http://localhost:" + appHost.HttpServerPort + "/swagger-ui/index.html", logger); OpenUrl("http://localhost:" + appHost.HttpPort + "/swagger-ui/index.html", logger);
} }
/// <summary> /// <summary>

View File

@ -213,7 +213,6 @@ namespace MediaBrowser.ServerApplication
options, options,
fileSystem, fileSystem,
"MBServer", "MBServer",
true,
nativeApp); nativeApp);
var initProgress = new Progress<double>(); var initProgress = new Progress<double>();

View File

@ -381,6 +381,7 @@ namespace MediaBrowser.WebDashboard.Api
"channelsettings.js", "channelsettings.js",
"connectlogin.js", "connectlogin.js",
"dashboardgeneral.js", "dashboardgeneral.js",
"dashboardhosting.js",
"dashboardpage.js", "dashboardpage.js",
"device.js", "device.js",
"devices.js", "devices.js",

View File

@ -96,6 +96,9 @@
<Content Include="dashboard-ui\css\images\tour\dashboard\help.png"> <Content Include="dashboard-ui\css\images\tour\dashboard\help.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="dashboard-ui\dashboardhosting.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\forgotpasswordpin.html"> <Content Include="dashboard-ui\forgotpasswordpin.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
@ -105,6 +108,9 @@
<Content Include="dashboard-ui\mysyncjob.html"> <Content Include="dashboard-ui\mysyncjob.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="dashboard-ui\scripts\dashboardhosting.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\scripts\forgotpassword.js"> <Content Include="dashboard-ui\scripts\forgotpassword.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>