1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-02 00:22:50 -05:00

move ip address method to core helpers

This commit is contained in:
Kyle Spearrin
2019-09-03 14:08:08 -04:00
parent 4982c21c37
commit 72310701d2
2 changed files with 24 additions and 23 deletions

View File

@ -33,6 +33,8 @@ namespace Bit.Core.Utilities
"RL?+AOEUIDHTNS_:QJKXBMWVZ";
private static readonly string _qwertyColemakMap = "qwertyuiopasdfghjkl;zxcvbnmQWERTYUIOPASDFGHJKL:ZXCVBNM";
private static readonly string _colemakMap = "qwfpgjluy;arstdhneiozxcvbkmQWFPGJLUY:ARSTDHNEIOZXCVBKM";
private static readonly string CloudFlareConnectingIp = "CF-Connecting-IP";
private static readonly string RealIp = "X-Real-IP";
/// <summary>
/// Generate sequential Guid for Sql Server.
@ -569,5 +571,25 @@ namespace Bit.Core.Utilities
}
return subName;
}
public static string GetIpAddress(this Microsoft.AspNetCore.Http.HttpContext httpContext,
GlobalSettings globalSettings)
{
if(httpContext == null)
{
return null;
}
if(!globalSettings.SelfHosted && httpContext.Request.Headers.ContainsKey(CloudFlareConnectingIp))
{
return httpContext.Request.Headers[CloudFlareConnectingIp].ToString();
}
if(globalSettings.SelfHosted && httpContext.Request.Headers.ContainsKey(RealIp))
{
return httpContext.Request.Headers[RealIp].ToString();
}
return httpContext.Connection?.RemoteIpAddress?.ToString();
}
}
}