예제 #1
0
 public static bool Delete(string zoneId, int id)
 {
     try
     {
         return(BanIpHistoryAccess.Delete(id));
     }
     catch (Exception ex)
     {
         var zoneTableId = ZoneAccess.GetZoneByZoneId(zoneId).TableID;
         AuditLogBusiness.Add(new AuditLogEntity(zoneTableId, LogLevel.Error,
                                                 $"delete ban ip histories failure, the reason is:[{ex.Message}].<br />stack trace:{ex.StackTrace}."));
         return(false);
     }
 }
예제 #2
0
 public static List <BanIpHistory> Get(string zoneId, string ip = null)
 {
     try
     {
         return(BanIpHistoryAccess.Get(zoneId, ip));
     }
     catch (Exception ex)
     {
         var zoneTableId = ZoneAccess.GetZoneByZoneId(zoneId).TableID;
         AuditLogBusiness.Add(new AuditLogEntity(zoneTableId, LogLevel.Error,
                                                 $"Get ban ip histories failure, the reason is:[{ex.Message}].<br />stack trace:{ex.StackTrace}."));
         return(new List <BanIpHistory>());
     }
 }
        public List <CloudflareLog> GetLogs(DateTime start, DateTime end, double sample, out bool retry)
        {
            var zoneTableId = ZoneBusiness.GetZoneByZoneId(_zoneId).TableID;

            retry = false;
            var cloudflareLogs = new List <CloudflareLog>();

            try
            {
                string fields    = "RayID,ClientIP,ClientRequestHost,ClientRequestMethod,ClientRequestURI,EdgeEndTimestamp,EdgeResponseBytes,EdgeResponseStatus,EdgeStartTimestamp,CacheResponseStatus,ClientRequestBytes,CacheCacheStatus,OriginResponseStatus,OriginResponseTime";
                string startTime = GetUTCTimeString(start);
                string endTime   = GetUTCTimeString(end);
                string url       = "{5}/zones/{0}/logs/received?start={1}&end={2}&fields={3}&sample={4}";
                url = string.Format(url, _zoneId, startTime, endTime, fields, sample, _apiUrlPrefix);
                string content = HttpGet(url, 240);
                if (content.Contains(@"""success"":false"))
                {
                    if (content.Contains("429 Too Many Requests"))
                    {
                        retry = true;
                    }
                    else
                    {
                        var errorResponse = JsonConvert.DeserializeObject <CloudflareLogErrorResponse>(content);
                        AuditLogBusiness.Add(new AuditLogEntity(zoneTableId, LogLevel.Error,
                                                                $"Got logs failure, the reason is:[{ (errorResponse.Errors.Count > 0 ? errorResponse.Errors[0].Message : "No error message from Cloudflare.")}]."));
                    }
                }
                else
                {
                    content        = content.Replace("\"}", "\"},");
                    cloudflareLogs = JsonConvert.DeserializeObject <List <CloudflareLog> >($"[{content}]");
                    cloudflareLogs.RemoveAll(x =>
                                             (null != x.CacheCacheStatus && x.CacheCacheStatus.ToLower().Equals("hit")) ||
                                             0 == x.OriginResponseStatus);
                }

                return(cloudflareLogs);
            }
            catch (Exception ex)
            {
                retry = true;
                AuditLogBusiness.Add(new AuditLogEntity(zoneTableId, LogLevel.Error,
                                                        $"Got logs failure, the reason is:[{ex.Message}]. <br />stack trace:{ex.StackTrace}]."));
                return(cloudflareLogs);
            }
        }
예제 #4
0
 public static bool Add(BanIpHistory banIpHistory)
 {
     try
     {
         var banIpHistories = BanIpHistoryAccess.Get(banIpHistory.ZoneId, banIpHistory.IP);
         if (null != banIpHistories && banIpHistories.Count > 0)
         {
             return(BanIpHistoryAccess.Update(banIpHistory));
         }
         else
         {
             return(BanIpHistoryAccess.Add(banIpHistory));
         }
     }
     catch (Exception ex)
     {
         var zoneTableId = ZoneAccess.GetZoneByZoneId(banIpHistory.ZoneId).TableID;
         AuditLogBusiness.Add(new AuditLogEntity(zoneTableId, LogLevel.Error,
                                                 $"Add ban ip histories failure, the reason is:[{ex.Message}].<br />stack trace:{ex.StackTrace}."));
         return(false);
     }
 }