From 164cea3fb41626191d3dddffea95d5485b3e163f Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 21 Sep 2017 16:54:42 -0400 Subject: refresh users on startup --- Emby.Server.Implementations/EntryPoints/RefreshUsersMetadata.cs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Emby.Server.Implementations/EntryPoints') diff --git a/Emby.Server.Implementations/EntryPoints/RefreshUsersMetadata.cs b/Emby.Server.Implementations/EntryPoints/RefreshUsersMetadata.cs index 4c16b1d39..6f346c2e0 100644 --- a/Emby.Server.Implementations/EntryPoints/RefreshUsersMetadata.cs +++ b/Emby.Server.Implementations/EntryPoints/RefreshUsersMetadata.cs @@ -67,6 +67,10 @@ namespace Emby.Server.Implementations.EntryPoints { IntervalTicks = TimeSpan.FromDays(1).Ticks, Type = TaskTriggerInfo.TriggerInterval + }, + new TaskTriggerInfo + { + Type = TaskTriggerInfo.TriggerStartup } }; } -- cgit v1.2.3 From b4851d4789be94796b7bf964d5dba26bd2d82388 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 21 Sep 2017 17:36:19 -0400 Subject: separate deinterlacing params by video codec --- Emby.Server.Implementations/ApplicationHost.cs | 2 +- Emby.Server.Implementations/Dto/DtoService.cs | 2 +- .../EntryPoints/RefreshUsersMetadata.cs | 4 - .../MediaEncoding/EncodingHelper.cs | 10 +-- .../MediaEncoding/EncodingJobInfo.cs | 45 ++++++++++- .../MediaEncoding/EncodingJobOptions.cs | 33 ++++++++- MediaBrowser.Model/Dlna/StreamBuilder.cs | 86 +++++++++++++++++++--- MediaBrowser.Model/Dlna/StreamInfo.cs | 68 +++++++++++++++-- SharedVersion.cs | 2 +- 9 files changed, 217 insertions(+), 35 deletions(-) (limited to 'Emby.Server.Implementations/EntryPoints') diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 713ece421..47b969eca 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -2208,7 +2208,7 @@ namespace Emby.Server.Implementations { var updateLevel = SystemUpdateLevel; var cacheLength = updateLevel == PackageVersionClass.Release ? - TimeSpan.FromHours(4) : + TimeSpan.FromHours(12) : TimeSpan.FromMinutes(5); var result = await new GithubUpdater(HttpClient, JsonSerializer).CheckForUpdateResult("MediaBrowser", diff --git a/Emby.Server.Implementations/Dto/DtoService.cs b/Emby.Server.Implementations/Dto/DtoService.cs index c5fcc0e4c..1854829a2 100644 --- a/Emby.Server.Implementations/Dto/DtoService.cs +++ b/Emby.Server.Implementations/Dto/DtoService.cs @@ -571,7 +571,7 @@ namespace Emby.Server.Implementations.Dto } } - if (!(item is LiveTvProgram) || fields.Contains(ItemFields.PlayAccess)) + if (/*!(item is LiveTvProgram) ||*/ fields.Contains(ItemFields.PlayAccess)) { dto.PlayAccess = item.GetPlayAccess(user); } diff --git a/Emby.Server.Implementations/EntryPoints/RefreshUsersMetadata.cs b/Emby.Server.Implementations/EntryPoints/RefreshUsersMetadata.cs index 6f346c2e0..4c16b1d39 100644 --- a/Emby.Server.Implementations/EntryPoints/RefreshUsersMetadata.cs +++ b/Emby.Server.Implementations/EntryPoints/RefreshUsersMetadata.cs @@ -67,10 +67,6 @@ namespace Emby.Server.Implementations.EntryPoints { IntervalTicks = TimeSpan.FromDays(1).Ticks, Type = TaskTriggerInfo.TriggerInterval - }, - new TaskTriggerInfo - { - Type = TaskTriggerInfo.TriggerStartup } }; } diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs index 657b9c959..642a42c8e 100644 --- a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs +++ b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs @@ -796,12 +796,13 @@ namespace MediaBrowser.Controller.MediaEncoding if (videoStream.IsInterlaced) { - if (request.DeInterlace) + if (state.DeInterlace(videoStream.Codec)) { return false; } } + if (videoStream.IsAnamorphic ?? false) { if (request.RequireNonAnamorphic) @@ -1357,7 +1358,7 @@ namespace MediaBrowser.Controller.MediaEncoding filters.Add("hwupload"); } - if (state.DeInterlace && !string.Equals(outputVideoCodec, "h264_vaapi", StringComparison.OrdinalIgnoreCase)) + if (state.DeInterlace("h264") && !string.Equals(outputVideoCodec, "h264_vaapi", StringComparison.OrdinalIgnoreCase)) { if (string.Equals(options.DeinterlaceMethod, "bobandweave", StringComparison.OrdinalIgnoreCase)) { @@ -1799,11 +1800,6 @@ namespace MediaBrowser.Controller.MediaEncoding state.InternalSubtitleStreamOffset = mediaStreams.Where(i => i.Type == MediaStreamType.Subtitle && !i.IsExternal).ToList().IndexOf(state.SubtitleStream); } - if (state.VideoStream != null && state.VideoStream.IsInterlaced) - { - state.DeInterlace = true; - } - EnforceResolutionLimit(state); NormalizeSubtitleEmbed(state); diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingJobInfo.cs b/MediaBrowser.Controller/MediaEncoding/EncodingJobInfo.cs index e76217fda..fb8aa9767 100644 --- a/MediaBrowser.Controller/MediaEncoding/EncodingJobInfo.cs +++ b/MediaBrowser.Controller/MediaEncoding/EncodingJobInfo.cs @@ -160,7 +160,26 @@ namespace MediaBrowser.Controller.MediaEncoding public int? OutputAudioBitrate; public int? OutputAudioChannels; - public bool DeInterlace { get; set; } + + public bool DeInterlace(string videoCodec) + { + // Support general param + if (BaseRequest.DeInterlace) + { + return true; + } + + if (!string.IsNullOrWhiteSpace(videoCodec)) + { + if (string.Equals(BaseRequest.GetOption(videoCodec, "deinterlace"), "true", StringComparison.OrdinalIgnoreCase)) + { + return true; + } + } + + return false; + } + public bool IsVideoRequest { get; set; } public TranscodingJobType TranscodingType { get; set; } @@ -435,6 +454,28 @@ namespace MediaBrowser.Controller.MediaEncoding } } + public string ActualOutputVideoCodec + { + get + { + var codec = OutputVideoCodec; + + if (string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase)) + { + var stream = VideoStream; + + if (stream != null) + { + return stream.Codec; + } + + return null; + } + + return codec; + } + } + public bool? IsTargetInterlaced { get @@ -444,7 +485,7 @@ namespace MediaBrowser.Controller.MediaEncoding return VideoStream == null ? (bool?)null : VideoStream.IsInterlaced; } - if (DeInterlace) + if (DeInterlace(ActualOutputVideoCodec)) { return false; } diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingJobOptions.cs b/MediaBrowser.Controller/MediaEncoding/EncodingJobOptions.cs index 5fc93bf38..cb675ba68 100644 --- a/MediaBrowser.Controller/MediaEncoding/EncodingJobOptions.cs +++ b/MediaBrowser.Controller/MediaEncoding/EncodingJobOptions.cs @@ -1,4 +1,6 @@ -using System.Globalization; +using System; +using System.Collections.Generic; +using System.Globalization; using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Services; @@ -224,12 +226,41 @@ namespace MediaBrowser.Controller.MediaEncoding public EncodingContext Context { get; set; } + public void SetOption(string qualifier, string name, string value) + { + SetOption(qualifier + "-" + name, value); + } + + public Dictionary StreamOptions { get; private set; } + + public void SetOption(string name, string value) + { + StreamOptions[name] = value; + } + + public string GetOption(string qualifier, string name) + { + return GetOption(qualifier + "-" + name); + } + + public string GetOption(string name) + { + string value; + if (StreamOptions.TryGetValue(name, out value)) + { + return value; + } + + return null; + } + public BaseEncodingJobOptions() { EnableAutoStreamCopy = true; AllowVideoStreamCopy = true; AllowAudioStreamCopy = true; Context = EncodingContext.Streaming; + StreamOptions = new Dictionary(StringComparer.OrdinalIgnoreCase); } } } diff --git a/MediaBrowser.Model/Dlna/StreamBuilder.cs b/MediaBrowser.Model/Dlna/StreamBuilder.cs index a5ec0f26c..130b4c08e 100644 --- a/MediaBrowser.Model/Dlna/StreamBuilder.cs +++ b/MediaBrowser.Model/Dlna/StreamBuilder.cs @@ -406,7 +406,7 @@ namespace MediaBrowser.Model.Dlna } } - ApplyTranscodingConditions(playlistItem, audioTranscodingConditions); + ApplyTranscodingConditions(playlistItem, audioTranscodingConditions, null, false); // Honor requested max channels if (options.MaxAudioChannels.HasValue) @@ -769,7 +769,7 @@ namespace MediaBrowser.Model.Dlna playlistItem.AudioStreamIndex = audioStreamIndex; ConditionProcessor conditionProcessor = new ConditionProcessor(); - var videoTranscodingConditions = new List(); + var isFirstAppliedCodecProfile = true; foreach (CodecProfile i in options.Profile.CodecProfiles) { if (i.Type == CodecType.Video && i.ContainsCodec(transcodingProfile.VideoCodec, transcodingProfile.Container)) @@ -786,7 +786,7 @@ namespace MediaBrowser.Model.Dlna if (!conditionProcessor.IsVideoAudioConditionSatisfied(applyCondition, audioChannels, inputAudioBitrate, inputAudioSampleRate, inputAudioBitDepth, audioProfile, isSecondaryAudio)) { - LogConditionFailure(options.Profile, "AudioCodecProfile", applyCondition, item); + LogConditionFailure(options.Profile, "VideoAudioCodecProfile", applyCondition, item); applyConditions = false; break; } @@ -794,15 +794,14 @@ namespace MediaBrowser.Model.Dlna if (applyConditions) { - foreach (ProfileCondition c in i.Conditions) + foreach (var transcodingVideoCodec in ContainerProfile.SplitValue(transcodingProfile.VideoCodec)) { - videoTranscodingConditions.Add(c); + ApplyTranscodingConditions(playlistItem, i.Conditions, transcodingVideoCodec, !isFirstAppliedCodecProfile); + isFirstAppliedCodecProfile = false; } - break; } } } - ApplyTranscodingConditions(playlistItem, videoTranscodingConditions); var audioTranscodingConditions = new List(); foreach (CodecProfile i in options.Profile.CodecProfiles) @@ -878,7 +877,7 @@ namespace MediaBrowser.Model.Dlna } // Do this after initial values are set to account for greater than/less than conditions - ApplyTranscodingConditions(playlistItem, audioTranscodingConditions); + ApplyTranscodingConditions(playlistItem, audioTranscodingConditions, null, false); } playlistItem.TranscodeReasons = transcodeReasons; @@ -1407,7 +1406,7 @@ namespace MediaBrowser.Model.Dlna } } - private void ApplyTranscodingConditions(StreamInfo item, IEnumerable conditions) + private void ApplyTranscodingConditions(StreamInfo item, IEnumerable conditions, string qualifier, bool qualifiedOnly) { foreach (ProfileCondition condition in conditions) { @@ -1428,6 +1427,11 @@ namespace MediaBrowser.Model.Dlna { case ProfileConditionValue.AudioBitrate: { + if (qualifiedOnly) + { + continue; + } + int num; if (int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out num)) { @@ -1448,6 +1452,11 @@ namespace MediaBrowser.Model.Dlna } case ProfileConditionValue.AudioChannels: { + if (qualifiedOnly) + { + continue; + } + int num; if (int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out num)) { @@ -1468,6 +1477,11 @@ namespace MediaBrowser.Model.Dlna } case ProfileConditionValue.IsAvc: { + if (qualifiedOnly) + { + continue; + } + bool isAvc; if (bool.TryParse(value, out isAvc)) { @@ -1484,6 +1498,11 @@ namespace MediaBrowser.Model.Dlna } case ProfileConditionValue.IsAnamorphic: { + if (qualifiedOnly) + { + continue; + } + bool isAnamorphic; if (bool.TryParse(value, out isAnamorphic)) { @@ -1500,16 +1519,21 @@ namespace MediaBrowser.Model.Dlna } case ProfileConditionValue.IsInterlaced: { + if (string.IsNullOrWhiteSpace(qualifier)) + { + continue; + } + bool isInterlaced; if (bool.TryParse(value, out isInterlaced)) { if (!isInterlaced && condition.Condition == ProfileConditionType.Equals) { - item.DeInterlace = true; + item.SetOption(qualifier, "deinterlace", "true"); } else if (isInterlaced && condition.Condition == ProfileConditionType.NotEquals) { - item.DeInterlace = true; + item.SetOption(qualifier, "deinterlace", "true"); } } break; @@ -1527,6 +1551,11 @@ namespace MediaBrowser.Model.Dlna } case ProfileConditionValue.RefFrames: { + if (qualifiedOnly) + { + continue; + } + int num; if (int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out num)) { @@ -1547,6 +1576,11 @@ namespace MediaBrowser.Model.Dlna } case ProfileConditionValue.VideoBitDepth: { + if (qualifiedOnly) + { + continue; + } + int num; if (int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out num)) { @@ -1567,11 +1601,21 @@ namespace MediaBrowser.Model.Dlna } case ProfileConditionValue.VideoProfile: { + if (qualifiedOnly) + { + continue; + } + item.VideoProfile = (value ?? string.Empty).Split('|')[0]; break; } case ProfileConditionValue.Height: { + if (qualifiedOnly) + { + continue; + } + int num; if (int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out num)) { @@ -1592,6 +1636,11 @@ namespace MediaBrowser.Model.Dlna } case ProfileConditionValue.VideoBitrate: { + if (qualifiedOnly) + { + continue; + } + int num; if (int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out num)) { @@ -1612,6 +1661,11 @@ namespace MediaBrowser.Model.Dlna } case ProfileConditionValue.VideoFramerate: { + if (qualifiedOnly) + { + continue; + } + float num; if (float.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out num)) { @@ -1632,6 +1686,11 @@ namespace MediaBrowser.Model.Dlna } case ProfileConditionValue.VideoLevel: { + if (qualifiedOnly) + { + continue; + } + int num; if (int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out num)) { @@ -1652,6 +1711,11 @@ namespace MediaBrowser.Model.Dlna } case ProfileConditionValue.Width: { + if (qualifiedOnly) + { + continue; + } + int num; if (int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out num)) { diff --git a/MediaBrowser.Model/Dlna/StreamInfo.cs b/MediaBrowser.Model/Dlna/StreamInfo.cs index c63e74eaf..3e7ff9c3d 100644 --- a/MediaBrowser.Model/Dlna/StreamInfo.cs +++ b/MediaBrowser.Model/Dlna/StreamInfo.cs @@ -22,6 +22,33 @@ namespace MediaBrowser.Model.Dlna VideoCodecs = new string[] { }; SubtitleCodecs = new string[] { }; TranscodeReasons = new List(); + StreamOptions = new Dictionary(StringComparer.OrdinalIgnoreCase); + } + + public void SetOption(string qualifier, string name, string value) + { + SetOption(qualifier + "-" + name, value); + } + + public void SetOption(string name, string value) + { + StreamOptions[name] = value; + } + + public string GetOption(string qualifier, string name) + { + return GetOption(qualifier + "-" + name); + } + + public string GetOption(string name) + { + string value; + if (StreamOptions.TryGetValue(name, out value)) + { + return value; + } + + return null; } public string ItemId { get; set; } @@ -44,7 +71,6 @@ namespace MediaBrowser.Model.Dlna public bool BreakOnNonKeyFrames { get; set; } public bool RequireAvc { get; set; } - public bool DeInterlace { get; set; } public bool RequireNonAnamorphic { get; set; } public bool CopyTimestamps { get; set; } public bool EnableSubtitlesInManifest { get; set; } @@ -92,6 +118,8 @@ namespace MediaBrowser.Model.Dlna public List AllMediaSources { get; set; } public List TranscodeReasons { get; set; } + public Dictionary StreamOptions { get; private set; } + public string MediaSourceId { get @@ -282,7 +310,16 @@ namespace MediaBrowser.Model.Dlna list.Add(new NameValuePair("SubtitleCodec", item.SubtitleStreamIndex.HasValue && item.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Embed ? subtitleCodecs : string.Empty)); list.Add(new NameValuePair("RequireNonAnamorphic", item.RequireNonAnamorphic.ToString().ToLower())); - list.Add(new NameValuePair("DeInterlace", item.DeInterlace.ToString().ToLower())); + + if (isDlna) + { + // hack alert + // dlna needs to be update to support the qualified params + var deinterlace = string.Equals(item.GetOption("h264", "deinterlace"), "true", StringComparison.OrdinalIgnoreCase) || + string.Equals(item.GetOption("mpeg2video", "deinterlace"), "true", StringComparison.OrdinalIgnoreCase); + + list.Add(new NameValuePair("DeInterlace", deinterlace.ToString().ToLower())); + } if (!isDlna && isHls) { @@ -306,6 +343,19 @@ namespace MediaBrowser.Model.Dlna list.Add(new NameValuePair("TranscodeReasons", string.Join(",", item.TranscodeReasons.Distinct().Select(i => i.ToString()).ToArray()))); } + if (!isDlna) + { + foreach (var pair in item.StreamOptions) + { + if (string.IsNullOrWhiteSpace(pair.Value)) + { + continue; + } + + list.Add(new NameValuePair(pair.Key, pair.Value)); + } + } + return list; } @@ -675,10 +725,10 @@ namespace MediaBrowser.Model.Dlna return VideoCodecs.Length == 0 ? null : VideoCodecs[0]; } } - + /// - /// Predicts the audio channels that will be in the output stream - /// + /// Predicts the audio channels that will be in the output stream + /// public long? TargetSize { get @@ -763,9 +813,13 @@ namespace MediaBrowser.Model.Dlna return TargetVideoStream == null ? (bool?)null : TargetVideoStream.IsInterlaced; } - if (DeInterlace) + var videoCodec = TargetVideoCodec; + if (!string.IsNullOrWhiteSpace(videoCodec)) { - return false; + if (string.Equals(GetOption(videoCodec, "deinterlace"), "true", StringComparison.OrdinalIgnoreCase)) + { + return false; + } } return TargetVideoStream == null ? (bool?)null : TargetVideoStream.IsInterlaced; diff --git a/SharedVersion.cs b/SharedVersion.cs index d2828ea18..c2e8ba905 100644 --- a/SharedVersion.cs +++ b/SharedVersion.cs @@ -1,3 +1,3 @@ using System.Reflection; -[assembly: AssemblyVersion("3.2.31")] +[assembly: AssemblyVersion("3.2.31.1")] -- cgit v1.2.3 From 64d85e4c3337adf6ca3fe66dac66a2b241d94c18 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 25 Sep 2017 15:13:34 -0400 Subject: remove unused data --- Emby.Server.Implementations/EntryPoints/UsageEntryPoint.cs | 4 ++-- Emby.Server.Implementations/EntryPoints/UsageReporter.cs | 10 +--------- 2 files changed, 3 insertions(+), 11 deletions(-) (limited to 'Emby.Server.Implementations/EntryPoints') diff --git a/Emby.Server.Implementations/EntryPoints/UsageEntryPoint.cs b/Emby.Server.Implementations/EntryPoints/UsageEntryPoint.cs index fb9402986..11e806b0c 100644 --- a/Emby.Server.Implementations/EntryPoints/UsageEntryPoint.cs +++ b/Emby.Server.Implementations/EntryPoints/UsageEntryPoint.cs @@ -74,7 +74,7 @@ namespace Emby.Server.Implementations.EntryPoints try { - await new UsageReporter(_applicationHost, _httpClient, _userManager, _logger) + await new UsageReporter(_applicationHost, _httpClient, _logger) .ReportAppUsage(client, CancellationToken.None) .ConfigureAwait(false); } @@ -117,7 +117,7 @@ namespace Emby.Server.Implementations.EntryPoints try { - await new UsageReporter(_applicationHost, _httpClient, _userManager, _logger) + await new UsageReporter(_applicationHost, _httpClient, _logger) .ReportServerUsage(CancellationToken.None) .ConfigureAwait(false); } diff --git a/Emby.Server.Implementations/EntryPoints/UsageReporter.cs b/Emby.Server.Implementations/EntryPoints/UsageReporter.cs index 778c8a6ce..deee8d64b 100644 --- a/Emby.Server.Implementations/EntryPoints/UsageReporter.cs +++ b/Emby.Server.Implementations/EntryPoints/UsageReporter.cs @@ -17,15 +17,13 @@ namespace Emby.Server.Implementations.EntryPoints { private readonly IServerApplicationHost _applicationHost; private readonly IHttpClient _httpClient; - private readonly IUserManager _userManager; private readonly ILogger _logger; private const string MbAdminUrl = "https://www.mb3admin.com/admin/"; - public UsageReporter(IServerApplicationHost applicationHost, IHttpClient httpClient, IUserManager userManager, ILogger logger) + public UsageReporter(IServerApplicationHost applicationHost, IHttpClient httpClient, ILogger logger) { _applicationHost = applicationHost; _httpClient = httpClient; - _userManager = userManager; _logger = logger; } @@ -43,12 +41,6 @@ namespace Emby.Server.Implementations.EntryPoints { "platform", _applicationHost.OperatingSystemDisplayName } }; - var users = _userManager.Users.ToList(); - - data["localusers"] = users.Count(i => !i.ConnectLinkType.HasValue).ToString(CultureInfo.InvariantCulture); - data["guests"] = users.Count(i => i.ConnectLinkType.HasValue && i.ConnectLinkType.Value == UserLinkType.Guest).ToString(CultureInfo.InvariantCulture); - data["linkedusers"] = users.Count(i => i.ConnectLinkType.HasValue && i.ConnectLinkType.Value == UserLinkType.LinkedUser).ToString(CultureInfo.InvariantCulture); - data["plugins"] = string.Join(",", _applicationHost.Plugins.Select(i => i.Id).ToArray()); var logErrors = false; -- cgit v1.2.3 From 878abbddda4da46811d8709ec90248b9c1b5f569 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 29 Sep 2017 15:17:54 -0400 Subject: fixes #1427 - [Feature Request]: Require Encryption --- Emby.Server.Implementations/ApplicationHost.cs | 4 ++-- .../EntryPoints/ExternalPortForwarding.cs | 2 +- .../HttpServer/HttpListenerHost.cs | 19 +++++++++++++++++++ .../Configuration/ServerConfiguration.cs | 2 ++ 4 files changed, 24 insertions(+), 3 deletions(-) (limited to 'Emby.Server.Implementations/EntryPoints') diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 699621043..57c509923 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1931,13 +1931,13 @@ namespace Emby.Server.Implementations { get { - return SupportsHttps && ServerConfigurationManager.Configuration.EnableHttps; + return SupportsHttps && (ServerConfigurationManager.Configuration.EnableHttps || ServerConfigurationManager.Configuration.RequireHttps); } } public bool SupportsHttps { - get { return Certificate != null; } + get { return Certificate != null || ServerConfigurationManager.Configuration.IsBehindProxy; } } public async Task GetLocalApiUrl() diff --git a/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs b/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs index 9b434d606..2cef46839 100644 --- a/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs +++ b/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs @@ -48,7 +48,7 @@ namespace Emby.Server.Implementations.EntryPoints 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((config.EnableHttps || config.RequireHttps).ToString()); values.Add(_appHost.EnableHttps.ToString()); return string.Join("|", values.ToArray(values.Count)); diff --git a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs index 031d1d90b..acc247e45 100644 --- a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -423,6 +423,19 @@ namespace Emby.Server.Implementations.HttpServer return true; } + private bool ValidateSsl(string remoteIp) + { + if (_config.Configuration.RequireHttps && _appHost.EnableHttps) + { + if (!_networkManager.IsInLocalNetwork(remoteIp)) + { + return false; + } + } + + return true; + } + /// /// Overridable method that can be used to implement a custom hnandler /// @@ -453,6 +466,12 @@ namespace Emby.Server.Implementations.HttpServer return; } + if (!ValidateSsl(httpReq.RemoteIp)) + { + RedirectToUrl(httpRes, urlString.Replace("http://", "https://", StringComparison.OrdinalIgnoreCase)); + return; + } + if (string.Equals(httpReq.Verb, "OPTIONS", StringComparison.OrdinalIgnoreCase)) { httpRes.StatusCode = 200; diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index 7c7358845..f7fffbf79 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -181,6 +181,8 @@ namespace MediaBrowser.Model.Configuration public string[] CodecsUsed { get; set; } public bool EnableChannelView { get; set; } public bool EnableExternalContentInSuggestions { get; set; } + public bool RequireHttps { get; set; } + public bool IsBehindProxy { get; set; } public int ImageExtractionTimeoutMs { get; set; } -- cgit v1.2.3