public ActionResult Add(BannedIPModel model) { string ip = ""; if (string.IsNullOrWhiteSpace(model.IP4)) { ip = string.Format("{0}.{1}.{2}", model.IP1, model.IP2, model.IP3); } else { ip = string.Format("{0}.{1}.{2}.{3}", model.IP1, model.IP2, model.IP3, model.IP4); } if (AdminBannedIPs.GetBannedIPIdByIP(ip) > 0) { ModelState.AddModelError("IP4", "IP已经存在"); } if (ModelState.IsValid) { BannedIPInfo bannedIPInfo = new BannedIPInfo() { IP = ip, LiftBanTime = model.LiftBanTime }; AdminBannedIPs.AddBannedIP(bannedIPInfo); AddAdminOperateLog("添加禁止IP", "添加禁止IP,禁止IP为:" + ip); return(PromptView("禁止IP添加成功")); } ViewData["referer"] = ShopUtils.GetAdminRefererCookie(); return(View(model)); }
/// <summary> /// Gets and bulk updates banned IPs. Called when the "Get and bulk update ips" button is pressed. /// Expects the CreateBannedIp method to be run first. /// </summary> private bool GetAndBulkUpdateBannedIps() { // Prepare the parameters string where = "IPAddress LIKE N'MyNewIp%'"; // Get the data DataSet ips = BannedIPInfoProvider.GetBannedIPs(where, null); if (!DataHelper.DataSourceIsEmpty(ips)) { // Loop through the individual items foreach (DataRow ipDr in ips.Tables[0].Rows) { // Create object from DataRow BannedIPInfo modifyIp = new BannedIPInfo(ipDr); // Update the properties modifyIp.IPAddress = modifyIp.IPAddress.ToUpper(); // Save the changes BannedIPInfoProvider.SetBannedIPInfo(modifyIp); } return(true); } return(false); }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { // Check 'Modify' permission CheckPermissions("Modify"); string errorMessage = new Validator().NotEmpty(txtIPAddress.Text, GetString("banip.IPAddressEmpty")).Result; // Check if regularized ip address doesn't overflow database column if (BannedIPInfoProvider.GetRegularIPAddress(txtIPAddress.Text).Length > 200) { errorMessage = GetString("banip.IPAddressInvalid"); } if (errorMessage == "") { // If bannedIP doesn't already exist, create new one BannedIPInfo bannedIPObj = BannedIPInfoProvider.GetBannedIPInfo(itemid) ?? new BannedIPInfo(); bannedIPObj.IPAddressAllowed = radAllowIP.Checked; bannedIPObj.IPAddressBanType = drpIPAddressBanType.SelectedValue; bannedIPObj.IPAddressBanEnabled = chkIPAddressBanEnabled.Checked; bannedIPObj.IPAddress = txtIPAddress.Text.Trim(); // Make sure text is not too long if (txtIPAddressBanReason.Text.Length > 450) { txtIPAddressBanReason.Text = txtIPAddressBanReason.Text.Substring(0, 450); } bannedIPObj.IPAddressBanReason = txtIPAddressBanReason.Text.Trim(); if (SiteID == 0) { // For (global) set overriding from checkbox, otherwise is true bannedIPObj.IPAddressAllowOverride = (SelectedSiteID > 0) || chkIPAddressAllowOverride.Checked; // If site selected assign it to banned IP if (SelectedSiteID > 0) { bannedIPObj.IPAddressSiteID = SelectedSiteID; } } else { // Default setting for editing from CMSDesk bannedIPObj.IPAddressAllowOverride = true; bannedIPObj.IPAddressSiteID = SiteID; } BannedIPInfoProvider.SetBannedIPInfo(bannedIPObj); URLHelper.Redirect("Bannedip_Edit.aspx?siteid=" + SiteID + "&selectedsiteid=" + SelectedSiteID + "&itemid=" + bannedIPObj.IPAddressID + "&saved=1"); } else { ShowError(errorMessage); } }
/// <summary> /// Checks banned ip if current action is allowed. Called when the "Check banned IP for action" button is pressed. /// Expects the CreateBannedIp method to be run first. /// </summary> private bool CheckBannedIp() { // Prepare the parameters string where = "IPAddress LIKE N'MyNewIp%'"; // Get object from database BannedIPInfo checkIp = BannedIPInfoProvider.GetBannedIPs().Where(where).FirstResult().FirstObject; // Check if IP is allowed if ((checkIp == null) || !BannedIPInfoProvider.IsAllowed(checkIp.IPAddress, SiteContext.CurrentSiteName, BanControlEnum.AllNonComplete)) { return(false); } return(true); }
/// <summary> /// 获得禁止的ip /// </summary> /// <param name="id">id</param> /// <returns></returns> public static BannedIPInfo GetBannedIPById(int id) { BannedIPInfo bannedIPInfo = null; IDataReader reader = BrnMall.Core.BMAData.RDBS.GetBannedIPById(id); if (reader.Read()) { bannedIPInfo = new BannedIPInfo(); bannedIPInfo.Id = TypeHelper.ObjectToInt(reader["id"]); bannedIPInfo.IP = reader["ip"].ToString(); bannedIPInfo.LiftBanTime = TypeHelper.ObjectToDateTime(reader["liftbantime"]); } reader.Close(); return(bannedIPInfo); }
/// <summary> /// Creates banned ip. Called when the "Create ip" button is pressed. /// </summary> private bool CreateBannedIp() { // Create new banned ip object BannedIPInfo newIp = new BannedIPInfo(); // Set the properties newIp.IPAddress = "MyNewIp"; newIp.IPAddressBanReason = "Ban reason"; newIp.IPAddressAllowed = true; newIp.IPAddressAllowOverride = true; newIp.IPAddressBanType = BannedIPInfoProvider.BanControlEnumString(BanControlEnum.AllNonComplete); newIp.IPAddressBanEnabled = true; // Save the banned IP BannedIPInfoProvider.SetBannedIPInfo(newIp); return(true); }
/// <summary> /// Creates banned ip. Called when the "Create ip" button is pressed. /// </summary> private bool CreateBannedIp() { // Create new banned ip object BannedIPInfo newIp = new BannedIPInfo(); // Set the properties newIp.IPAddress = "MyNewIp"; newIp.IPAddressBanReason = "Ban reason"; newIp.IPAddressAllowed = true; newIp.IPAddressAllowOverride = true; newIp.IPAddressBanType = BannedIPInfoProvider.BanControlEnumString(BanControlEnum.AllNonComplete); newIp.IPAddressBanEnabled = true; // Save the banned IP BannedIPInfoProvider.SetBannedIPInfo(newIp); return true; }
/// <summary> /// Deletes banned ip. Called when the "Delete ip" button is pressed. /// Expects the CreateBannedIp method to be run first. /// </summary> private bool DeleteBannedIp() { // Prepare the parameters string where = "IPAddress LIKE N'MyNewIp%'"; // Get object from database BannedIPInfo deleteIp = BannedIPInfoProvider.GetBannedIPs().Where(where).FirstResult().FirstObject; if (deleteIp != null) { // Delete the banned ip BannedIPInfoProvider.DeleteBannedIPInfo(deleteIp); return(true); } return(false); }
/// <summary> /// Checks banned ip if current action is allowed. Called when the "Check banned IP for action" button is pressed. /// Expects the CreateBannedIp method to be run first. /// </summary> private bool CheckBannedIp() { string where = "IPAddress LIKE N'MyNewIp%'"; // Get DataSet DataSet ips = BannedIPInfoProvider.GetBannedIPs(where, null); if (!DataHelper.DataSourceIsEmpty(ips)) { // Get the first banned ip BannedIPInfo checkIp = new BannedIPInfo(ips.Tables[0].Rows[0]); if (!BannedIPInfoProvider.IsAllowed(checkIp.IPAddress, CMSContext.CurrentSiteName, BanControlEnum.AllNonComplete)) { return true; } } return false; }
/// <summary> /// Deletes banned ip. Called when the "Delete ip" button is pressed. /// Expects the CreateBannedIp method to be run first. /// </summary> private bool DeleteBannedIp() { string where = "IPAddress LIKE N'MyNewIp%'"; // Get DataSet DataSet ips = BannedIPInfoProvider.GetBannedIPs(where, null); if (!DataHelper.DataSourceIsEmpty(ips)) { // Get the first banned ip BannedIPInfo deleteIp = new BannedIPInfo(ips.Tables[0].Rows[0]); // Delete the banned ip BannedIPInfoProvider.DeleteBannedIPInfo(deleteIp); return(true); } return(false); }
/// <summary> /// Checks banned ip if current action is allowed. Called when the "Check banned IP for action" button is pressed. /// Expects the CreateBannedIp method to be run first. /// </summary> private bool CheckBannedIp() { string where = "IPAddress LIKE N'MyNewIp%'"; // Get DataSet DataSet ips = BannedIPInfoProvider.GetBannedIPs(where, null); if (!DataHelper.DataSourceIsEmpty(ips)) { // Get the first banned ip BannedIPInfo checkIp = new BannedIPInfo(ips.Tables[0].Rows[0]); if (!BannedIPInfoProvider.IsAllowed(checkIp.IPAddress, CMSContext.CurrentSiteName, BanControlEnum.AllNonComplete)) { return(true); } } return(false); }
/// <summary> /// Gets and updates banned IP. Called when the "Get and update IP" button is pressed. /// Expects the CreateBannedIp method to be run first. /// </summary> private bool GetAndUpdateBannedIp() { // Prepare the parameters string where = "IPAddress LIKE N'MyNewIp%'"; // Get object from database BannedIPInfo modifyIp = BannedIPInfoProvider.GetBannedIPs().Where(where).FirstResult().FirstObject; if (modifyIp != null) { // Update the properties modifyIp.IPAddress = modifyIp.IPAddress.ToLowerCSafe(); // Save the changes BannedIPInfoProvider.SetBannedIPInfo(modifyIp); return(true); } return(false); }
public ActionResult Edit(BannedIPModel model, int id = -1) { BannedIPInfo bannedIPInfo = AdminBannedIPs.GetBannedIPById(id); if (bannedIPInfo == null) { return(PromptView("禁止IP不存在")); } string ip = ""; if (string.IsNullOrWhiteSpace(model.IP4)) { ip = string.Format("{0}.{1}.{2}", model.IP1, model.IP2, model.IP3); } else { ip = string.Format("{0}.{1}.{2}.{3}", model.IP1, model.IP2, model.IP3, model.IP4); } int id2 = AdminBannedIPs.GetBannedIPIdByIP(ip); if (id2 > 0 && id2 != id) { ModelState.AddModelError("IP4", "IP已经存在"); } if (ModelState.IsValid) { bannedIPInfo.IP = ip; bannedIPInfo.LiftBanTime = model.LiftBanTime; AdminBannedIPs.UpdateBannedIP(bannedIPInfo); AddAdminOperateLog("修改禁止IP", "修改禁止IP,禁止IPID为:" + id); return(PromptView("禁止IP修改成功")); } ViewData["referer"] = ShopUtils.GetAdminRefererCookie(); return(View(model)); }
/// <summary> /// Gets and updates banned IP. Called when the "Get and update IP" button is pressed. /// Expects the CreateBannedIp method to be run first. /// </summary> private bool GetAndUpdateBannedIp() { string where = "IPAddress LIKE N'MyNewIp%'"; DataSet ips = BannedIPInfoProvider.GetBannedIPs(where, null); if (!DataHelper.DataSourceIsEmpty(ips)) { // Create object from DataRow BannedIPInfo modifyIp = new BannedIPInfo(ips.Tables[0].Rows[0]); // Update the properties modifyIp.IPAddress = modifyIp.IPAddress.ToLower(); // Save the changes BannedIPInfoProvider.SetBannedIPInfo(modifyIp); return(true); } return(false); }
/// <summary> /// Load data of editing bannedIP. /// </summary> /// <param name="bannedIPObj">BannedIP object</param> protected void LoadData(BannedIPInfo bannedIPObj) { // Check proper radio button if (bannedIPObj.IPAddressAllowed) { radAllowIP.Checked = true; } else { radBanIP.Checked = true; } drpIPAddressBanType.SelectedValue = bannedIPObj.IPAddressBanType; chkIPAddressBanEnabled.Checked = bannedIPObj.IPAddressBanEnabled; txtIPAddress.Text = bannedIPObj.IPAddress; txtIPAddressBanReason.Text = bannedIPObj.IPAddressBanReason; if (SiteID == 0) { chkIPAddressAllowOverride.Checked = bannedIPObj.IPAddressAllowOverride; } }
public ActionResult Edit(int id = -1) { BannedIPInfo bannedIPInfo = AdminBannedIPs.GetBannedIPById(id); if (bannedIPInfo == null) { return(PromptView("禁止IP不存在")); } string[] ipList = StringHelper.SplitString(bannedIPInfo.IP, "."); BannedIPModel model = new BannedIPModel(); model.IP1 = ipList[0]; model.IP2 = ipList[1]; model.IP3 = ipList[2]; model.IP4 = ipList.Length == 4 ? ipList[3] : ""; model.LiftBanTime = bannedIPInfo.LiftBanTime; ViewData["referer"] = ShopUtils.GetAdminRefererCookie(); return(View(model)); }
/// <summary> /// 添加禁止的ip /// </summary> public static void AddBannedIP(BannedIPInfo bannedIPInfo) { BrnMall.Data.BannedIPs.AddBannedIP(bannedIPInfo); BrnMall.Core.BMACache.Remove(CacheKeys.MALL_BANNEDIP_HASHSET); }
/// <summary> /// 更新禁止的ip /// </summary> public static void UpdateBannedIP(BannedIPInfo bannedIPInfo) { BrnShop.Core.BSPData.RDBS.UpdateBannedIP(bannedIPInfo); }
/// <summary> /// 更新禁止的ip /// </summary> public static void UpdateBannedIP(BannedIPInfo bannedIPInfo) { NStore.Data.BannedIPs.UpdateBannedIP(bannedIPInfo); NStore.Core.BMACache.Remove(CacheKeys.MALL_BANNEDIP_HASHSET); }
/// <summary> /// 添加禁止的ip /// </summary> public static void AddBannedIP(BannedIPInfo bannedIPInfo) { BrnMall.Core.BMAData.RDBS.AddBannedIP(bannedIPInfo); }
/// <summary> /// 更新禁止的ip /// </summary> public static void UpdateBannedIP(BannedIPInfo bannedIPInfo) { BrnMall.Core.BMAData.RDBS.UpdateBannedIP(bannedIPInfo); }
protected void Page_Load(object sender, EventArgs e) { // Controls initialization radBanIP.Text = GetString("banip.radBanIP"); radAllowIP.Text = GetString("banip.radAllowIP"); lblIPAddressBanType.Text = GetString("banip.IPAddressBanType") + ResHelper.Colon; lblIPAddressBanEnabled.Text = GetString("general.enabled") + ResHelper.Colon; lblIPAddress.Text = GetString("banip.IPAddress") + ResHelper.Colon; lblIPAddressBanReason.Text = GetString("banip.IPAddressBanReason") + ResHelper.Colon; rfvIPAddress.ErrorMessage = GetString("banip.IPAddressEmpty"); lblIPAddressAllowOverride.Text = GetString("banip.IPAddressAllowOverride") + ResHelper.Colon; if (!RequestHelper.IsPostBack()) { // Add list items to ban type drop down list ControlsHelper.FillListControlWithEnum <BanControlEnum>(drpIPAddressBanType, "banip.bantype", useStringRepresentation: true); drpIPAddressBanType.SelectedValue = BanControlEnum.AllNonComplete.ToStringRepresentation(); } string currentBannedIP = GetString("banip.NewItemCaption"); // Get bannedIP id from querystring itemid = QueryHelper.GetInteger("itemid", 0); if (itemid > 0) { BannedIPInfo bannedIPObj = BannedIPInfoProvider.GetBannedIPInfo(itemid); EditedObject = bannedIPObj; if (bannedIPObj != null) { //Check whether the item truly belogs to specified site if (((SiteID > 0) && (bannedIPObj.IPAddressSiteID != SiteID)) || ((SelectedSiteID > 0) && (bannedIPObj.IPAddressSiteID != SelectedSiteID))) { RedirectToAccessDenied(GetString("banip.invaliditem")); } currentBannedIP = bannedIPObj.IPAddress; // Add site info to breadcrumbs if (SiteID == 0) { if (bannedIPObj.IPAddressSiteID == 0) { currentBannedIP += " (global)"; radAllowIP.Text = GetString("banip.radAllowIPglobal"); plcIPOveride.Visible = true; } else { SiteInfo si = SiteInfoProvider.GetSiteInfo(bannedIPObj.IPAddressSiteID); if (si != null) { currentBannedIP += " (" + si.DisplayName + ")"; } } } // Fill editing form if (!RequestHelper.IsPostBack()) { LoadData(bannedIPObj); // Show that the bannedIP was created or updated successfully if ((QueryHelper.GetInteger("saved", 0) == 1) && !RequestHelper.IsPostBack()) { ShowChangesSaved(); } } } } // Initializes page title control SetBreadcrumb(0, GetString("banip.listHeaderCaption"), ResolveUrl("BannedIP_List.aspx?siteId=" + SiteID + "&selectedsiteid=" + SelectedSiteID), null, null); SetBreadcrumb(1, currentBannedIP, null, null, null); // Add info about selected site in Site manager for new item if ((SiteID == 0) && (itemid == 0)) { if (SelectedSiteID > 0) { // Site banned IP SiteInfo si = SiteInfoProvider.GetSiteInfo(SelectedSiteID); if (si != null) { SetBreadcrumb(1, currentBannedIP + " (" + si.DisplayName + ")", null, null, null); } } else { // Global banned IP SetBreadcrumb(1, currentBannedIP + " (global)", null, null, null); radAllowIP.Text = GetString("banip.radAllowIPglobal"); plcIPOveride.Visible = true; } } // Different header and icon if it is new item if (itemid <= 0) { SetTitle(GetString("banip.newHeaderCaption")); } }
/// <summary> /// Deletes banned ip. Called when the "Delete ip" button is pressed. /// Expects the CreateBannedIp method to be run first. /// </summary> private bool DeleteBannedIp() { string where = "IPAddress LIKE N'MyNewIp%'"; // Get DataSet DataSet ips = BannedIPInfoProvider.GetBannedIPs(where, null); if (!DataHelper.DataSourceIsEmpty(ips)) { // Get the first banned ip BannedIPInfo deleteIp = new BannedIPInfo(ips.Tables[0].Rows[0]); // Delete the banned ip BannedIPInfoProvider.DeleteBannedIPInfo(deleteIp); return true; } return false; }
/// <summary> /// Gets and bulk updates banned IPs. Called when the "Get and bulk update ips" button is pressed. /// Expects the CreateBannedIp method to be run first. /// </summary> private bool GetAndBulkUpdateBannedIps() { // Prepare the parameters string where = "IPAddress LIKE N'MyNewIp%'"; // Get the data DataSet ips = BannedIPInfoProvider.GetBannedIPs(where, null); if (!DataHelper.DataSourceIsEmpty(ips)) { // Loop through the individual items foreach (DataRow ipDr in ips.Tables[0].Rows) { // Create object from DataRow BannedIPInfo modifyIp = new BannedIPInfo(ipDr); // Update the properties modifyIp.IPAddress = modifyIp.IPAddress.ToUpper(); // Save the changes BannedIPInfoProvider.SetBannedIPInfo(modifyIp); } return true; } return false; }
/// <summary> /// Gets and updates banned IP. Called when the "Get and update IP" button is pressed. /// Expects the CreateBannedIp method to be run first. /// </summary> private bool GetAndUpdateBannedIp() { string where = "IPAddress LIKE N'MyNewIp%'"; DataSet ips = BannedIPInfoProvider.GetBannedIPs(where, null); if (!DataHelper.DataSourceIsEmpty(ips)) { // Create object from DataRow BannedIPInfo modifyIp = new BannedIPInfo(ips.Tables[0].Rows[0]); // Update the properties modifyIp.IPAddress = modifyIp.IPAddress.ToLower(); // Save the changes BannedIPInfoProvider.SetBannedIPInfo(modifyIp); return true; } return false; }
/// <summary> /// 添加禁止的ip /// </summary> public static void AddBannedIP(BannedIPInfo bannedIPInfo) { OWZX.Data.BannedIPs.AddBannedIP(bannedIPInfo); OWZX.Core.BSPCache.Remove(CacheKeys.SHOP_BANNEDIP_HASHSET); }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { // check 'Modify' permission CheckPermissions("Modify"); string errorMessage = new Validator().NotEmpty(txtIPAddress.Text, GetString("banip.IPAddressEmpty")).Result; // Check if regularized ip address doesn't overflow database column if (BannedIPInfoProvider.GetRegularIPAddress(txtIPAddress.Text).Length > 200) { errorMessage = GetString("banip.IPAddressInvalid"); } if (errorMessage == "") { BannedIPInfo bannedIPObj = BannedIPInfoProvider.GetBannedIPInfo(itemid); // if bannedIP doesnt already exist, create new one if (bannedIPObj == null) { bannedIPObj = new BannedIPInfo(); } bannedIPObj.IPAddressAllowed = radAllowIP.Checked; bannedIPObj.IPAddressBanType = drpIPAddressBanType.SelectedValue; bannedIPObj.IPAddressBanEnabled = chkIPAddressBanEnabled.Checked; bannedIPObj.IPAddress = txtIPAddress.Text.Trim(); // Make sure text is not too long if (txtIPAddressBanReason.Text.Length > 450) { txtIPAddressBanReason.Text = txtIPAddressBanReason.Text.Substring(0, 450); } bannedIPObj.IPAddressBanReason = txtIPAddressBanReason.Text.Trim(); if (SiteID == 0) { // For (global) set overriding from checkbox, otherwise is true bannedIPObj.IPAddressAllowOverride = (SelectedSiteID > 0) || chkIPAddressAllowOverride.Checked; // If site selected assign it to banned IP if (SelectedSiteID > 0) { bannedIPObj.IPAddressSiteID = SelectedSiteID; } } else { // default setting for editing from CMSDesk bannedIPObj.IPAddressAllowOverride = true; bannedIPObj.IPAddressSiteID = SiteID; } BannedIPInfoProvider.SetBannedIPInfo(bannedIPObj); URLHelper.Redirect("Bannedip_Edit.aspx?siteid=" + SiteID + "&selectedsiteid=" + SelectedSiteID + "&itemid=" + bannedIPObj.IPAddressID + "&saved=1"); } else { ShowError(errorMessage); } }
/// <summary> /// 添加禁止的ip /// </summary> public static void AddBannedIP(BannedIPInfo bannedIPInfo) { BrnShop.Core.BSPData.RDBS.AddBannedIP(bannedIPInfo); }
/// <summary> /// 更新禁止的ip /// </summary> public static void UpdateBannedIP(BannedIPInfo bannedIPInfo) { BrnShop.Data.BannedIPs.UpdateBannedIP(bannedIPInfo); BrnShop.Core.BSPCache.Remove(CacheKeys.SHOP_BANNEDIP_HASHSET); }