From 414a318a0d422a893401d1ecf84526043df36210 Mon Sep 17 00:00:00 2001 From: Phlogi Date: Sun, 24 Mar 2019 11:59:40 +0100 Subject: [PATCH 01/20] WAN Address should use public ports instead of local ports. https://github.com/jellyfin/jellyfin/issues/601#issuecomment-475941080 --- .../ApplicationHost.cs | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 484942946..5f4c30f0f 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1476,7 +1476,7 @@ namespace Emby.Server.Implementations CancellationToken = cancellationToken }).ConfigureAwait(false)) { - return GetLocalApiUrl(response.ReadToEnd().Trim()); + return GetWanApiUrl(response.ReadToEnd().Trim()); } } catch (Exception ex) @@ -1493,16 +1493,45 @@ namespace Emby.Server.Implementations return GetLocalApiUrl("[" + ipAddress.Address + "]"); } - return GetLocalApiUrl(ipAddress.Address); + return GetLocalApiUrlWithPort(ipAddress.Address); } - public string GetLocalApiUrl(string host) + public string GetLocalApiUrlWithPort(string host) { + if (EnableHttps) + { + return string.Format("http://{0}:{1}", + host, + HttpsPort.ToString(CultureInfo.InvariantCulture)); + } return string.Format("http://{0}:{1}", - host, - HttpPort.ToString(CultureInfo.InvariantCulture)); + host, + HttpPort.ToString(CultureInfo.InvariantCulture)); } + public string GetWanApiUrl(IpAddressInfo ipAddress) + { + if (ipAddress.AddressFamily == IpAddressFamily.InterNetworkV6) + { + return GetLocalApiUrl("[" + ipAddress.Address + "]"); + } + + return GetWanApiUrlWithPort(ipAddress.Address); + } + + public string GetWanApiUrlWithPort(string host) + { + if (EnableHttps) + { + return string.Format("http://{0}:{1}", + host, + ServerConfiguration.PublicHttpsPort.ToString(CultureInfo.InvariantCulture)); + } + return string.Format("http://{0}:{1}", + host, + ServerConfiguration.PublicPort.ToString(CultureInfo.InvariantCulture)); + } + public Task> GetLocalIpAddresses(CancellationToken cancellationToken) { return GetLocalIpAddressesInternal(true, 0, cancellationToken); From 69cc5814d85733f5bec9cac03e78caa1324406fe Mon Sep 17 00:00:00 2001 From: Phlogi Date: Sun, 24 Mar 2019 12:11:46 +0100 Subject: [PATCH 02/20] Change WAN IP behaviour: Use ServerConfiguration.WanDdns if set in configuration. --- Emby.Server.Implementations/ApplicationHost.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 5f4c30f0f..7e236002a 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1372,7 +1372,15 @@ namespace Emby.Server.Implementations public async Task GetSystemInfo(CancellationToken cancellationToken) { var localAddress = await GetLocalApiUrl(cancellationToken).ConfigureAwait(false); - var wanAddress = await GetWanApiUrl(cancellationToken).ConfigureAwait(false); + + if ( String.IsNullOrEmpty(ServerConfiguration.WanDdns) ){ + var wanAddress = await GetWanApiUrl(cancellationToken).ConfigureAwait(false); + } else { + // Use the (dynmic) domain name set in the configuration if available instead of querying + // an external service to get the IP address + // The domain resolution to the ip should be part of the client, not the server. + var wanAddress = ServerConfiguration.WanDdns; + } return new SystemInfo { From 4ffec8ad260fb8829ea220137934596de19a1c1b Mon Sep 17 00:00:00 2001 From: Phlogi Date: Sun, 24 Mar 2019 12:19:10 +0100 Subject: [PATCH 03/20] Fix build, missing changes. --- Emby.Server.Implementations/ApplicationHost.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 7e236002a..1ea9c599b 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1498,7 +1498,7 @@ namespace Emby.Server.Implementations { if (ipAddress.AddressFamily == IpAddressFamily.InterNetworkV6) { - return GetLocalApiUrl("[" + ipAddress.Address + "]"); + return GetLocalApiUrlWithPort("[" + ipAddress.Address + "]"); } return GetLocalApiUrlWithPort(ipAddress.Address); @@ -1521,7 +1521,7 @@ namespace Emby.Server.Implementations { if (ipAddress.AddressFamily == IpAddressFamily.InterNetworkV6) { - return GetLocalApiUrl("[" + ipAddress.Address + "]"); + return GetWanApiUrlWithPort("[" + ipAddress.Address + "]"); } return GetWanApiUrlWithPort(ipAddress.Address); From f30af9cd5f484dad763eb67b5b7076cd03bd59df Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Sun, 24 Mar 2019 16:47:42 +0100 Subject: [PATCH 04/20] Update Emby.Server.Implementations/ApplicationHost.cs Co-Authored-By: Phlogi --- Emby.Server.Implementations/ApplicationHost.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 1ea9c599b..1ecbeedad 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1373,7 +1373,7 @@ namespace Emby.Server.Implementations { var localAddress = await GetLocalApiUrl(cancellationToken).ConfigureAwait(false); - if ( String.IsNullOrEmpty(ServerConfiguration.WanDdns) ){ + if (string.IsNullOrEmpty(ServerConfiguration.WanDdns)){ var wanAddress = await GetWanApiUrl(cancellationToken).ConfigureAwait(false); } else { // Use the (dynmic) domain name set in the configuration if available instead of querying From cf36aaef2b1724931b94bf12b95d2b6c43f68133 Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Sun, 24 Mar 2019 16:47:48 +0100 Subject: [PATCH 05/20] Update Emby.Server.Implementations/ApplicationHost.cs Co-Authored-By: Phlogi --- Emby.Server.Implementations/ApplicationHost.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 1ecbeedad..6b7796be7 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1508,7 +1508,7 @@ namespace Emby.Server.Implementations { if (EnableHttps) { - return string.Format("http://{0}:{1}", + return string.Format("https://{0}:{1}", host, HttpsPort.ToString(CultureInfo.InvariantCulture)); } From 598b1c99660547d7c8e3b253c4664a6faa78a03d Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Sun, 24 Mar 2019 16:47:59 +0100 Subject: [PATCH 06/20] Update Emby.Server.Implementations/ApplicationHost.cs Co-Authored-By: Phlogi --- Emby.Server.Implementations/ApplicationHost.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 6b7796be7..20a3c23ae 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1531,7 +1531,7 @@ namespace Emby.Server.Implementations { if (EnableHttps) { - return string.Format("http://{0}:{1}", + return string.Format("https://{0}:{1}", host, ServerConfiguration.PublicHttpsPort.ToString(CultureInfo.InvariantCulture)); } From 7ebb043249d9c13c3bf2cc41c52d71c4e73f40f9 Mon Sep 17 00:00:00 2001 From: Phlogi Date: Sun, 24 Mar 2019 16:50:39 +0100 Subject: [PATCH 07/20] Removed comment, renamed methods consistently. --- Emby.Server.Implementations/ApplicationHost.cs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 20a3c23ae..1a64c8eaa 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1376,9 +1376,6 @@ namespace Emby.Server.Implementations if (string.IsNullOrEmpty(ServerConfiguration.WanDdns)){ var wanAddress = await GetWanApiUrl(cancellationToken).ConfigureAwait(false); } else { - // Use the (dynmic) domain name set in the configuration if available instead of querying - // an external service to get the IP address - // The domain resolution to the ip should be part of the client, not the server. var wanAddress = ServerConfiguration.WanDdns; } @@ -1498,13 +1495,13 @@ namespace Emby.Server.Implementations { if (ipAddress.AddressFamily == IpAddressFamily.InterNetworkV6) { - return GetLocalApiUrlWithPort("[" + ipAddress.Address + "]"); + return GetLocalApiUrl("[" + ipAddress.Address + "]"); } - return GetLocalApiUrlWithPort(ipAddress.Address); + return GetLocalApiUrl(ipAddress.Address); } - public string GetLocalApiUrlWithPort(string host) + public string GetLocalApiUrl(string host) { if (EnableHttps) { @@ -1521,13 +1518,13 @@ namespace Emby.Server.Implementations { if (ipAddress.AddressFamily == IpAddressFamily.InterNetworkV6) { - return GetWanApiUrlWithPort("[" + ipAddress.Address + "]"); + return GetWanApiUrl("[" + ipAddress.Address + "]"); } - return GetWanApiUrlWithPort(ipAddress.Address); + return GetWanApiUrl(ipAddress.Address); } - public string GetWanApiUrlWithPort(string host) + public string GetWanApiUrl(string host) { if (EnableHttps) { From 030fcaac156e9d75d4e7e84b0bea1291b91c0079 Mon Sep 17 00:00:00 2001 From: Phlogi Date: Sun, 24 Mar 2019 17:02:03 +0100 Subject: [PATCH 08/20] Proper access to configuration objects --- Emby.Server.Implementations/ApplicationHost.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 1a64c8eaa..fea23a3d7 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1372,11 +1372,10 @@ namespace Emby.Server.Implementations public async Task GetSystemInfo(CancellationToken cancellationToken) { var localAddress = await GetLocalApiUrl(cancellationToken).ConfigureAwait(false); + var wanAddress = ServerConfigurationManager.Configuration.WanDdns; - if (string.IsNullOrEmpty(ServerConfiguration.WanDdns)){ + if (string.IsNullOrEmpty(wanAddress)){ var wanAddress = await GetWanApiUrl(cancellationToken).ConfigureAwait(false); - } else { - var wanAddress = ServerConfiguration.WanDdns; } return new SystemInfo @@ -1530,11 +1529,11 @@ namespace Emby.Server.Implementations { return string.Format("https://{0}:{1}", host, - ServerConfiguration.PublicHttpsPort.ToString(CultureInfo.InvariantCulture)); + ServerConfigurationManager.Configuration.PublicHttpsPort.ToString(CultureInfo.InvariantCulture)); } return string.Format("http://{0}:{1}", host, - ServerConfiguration.PublicPort.ToString(CultureInfo.InvariantCulture)); + ServerConfigurationManager.Configuration.PublicPort.ToString(CultureInfo.InvariantCulture)); } public Task> GetLocalIpAddresses(CancellationToken cancellationToken) From d18252542d81e1c279b10af0198be30a8b94edea Mon Sep 17 00:00:00 2001 From: Phlogi Date: Sun, 24 Mar 2019 17:11:21 +0100 Subject: [PATCH 09/20] Also add the WAN switch to the public system info. --- Emby.Server.Implementations/ApplicationHost.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index fea23a3d7..a20838daf 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1375,7 +1375,7 @@ namespace Emby.Server.Implementations var wanAddress = ServerConfigurationManager.Configuration.WanDdns; if (string.IsNullOrEmpty(wanAddress)){ - var wanAddress = await GetWanApiUrl(cancellationToken).ConfigureAwait(false); + wanAddress = await GetWanApiUrl(cancellationToken).ConfigureAwait(false); } return new SystemInfo @@ -1426,7 +1426,11 @@ namespace Emby.Server.Implementations public async Task GetPublicSystemInfo(CancellationToken cancellationToken) { var localAddress = await GetLocalApiUrl(cancellationToken).ConfigureAwait(false); - var wanAddress = await GetWanApiUrl(cancellationToken).ConfigureAwait(false); + var wanAddress = ServerConfigurationManager.Configuration.WanDdns; + + if (string.IsNullOrEmpty(wanAddress)){ + wanAddress = await GetWanApiUrl(cancellationToken).ConfigureAwait(false); + } return new PublicSystemInfo { Version = ApplicationVersion, From fb7f29de18bc6089e247041c7aa15b2ad7677339 Mon Sep 17 00:00:00 2001 From: Phlogi Date: Sun, 24 Mar 2019 18:33:21 +0100 Subject: [PATCH 10/20] Format the WAN API Url correctly with https and Port. --- Emby.Server.Implementations/ApplicationHost.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index a20838daf..8f66ff5f9 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1372,7 +1372,7 @@ namespace Emby.Server.Implementations public async Task GetSystemInfo(CancellationToken cancellationToken) { var localAddress = await GetLocalApiUrl(cancellationToken).ConfigureAwait(false); - var wanAddress = ServerConfigurationManager.Configuration.WanDdns; + var wanAddress = GetWanApiUrl(ServerConfigurationManager.Configuration.WanDdns); if (string.IsNullOrEmpty(wanAddress)){ wanAddress = await GetWanApiUrl(cancellationToken).ConfigureAwait(false); @@ -1426,7 +1426,7 @@ namespace Emby.Server.Implementations public async Task GetPublicSystemInfo(CancellationToken cancellationToken) { var localAddress = await GetLocalApiUrl(cancellationToken).ConfigureAwait(false); - var wanAddress = ServerConfigurationManager.Configuration.WanDdns; + var wanAddress = GetWanApiUrl(ServerConfigurationManager.Configuration.WanDdns); if (string.IsNullOrEmpty(wanAddress)){ wanAddress = await GetWanApiUrl(cancellationToken).ConfigureAwait(false); From 087d4153aed8a82651a057ddf898dea7f97ded4a Mon Sep 17 00:00:00 2001 From: Phlogi Date: Sun, 24 Mar 2019 21:47:18 +0100 Subject: [PATCH 11/20] Fix check for available WAN address. --- Emby.Server.Implementations/ApplicationHost.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 8f66ff5f9..52d525552 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1372,10 +1372,13 @@ namespace Emby.Server.Implementations public async Task GetSystemInfo(CancellationToken cancellationToken) { var localAddress = await GetLocalApiUrl(cancellationToken).ConfigureAwait(false); - var wanAddress = GetWanApiUrl(ServerConfigurationManager.Configuration.WanDdns); + var wanAddress = System.String.Empty; - if (string.IsNullOrEmpty(wanAddress)){ + if (string.IsNullOrEmpty(ServerConfigurationManager.Configuration.WanDdns)){ wanAddress = await GetWanApiUrl(cancellationToken).ConfigureAwait(false); + } else + { + wanAddress = GetWanApiUrl(ServerConfigurationManager.Configuration.WanDdns); } return new SystemInfo @@ -1425,11 +1428,14 @@ namespace Emby.Server.Implementations public async Task GetPublicSystemInfo(CancellationToken cancellationToken) { - var localAddress = await GetLocalApiUrl(cancellationToken).ConfigureAwait(false); - var wanAddress = GetWanApiUrl(ServerConfigurationManager.Configuration.WanDdns); + var localAddress = await GetLocalApiUrl(cancellationToken).ConfigureAwait(false); + var wanAddress = System.String.Empty; - if (string.IsNullOrEmpty(wanAddress)){ + if (string.IsNullOrEmpty(ServerConfigurationManager.Configuration.WanDdns)){ wanAddress = await GetWanApiUrl(cancellationToken).ConfigureAwait(false); + } else + { + wanAddress = GetWanApiUrl(ServerConfigurationManager.Configuration.WanDdns); } return new PublicSystemInfo { From 2c4c56d6d638ee22617c000719aabcef5b949d32 Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Mon, 25 Mar 2019 10:17:40 +0100 Subject: [PATCH 12/20] Formatting update Emby.Server.Implementations/ApplicationHost.cs Co-Authored-By: Phlogi --- Emby.Server.Implementations/ApplicationHost.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 52d525552..410f5becd 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1376,7 +1376,8 @@ namespace Emby.Server.Implementations if (string.IsNullOrEmpty(ServerConfigurationManager.Configuration.WanDdns)){ wanAddress = await GetWanApiUrl(cancellationToken).ConfigureAwait(false); - } else + } + else { wanAddress = GetWanApiUrl(ServerConfigurationManager.Configuration.WanDdns); } From 89f2dfd78a5c73c9d9d5cc832ff0427fa732ae3e Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Mon, 25 Mar 2019 10:17:53 +0100 Subject: [PATCH 13/20] Update Emby.Server.Implementations/ApplicationHost.cs Co-Authored-By: Phlogi --- Emby.Server.Implementations/ApplicationHost.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 410f5becd..8ff17f35c 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1430,7 +1430,7 @@ namespace Emby.Server.Implementations public async Task GetPublicSystemInfo(CancellationToken cancellationToken) { var localAddress = await GetLocalApiUrl(cancellationToken).ConfigureAwait(false); - var wanAddress = System.String.Empty; + var wanAddress = string.Empty; if (string.IsNullOrEmpty(ServerConfigurationManager.Configuration.WanDdns)){ wanAddress = await GetWanApiUrl(cancellationToken).ConfigureAwait(false); From 3474568ce2864d05fc47575fed3bfe5c7b21a435 Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Mon, 25 Mar 2019 10:18:04 +0100 Subject: [PATCH 14/20] Update Emby.Server.Implementations/ApplicationHost.cs Co-Authored-By: Phlogi --- Emby.Server.Implementations/ApplicationHost.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 8ff17f35c..ba705f1f2 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1372,7 +1372,7 @@ namespace Emby.Server.Implementations public async Task GetSystemInfo(CancellationToken cancellationToken) { var localAddress = await GetLocalApiUrl(cancellationToken).ConfigureAwait(false); - var wanAddress = System.String.Empty; + var wanAddress = string.Empty; if (string.IsNullOrEmpty(ServerConfigurationManager.Configuration.WanDdns)){ wanAddress = await GetWanApiUrl(cancellationToken).ConfigureAwait(false); From f7e7d726880f87c18e799420ee6eb0ab42d86a47 Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Mon, 25 Mar 2019 10:18:18 +0100 Subject: [PATCH 15/20] Formatting update Emby.Server.Implementations/ApplicationHost.cs Co-Authored-By: Phlogi --- Emby.Server.Implementations/ApplicationHost.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index ba705f1f2..5c5e8e5bf 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1374,7 +1374,8 @@ namespace Emby.Server.Implementations var localAddress = await GetLocalApiUrl(cancellationToken).ConfigureAwait(false); var wanAddress = string.Empty; - if (string.IsNullOrEmpty(ServerConfigurationManager.Configuration.WanDdns)){ + if (string.IsNullOrEmpty(ServerConfigurationManager.Configuration.WanDdns)) + { wanAddress = await GetWanApiUrl(cancellationToken).ConfigureAwait(false); } else From e36d424b5f61e2785c26af49db7d120d66933935 Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Mon, 25 Mar 2019 10:18:47 +0100 Subject: [PATCH 16/20] Formatting update Emby.Server.Implementations/ApplicationHost.cs Co-Authored-By: Phlogi --- Emby.Server.Implementations/ApplicationHost.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 5c5e8e5bf..9ace9a48f 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1433,7 +1433,8 @@ namespace Emby.Server.Implementations var localAddress = await GetLocalApiUrl(cancellationToken).ConfigureAwait(false); var wanAddress = string.Empty; - if (string.IsNullOrEmpty(ServerConfigurationManager.Configuration.WanDdns)){ + if (string.IsNullOrEmpty(ServerConfigurationManager.Configuration.WanDdns)) + { wanAddress = await GetWanApiUrl(cancellationToken).ConfigureAwait(false); } else { From 6480cfcc87b65331b15bf787633f978b30e2e829 Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Mon, 25 Mar 2019 10:19:08 +0100 Subject: [PATCH 17/20] Formatting update Emby.Server.Implementations/ApplicationHost.cs Co-Authored-By: Phlogi --- Emby.Server.Implementations/ApplicationHost.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 9ace9a48f..7c8fb7f62 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1436,7 +1436,8 @@ namespace Emby.Server.Implementations if (string.IsNullOrEmpty(ServerConfigurationManager.Configuration.WanDdns)) { wanAddress = await GetWanApiUrl(cancellationToken).ConfigureAwait(false); - } else + } + else { wanAddress = GetWanApiUrl(ServerConfigurationManager.Configuration.WanDdns); } From 4c8f8cf64cc81fb5f1bb32aeb8349ce38badf457 Mon Sep 17 00:00:00 2001 From: Phlogi Date: Mon, 25 Mar 2019 21:34:55 +0100 Subject: [PATCH 18/20] Removed trailing spaces, renamed get wan IP function. --- Emby.Server.Implementations/ApplicationHost.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 7c8fb7f62..b5582ae4f 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1376,7 +1376,7 @@ namespace Emby.Server.Implementations if (string.IsNullOrEmpty(ServerConfigurationManager.Configuration.WanDdns)) { - wanAddress = await GetWanApiUrl(cancellationToken).ConfigureAwait(false); + wanAddress = await GetWanApiUrlFromExternal(cancellationToken).ConfigureAwait(false); } else { @@ -1435,7 +1435,7 @@ namespace Emby.Server.Implementations if (string.IsNullOrEmpty(ServerConfigurationManager.Configuration.WanDdns)) { - wanAddress = await GetWanApiUrl(cancellationToken).ConfigureAwait(false); + wanAddress = await GetWanApiUrlFromExternal(cancellationToken).ConfigureAwait(false); } else { @@ -1478,7 +1478,7 @@ namespace Emby.Server.Implementations return null; } - public async Task GetWanApiUrl(CancellationToken cancellationToken) + public async Task GetWanApiUrlFromExternal(CancellationToken cancellationToken) { const string Url = "http://ipv4.icanhazip.com"; try @@ -1524,7 +1524,7 @@ namespace Emby.Server.Implementations } return string.Format("http://{0}:{1}", host, - HttpPort.ToString(CultureInfo.InvariantCulture)); + HttpPort.ToString(CultureInfo.InvariantCulture)); } public string GetWanApiUrl(IpAddressInfo ipAddress) From 1b03f078b92021b8f3c2e7c148f1e67debd27fac Mon Sep 17 00:00:00 2001 From: Phlogi Date: Mon, 25 Mar 2019 21:43:50 +0100 Subject: [PATCH 19/20] No need to assign empty string. --- Emby.Server.Implementations/ApplicationHost.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index b5582ae4f..49da67292 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1372,15 +1372,14 @@ namespace Emby.Server.Implementations public async Task GetSystemInfo(CancellationToken cancellationToken) { var localAddress = await GetLocalApiUrl(cancellationToken).ConfigureAwait(false); - var wanAddress = string.Empty; if (string.IsNullOrEmpty(ServerConfigurationManager.Configuration.WanDdns)) { - wanAddress = await GetWanApiUrlFromExternal(cancellationToken).ConfigureAwait(false); + var wanAddress = await GetWanApiUrlFromExternal(cancellationToken).ConfigureAwait(false); } else { - wanAddress = GetWanApiUrl(ServerConfigurationManager.Configuration.WanDdns); + var wanAddress = GetWanApiUrl(ServerConfigurationManager.Configuration.WanDdns); } return new SystemInfo @@ -1431,15 +1430,14 @@ namespace Emby.Server.Implementations public async Task GetPublicSystemInfo(CancellationToken cancellationToken) { var localAddress = await GetLocalApiUrl(cancellationToken).ConfigureAwait(false); - var wanAddress = string.Empty; if (string.IsNullOrEmpty(ServerConfigurationManager.Configuration.WanDdns)) { - wanAddress = await GetWanApiUrlFromExternal(cancellationToken).ConfigureAwait(false); + var wanAddress = await GetWanApiUrlFromExternal(cancellationToken).ConfigureAwait(false); } else { - wanAddress = GetWanApiUrl(ServerConfigurationManager.Configuration.WanDdns); + var wanAddress = GetWanApiUrl(ServerConfigurationManager.Configuration.WanDdns); } return new PublicSystemInfo { From 122cba2aa755df7d7c3e63aaa441f639b126b55c Mon Sep 17 00:00:00 2001 From: Phlogi Date: Mon, 25 Mar 2019 22:26:05 +0100 Subject: [PATCH 20/20] Correct use of local variable wanAddress. --- Emby.Server.Implementations/ApplicationHost.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 49da67292..fd14cb89d 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1373,13 +1373,15 @@ namespace Emby.Server.Implementations { var localAddress = await GetLocalApiUrl(cancellationToken).ConfigureAwait(false); + string wanAddress; + if (string.IsNullOrEmpty(ServerConfigurationManager.Configuration.WanDdns)) { - var wanAddress = await GetWanApiUrlFromExternal(cancellationToken).ConfigureAwait(false); + wanAddress = await GetWanApiUrlFromExternal(cancellationToken).ConfigureAwait(false); } else { - var wanAddress = GetWanApiUrl(ServerConfigurationManager.Configuration.WanDdns); + wanAddress = GetWanApiUrl(ServerConfigurationManager.Configuration.WanDdns); } return new SystemInfo @@ -1431,13 +1433,15 @@ namespace Emby.Server.Implementations { var localAddress = await GetLocalApiUrl(cancellationToken).ConfigureAwait(false); + string wanAddress; + if (string.IsNullOrEmpty(ServerConfigurationManager.Configuration.WanDdns)) { - var wanAddress = await GetWanApiUrlFromExternal(cancellationToken).ConfigureAwait(false); + wanAddress = await GetWanApiUrlFromExternal(cancellationToken).ConfigureAwait(false); } else { - var wanAddress = GetWanApiUrl(ServerConfigurationManager.Configuration.WanDdns); + wanAddress = GetWanApiUrl(ServerConfigurationManager.Configuration.WanDdns); } return new PublicSystemInfo {