/// <summary> /// 查找黑名单 /// </summary> /// <param name="Address"></param> /// <returns>true找到</returns> public static bool FindBlackList(string Address) { Logger logger = LogManager.GetCurrentClassLogger(); try { List <tbBlackList> backList = DataCacheHelper.GetData <tbBlackList>(); if (backList == null || backList.Count <= 0) { return(false); } else { int DataCount = backList.Where(p => p.Address == Address).Count <tbBlackList>(); if (DataCount > 0) { return(true); } else { return(false); } } } catch (Exception ex) { logger.Log(LogLevel.Info, string.Format("检索黑名单异常:{0}", ex.Message)); return(true); } }
public async Task <IActionResult> Get([FromRoute][Username] string username, [FromHeader(Name = "If-None-Match")] string?ifNoneMatch) { _ = ifNoneMatch; long userId = await _userService.GetUserIdByUsernameAsync(username); return(await DataCacheHelper.GenerateActionResult(this, () => _service.GetAvatarDigestAsync(userId), () => _service.GetAvatarAsync(userId))); }
public static bool Analysis(string Address) { Logger logger = LogManager.GetCurrentClassLogger(); try { string BlackCount = System.Configuration.ConfigurationManager.AppSettings["BlackCount"]; int blackCount = string.IsNullOrEmpty(BlackCount) ? 0 : Convert.ToInt32(BlackCount); if (!string.IsNullOrEmpty(Address)) { if (FindBlackList(Address)) { logger.Log(LogLevel.Error, string.Format("{0}为黑名单地址禁止访问", Address)); return(false); } List <IPCountInfoModel> ipList = DataCacheHelper.GetData <IPCountInfoModel>(); int fondCount = 0; if (ipList != null && ipList.Count > 0) { for (int i = 0; i < ipList.Count; i++) { if (ipList[i].Address == Address) { ipList[i].Count = ipList[i].Count + 1; fondCount = ipList[i].Count; break; } } } else { IPCountInfoModel temp = new IPCountInfoModel() { Count = 1, Address = Address }; ipList.Add(temp); } DataCacheHelper.Updata <IPCountInfoModel>(ipList); if (fondCount > blackCount) { return(false); } } } catch (Exception ex) { logger.Log(LogLevel.Info, string.Format("检索访问缓存异常:{0}", ex.Message)); return(false); } return(true); }
public static void LoadBlackList() { try { Logger logger = LogManager.GetCurrentClassLogger(); AchieveDBEntities myDbContext = new AchieveDBEntities(); List <tbBlackList> templist = new List <tbBlackList>(); int DataCount = 0; DataCount = myDbContext.tbBlackList.Count <tbBlackList>(); logger.Log(LogLevel.Info, string.Format("已提取黑名单用户共计{0}条", DataCount)); templist = myDbContext.tbBlackList.ToList(); DataCacheHelper.Updata <tbBlackList>(templist); logger.Log(LogLevel.Info, string.Format("黑名单用户已加载至缓存")); } catch (Exception ex) { throw ex; } }
public async Task <ActionResult> DataGet([FromRoute][GeneralTimelineName] string timeline, [FromRoute] long post, [FromRoute(Name = "data_index")][Range(0, 100)] long dataIndex) { var timelineId = await _timelineService.GetTimelineIdByNameAsync(timeline); if (!UserHasAllTimelineManagementPermission && !await _timelineService.HasReadPermissionAsync(timelineId, GetOptionalUserId())) { return(ForbidWithCommonResponse()); } return(await DataCacheHelper.GenerateActionResult(this, () => _postService.GetPostDataDigestAsync(timelineId, post, dataIndex), async() => { var data = await _postService.GetPostDataAsync(timelineId, post, dataIndex); if (data.ContentType == MimeTypes.TextMarkdown) { return new ByteData(_markdownProcessor.Process(data.Data, Url, timeline, post), data.ContentType); } return data; } )); }
public static void AnalysisBlackList() { try { Logger logger = LogManager.GetCurrentClassLogger(); AchieveDBEntities myDbContext = new AchieveDBEntities(); List <tbBlackList> templist = new List <tbBlackList>(); logger.Log(LogLevel.Info, string.Format("启动分析黑名单进程!")); string BlackCount = System.Configuration.ConfigurationManager.AppSettings["BlackCount"]; int blackCount = string.IsNullOrEmpty(BlackCount) ? 0 : Convert.ToInt32(BlackCount); List <IPCountInfoModel> ipList = DataCacheHelper.GetData <IPCountInfoModel>(); if (ipList != null && ipList.Count > 0) { ipList = ipList.Where(p => p.Count > blackCount).ToList(); if (ipList != null && ipList.Count > 0) { foreach (var temp in ipList) { int DataCount = myDbContext.tbBlackList.Where(p => p.Address == temp.Address && p.IsAble == 1).Count <tbBlackList>(); if (DataCount > 0) { } else { DataCount = myDbContext.tbBlackList.Where(p => p.Address == temp.Address).Count <tbBlackList>(); if (DataCount > 0) { tbBlackList tp1 = new tbBlackList() { Address = temp.Address, }; myDbContext.tbBlackList.Remove(tp1); } tbBlackList tp = new tbBlackList() { Address = temp.Address, IsAble = 1, CreateTime = DateTime.Now, Notes = string.Format("心跳周期内访问{0}次,系统自动屏蔽!", temp.Count) }; myDbContext.tbBlackList.Add(tp); } } myDbContext.SaveChanges(); logger.Log(LogLevel.Info, string.Format("通过本次分析,黑名单共新增{0}条记录!", ipList.Count)); } } ipList = new List <IPCountInfoModel>(); DataCacheHelper.Updata <IPCountInfoModel>(ipList); logger.Log(LogLevel.Info, string.Format("结束分析黑名单进程!")); //缓存重新加载黑名单信息 LoadBlackList(); } catch (Exception ex) { throw ex; } }