From a91a28c408a648a951558c87560df70141e0940d Mon Sep 17 00:00:00 2001 From: Flemming Thesbjerg Date: Sat, 29 Dec 2018 01:48:31 +0100 Subject: [PATCH] re-adds wan ip on dashboard by requesting it from http://ipv4.icanhazip.com --- CONTRIBUTORS.md | 1 + .../ApplicationHost.cs | 35 ++++++++++++++++--- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index fd9bab8ccd..b390b4441a 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -4,6 +4,7 @@ - [nvllsvm](https://github.com/nvllsvm) - [JustAMan](https://github.com/JustAMan) - [dcrdev](https://github.com/dcrdev) + - [flemse](https://github.com/flemse) # Emby Contributors diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index f8dd65bbc4..ad15b015de 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1962,6 +1962,7 @@ namespace Emby.Server.Implementations public async Task GetSystemInfo(CancellationToken cancellationToken) { var localAddress = await GetLocalApiUrl(cancellationToken).ConfigureAwait(false); + var wanAddress = await GetWanApiUrl(cancellationToken).ConfigureAwait(false); return new SystemInfo { @@ -1984,8 +1985,7 @@ namespace Emby.Server.Implementations CanSelfRestart = CanSelfRestart, CanSelfUpdate = CanSelfUpdate, CanLaunchWebBrowser = CanLaunchWebBrowser, - // TODO - remove WanAddress - WanAddress = "0.0.0.0", + WanAddress = wanAddress, HasUpdateAvailable = HasUpdateAvailable, SupportsAutoRunAtStartup = SupportsAutoRunAtStartup, TranscodingTempPath = ApplicationPaths.TranscodingTempPath, @@ -2012,14 +2012,13 @@ namespace Emby.Server.Implementations public async Task GetPublicSystemInfo(CancellationToken cancellationToken) { var localAddress = await GetLocalApiUrl(cancellationToken).ConfigureAwait(false); - + var wanAddress = await GetWanApiUrl(cancellationToken).ConfigureAwait(false); return new PublicSystemInfo { Version = ApplicationVersion.ToString(), Id = SystemId, OperatingSystem = EnvironmentInfo.OperatingSystem.ToString(), - // TODO - remove WanAddress - WanAddress = "0.0.0.0", + WanAddress = wanAddress, ServerName = FriendlyName, LocalAddress = localAddress }; @@ -2060,6 +2059,32 @@ namespace Emby.Server.Implementations return null; } + public async Task GetWanApiUrl(CancellationToken cancellationToken) + { + var url = "http://ipv4.icanhazip.com"; + try + { + using (var response = await HttpClient.Get(new HttpRequestOptions + { + Url = url, + LogErrorResponseBody = false, + LogErrors = false, + LogRequest = false, + TimeoutMs = 10000, + BufferContent = false, + CancellationToken = cancellationToken + })) + { + return GetLocalApiUrl(response.ReadToEnd().Trim()); + } + } + catch(Exception ex) + { + Logger.ErrorException("Error getting WAN Ip address information", ex); + } + return null; + } + public string GetLocalApiUrl(IpAddressInfo ipAddress) { if (ipAddress.AddressFamily == IpAddressFamily.InterNetworkV6)