Example #1
0
        public static bool Check(EventMessage message)
        {
            if (message == null) return false;
            if (string.IsNullOrEmpty(message.IP)) return true;

            var ip = GetIpWithoutPort(message.IP);
            return secretIps.All(x => x != ip);
        }
Example #2
0
        public static EventMessage Create(MessageUserData userData, Dictionary<string, string> headers, MessageAction action, params string[] description)
        {
            try
            {
                var message = new EventMessage
                    {
                        Date = DateTime.UtcNow,
                        TenantId = userData == null ? CoreContext.TenantManager.GetCurrentTenant().TenantId : userData.TenantId,
                        UserId = userData == null ? SecurityContext.CurrentAccount.ID : userData.UserId,
                        Action = action,
                        Description = description
                    };

                if (headers != null)
                {
                    var userAgent = headers.ContainsKey(userAgentHeader) ? headers[userAgentHeader] : null;
                    var forwarded = headers.ContainsKey(forwardedHeader) ? headers[forwardedHeader] : null;
                    var host = headers.ContainsKey(hostHeader) ? headers[hostHeader] : null;
                    var referer = headers.ContainsKey(refererHeader) ? headers[refererHeader] : null;

                    var uaParser = Parser.GetDefault();
                    ClientInfo clientInfo;

                    try
                    {
                        clientInfo = userAgent != null ? uaParser.Parse(userAgent) : null;
                    }
                    catch (Exception)
                    {
                        clientInfo = null;
                    }

                    message.IP = forwarded ?? host;
                    message.Browser = GetBrowser(clientInfo);
                    message.Platform = GetPlatform(clientInfo);
                    message.Page = referer;
                }

                return message;
            }
            catch (Exception ex)
            {
                log.Error(string.Format("Error while parse Http Message for \"{0}\" type of event: {1}", action, ex));
                return null;
            }
        }
 public static bool Check(EventMessage message)
 {
     var ip = GetIpWithoutPort(message.IP);
     return secretIps.All(x => x != ip);
 }