/// <summary>
        /// Event handler for BeginRequest.
        /// </summary>
        /// <param name="sender">Sender object instance.</param>
        /// <param name="e">Event arguments.</param>
        void Context_BeginRequest(object sender, EventArgs e)
        {
            if (InstallerHelper.ConnectionStringIsSet())
            {
                try
                {
                    if (HttpContext.Current != null && !HttpContext.Current.Request.Url.IsLoopback)
                    {
                        HttpApplication application = sender as HttpApplication;
                        BannedIpAddress clientIP    = new BannedIpAddress();
                        clientIP.Address = application.Request.UserHostAddress;
                        // On any unexpected error we let visitor to visit website
                        if (IpBlacklistManager.IsIpAddressBanned(clientIP))
                        {
                            // Blocking process

                            // for now just show error 404 - Forbidden
                            // later let the user know that his ip address/network
                            // was banned and a reason why... this means we need an error page (aspx)
                            application.Response.StatusCode = 403;
                            application.Server.Transfer("~/BannedAddress.htm");
                            application.Response.StatusDescription = "Access is denied";
                            application.Response.End();
                        }
                    }
                }
                catch (Exception exc)
                {
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Saves a BannedIpNetwork
        /// </summary>
        /// <returns>BannedIpNetwork</returns>
        public BannedIpNetwork SaveBannedIpNetworkInfo()
        {
            DateTime nowDT = DateTime.Now;

            //split the text in the BannedIP to get the current IPs
            string[] rangeItems = txtBannedIP.Text.ToString().Split("-".ToCharArray());

            // Check if the 1st IP is valid
            if (!IpBlacklistManager.IsValidIp(rangeItems[0].Trim()))
            {
                throw new NopException("The following isn't a valid IP address: " + rangeItems[0]);
            }

            // Check if the 2nd IP is valid
            if (!IpBlacklistManager.IsValidIp(rangeItems[1].Trim()))
            {
                throw new NopException("The following isn't a valid IP address: " + rangeItems[1]);
            }

            BannedIpNetwork ipNetwork = IpBlacklistManager.GetBannedIpNetworkById(BannedIpNetworkID);

            //if ip network is not null update
            if (ipNetwork != null)
            {
                ipNetwork = IpBlacklistManager.UpdateBannedIpNetwork(BannedIpNetworkID, rangeItems[0], rangeItems[1],
                                                                     txtComment.Text, txtIpException.Text, ipNetwork.CreatedOn, nowDT);
            }
            else //insert
            {
                ipNetwork = IpBlacklistManager.InsertBannedIpNetwork(rangeItems[0], rangeItems[1],
                                                                     txtComment.Text, txtIpException.Text, nowDT, nowDT);
            }

            return(ipNetwork);
        }
Ejemplo n.º 3
0
        private void BindGrid()
        {
            var ipAddressCollection = IpBlacklistManager.GetBannedIpAddressAll();

            gvBannedIpAddress.DataSource = ipAddressCollection;
            gvBannedIpAddress.DataBind();

            var ipNetworkCollection = IpBlacklistManager.GetBannedIpNetworkAll();

            gvBannedIpNetwork.DataSource = ipNetworkCollection;
            gvBannedIpNetwork.DataBind();
        }
Ejemplo n.º 4
0
 protected void OnDeleteClick(object sender, EventArgs e)
 {
     try
     {
         IpBlacklistManager.DeleteBannedIpAddress(BannedIpAddressID);
         Response.Redirect("Blacklist.aspx");
     }
     catch (Exception exc)
     {
         ProcessException(exc);
     }
 }
Ejemplo n.º 5
0
 protected void DeleteButton_Click(object sender, EventArgs e)
 {
     try
     {
         IpBlacklistManager.DeleteBannedIpNetwork(this.BannedIpNetworkId);
         Response.Redirect("Blacklist.aspx");
     }
     catch (Exception exc)
     {
         ProcessException(exc);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Bind controls on the form
        /// </summary>
        private void BindData()
        {
            BannedIpAddress ipAddress = IpBlacklistManager.GetBannedIpAddressById(this.BannedIpAddressId);

            if (ipAddress != null)
            {
                txtBannedIP.Text          = ipAddress.Address;
                txtComment.Text           = ipAddress.Comment;
                this.pnlCreatedOn.Visible = true;
                this.pnlUpdatedOn.Visible = true;
                lblCreatedOn.Text         = DateTimeHelper.ConvertToUserTime(ipAddress.CreatedOn, DateTimeKind.Utc).ToString();
                lblUpdatedOn.Text         = DateTimeHelper.ConvertToUserTime(ipAddress.UpdatedOn, DateTimeKind.Utc).ToString();
            }
            else
            {
                this.pnlCreatedOn.Visible = false;
                this.pnlUpdatedOn.Visible = false;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Bind controls on the form
        /// </summary>
        private void BindData()
        {
            BannedIpNetwork ipNetwork = IpBlacklistManager.GetBannedIpNetworkById(BannedIpNetworkID);

            if (ipNetwork != null)
            {
                txtBannedIP.Text          = ipNetwork.ToString();
                txtComment.Text           = ipNetwork.Comment;
                txtIpException.Text       = ipNetwork.IpException;
                this.pnlCreatedOn.Visible = true;
                this.pnlUpdatedOn.Visible = true;
                lblCreatedOn.Text         = DateTimeHelper.ConvertToUserTime(ipNetwork.CreatedOn).ToString();
                lblUpdatedOn.Text         = DateTimeHelper.ConvertToUserTime(ipNetwork.UpdatedOn).ToString();
            }
            else
            {
                this.pnlCreatedOn.Visible = false;
                this.pnlUpdatedOn.Visible = false;
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Saves a BannedIpAddress
        /// </summary>
        /// <returns>BannedIpAddress</returns>
        public BannedIpAddress SaveBannedIpAddressInfo()
        {
            DateTime        nowDT     = DateTime.UtcNow;
            BannedIpAddress ipAddress = IpBlacklistManager.GetBannedIpAddressById(this.BannedIpAddressId);

            // Check if the IP is valid
            if (!IpBlacklistManager.IsValidIp(txtBannedIP.Text.Trim()))
            {
                throw new NopException("The following isn't a valid IP address: " + txtBannedIP.Text);
            }

            //if ip address is not null update
            if (ipAddress != null)
            {
                ipAddress = IpBlacklistManager.UpdateBannedIpAddress(this.BannedIpAddressId, txtBannedIP.Text,
                                                                     txtComment.Text, ipAddress.CreatedOn, nowDT);
            }
            else //insert
            {
                ipAddress = IpBlacklistManager.InsertBannedIpAddress(txtBannedIP.Text, txtComment.Text, nowDT, nowDT);
            }

            return(ipAddress);
        }
Ejemplo n.º 9
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    // Check IP list
                    string ipList = txtAllowedIPList.Text.Trim();
                    if (!String.IsNullOrEmpty(ipList))
                    {
                        foreach (string s in ipList.Split(new char[1] {
                            ','
                        }))
                        {
                            if (!IpBlacklistManager.IsValidIp(s.Trim()))
                            {
                                throw new NopException("IP list is not valid.");
                            }
                        }
                    }

                    SettingManager.StoreName = txtStoreName.Text;
                    SettingManager.StoreUrl  = txtStoreURL.Text;
                    SettingManager.SetParam("Common.StoreClosed", cbStoreClosed.Checked.ToString());
                    CustomerManager.AnonymousCheckoutAllowed = cbAnonymousCheckoutAllowed.Checked;
                    SettingManager.SetParam("Checkout.UseOnePageCheckout", cbUseOnePageCheckout.Checked.ToString());
                    SettingManager.SetParam("Checkout.TermsOfServiceEnabled", cbCheckoutTermsOfService.Checked.ToString());

                    SettingManager.SetParam("SEO.IncludeStoreNameInTitle", cbStoreNameInTitle.Checked.ToString());
                    SettingManager.SetParam("SEO.DefaultTitle", txtDefaulSEOTitle.Text);
                    SettingManager.SetParam("SEO.DefaultMetaDescription", txtDefaulSEODescription.Text);
                    SettingManager.SetParam("SEO.DefaultMetaKeywords", txtDefaulSEOKeywords.Text);
                    SettingManager.SetParam("Display.PublicStoreTheme", ctrlThemeSelector.SelectedTheme);
                    if (fileFavicon.HasFile)
                    {
                        HttpPostedFile postedFile = fileFavicon.PostedFile;
                        if (!postedFile.ContentType.Equals("image/x-icon"))
                        {
                            throw new NopException("Image format not recognized, allowed formats are: .ico");
                        }
                        postedFile.SaveAs(HttpContext.Current.Request.PhysicalApplicationPath + "favicon.ico");
                    }
                    SettingManager.SetParam("Display.ShowWelcomeMessageOnMainPage", cbShowWelcomeMessage.Checked.ToString());
                    SettingManager.SetParam("Display.ShowNewsHeaderRssURL", cbShowNewsHeaderRssURL.Checked.ToString());
                    SettingManager.SetParam("Display.ShowBlogHeaderRssURL", cbShowBlogHeaderRssURL.Checked.ToString());
                    SettingManager.SetParam("SEO.Product.UrlRewriteFormat", txtProductUrlRewriteFormat.Text);
                    SettingManager.SetParam("SEO.Category.UrlRewriteFormat", txtCategoryUrlRewriteFormat.Text);
                    SettingManager.SetParam("SEO.Manufacturer.UrlRewriteFormat", txtManufacturerUrlRewriteFormat.Text);
                    SettingManager.SetParam("SEO.News.UrlRewriteFormat", txtNewsUrlRewriteFormat.Text);
                    SettingManager.SetParam("SEO.Blog.UrlRewriteFormat", txtBlogUrlRewriteFormat.Text);
                    SettingManager.SetParam("SEO.Topic.UrlRewriteFormat", txtTopicUrlRewriteFormat.Text);
                    SettingManager.SetParam("SEO.Forum.UrlRewriteFormat", txtForumUrlRewriteFormat.Text);
                    SettingManager.SetParam("SEO.ForumGroup.UrlRewriteFormat", txtForumGroupUrlRewriteFormat.Text);
                    SettingManager.SetParam("SEO.ForumTopic.UrlRewriteFormat", txtForumTopicUrlRewriteFormat.Text);


                    SettingManager.SetParam("Media.MaximumImageSize", txtMaxImageSize.Value.ToString());
                    SettingManager.SetParam("Media.Product.ThumbnailImageSize", txtProductThumbSize.Value.ToString());
                    SettingManager.SetParam("Media.Product.DetailImageSize", txtProductDetailSize.Value.ToString());
                    SettingManager.SetParam("Media.Product.VariantImageSize", txtProductVariantSize.Value.ToString());
                    SettingManager.SetParam("Media.Category.ThumbnailImageSize", txtCategoryThumbSize.Value.ToString());
                    SettingManager.SetParam("Media.Manufacturer.ThumbnailImageSize", txtManufacturerThumbSize.Value.ToString());
                    SettingManager.SetParam("Display.ShowProductImagesOnShoppingCart", cbShowCartImages.Checked.ToString());
                    SettingManager.SetParam("Display.ShowProductImagesOnWishList", cbShowWishListImages.Checked.ToString());
                    SettingManager.SetParam("Media.ShoppingCart.ThumbnailImageSize", txtShoppingCartThumbSize.Value.ToString());
                    SettingManager.SetParam("Display.ShowAdminProductImages", cbShowAdminProductImages.Checked.ToString());

                    MessageManager.AdminEmailAddress     = txtAdminEmailAddress.Text;
                    MessageManager.AdminEmailDisplayName = txtAdminEmailDisplayName.Text;
                    MessageManager.AdminEmailHost        = txtAdminEmailHost.Text;
                    if (!String.IsNullOrEmpty(txtAdminEmailPort.Text))
                    {
                        MessageManager.AdminEmailPort = int.Parse(txtAdminEmailPort.Text);
                    }
                    else
                    {
                        MessageManager.AdminEmailPort = 0;
                    }
                    MessageManager.AdminEmailUser                  = txtAdminEmailUser.Text;
                    MessageManager.AdminEmailPassword              = txtAdminEmailPassword.Text;
                    MessageManager.AdminEmailEnableSsl             = cbAdminEmailEnableSsl.Checked;
                    MessageManager.AdminEmailUseDefaultCredentials = cbAdminEmailUseDefaultCredentials.Checked;

                    SettingManager.SetParam("Security.AdminAreaAllowedIP", ipList);

                    SettingManager.SetParam("Common.LoginCaptchaImageEnabled", cbEnableLoginCaptchaImage.Checked.ToString());
                    SettingManager.SetParam("Common.RegisterCaptchaImageEnabled", cbEnableRegisterCaptchaImage.Checked.ToString());


                    CustomerManager.CustomerNameFormatting        = (CustomerNameFormatEnum)Enum.ToObject(typeof(CustomerNameFormatEnum), int.Parse(this.ddlCustomerNameFormat.SelectedItem.Value));
                    CustomerManager.ShowCustomersLocation         = cbShowCustomersLocation.Checked;
                    CustomerManager.ShowCustomersJoinDate         = cbShowCustomersJoinDate.Checked;
                    ForumManager.AllowPrivateMessages             = cbAllowPM.Checked;
                    CustomerManager.AllowViewingProfiles          = cbAllowViewingProfiles.Checked;
                    CustomerManager.AllowCustomersToUploadAvatars = cbCustomersAllowedToUploadAvatars.Checked;
                    CustomerManager.DefaultAvatarEnabled          = cbDefaultAvatarEnabled.Checked;
                    string defaultStoreTimeZoneId = ddlDefaultStoreTimeZone.SelectedItem.Value;
                    DateTimeHelper.DefaultStoreTimeZone        = DateTimeHelper.FindTimeZoneById(defaultStoreTimeZoneId);
                    DateTimeHelper.AllowCustomersToSetTimeZone = cbAllowCustomersToSetTimeZone.Checked;


                    CustomerManager.UsernamesEnabled         = cbUsernamesEnabled.Checked;
                    CustomerManager.CustomerRegistrationType = (CustomerRegistrationTypeEnum)Enum.ToObject(typeof(CustomerRegistrationTypeEnum), int.Parse(this.ddlRegistrationMethod.SelectedItem.Value));
                    CustomerManager.AllowNavigationOnlyRegisteredCustomers = cbAllowNavigationOnlyRegisteredCustomers.Checked;
                    SettingManager.SetParam("Common.HidePricesForNonRegistered", cbHidePricesForNonRegistered.Checked.ToString());
                    SettingManager.SetParam("ProductAttribute.EnableDynamicPriceUpdate", cbEnableDynamicPriceUpdate.Checked.ToString());
                    SettingManager.SetParam("Common.AllowProductSorting", cbAllowProductSorting.Checked.ToString());
                    ProductManager.ShowShareButton = cbShowShareButton.Checked;
                    SettingManager.SetParam("Common.UseImagesForLanguageSelection", cbUseImagesForLanguageSelection.Checked.ToString());
                    ProductManager.CompareProductsEnabled = cbEnableCompareProducts.Checked;
                    SettingManager.SetParam("Common.EnableWishlist", cbEnableWishlist.Checked.ToString());
                    OrderManager.IsReOrderAllowed = cbIsReOrderAllowed.Checked;
                    SettingManager.SetParam("Common.EnableEmailAFirend", cbEnableEmailAFriend.Checked.ToString());
                    SettingManager.SetParam("Common.ShowMiniShoppingCart", cbShowMiniShoppingCart.Checked.ToString());
                    ProductManager.RecentlyViewedProductsEnabled           = cbRecentlyViewedProductsEnabled.Checked;
                    ProductManager.RecentlyViewedProductsNumber            = txtRecentlyViewedProductsNumber.Value;
                    ProductManager.RecentlyAddedProductsEnabled            = cbRecentlyAddedProductsEnabled.Checked;
                    ProductManager.RecentlyAddedProductsNumber             = txtRecentlyAddedProductsNumber.Value;
                    ProductManager.NotifyAboutNewProductReviews            = cbNotifyAboutNewProductReviews.Checked;
                    CustomerManager.ProductReviewsMustBeApproved           = cbProductReviewsMustBeApproved.Checked;
                    CustomerManager.AllowAnonymousUsersToReviewProduct     = cbAllowAnonymousUsersToReviewProduct.Checked;
                    CustomerManager.AllowAnonymousUsersToEmailAFriend      = cbAllowAnonymousUsersToEmailAFriend.Checked;
                    CustomerManager.AllowAnonymousUsersToSetProductRatings = cbAllowAnonymousUsersToSetProductRatings.Checked;
                    SettingManager.SetParam("Display.ShowBestsellersOnMainPage", cbShowBestsellersOnHomePage.Checked.ToString());
                    SettingManager.SetParam("Display.ShowBestsellersOnMainPageNumber", txtShowBestsellersOnHomePageNumber.Value.ToString());
                    ProductManager.ProductsAlsoPurchasedEnabled = cbProductsAlsoPurchased.Checked;
                    ProductManager.ProductsAlsoPurchasedNumber  = txtProductsAlsoPurchasedNumber.Value;

                    SMSManager.IsSMSAlertsEnabled = cbIsSMSAlertsEnabled.Checked;
                    SMSManager.PhoneNumber        = txtSMSAlertsPhoneNumber.Text;
                    SMSManager.ClickatellAPIId    = txtSMSAlertsClickatellAPIId.Text;
                    SMSManager.ClickatellUsername = txtSMSAlertsClickatellUsername.Text;
                    SMSManager.ClickatellPassword = txtSMSAlertsClickatellPassword.Text;

                    SettingManager.SetParam("LiveChat.Enabled", cbLiveChatEnabled.Checked.ToString());
                    SettingManager.SetParam("LiveChat.BtnCode", txtLiveChatBtnCode.Text);
                    SettingManager.SetParam("LiveChat.MonCode", txtLiveChatMonCode.Text);

                    if (uplPdfLogo.HasFile)
                    {
                        HttpPostedFile postedFile = uplPdfLogo.PostedFile;
                        if (!postedFile.ContentType.Equals("image/jpeg") && !postedFile.ContentType.Equals("image/gif") && !postedFile.ContentType.Equals("image/png"))
                        {
                            throw new NopException("Image format not recognized, allowed formats are: .png, .jpg, .jpeg, .gif");
                        }
                        postedFile.SaveAs(PDFHelper.LogoFilePath);
                    }

                    //reward point
                    OrderManager.RewardPointsEnabled               = cbRewardPointsEnabled.Checked;
                    OrderManager.RewardPointsExchangeRate          = txtRewardPointsRate.Value;
                    OrderManager.RewardPointsForRegistration       = txtRewardPointsForRegistration.Value;
                    OrderManager.RewardPointsForPurchases_Amount   = txtRewardPointsForPurchases_Amount.Value;
                    OrderManager.RewardPointsForPurchases_Points   = txtRewardPointsForPurchases_Points.Value;
                    OrderManager.RewardPointsForPurchases_Awarded  = (OrderStatusEnum)int.Parse(ddlRewardPointsAwardedOrderStatus.SelectedItem.Value);
                    OrderManager.RewardPointsForPurchases_Canceled = (OrderStatusEnum)int.Parse(ddlRewardPointsCanceledOrderStatus.SelectedItem.Value);

                    //form fields
                    CustomerManager.FormFieldGenderEnabled          = cbffGenderEnabled.Checked;
                    CustomerManager.FormFieldDateOfBirthEnabled     = cbffDateOfBirthEnabled.Checked;
                    CustomerManager.FormFieldCompanyEnabled         = cbffCompanyEnabled.Checked;
                    CustomerManager.FormFieldCompanyRequired        = cbffCompanyRequired.Checked;
                    CustomerManager.FormFieldStreetAddressEnabled   = cbffStreetAddressEnabled.Checked;
                    CustomerManager.FormFieldStreetAddressRequired  = cbffStreetAddressRequired.Checked;
                    CustomerManager.FormFieldStreetAddress2Enabled  = cbffStreetAddress2Enabled.Checked;
                    CustomerManager.FormFieldStreetAddress2Required = cbffStreetAddress2Required.Checked;
                    CustomerManager.FormFieldPostCodeEnabled        = cbffPostCodeEnabled.Checked;
                    CustomerManager.FormFieldPostCodeRequired       = cbffPostCodeRequired.Checked;
                    CustomerManager.FormFieldCityEnabled            = cbffCityEnabled.Checked;
                    CustomerManager.FormFieldCityRequired           = cbffCityRequired.Checked;
                    CustomerManager.FormFieldCountryEnabled         = cbffCountryEnabled.Checked;
                    CustomerManager.FormFieldStateEnabled           = cbffStateEnabled.Checked;
                    CustomerManager.FormFieldPhoneEnabled           = cbffPhoneEnabled.Checked;
                    CustomerManager.FormFieldPhoneRequired          = cbffPhoneRequired.Checked;
                    CustomerManager.FormFieldFaxEnabled             = cbffFaxEnabled.Checked;
                    CustomerManager.FormFieldFaxRequired            = cbffFaxRequired.Checked;

                    CustomerActivityManager.InsertActivity(
                        "EditGlobalSettings",
                        GetLocaleResourceString("ActivityLog.EditGlobalSettings"));

                    Response.Redirect(string.Format("GlobalSettings.aspx?TabID={0}", this.GetActiveTabId(this.CommonSettingsTabs)));
                }
                catch (Exception exc)
                {
                    ProcessException(exc);
                }
            }
        }