diff --git a/DragonFruit.OnionFruit.Web/Controllers/ConnectionStatusController.cs b/DragonFruit.OnionFruit.Web/Controllers/ConnectionStatusController.cs index 87ae25f..e214a7b 100644 --- a/DragonFruit.OnionFruit.Web/Controllers/ConnectionStatusController.cs +++ b/DragonFruit.OnionFruit.Web/Controllers/ConnectionStatusController.cs @@ -55,13 +55,13 @@ public async Task GetConnectionStatus() } // if not on redis, use cloudflare to check if tor and libloc to get network info - var (country, asInfo) = await _libloc.PerformAsync(a => GetConnectionInfo(a, ipAddress)).ConfigureAwait(false); - var isTor = HttpContext.Request.Headers.TryGetValue("CF-IPCountry", out var cloudflareCountry) && cloudflareCountry == "T1"; + var cloudflareCountryDetected = HttpContext.Request.Headers.TryGetValue("CF-IPCountry", out var cloudflareCountry); + var (country, asInfo) = await _libloc.PerformAsync(a => GetConnectionInfo(a, ipAddress, cloudflareCountryDetected ? cloudflareCountry.ToString() : null)).ConfigureAwait(false); - return new ConnectionStatusResponse(ipAddress.ToString(), isTor, country?.Code ?? "XX", country?.Name ?? "Unknown Country", asInfo?.Number, asInfo?.Name); + return new ConnectionStatusResponse(ipAddress.ToString(), cloudflareCountryDetected && cloudflareCountry == "T1", country?.Code ?? "XX", country?.Name ?? "Unknown Country", asInfo?.Number, asInfo?.Name); } - private (IDatabaseCountry country, IDatabaseAS asInfo) GetConnectionInfo(ILocationDatabase x, IPAddress address) + private (IDatabaseCountry country, IDatabaseAS asInfo) GetConnectionInfo(ILocationDatabase x, IPAddress address, [CanBeNull] string countryCodeOverride) { IDatabaseAS asInfo = null; IDatabaseCountry country = null; @@ -71,7 +71,7 @@ public async Task GetConnectionStatus() if (addr != null) { asInfo = x.AS.GetAS((int)addr.ASN); - country = x.Countries.GetCountry(addr.CountryCode); + country = x.Countries.GetCountry(countryCodeOverride ?? addr.CountryCode); } return (country, asInfo);