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:
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user