From 6e42398f9ece91358fc52a822e07e6bc9a0e0640 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 15 Jan 2017 16:29:00 -0500 Subject: [PATCH 1/3] update video osd --- Emby.Server.Implementations/Dto/DtoService.cs | 3 +- Mono.Nat/Pmp/PmpNatDevice.cs | 84 ++++++++++--------- 2 files changed, 48 insertions(+), 39 deletions(-) diff --git a/Emby.Server.Implementations/Dto/DtoService.cs b/Emby.Server.Implementations/Dto/DtoService.cs index 06ac7031a..f866c34de 100644 --- a/Emby.Server.Implementations/Dto/DtoService.cs +++ b/Emby.Server.Implementations/Dto/DtoService.cs @@ -1512,7 +1512,8 @@ namespace Emby.Server.Implementations.Dto return artist; } } - return item.GetParent(); + + return item.DisplayParent ?? item.GetParent(); } private void AddInheritedImages(BaseItemDto dto, BaseItem item, DtoOptions options, BaseItem owner) diff --git a/Mono.Nat/Pmp/PmpNatDevice.cs b/Mono.Nat/Pmp/PmpNatDevice.cs index 93007cb8a..10ebbdc2c 100644 --- a/Mono.Nat/Pmp/PmpNatDevice.cs +++ b/Mono.Nat/Pmp/PmpNatDevice.cs @@ -136,34 +136,36 @@ namespace Mono.Nat.Pmp { while (!cancellationToken.IsCancellationRequested) { - var result = await udpClient.ReceiveAsync().ConfigureAwait(false); - var endPoint = result.RemoteEndPoint; - byte[] data = data = result.Buffer; - - if (data.Length < 16) - continue; - - if (data[0] != PmpConstants.Version) - continue; - - var opCode = (byte)(data[1] & 127); - - var protocol = Protocol.Tcp; - if (opCode == PmpConstants.OperationCodeUdp) - protocol = Protocol.Udp; - - short resultCode = IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, 2)); - int epoch = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(data, 4)); - - short privatePort = IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, 8)); - short publicPort = IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, 10)); - - var lifetime = (uint)IPAddress.NetworkToHostOrder(BitConverter.ToInt32(data, 12)); - - if (privatePort < 0 || publicPort < 0 || resultCode != PmpConstants.ResultCodeSuccess) + try { - var errors = new[] - { + var result = await udpClient.ReceiveAsync().ConfigureAwait(false); + var endPoint = result.RemoteEndPoint; + byte[] data = data = result.Buffer; + + if (data.Length < 16) + continue; + + if (data[0] != PmpConstants.Version) + continue; + + var opCode = (byte)(data[1] & 127); + + var protocol = Protocol.Tcp; + if (opCode == PmpConstants.OperationCodeUdp) + protocol = Protocol.Udp; + + short resultCode = IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, 2)); + int epoch = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(data, 4)); + + short privatePort = IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, 8)); + short publicPort = IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, 10)); + + var lifetime = (uint)IPAddress.NetworkToHostOrder(BitConverter.ToInt32(data, 12)); + + if (privatePort < 0 || publicPort < 0 || resultCode != PmpConstants.ResultCodeSuccess) + { + var errors = new[] + { "Success", "Unsupported Version", "Not Authorized/Refused (e.g. box supports mapping, but user has turned feature off)" @@ -173,19 +175,25 @@ namespace Mono.Nat.Pmp "Unsupported opcode" }; - var errorMsg = errors[resultCode]; - NatUtility.Log("Error in CreatePortMapListen: " + errorMsg); + var errorMsg = errors[resultCode]; + NatUtility.Log("Error in CreatePortMapListen: " + errorMsg); + return; + } + + if (lifetime == 0) return; //mapping was deleted + + //mapping was created + //TODO: verify that the private port+protocol are a match + mapping.PublicPort = publicPort; + mapping.Protocol = protocol; + mapping.Expiration = DateTime.Now.AddSeconds(lifetime); + return; + } + catch (Exception ex) + { + NatUtility.Logger.ErrorException("Error in CreatePortMapListen", ex); return; } - - if (lifetime == 0) return; //mapping was deleted - - //mapping was created - //TODO: verify that the private port+protocol are a match - mapping.PublicPort = publicPort; - mapping.Protocol = protocol; - mapping.Expiration = DateTime.Now.AddSeconds(lifetime); - return; } } From c47b602499ee642258526526e748e12b096d449b Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 15 Jan 2017 17:52:59 -0500 Subject: [PATCH 2/3] handle users logging in locally with Emby Connect --- .../Connect/ConnectManager.cs | 3 +- .../Library/UserManager.cs | 60 +++++++++++++++---- .../Connect/IConnectManager.cs | 2 +- 3 files changed, 50 insertions(+), 15 deletions(-) diff --git a/Emby.Server.Implementations/Connect/ConnectManager.cs b/Emby.Server.Implementations/Connect/ConnectManager.cs index 23fafed15..7e6755f6a 100644 --- a/Emby.Server.Implementations/Connect/ConnectManager.cs +++ b/Emby.Server.Implementations/Connect/ConnectManager.cs @@ -1122,7 +1122,7 @@ namespace Emby.Server.Implementations.Connect } } - public async Task Authenticate(string username, string passwordMd5) + public async Task Authenticate(string username, string passwordMd5) { if (string.IsNullOrWhiteSpace(username)) { @@ -1151,6 +1151,7 @@ namespace Emby.Server.Implementations.Connect // No need to examine the response using (var response = (await _httpClient.SendAsync(options, "POST").ConfigureAwait(false)).Content) { + return _json.DeserializeFromStream(response); } } diff --git a/Emby.Server.Implementations/Library/UserManager.cs b/Emby.Server.Implementations/Library/UserManager.cs index 2a5706b3b..eb0d0cf9b 100644 --- a/Emby.Server.Implementations/Library/UserManager.cs +++ b/Emby.Server.Implementations/Library/UserManager.cs @@ -236,6 +236,53 @@ namespace Emby.Server.Implementations.Library var user = Users .FirstOrDefault(i => string.Equals(username, i.Name, StringComparison.OrdinalIgnoreCase)); + var success = false; + + if (user != null) + { + // Authenticate using local credentials if not a guest + if (!user.ConnectLinkType.HasValue || user.ConnectLinkType.Value != UserLinkType.Guest) + { + success = string.Equals(GetPasswordHash(user), passwordSha1.Replace("-", string.Empty), StringComparison.OrdinalIgnoreCase); + + if (!success && _networkManager.IsInLocalNetwork(remoteEndPoint) && user.Configuration.EnableLocalPassword) + { + success = string.Equals(GetLocalPasswordHash(user), passwordSha1.Replace("-", string.Empty), StringComparison.OrdinalIgnoreCase); + } + } + + // Maybe user accidently entered connect credentials. let's be flexible + if (!success && user.ConnectLinkType.HasValue && !string.IsNullOrWhiteSpace(passwordMd5) && !string.IsNullOrWhiteSpace(user.ConnectUserName)) + { + try + { + await _connectFactory().Authenticate(user.ConnectUserName, passwordMd5).ConfigureAwait(false); + success = true; + } + catch + { + + } + } + } + + // Try originally entered username + if (!success && (user == null || !string.Equals(user.ConnectUserName, username, StringComparison.OrdinalIgnoreCase))) + { + try + { + var connectAuthResult = await _connectFactory().Authenticate(username, passwordMd5).ConfigureAwait(false); + + user = Users.FirstOrDefault(i => string.Equals(i.ConnectUserId, connectAuthResult.User.Id, StringComparison.OrdinalIgnoreCase)); + + success = user != null; + } + catch + { + + } + } + if (user == null) { throw new SecurityException("Invalid username or password entered."); @@ -246,19 +293,6 @@ namespace Emby.Server.Implementations.Library throw new SecurityException(string.Format("The {0} account is currently disabled. Please consult with your administrator.", user.Name)); } - var success = false; - - // Authenticate using local credentials if not a guest - if (!user.ConnectLinkType.HasValue || user.ConnectLinkType.Value != UserLinkType.Guest) - { - success = string.Equals(GetPasswordHash(user), passwordSha1.Replace("-", string.Empty), StringComparison.OrdinalIgnoreCase); - - if (!success && _networkManager.IsInLocalNetwork(remoteEndPoint) && user.Configuration.EnableLocalPassword) - { - success = string.Equals(GetLocalPasswordHash(user), passwordSha1.Replace("-", string.Empty), StringComparison.OrdinalIgnoreCase); - } - } - // Update LastActivityDate and LastLoginDate, then save if (success) { diff --git a/MediaBrowser.Controller/Connect/IConnectManager.cs b/MediaBrowser.Controller/Connect/IConnectManager.cs index e004eaccf..f899c7262 100644 --- a/MediaBrowser.Controller/Connect/IConnectManager.cs +++ b/MediaBrowser.Controller/Connect/IConnectManager.cs @@ -61,7 +61,7 @@ namespace MediaBrowser.Controller.Connect /// The username. /// The password MD5. /// Task. - Task Authenticate(string username, string passwordMd5); + Task Authenticate(string username, string passwordMd5); /// /// Gets the local user. From 45da5c64b150b0da74b7c265f0ccb5508b25823f Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 15 Jan 2017 17:53:24 -0500 Subject: [PATCH 3/3] fix folders affecting album resolver --- .../Library/Resolvers/Audio/MusicAlbumResolver.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Emby.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs b/Emby.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs index 871b2d46d..b3d6d4ad7 100644 --- a/Emby.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs +++ b/Emby.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs @@ -142,12 +142,14 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio } } } - - var fullName = fileSystemInfo.FullName; - - if (libraryManager.IsAudioFile(fullName, libraryOptions)) + else { - return true; + var fullName = fileSystemInfo.FullName; + + if (libraryManager.IsAudioFile(fullName, libraryOptions)) + { + return true; + } } }