static CacheHelper() { IAdminApplication adminApplication = MyIoc.Create <IAdminApplication>(); var task = adminApplication.GetAdminCookieList().RunSync(); //adminApplication.GetAdminSessionId().RunSynchronously() foreach (var item in task) { AdminSessionIdCaches[item.Id] = item.LastSessionID; AdminBrowserPasswordCaches[item.Id] = item.LastBrowserPassword; } var settingValue = adminApplication.GetSettingValueByCode("UseWatermark").RunSync(); if (settingValue != null) { UseWatermark = settingValue.Value == "1"; } var settingValue2 = adminApplication.GetSettingValueByCode("WatermarkText").RunSync(); if (settingValue2 != null) { WatermarkText = settingValue2.Value; } else { WatermarkText = "{trueName} {yyyy}-{MM}-{dd}"; } }
public static async Task Init() { IAdminSecurityApplication ipAddressApplication = MyIoc.Create <IAdminSecurityApplication>(); var useIpType = await ipAddressApplication.GetUseIpType(); var ipFirewall = IpFirewallHelper.GetIpFirewall(); var list = await ipAddressApplication.GetIpBanAll(); ipFirewall.SetIpBanList(list.Select(q => q.Ip).ToList()); var list2 = await ipAddressApplication.GetIpAllowAll(); ipFirewall.SetIpAllowList(list2.Select(q => q.Ip).ToList()); if (useIpType == 1) { ipFirewall.UseIpBanList(); } else if (useIpType == 2) { ipFirewall.UseIpAllowList(); } else { ipFirewall.CloseFirewall(); } }
public static void UpdateWatermarkText() { IAdminApplication adminApplication = MyIoc.Create <IAdminApplication>(); var settingValue = adminApplication.GetSettingValueByCode("UseWatermark").RunSync(); if (settingValue != null) { UseWatermark = settingValue.Value == "1"; } var settingValue2 = adminApplication.GetSettingValueByCode("WatermarkText").RunSync(); if (settingValue2 != null) { WatermarkText = settingValue2.Value; } else { WatermarkText = "{trueName} {yyyy}-{MM}-{dd}"; } }
public override void OnActionExecuting(ActionExecutingContext context) { var adminApplication = MyIoc.Create <IAdminApplication>(); #region 检测登录,cookie登录 AdminSessionDto adminSessionDto = context.GetSession <AdminSessionDto>(SessionSetting.AdminSession); //if (adminSessionDto == null) { // var userDto = GetAdminCookieDto(context); // if (userDto != null && userDto.ExpireTime > DateTime.Now) { // if (CacheHelper.CheckAdminSessionId(userDto.UserId, context.GetCookie(CookieSetting.AdminCookie))) { // var admin = adminApplication.GetAdminById(userDto.UserId).RunSync(); // if (null != admin && admin.IsFrozen == 0) { // bool pwd = HashUtil.GetMd5String(admin.Password) == userDto.PasswordHash; // if (pwd) { // adminSessionDto = new AdminSessionDto(admin.Id, admin.Name, admin.TrueName, admin.JobNo); // context.SetSession(SessionSetting.AdminSession, adminSessionDto); // } // } // } // } //} if (null == adminSessionDto) { if (context.HttpContext.Request.Method.ToUpper() == "GET") { var url = UrlSetting.AdminLoginUrl; context.Result = ActionResultUtil.JumpTopUrl(url, "cookie无效,请先登录!"); } else { context.Result = ActionResultUtil.Error(); } return; } #endregion #region 检测菜单权限 var menus = this.GetType().GetCustomAttributes <AdminMenuAttribute>(true); List <AdminMenuAttribute> adminMenus = new List <AdminMenuAttribute>(); if (menus.Count() > 0) { foreach (var item in menus) { var isPass = CacheHelper.AdminMenuButtonCache.GetOrAdd(adminSessionDto.Id + "-" + item.MenuCode + "-" + item.ButtonCode, () => { return(adminApplication.IsPass(adminSessionDto.Id, item.MenuCode, item.ButtonCode).RunSync()); }); if (isPass) { adminMenus.Add(item); } } if (adminMenus.Count == 0) { context.Result = new RedirectResult(UrlSetting.AdminNoAccessUrl); return; } ViewData["MenuCode"] = adminMenus[0].MenuCode; ViewData["ButtonCode"] = adminMenus[0].ButtonCode; } #endregion base.OnActionExecuting(context); if (context.Result != null) { return; } #region 检测参数是否正常 AdminDto = adminSessionDto; var rsaHelper = RsaHelper.Instance; IRequest temp = null; foreach (var item in context.ActionArguments) { if (item.Value is EncryptedQueryArgs rsaData) { rsaData.PasswordString = CacheHelper.GetBrowserPassword(AdminDto.Id); if (rsaData.CheckSign(rsaHelper.RsaModulus, rsaHelper.RsaExponent, out string msg) == false) { DeleteCookie(CookieSetting.AdminCookieLogin); context.Result = Error(msg); return; } if (rsaData.DecryptData() == false) { context.Result = Error("数据错误!"); return; } if (rsaData.CheckData(out string msg2) == false) { context.Result = Error(msg2); return; } if (rsaData is IRequest adminRequest) { adminRequest.OperatorId = AdminDto.Id; adminRequest.OperatorName = AdminDto.TrueName; temp = adminRequest; } } } #endregion #region 检测是否启用管理模式 if (adminSessionDto.IsAdminMode() == false) { foreach (var item in adminMenus) { var useCheck = CacheHelper.AdminMenuCheckCache.GetOrAdd(item.MenuCode + "-" + item.ButtonCode, () => { return(adminApplication.GetMenuCheck(item.MenuCode, item.ButtonCode).RunSync()); }); if (useCheck) { if (context.HttpContext.Request.Method.ToUpper() == "GET") { var urlP = System.Web.HttpUtility.UrlEncode(context.HttpContext.Request.Path.ToSafeString() + context.HttpContext.Request.QueryString.ToSafeString()); var url = UrlSetting.AdminModeUrl + urlP;// $"/admin/tools/AdminMode?url={urlP}"; context.Result = ActionResultUtil.JumpUrl(url); return; } else { if (temp == null) { context.Result = ActionResultUtil.Error("TryAdminMode"); return; } if (string.IsNullOrEmpty(temp.OperatorPassword)) { context.Result = ActionResultUtil.Error("TryAdminMode"); return; } if (adminApplication.CheckPassword(temp.OperatorId, temp.OperatorPassword, temp).RunSync() == false) { context.Result = ActionResultUtil.Error("密码不正确"); return; } AdminDto.SetAdminMode(DateTime.Now.AddMinutes(temp.AdminModeTime)); SetSession(SessionSetting.AdminSession, AdminDto); break; } } } } #endregion }