public void PingPortals() { var clientIps = ClientIpValues.GetClientIps(); var clientIp = new ClientIp(); Ping pinger = new Ping(); try { clientIps.ForEach(p => { clientIp = p; var ip = _context.ClientIp.FirstOrDefault(c => c.Ip.ToLower().Equals(clientIp.Ip.ToLower())); PingReply reply = pinger.Send(p.Ip); ip.Fails = 0; }); _context.SaveChanges(); } catch (PingException) { var ip = _context.ClientIp.FirstOrDefault(c => c.Ip.ToLower().Equals(clientIp.Ip.ToLower())); if (ip.Fails < 2) { ip.Fails = ip.Fails + 1; } else { ip.Fails = 0; //NotifyPortalDown(ip); } _context.SaveChanges(); } pinger.Dispose(); }
public override int GetHashCode() { int hash = 1; if (ServerTimestamp != 0) { hash ^= ServerTimestamp.GetHashCode(); } if (ClientIp != 0) { hash ^= ClientIp.GetHashCode(); } if (RedirectIp != 0) { hash ^= RedirectIp.GetHashCode(); } if (RedirectPort != 0) { hash ^= RedirectPort.GetHashCode(); } if (ClientIpV6.Length != 0) { hash ^= ClientIpV6.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
private void NotifyPortalDown(ClientIp ip) { var mailReceiver = "*****@*****.**"; try { var emailContent = new MailsViewModel { Code = ip.Institution, Email = mailReceiver, MailMethod = MailSendMethod.PortalDown, Subject = $"{ip.Institution} portal is inaccessible", PortalUrl = ip.Ip }; var emailResponse = emailSender.SendEmail(emailContent); _context.InaccessibiltyLog.Add(new InaccessibiltyLog { Ip = ip.Ip, Institution = ip.Institution, MailReceiver = mailReceiver, DateCreated = DateTime.UtcNow.AddHours(3) }); } catch (Exception) { } }
public async Task Invoke(HttpContext context) { Request request = Repository.AddRequest(context.Request); Task.Delay(Configuration.CostKeepingTime * 60 * 100).ContinueWith((t) => Repository.RemoveRequest(request)); ClientIp clientIp = request.ClientIp; if (clientIp.IsWhiteListed) { await _next.Invoke(context); } else { if (clientIp.IsBlackListed || clientIp.CurrentRequestCosts > Configuration.BlockingLimitPerIp) { _logger.LogError(0, $"Request blocked from: {clientIp.Ip}"); request.IsBlocked = true; request.Costs = Configuration.BlockingLimitPerIp; context.Abort(); return; } Task requestTask = _next.Invoke(context); request.Costs = CalculateStaticCosts(request); await requestTask; CalculateDynamicRequestCosts(context, request); foreach (ICostMultiplier multiplier in Configuration.CostMultipliers) { request.Costs = request.Costs * (int)multiplier.Calculate(request); } //Task.Run(() => CheckBlocking(request)); _logger.LogInformation(0, $"Request from: {clientIp.Ip}, Costs: {request.Costs}, Costs for IP: {clientIp.CurrentRequestCosts}, Duration: {DateTime.Now.Subtract(request.Time).Milliseconds} ms"); } }
public override int GetHashCode() { int hash = 1; if (ClientIp.Length != 0) { hash ^= ClientIp.GetHashCode(); } if (XRequestId.Length != 0) { hash ^= XRequestId.GetHashCode(); } if (ServiceId != 0) { hash ^= ServiceId.GetHashCode(); } if (MessageId != 0) { hash ^= MessageId.GetHashCode(); } if (Delay != 0) { hash ^= Delay.GetHashCode(); } if (Data.Length != 0) { hash ^= Data.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public override int GetHashCode() { int hash = 1; if (ClientIp.Length != 0) { hash ^= ClientIp.GetHashCode(); } if (ClientPort != 0) { hash ^= ClientPort.GetHashCode(); } if (Type.Length != 0) { hash ^= Type.GetHashCode(); } if (ConnectionId.Length != 0) { hash ^= ConnectionId.GetHashCode(); } if (ClientVersion.Length != 0) { hash ^= ClientVersion.GetHashCode(); } hash ^= Labels.GetHashCode(); hash ^= Headers.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public override int GetHashCode() { unchecked { int hashCode = Id; hashCode = (hashCode * 397) ^ UrlItemId; hashCode = (hashCode * 397) ^ (ClientIp != null ? ClientIp.GetHashCode() : 0); hashCode = (hashCode * 397) ^ HitOn.GetHashCode(); return(hashCode); } }
private void CheckBlocking(Request request) { ClientIp clientIp = request.ClientIp; if (DateTime.Now.Subtract(clientIp.BlockingTime).TotalMinutes <= Configuration.CostKeepingTime || !clientIp.IsWhiteListed && clientIp.CurrentRequestCosts > Configuration.BlockingLimitPerIp) { clientIp.BlockingTime = DateTime.Now; request.BlockingTime = clientIp.BlockingTime; } }
public override int GetHashCode() { int hash = 1; if (ClientType != global::AcFunDanmu.DeviceInfo.Types.PlatformType.KInvalid) { hash ^= ClientType.GetHashCode(); } if (DeviceId.Length != 0) { hash ^= DeviceId.GetHashCode(); } if (ClientIp.Length != 0) { hash ^= ClientIp.GetHashCode(); } if (AppVersion.Length != 0) { hash ^= AppVersion.GetHashCode(); } if (Channel.Length != 0) { hash ^= Channel.GetHashCode(); } if (appInfo_ != null) { hash ^= AppInfo.GetHashCode(); } if (deviceInfo_ != null) { hash ^= DeviceInfo.GetHashCode(); } if (envInfo_ != null) { hash ^= EnvInfo.GetHashCode(); } if (ClientPort != 0) { hash ^= ClientPort.GetHashCode(); } if (Location.Length != 0) { hash ^= Location.GetHashCode(); } if (Kpf.Length != 0) { hash ^= Kpf.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
/// <summary> /// 写入登陆日志 /// </summary> /// <param name="u"></param> public void Add(user u) { QQWry.NET.QQWryLocator qqWry = new QQWry.NET.QQWryLocator(System.Web.HttpContext.Current.Server.MapPath(Config.GetValue <string>("qqwry"))); BaseRepository <loginlog> dal = new BaseRepository <loginlog>(); loginlog log = new loginlog(); log.Uid = u.Id; log.Ip = ClientIp.GetClientIP(); log.LogTime = DateTime.Now; log.Address = qqWry.Query(log.Ip).Country; dal.AddEntities(log); }
public override int GetHashCode() { int hash = 1; if (TimeStamp != 0L) { hash ^= TimeStamp.GetHashCode(); } if (HostName.Length != 0) { hash ^= HostName.GetHashCode(); } if (ServiceType != 0) { hash ^= ServiceType.GetHashCode(); } if (Developer != 0) { hash ^= Developer.GetHashCode(); } if (ClientIp.Length != 0) { hash ^= ClientIp.GetHashCode(); } if (Stack.Length != 0) { hash ^= Stack.GetHashCode(); } if (Message.Length != 0) { hash ^= Message.GetHashCode(); } if (Action.Length != 0) { hash ^= Action.GetHashCode(); } if (AccountId.Length != 0) { hash ^= AccountId.GetHashCode(); } if (ProjectId.Length != 0) { hash ^= ProjectId.GetHashCode(); } if (Level != 0) { hash ^= Level.GetHashCode(); } hash ^= Extras.GetHashCode(); return(hash); }
public MoesifMiddlewareNetFramework(OwinMiddleware next, Dictionary <string, object> _middleware) : base(next) { moesifOptions = _middleware; try { // Initialize client debug = LoggerHelper.GetConfigBoolValues(moesifOptions, "LocalDebug", false); client = new MoesifApiClient(moesifOptions["ApplicationId"].ToString(), "moesif-netframework/1.3.8", debug); logBody = LoggerHelper.GetConfigBoolValues(moesifOptions, "LogBody", true); isBatchingEnabled = LoggerHelper.GetConfigBoolValues(moesifOptions, "EnableBatching", true); // Enable batching disableStreamOverride = LoggerHelper.GetConfigBoolValues(moesifOptions, "DisableStreamOverride", false); // Reset Request Body position batchSize = LoggerHelper.GetConfigIntValues(moesifOptions, "BatchSize", 25); // Batch Size queueSize = LoggerHelper.GetConfigIntValues(moesifOptions, "QueueSize", 1000); // Event Queue Size batchMaxTime = LoggerHelper.GetConfigIntValues(moesifOptions, "batchMaxTime", 2); // Batch max time in seconds appConfigSyncTime = LoggerHelper.GetConfigIntValues(moesifOptions, "appConfigSyncTime", 300); // App config sync time in seconds appConfig = new AppConfig(); // Create a new instance of AppConfig userHelper = new UserHelper(); // Create a new instance of userHelper companyHelper = new CompanyHelper(); // Create a new instane of companyHelper clientIpHelper = new ClientIp(); // Create a new instance of client Ip authorizationHeaderName = LoggerHelper.GetConfigStringValues(moesifOptions, "AuthorizationHeaderName", "authorization"); authorizationUserIdField = LoggerHelper.GetConfigStringValues(moesifOptions, "AuthorizationUserIdField", "sub"); samplingPercentage = 100; // Default sampling percentage configETag = null; // Default configETag lastUpdatedTime = DateTime.UtcNow; // Default lastUpdatedTime MoesifQueue = new ConcurrentQueue <EventModel>(); // Initialize queue new Thread(async() => // Create a new thread to read the queue and send event to moesif { Thread.CurrentThread.IsBackground = true; if (isBatchingEnabled) { ScheduleWorker(); } else { ScheduleAppConfig(); // Scheduler to fetch application configuration every 5 minutes } }).Start(); } catch (Exception e) { throw new Exception("Please provide the application Id to send events to Moesif"); } }
public override int GetHashCode() { int hash = 1; hash ^= nameServers_.GetHashCode(); hash ^= nameServer_.GetHashCode(); hash ^= Hosts.GetHashCode(); if (ClientIp.Length != 0) { hash ^= ClientIp.GetHashCode(); } hash ^= staticHosts_.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
/// <summary> /// Format the data section of a FTP termination record. /// </summary> /// <returns>String representation of a FTP termination record.</returns> public override string ToString() { return(StartTime.ToString().PadRight(22, ' ') + " " + EndTime.ToString().PadRight(22, ' ') + " " + VseTaskId.ToString().PadRight(2 + 5, ' ') + " " + FtpNodeName.PadRight(16, ' ') + " " + FtpUserId.PadRight(8, ' ') + " " + VseIp.PadRight(15, ' ') + " " + VsePort.ToString().PadRight(8, ' ') + " " + ClientPort.ToString().PadRight(11, ' ') + " " + ClientIp.PadRight(15, ' ') + " " + ForeignDataIp.PadRight(15, ' ') + " " + FilesSent.ToString().PadRight(10, ' ') + " " + FilesReceived.ToString().PadRight(10, ' ') + " " + BytesSentAcked.ToString().PadRight(20, ' ') + " " + BytesReceived.ToString().PadRight(20, ' ') + " " + GeneralFlagFormatter(GeneralFlag).PadRight(8, ' ') + " " + SslFlagFormatter(SslFlag).ToString().PadRight(5, ' ')); }
public override int GetHashCode() { int hash = 1; if (Type.Length != 0) { hash ^= Type.GetHashCode(); } if (ClientIp.Length != 0) { hash ^= ClientIp.GetHashCode(); } hash ^= Headers.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public override int GetHashCode() { int hash = 1; if (ClientIp.Length != 0) { hash ^= ClientIp.GetHashCode(); } if (Identity.Length != 0) { hash ^= Identity.GetHashCode(); } if (XRequestId.Length != 0) { hash ^= XRequestId.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
private static ClientIp AddClientIp(IPAddress address) { var clientIp = new ClientIp() { Ip = address, BinaryIp = GetBinaryIp(address), IsIpV6 = address.GetAddressBytes().Length != 4, }; clientIp.IsWhiteListed = Configuration.WhiteList.Any( range => range.AddressFamily == clientIp.Ip.AddressFamily && range.Contains(clientIp.Ip)); clientIp.IsBlackListed = Configuration.BlackList.Any( range => range.AddressFamily == clientIp.Ip.AddressFamily && range.Contains(clientIp.Ip)); if (clientIp.IsWhiteListed && clientIp.IsBlackListed) { throw new Exception($"IP {address} cannot be both black and white listed"); } //_NewClientIps.Add(clientIp); _ClientIps.Add(clientIp); return(clientIp); }
private async Task <EventRequestModel> FormatRequest(HttpRequest request) { var body = request.Body; request.EnableRewind(); var buffer = new byte[Convert.ToInt32(request.ContentLength)]; await request.Body.ReadAsync(buffer, 0, buffer.Length); var bodyAsText = Encoding.UTF8.GetString(buffer); request.Body = body; var reqHeaders = new Dictionary <string, string>(); try { reqHeaders = request.Headers.ToDictionary(k => k.Key, k => k.Value.ToString(), StringComparer.OrdinalIgnoreCase); } catch (Exception inst) { if (debug) { Console.WriteLine("error encountered while copying request header"); Console.WriteLine(inst); } } // Add Transaction Id to the Request Header var transation_id_out = new Object(); var captureTransactionId = moesifOptions.TryGetValue("DisableTransactionId", out transation_id_out); bool GetCaptureTransactionId = false; if (captureTransactionId) { GetCaptureTransactionId = (bool)(transation_id_out); } if (!GetCaptureTransactionId) { if (reqHeaders.ContainsKey("X-Moesif-Transaction-Id")) { string reqTransId = reqHeaders["X-Moesif-Transaction-Id"]; if (!string.IsNullOrEmpty(reqTransId)) { transactionId = reqTransId; if (string.IsNullOrEmpty(transactionId)) { transactionId = Guid.NewGuid().ToString(); } } else { transactionId = Guid.NewGuid().ToString(); } } else { transactionId = Guid.NewGuid().ToString(); } // Add Transaction Id to the Request Header reqHeaders["X-Moesif-Transaction-Id"] = transactionId; } var reqBody = new object(); reqBody = null; try { reqBody = ApiHelper.JsonDeserialize <object>(bodyAsText); } catch (Exception inst) { Console.WriteLine("error encountered while trying to serialize request body"); Console.WriteLine(inst); } string ip = null; try { List <string> proxyHeaders = new List <string> { "X-Client-Ip", "X-Forwarded-For", "Cf-Connecting-Ip", "True-Client-Ip", "X-Real-Ip", "X-Cluster-Client-Ip", "X-Forwarded", "Forwarded-For", "Forwarded" }; if (!proxyHeaders.Intersect(reqHeaders.Keys.ToList(), StringComparer.OrdinalIgnoreCase).Any()) { ip = request.HttpContext.Connection.RemoteIpAddress.ToString(); } else { ClientIp helpers = new ClientIp(); ip = helpers.GetClientIp(reqHeaders, request); } } catch (Exception inst) { Console.WriteLine("error encountered while trying to get the client IP address"); Console.WriteLine(inst); } var uri = new Uri(request.GetDisplayUrl()).ToString(); string apiVersion = null; var apiVersion_out = new object(); var getApiVersion = moesifOptions.TryGetValue("ApiVersion", out apiVersion_out); if (getApiVersion) { apiVersion = apiVersion_out.ToString(); } var eventReq = new EventRequestModel() { Time = DateTime.UtcNow, Uri = uri, Verb = request.Method, ApiVersion = apiVersion, IpAddress = ip, Headers = reqHeaders, Body = reqBody }; return(eventReq); }
public override int GetHashCode() { int hash = 1; if (Kpn.Length != 0) { hash ^= Kpn.GetHashCode(); } if (Kpf.Length != 0) { hash ^= Kpf.GetHashCode(); } if (SubBiz.Length != 0) { hash ^= SubBiz.GetHashCode(); } if (Uid != 0L) { hash ^= Uid.GetHashCode(); } if (Did.Length != 0) { hash ^= Did.GetHashCode(); } if (ClientIp != 0L) { hash ^= ClientIp.GetHashCode(); } if (AppVer.Length != 0) { hash ^= AppVer.GetHashCode(); } if (Ver.Length != 0) { hash ^= Ver.GetHashCode(); } if (Lat.Length != 0) { hash ^= Lat.GetHashCode(); } if (Lon.Length != 0) { hash ^= Lon.GetHashCode(); } if (Mod.Length != 0) { hash ^= Mod.GetHashCode(); } if (Net.Length != 0) { hash ^= Net.GetHashCode(); } if (Sys.Length != 0) { hash ^= Sys.GetHashCode(); } if (C.Length != 0) { hash ^= C.GetHashCode(); } if (Language.Length != 0) { hash ^= Language.GetHashCode(); } if (CountryCode.Length != 0) { hash ^= CountryCode.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
private async Task <EventRequestModel> FormatRequest(IOwinRequest request) { var body = request.Body; string requestBody = await new StreamReader(request.Body).ReadToEndAsync(); // Read request Body byte[] requestData = Encoding.UTF8.GetBytes(requestBody); request.Body = new MemoryStream(requestData); var reqHeaders = new Dictionary <string, string>(); try { reqHeaders = request.Headers.ToDictionary(k => k.Key, k => k.Value.First(), StringComparer.OrdinalIgnoreCase); } catch (Exception inst) { if (debug) { Console.WriteLine("error encountered while copying request header"); Console.WriteLine(inst); } } // Add Transaction Id to the Request Header var transation_id_out = new Object(); var captureTransactionId = moesifOptions.TryGetValue("DisableTransactionId", out transation_id_out); bool GetCaptureTransactionId = false; if (captureTransactionId) { GetCaptureTransactionId = (bool)(transation_id_out); } if (!GetCaptureTransactionId) { if (reqHeaders.ContainsKey("X-Moesif-Transaction-Id")) { string reqTransId = reqHeaders["X-Moesif-Transaction-Id"]; if (!string.IsNullOrEmpty(reqTransId)) { transactionId = reqTransId; if (string.IsNullOrEmpty(transactionId)) { transactionId = Guid.NewGuid().ToString(); } } else { transactionId = Guid.NewGuid().ToString(); } } else { transactionId = Guid.NewGuid().ToString(); } // Add Transaction Id to the Request Header reqHeaders["X-Moesif-Transaction-Id"] = transactionId; } var reqBody = new object(); reqBody = null; string requestTransferEncoding; requestTransferEncoding = null; if (logBody) { try { reqBody = ApiHelper.JsonDeserialize <object>(requestBody); } catch (Exception inst) { if (debug) { Console.WriteLine("About to parse Request body as Base64 encoding"); } // Get Request Body reqBody = Base64Encode(requestBody); requestTransferEncoding = "base64"; } } string ip = null; try { List <string> proxyHeaders = new List <string> { "X-Client-Ip", "X-Forwarded-For", "Cf-Connecting-Ip", "True-Client-Ip", "X-Real-Ip", "X-Cluster-Client-Ip", "X-Forwarded", "Forwarded-For", "Forwarded" }; if (!proxyHeaders.Intersect(reqHeaders.Keys.ToList(), StringComparer.OrdinalIgnoreCase).Any()) { ip = request.RemoteIpAddress.ToString(); } else { ClientIp helpers = new ClientIp(); ip = helpers.GetClientIp(reqHeaders, request); } } catch (Exception inst) { Console.WriteLine("error encountered while trying to get the client IP address"); Console.WriteLine(inst); } var uri = request.Uri.ToString(); string apiVersion = null; var apiVersion_out = new object(); var getApiVersion = moesifOptions.TryGetValue("ApiVersion", out apiVersion_out); if (getApiVersion) { apiVersion = apiVersion_out.ToString(); } var eventReq = new EventRequestModel() { Time = DateTime.UtcNow, Uri = uri, Verb = request.Method, ApiVersion = apiVersion, IpAddress = ip, Headers = reqHeaders, Body = reqBody, TransferEncoding = requestTransferEncoding }; return(eventReq); }