blob: 5bba471e1d07a9c0183c0c8a65e6a3893ff35d8d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
namespace VPNAuth.Server;
public static class HttpContextUtils
{
public static string GetRemoteIpAddress(this HttpContext context)
=> context.Request.Headers["X-Forwarded-For"].DefaultIfEmpty(context.Connection.RemoteIpAddress!.ToString())
.First()!;
public static ConfigUser? GetUser(this HttpContext context)
{
var config = Config.Read();
if (config.Users == null || config.Users.Count == 0) return null;
return config.Users!.Find(user => user.Ips!.Contains(context.GetRemoteIpAddress()));
}
}
|