Exemplo n.º 1
0
        public bool IsWCFConfigService(AnalyzerResult analyzerResult)
        {
            string projectDir = analyzerResult.ProjectResult.ProjectRootPath;

            string webConfigFile = Path.Combine(projectDir, Rules.Config.Constants.WebConfig);
            string appConfigFile = Path.Combine(projectDir, Rules.Config.Constants.AppConfig);

            // For Config based look for <services> element.
            if (File.Exists(webConfigFile))
            {
                var config = WebConfigManager.LoadWebConfigAsXDocument(projectDir);
                if (config.ContainsElement(Constants.WCFServiceElementPath))
                {
                    return(true);
                }
            }
            if (File.Exists(appConfigFile))
            {
                var config = WebConfigManager.LoadAppConfigAsXDocument(projectDir);
                if (config.ContainsElement(Constants.WCFServiceElementPath))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        public void MustHaveUserMustHaveAUserWithFullProfile()
        {
            WebConfigManager.SyncConfig(PhysicalPath);

            var user = UserController.GetUserByName(0, "MichaelWoods");

            if (user == null)
            {
                user = new UserInfo
                {
                    PortalID    = 0,
                    Username    = "******",
                    IsSuperUser = false,
                    Email       = "*****@*****.**",
                    FirstName   = "Michael",
                    LastName    = "Woods",
                    DisplayName = "Michael Woods"
                };
                user.Membership.Password = "******";
                UserController.CreateUser(ref user);

                user.Profile.City       = "Vancouver";
                user.Profile.Country    = "Canada";
                user.Profile.PostalCode = "V1M 4A6";
                user.Profile.Region     = "British Columbia";
                user.Profile.Street     = "211 – 9440 202nd Street Langley";
                var provider = ProfileProvider.Instance();
                provider.UpdateUserProfile(user);
            }
            else if (user.IsDeleted)
            {
                UserController.RestoreUser(ref user);
            }
            Config.Touch();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Determines if a project is a WCF Client Project based on the following :-
        ///     If it has a web.config or App.config based configuaration, and has a client tag
        ///     in the nested configuration/system.serviceModel tag.
        /// </summary>
        /// <param name="analyzerResult"></param>
        /// <returns>Whether a project is a WCF Client</returns>
        public override bool IsPresent(AnalyzerResult analyzerResult)
        {
            string projectDir = analyzerResult.ProjectResult.ProjectRootPath;

            string webConfigFile = Path.Combine(projectDir, Rules.Config.Constants.WebConfig);
            string appConfigFile = Path.Combine(projectDir, Rules.Config.Constants.AppConfig);

            if (File.Exists(webConfigFile))
            {
                var config = WebConfigManager.LoadWebConfigAsXDocument(projectDir);
                if (config.ContainsElement(Constants.WCFClientElementPath))
                {
                    return(true);
                }
            }
            if (File.Exists(appConfigFile))
            {
                var config = WebConfigManager.LoadAppConfigAsXDocument(projectDir);
                if (config.ContainsElement(Constants.WCFClientElementPath))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 4
0
        public void When_WebConfigExists_Constructor_Should_BackupConfigFile()
        {
            _fileWrapperMock.Setup(f => f.Exists(It.IsAny <string>())).Returns(true);

            _writer = new WebConfigManager(
                _fileWrapperMock.Object,
                _xmlDocumentWrapperMock.Object,
                WEB_CONFIG_FILE_NAME);

            _fileWrapperMock.Verify(f => f.Copy(It.IsAny <string>(), It.IsAny <string>()), Times.Once);
        }
Exemplo n.º 5
0
        public void When_WebConfigExists_Constructor_Should_LoadConfigAsXmlDocument()
        {
            _fileWrapperMock.Setup(f => f.Exists(It.IsAny <string>())).Returns(true);

            _writer = new WebConfigManager(
                _fileWrapperMock.Object,
                _xmlDocumentWrapperMock.Object,
                WEB_CONFIG_FILE_NAME);

            _xmlDocumentWrapperMock.Verify(x => x.CreateXmlDocFromFile(It.IsAny <string>()), Times.Once);
        }
Exemplo n.º 6
0
        public static void SetUpMailDumpFolder()
        {
            string emailPath    = GetEmailDumpFolderPath();
            var    mailDropPath = Directory.GetCurrentDirectory().Replace("\\Fixtures", "\\Community\\Tests\\Packages");

            if (!Directory.Exists(emailPath))
            {
                Directory.CreateDirectory(emailPath);
            }

            WebConfigManager.UpdateConfigForMailDrop(mailDropPath, emailPath);
            HostController.Instance.Update("SMTPServer", "localhost", false);
        }
Exemplo n.º 7
0
        private void LoadWebConfigAsXmlDocument()
        {
            XmlDocument xmldoc = new XmlDocument();

            xmldoc.Load("web.config");

            _fileWrapperMock.Setup(f => f.Exists(It.IsAny <string>())).Returns(true);
            _xmlDocumentWrapperMock.Setup(f => f.CreateXmlDocFromFile(It.IsAny <string>())).Returns(xmldoc);

            _writer = new WebConfigManager(
                _fileWrapperMock.Object,
                _xmlDocumentWrapperMock.Object,
                WEB_CONFIG_FILE_NAME);
        }
Exemplo n.º 8
0
        public void MustHaveSandboxedPaymentSettings()
        {
            var portalController = new PortalController();
            var site             = portalController.GetPortal(0);

            if (site.ProcessorPassword == string.Empty)
            {
                PortalController.UpdatePortalSetting(0, "paypalsandbox", "true");
                //uses PayPal sandbox account.
                site.ProcessorUserId   = "PayPal";
                site.ProcessorPassword = "******";
                site.ProcessorUserId   = "*****@*****.**";
                portalController.UpdatePortalInfo(site);
            }
            WebConfigManager.TouchConfig(PhysicalPath);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Get Config File Path for the Project.
        /// </summary>
        /// <returns>Config File Path</returns>
        public string GetConfigFilePath()
        {
            var webConfig = WebConfigManager.LoadWebConfigAsXDocument(_projectPath);
            var appConfig = WebConfigManager.LoadAppConfigAsXDocument(_projectPath);

            if (webConfig.ContainsElement(Constants.SystemServiceModelElementPath))
            {
                return(Path.Combine(_projectPath, Constants.WebConfig));
            }
            else if (appConfig.ContainsElement(Constants.SystemServiceModelElementPath))
            {
                return(Path.Combine(_projectPath, Constants.AppConfig));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Generate New Config File for CoreWCF.
        /// </summary>
        /// <returns>New Config File for CoreWCF</returns>
        public string GetNewConfigFile()
        {
            var webConfig = WebConfigManager.LoadWebConfigAsXDocument(_projectPath);
            var appConfig = WebConfigManager.LoadAppConfigAsXDocument(_projectPath);

            WebConfigXDocument config;

            if (webConfig.ContainsElement(Constants.SystemServiceModelElementPath))
            {
                config = webConfig;
            }
            else if (appConfig.ContainsElement(Constants.SystemServiceModelElementPath))
            {
                config = appConfig;
            }
            else
            {
                return(null);
            }

            var wcfConfig = config.GetDescendantsAndSelf(Constants.SystemServiceModelElement);

            if (!wcfConfig.IsNullOrEmpty())
            {
                var newXDoc = new XDocument(new XDeclaration(Constants.ConfigXMLVersion, Constants.ConfigXMLEncoding, Constants.ConfigXMLStandalone), wcfConfig.First());

                newXDoc.Descendants().Where(d => d.Name == Constants.HostElement).Remove();
                newXDoc.Descendants().Where(d => d.Name == Constants.EndpointElement && d.Attribute(Constants.BindingAttribute)?.Value == Constants.MexBinding).Remove();

                var serviceModelElement = newXDoc.Element(Constants.SystemServiceModelElement);

                serviceModelElement.ReplaceWith(new XElement(Constants.ConfigurationElement, serviceModelElement));

                var newConfigFile = new StringWriter();
                newXDoc.Save(newConfigFile);

                return(newConfigFile.ToString());
            }

            return(config.GetDocAsString());
        }
Exemplo n.º 11
0
        /// <summary>
        /// Check for Binding and Mode in Config based WCF Service
        /// </summary>
        /// <param name="projectDir">Project Directory for Config based WCF Service</param>
        /// <param name="bindingsTransportMap">Dictionary of binding and transport mode</param>
        public static void ConfigBasedCheck(string projectDir, Dictionary <string, BindingConfiguration> bindingsTransportMap)
        {
            var webConfig = WebConfigManager.LoadWebConfigAsXDocument(projectDir);
            var appConfig = WebConfigManager.LoadAppConfigAsXDocument(projectDir);

            if (webConfig != null && webConfig.ContainsElement(Constants.WCFBindingElementPath))
            {
                BindingTagCheck(webConfig, bindingsTransportMap);
            }
            else if (appConfig != null && appConfig.ContainsElement(Constants.WCFBindingElementPath))
            {
                BindingTagCheck(appConfig, bindingsTransportMap);
            }
            else if (webConfig != null && webConfig.ContainsElement(Constants.WCFEndpointElementPath))
            {
                EndpointTagCheck(webConfig, bindingsTransportMap);
            }
            else if (appConfig != null && appConfig.ContainsElement(Constants.WCFEndpointElementPath))
            {
                EndpointTagCheck(appConfig, bindingsTransportMap);
            }
        }
Exemplo n.º 12
0
        public bool IsPresentInConfig(AnalyzerResult analyzerResult)
        {
            var config = WebConfigManager.LoadWebConfigAsXDocument(analyzerResult.ProjectResult.ProjectRootPath);

            return(config.ContainsAttributeWithValue(Constants.AuthenticationElementElementPath, Constants.ModeAttribute, Constants.FederatedAuthenticationType));
        }
        /// <summary>
        /// Determines if Forms Authentication with Membership is being used in a given project based on
        /// Web.config settings.
        ///
        /// Qualifications:
        /// 1. Web.config uses Forms authentication and Membership:
        ///    <configuration>
        ///      <system.web>
        ///        <authentication mode="Forms">
        ///        </authentication>
        ///        <membership>
        ///          ...
        ///        </membership>
        ///      </system.web>
        ///    </configuration>
        ///
        /// </summary>
        /// <param name="analyzerResult">Source code analysis results</param>
        /// <returns>Whether or not Forms Authentication with Membership is used</returns>
        public override bool IsPresent(AnalyzerResult analyzerResult)
        {
            var config = WebConfigManager.LoadWebConfigAsXDocument(analyzerResult.ProjectResult.ProjectRootPath);

            return(base.IsPresent(analyzerResult) && config.ContainsElement(Constants.MembershipElementPath));
        }
Exemplo n.º 14
0
 public SiteBaseControl() : base()
 {
     WebConfig = WebConfigManager.GetInstance();
 }
Exemplo n.º 15
0
 public void Dispose()
 {
     // Clear WebConfigManager cache if any WebConfig.IsPresent() methods are called
     WebConfigManager.ClearCache();
 }
Exemplo n.º 16
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            bool changeEncryptKeySelected = rblChangeEncryptKey.SelectedValue.Equals("true", StringComparison.InvariantCultureIgnoreCase);
            bool changeMachineKeySelected = rblChangeMachineKey.SelectedValue.Equals("true", StringComparison.InvariantCultureIgnoreCase);
            bool encryptKeyAutoGenerate   = rblEncryptKeyGenType.SelectedValue.Equals("auto", StringComparison.InvariantCultureIgnoreCase);
            bool machineKeyAutoGenerate   = rblMachineKeyGenType.SelectedValue.Equals("auto", StringComparison.InvariantCultureIgnoreCase);

            if (changeEncryptKeySelected && !encryptKeyAutoGenerate && (NewEncryptKey.Text.Trim().Length < 8 || NewEncryptKey.Text.Trim().Length > 50))
            {
                ErrorLabel.Text    = AppLogic.GetString("admin.changeencryptkey.AtLeast", SkinID, LocaleSetting);
                ErrorLabel.Visible = true;
                return;
            }

            if (changeMachineKeySelected)
            {
                if (!machineKeyAutoGenerate && (txtValidationKey.Text.Trim().Length < 32 || txtValidationKey.Text.Trim().Length > 64))
                {
                    ErrorLabel.Text    = AppLogic.GetString("admin.changeencryptkey.ValidationKeyAtLeast", SkinID, LocaleSetting);
                    ErrorLabel.Visible = true;
                    return;
                }
                else if (!machineKeyAutoGenerate && txtDecryptKey.Text.Trim().Length != 24)
                {
                    ErrorLabel.Text    = AppLogic.GetString("admin.changeencryptkey.DecryptKeyAtLeast", SkinID, LocaleSetting);
                    ErrorLabel.Visible = true;
                    return;
                }
            }

            try
            {
                WebConfigManager webMgr = new WebConfigManager();

                if (changeEncryptKeySelected)
                {
                    webMgr.SetEncryptKey       = true;
                    webMgr.EncryptKeyGenMethod = (WebConfigManager.KeyGenerationMethod)Enum.Parse(typeof(WebConfigManager.KeyGenerationMethod),
                                                                                                  rblEncryptKeyGenType.SelectedValue, true);

                    if (webMgr.EncryptKeyGenMethod == WebConfigManager.KeyGenerationMethod.Manual)
                    {
                        webMgr.EncryptKey = NewEncryptKey.Text;
                    }
                }

                if (changeMachineKeySelected)
                {
                    webMgr.SetMachineKey          = true;
                    webMgr.ValidationKeyGenMethod = (WebConfigManager.KeyGenerationMethod)Enum.Parse(typeof(WebConfigManager.KeyGenerationMethod),
                                                                                                     rblMachineKeyGenType.SelectedValue, true);

                    webMgr.DecryptKeyGenMethod = webMgr.ValidationKeyGenMethod;

                    if (webMgr.ValidationKeyGenMethod == WebConfigManager.KeyGenerationMethod.Manual)
                    {
                        webMgr.ValidationKey = txtValidationKey.Text;
                        webMgr.DecryptKey    = txtDecryptKey.Text;
                    }
                }

                List <Exception> commitExceptions = webMgr.Commit();

                if (commitExceptions.Count > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("Your web.config could not be saved for the following reasons:<br/>");
                    foreach (Exception ex in commitExceptions)
                    {
                        sb.Append(ex.Message + "<br />");
                    }

                    ErrorLabel.Text    = sb.ToString();
                    OkLabel.Visible    = false;
                    ErrorLabel.Visible = true;
                }
                else
                {
                    ErrorLabel.Visible = false;
                    OkLabel.Visible    = true;
                }
            }
            catch (Exception ex)
            {
                ErrorLabel.Text    = CommonLogic.GetExceptionDetail(ex, "<br/>");
                OkLabel.Visible    = false;
                ErrorLabel.Visible = true;
            }
        }
Exemplo n.º 17
0
 public SiteBaseMaster() : base()
 {
     WebConfig = WebConfigManager.GetInstance();
 }
Exemplo n.º 18
0
 protected WebConfigXDocument LoadWebConfig(string projectDir)
 {
     return(WebConfigManager.LoadWebConfigAsXDocument(projectDir));
 }
Exemplo n.º 19
0
 internal DeviceFilterTreeNode(WebConfigManager webConfig) : base()
 {
     DeviceFilter = new DeviceFilterNode(webConfig);
     base.Text    = DeviceFilter.Name;
 }
Exemplo n.º 20
0
        public void LoadWebConfigAsXDocument_Loads_Empty_Config_If_No_Config_Exists()
        {
            var xDocumentWebConfig = WebConfigManager.LoadWebConfigAsXDocument("");

            Assert.AreEqual(0, xDocumentWebConfig.GetConfigProperties().Count());
        }
Exemplo n.º 21
0
        public void LoadWebConfigAsXDocument_Loads_WebConfig_As_XDocument()
        {
            var xDocumentWebConfig = WebConfigManager.LoadWebConfigAsXDocument(_configsDir);

            Assert.True(xDocumentWebConfig.ContainsElement("configuration"));
        }
Exemplo n.º 22
0
 public void SiteMustRunInMediumTrust()
 {
     WebConfigManager.UpdateConfigForMediumTrust();
 }
Exemplo n.º 23
0
 public void SiteMustRunInFullTrust()
 {
     WebConfigManager.UpdateConfigForFullTrust();
 }
Exemplo n.º 24
0
 public void ClearSmtpSetings()
 {
     HostController.Instance.Update("SMTPServer", "", false);
     WebConfigManager.TouchConfig(PhysicalPath);
 }
        internal AppliedDeviceFiltersDialog(
            IDeviceSpecificDesigner designer,
            int mergingContext)
        {
            _designer = designer;
            _designer.SetDeviceSpecificEditor(this);

            // Required for Win Form Designer support
            InitializeComponent();

            _lblAvailableFilters.Text =
                SR.GetString(SR.AppliedDeviceFiltersDialog_AvailableDeviceFilters);
            _appliedFiltersList.LblTitle.Text =
                SR.GetString(SR.AppliedDeviceFiltersDialog_AppliedDeviceFilters);
            _btnEditFilters.Text = SR.GetString(SR.GenericDialog_Edit);
            _btnApplyFilter.Text =
                SR.GetString(SR.AppliedDeviceFiltersDialog_ApplyDeviceFilter);
            _lblArgument.Text =
                SR.GetString(SR.AppliedDeviceFiltersDialog_Argument);
            _cmdOK.Text     = SR.GetString(SR.GenericDialog_OKBtnCaption);
            _cmdCancel.Text = SR.GetString(SR.GenericDialog_CancelBtnCaption);
            _cmdHelp.Text   = SR.GetString(SR.GenericDialog_HelpBtnCaption);

            int tabOffset = GenericUI.InitDialog(
                this,
                _designer,
                mergingContext
                );

            this.Text = _designer.UnderlyingControl.ID
                        + " - " + SR.GetString(SR.AppliedDeviceFiltersDialog_Title);
            SetTabIndexes(tabOffset);
            _webConfig = new WebConfigManager(_designer.UnderlyingControl.Site);
            LoadAvailableFilters();

            // Note that the following can cause an
            // IDeviceSpecificDesigner.Refresh() to occur as a side-effect.
            _designer.RefreshHeader(mergingContext);

            _currentDeviceSpecificID = _designer.CurrentDeviceSpecificID;
            if (_currentDeviceSpecificID != null)
            {
                DeviceSpecific ds;
                _designer.GetDeviceSpecific(_currentDeviceSpecificID, out ds);
                LoadChoices(ds);
            }

            // Register Event Handlers
            _cbAvailableFilters.SelectedIndexChanged += new EventHandler(
                OnAvailableFilterSelected
                );
            _cbAvailableFilters.TextChanged += new EventHandler(
                OnAvailableFilterSelected
                );
            _btnApplyFilter.Click += new EventHandler(OnApplyFilter);
            _btnEditFilters.Click += new EventHandler(OnEditFilters);
            _appliedFiltersList.TvList.AfterSelect    += new TreeViewEventHandler(OnAppliedFilterSelected);
            _appliedFiltersList.TvList.AfterLabelEdit += new NodeLabelEditEventHandler(OnAfterLabelEdit);
            _appliedFiltersList.BtnUp.Click           += new EventHandler(OnAppliedFiltersReordered);
            _appliedFiltersList.BtnDown.Click         += new EventHandler(OnAppliedFiltersReordered);
            _appliedFiltersList.BtnRemove.Click       -= _appliedFiltersList.RemoveHandler;
            _appliedFiltersList.BtnRemove.Click       += new EventHandler(OnRemove);
            _tbArgument.TextChanged += new EventHandler(OnArgumentChanged);
            _cmdOK.Click            += new EventHandler(OnOK);
            _cmdCancel.Click        += new EventHandler(OnCancel);
            _cmdHelp.Click          += new EventHandler(OnHelp);

            UpdateUI();
        }
Exemplo n.º 26
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Page.Validate();
            if (!Page.IsValid)
            {
                return;
            }

            bool BadSSL = false;

            // save the config settings:
            AtomStoreZip.Save();
            AtomLiveServer.Save();

            StringBuilder errors = new StringBuilder();

            if (AppLogic.TrustLevel == AspNetHostingPermissionLevel.Unrestricted)
            {
                WebConfigManager webMgr = new WebConfigManager();
                if (webMgr.ProtectWebConfig != rblEncrypt.SelectedValue.Equals("true", StringComparison.InvariantCultureIgnoreCase) || rblStaticMachineKey.SelectedValue.Equals("true", StringComparison.InvariantCultureIgnoreCase))
                {
                    webMgr.ProtectWebConfig = rblEncrypt.SelectedValue.Equals("true", StringComparison.InvariantCultureIgnoreCase);

                    if (rblStaticMachineKey.SelectedValue.Equals("true", StringComparison.InvariantCultureIgnoreCase))
                    {
                        webMgr.SetMachineKey          = true;
                        webMgr.ValidationKeyGenMethod = WebConfigManager.KeyGenerationMethod.Auto;
                        webMgr.DecryptKeyGenMethod    = WebConfigManager.KeyGenerationMethod.Auto;
                    }

                    List <Exception> saveWebConfigExceptions = webMgr.Commit();

                    WebConfigManager webMgrNew = new WebConfigManager();

                    if (saveWebConfigExceptions.Count > 0 && (webMgr.ProtectWebConfig != webMgrNew.ProtectWebConfig || rblStaticMachineKey.SelectedValue.EqualsIgnoreCase("true")))
                    {
                        if (webMgr.ProtectWebConfig != webMgrNew.ProtectWebConfig)
                        {
                            errors.Append("Your web config encryption could not be changed due to the following error(s): <br />");
                        }
                        if (rblStaticMachineKey.SelectedValue.EqualsIgnoreCase("true"))
                        {
                            errors.Append("Could not set static machine key due to the following error(s): <br />");
                        }
                        foreach (Exception ex in saveWebConfigExceptions)
                        {
                            errors.Append(ex.Message + "<br />");
                        }
                    }
                }
            }

            if (AtomStoreUseSSL.GetValue(AppLogic.StoreID()).ToBool() || AtomStoreUseSSL.GetValue(0).ToBool())
            {
                BadSSL = true;
                String        WorkerWindowInSSL = String.Empty;
                List <string> urlsToTry         = new List <string>();
                urlsToTry.Add(AppLogic.GetStoreHTTPLocation(false).Replace("http://", "https://") + "empty.htm");
                urlsToTry.Add(AppLogic.GetStoreHTTPLocation(false).Replace("http://", "https://").Replace("https://", "https://www.") + "empty.htm");

                foreach (String urlToTry in urlsToTry)
                {
                    if (BadSSL)
                    {
                        try
                        {
                            WorkerWindowInSSL = CommonLogic.AspHTTP(AppLogic.GetStoreHTTPLocation(false).Replace("http://", "https://") + "empty.htm", 10);
                        }
                        catch { }

                        if (WorkerWindowInSSL.IndexOf("Worker") != -1)
                        {
                            AtomStoreUseSSL.Save();
                            BadSSL = false;
                            break;
                        }
                    }
                }
            }
            else
            {
                AtomStoreUseSSL.Save();
            }

            AtomLiveServer.Save();
            AtomStoreCurrency.Save();
            AtomStoreCurrencyNumeric.Save();
            AtomStoreName.Save();
            AtomStoreLiveTransactions.Save();

            string temp = GetCheckedPaymentMethods();

            AppConfig config = AppLogic.GetAppConfig(0, "UseSSL");

            config = AppLogic.GetAppConfig(0, "PaymentMethods");
            if (config != null)
            {
                if (temp.Length > 0)
                {
                    config.ConfigValue = temp;
                }
                else
                {
                    config.ConfigValue = string.Empty;
                }
            }

            config = AppLogic.GetAppConfig(0, "Micropay.Enabled");
            if (config != null)
            {
                if (temp.IndexOf(AppLogic.ro_PMMicropay, StringComparison.InvariantCultureIgnoreCase) != -1)
                {
                    config.ConfigValue = "true"; // preserve setting of obsolete appconfig
                }
                else
                {
                    config.ConfigValue = "false"; // preserve setting of obsolete appconfig
                }
            }

            config = AppLogic.GetAppConfig(0, "PaymentGateway");
            if (config != null)
            {
                string newGateway        = getSelectedGateway();
                string newGatewayProduct = getSelectedGatewayProduct();

                if (!String.IsNullOrEmpty(newGateway))
                {
                    config.ConfigValue = newGateway;
                }

                if (newGateway == "PayFlowPro")
                {
                    var payFlowProProduct = AppLogic.GetAppConfig(0, "PayFlowPro.Product");
                    payFlowProProduct.ConfigValue = newGatewayProduct;

                    // If PPA Gateway is selected, then set the PPA Method
                    if (newGatewayProduct == "PayPal Payments Advanced")
                    {
                        if (!temp.Contains("PayPalEmbeddedCheckout"))
                        {
                            var ppaConfig = AppLogic.GetAppConfig(0, "PaymentMethods");
                            ppaConfig.ConfigValue += ", PayPalEmbeddedCheckout";
                        }
                    }

                    // if any PayFlow gateway is selected, select PayPalExpress
                    if (!temp.Contains("PayPalExpress"))
                    {
                        var ppeConfig = AppLogic.GetAppConfig(0, "PaymentMethods");
                        ppeConfig.ConfigValue   += ", PayPalExpress";
                        cbxPayPalExpress.Checked = true;
                    }
                }
            }

            if ("WIZARD".Equals(AppLogic.AppConfig("OrderShowCCPwd", 0, false), StringComparison.InvariantCultureIgnoreCase))
            {
                config = AppLogic.GetAppConfig(0, "OrderShowCCPwd");
                if (config != null)
                {
                    config.ConfigValue = CommonLogic.GetRandomNumber(1000, 1000000).ToString() + CommonLogic.GetRandomNumber(1000, 1000000).ToString() + CommonLogic.GetRandomNumber(1000, 1000000).ToString();
                }
            }

            string BuySafeMessage = string.Empty;

            if (rblBuySafeEnabled.SelectedIndex == 1)
            {
                BuySafeRegistrationStatus bss = BuySafeController.BuySafeOneClickSignup();
                if (!bss.Sucessful)
                {
                    BuySafeMessage = "<br/><b style=\"color:red;\">buySAFE could not be enabled.{0}";
                    errors.Append(string.Format(BuySafeMessage, (string.IsNullOrEmpty(bss.ErrorMessage) ? "" : " Error message: " + bss.ErrorMessage)));
                }
            }

            if (BadSSL)
            {
                errors.Append("No SSL certificate was found on your site. Please check with your hosting company! You must be able to invoke your store site using https:// before turning SSL on in this admin site!<br />");
            }

            if (errors.ToString().Length > 0)
            {
                resetError(errors.ToString(), true);
            }
            else
            {
                resetError("Configuration Wizard completed successfully.", false);
            }

            loadData();
        }
Exemplo n.º 27
0
        // NOTE: A FileLoadException is thrown if an error occurs while reading
        //       web.config.
        internal DeviceFilterEditorDialog(ISite site, WebConfigManager webConfig) : base(site)
        {
            InitializeComponent();

            _lblArgument.Text  = SR.GetString(SR.DeviceFilterEditorDialog_Argument);
            _glAttributes.Text = SR.GetString(SR.DeviceFilterEditorDialog_Attributes);
            _lblMethod.Text    = SR.GetString(SR.DeviceFilterEditorDialog_Method);
            _glType.Text       = SR.GetString(SR.DeviceFilterEditorDialog_TypeGl);
            _rbCompare.Text    = SR.GetString(SR.DeviceFilterEditorDialog_Equality);
            _lblCompare.Text   = SR.GetString(SR.DeviceFilterEditorDialog_Compare);
            _rbDelegate.Text   = SR.GetString(SR.DeviceFilterEditorDialog_Evaluator);
            _lblType.Text      = SR.GetString(SR.DeviceFilterEditorDialog_TypeTxt);
            _lblHeader.Text    = SR.GetString(SR.DeviceFilterEditorDialog_Header);
            this.Text          = SR.GetString(SR.DeviceFilterEditorDialog_Title);

            int tabOffset = 0;

            this._pnlMain.TabIndex       = tabOffset++;
            this._filterList.TabIndex    = tabOffset++;
            this._pnlRight.TabIndex      = tabOffset++;
            this._glType.TabIndex        = tabOffset++;
            this._rbCompare.TabIndex     = tabOffset++;
            this._rbDelegate.TabIndex    = tabOffset++;
            this._glAttributes.TabIndex  = tabOffset++;
            this._pnlCompare.TabIndex    = tabOffset++;
            this._pnlDelegate.TabIndex   = tabOffset++;
            this._lblCompare.TabIndex    = tabOffset++;
            this._cbCompare.TabIndex     = tabOffset++;
            this._lblType.TabIndex       = tabOffset++;
            this._txtType.TabIndex       = tabOffset++;
            this._lblArgument.TabIndex   = tabOffset++;
            this._txtArgument.TabIndex   = tabOffset++;
            this._lblMethod.TabIndex     = tabOffset++;
            this._txtMethod.TabIndex     = tabOffset++;
            this._dialogButtons.TabIndex = tabOffset++;

            _webConfig = webConfig;
            this._site = site;
            GenericUI.InitDialog(this, site);

            _filterList.LblTitle.Text = SR.GetString(SR.DeviceFilterEditorDialog_DeviceFilters);
            _filterList.BtnAdd.Text   = SR.GetString(SR.DeviceFilterEditorDialog_NewDeviceFilter);

            // Attempt to load Device Filters
            ArrayList filters = null;

            try
            {
                filters = _webConfig.ReadDeviceFilters();
            }
            catch (FileNotFoundException e)
            {
                GenericUI.ShowWarningMessage(
                    SR.GetString(SR.DeviceFilterEditorDialog_Title),
                    SR.GetString(SR.DeviceFilterEditorDialog_WebConfigMissingOnOpen)
                    );
                throw new FileLoadException(
                          SR.GetString(SR.WebConfig_FileLoadException, e)
                          );
            }
            catch (Exception e)
            {
                if (e.Message.Equals(SR.GetString(SR.DeviceFilterEditorDialog_DuplicateNames)))
                {
                    GenericUI.ShowWarningMessage(
                        SR.GetString(SR.DeviceFilterEditorDialog_Title),
                        SR.GetString(SR.DeviceFilterEditorDialog_DuplicateNames)
                        );
                }
                else
                {
                    GenericUI.ShowWarningMessage(
                        SR.GetString(SR.DeviceFilterEditorDialog_Title),
                        SR.GetString(
                            SR.DeviceFilterEditorDialog_WebConfigParsingError,
                            e.Message
                            )
                        );
                }
                throw new FileLoadException(
                          SR.GetString(SR.WebConfig_FileLoadException, e)
                          );
            }

            // Make sure web.config is checked out before we make changes.
            _webConfig.EnsureWebConfigCheckedOut();

            // Insert the Device Filters into the List UI
            foreach (DeviceFilterNode filter in filters)
            {
                DeviceFilterTreeNode node = new DeviceFilterTreeNode(filter);
                _filterList.TvList.Nodes.Add(node);
            }

            // Make sure all filters have a name...
            // NOTE: Do not combine with the above loop or GetUniqueLabel()
            //       will not necessarily be unique.  It could be done if
            //       we wrote another implementation of GetUniqueLabel()
            //       that compared against filters [ArrayList returned
            //       from ReadDeviceFilters()].
            foreach (DeviceFilterTreeNode node in _filterList.TvList.Nodes)
            {
                if (String.IsNullOrEmpty(node.Text))
                {
                    node.Text = _filterList.GetUniqueLabel(
                        SR.GetString(SR.DeviceFilterNode_DefaultFilterName)
                        );
                }
            }

            // Initialize the UI
            _rbCompare.Click                  += new EventHandler(OnClickCompareRadioButton);
            _rbDelegate.Click                 += new EventHandler(OnClickDelegateRadioButton);
            _cbCompare.TextChanged            += new EventHandler(OnTextChanged);
            _cbCompare.SelectedIndexChanged   += new EventHandler(OnTextChanged);
            _txtArgument.TextChanged          += new EventHandler(OnTextChanged);
            _txtType.TextChanged              += new EventHandler(OnTextChanged);
            _txtMethod.TextChanged            += new EventHandler(OnTextChanged);
            _filterList.TvList.AfterLabelEdit += new NodeLabelEditEventHandler(OnAfterLabelEdit);
            _filterList.TvList.AfterSelect    += new TreeViewEventHandler(OnFilterSelected);
            _filterList.BtnAdd.Click          += new EventHandler(OnClickAddButton);
            _filterList.BtnRemove.Click       += new EventHandler(OnClickRemoveButton);
            _filterList.TvList.SelectedNode    = null;

            LoadAvailableCapabilities();
            UpdateButtonsEnabling();

            _dialogButtons.CmdOK.Click     += new EventHandler(OnClickOK);
            _dialogButtons.CmdCancel.Click += new EventHandler(OnClickCancel);
        }
Exemplo n.º 28
0
        /// <summary>
        /// Determines whether project config has <behaviors> tag
        /// </summary>
        /// <returns>Whether <behaviors> tag is present</returns>
        public bool HasBehavioursTag()
        {
            var config = WebConfigManager.LoadWebConfigAsXDocument(_projectPath);

            return(config.ContainsElement(Constants.BehaviorsPath));
        }
Exemplo n.º 29
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Page.Validate();
            if (!Page.IsValid)
            {
                return;
            }

            var BadSSL = false;

            // save the config settings:
            AtomStoreZip.Save();
            AtomLiveServer.Save();

            if (AtomStoreUseSSL.GetValue(AppLogic.StoreID()).ToBool() || AtomStoreUseSSL.GetValue(0).ToBool())
            {
                BadSSL = true;
                var WorkerWindowInSSL = string.Empty;
                var urlsToTry         = new List <string>();
                urlsToTry.Add(AppLogic.GetStoreHTTPLocation(false).Replace("http://", "https://") + "empty.htm");
                urlsToTry.Add(AppLogic.GetStoreHTTPLocation(false).Replace("http://", "https://").Replace("https://", "https://www.") + "empty.htm");

                foreach (var urlToTry in urlsToTry)
                {
                    if (BadSSL)
                    {
                        WorkerWindowInSSL = CommonLogic.AspHTTP(urlToTry, 10);

                        if (!string.IsNullOrEmpty(WorkerWindowInSSL) && WorkerWindowInSSL.IndexOf("Worker") != -1)
                        {
                            AtomStoreUseSSL.Save();
                            BadSSL = false;
                            break;
                        }
                    }
                }
            }
            else
            {
                AtomStoreUseSSL.Save();
            }

            AtomLiveServer.Save();
            AtomStoreCurrency.Save();
            AtomStoreCurrencyNumeric.Save();
            AtomStoreName.Save();
            AtomStoreLiveTransactions.Save();

            var checkedPaymentMethods = GetCheckedPaymentMethods();

            AppConfigManager.SetAppConfigValue("PaymentMethods", checkedPaymentMethods);

            if (AppConfigManager.AppConfigExists("PaymentGateway"))
            {
                var newGateway = getSelectedGateway();

                if (!string.IsNullOrEmpty(newGateway))
                {
                    AppConfigManager.SetAppConfigValue("PaymentGateway", newGateway);
                }

                if (newGateway == "PayFlowPro")
                {
                    var newGatewayProduct = getSelectedGatewayProduct();
                    AppConfigManager.SetAppConfigValue("PayFlowPro.Product", newGatewayProduct);

                    // If PPA Gateway is selected, then set the PPA Method
                    if (newGatewayProduct == "PayPal Payments Advanced")
                    {
                        if (!checkedPaymentMethods.Contains("PayPalPaymentsAdvanced"))
                        {
                            var currentPaymentMethods = AppConfigManager.GetAppConfigValue("PaymentMethods");
                            AppConfigManager.SetAppConfigValue("PaymentMethods", string.Format("{0}, PayPalPaymentsAdvanced", currentPaymentMethods));
                        }
                    }

                    // if any PayFlow gateway is selected, select PayPalExpress
                    if (!checkedPaymentMethods.Contains("PayPalExpress"))
                    {
                        var currentPaymentMethods = AppConfigManager.GetAppConfigValue("PaymentMethods");
                        AppConfigManager.SetAppConfigValue("PaymentMethods", string.Format("{0}, PayPalExpress", currentPaymentMethods));
                        cbxPayPalExpress.Checked = true;
                    }
                }
            }

            string BuySafeMessage = string.Empty;

            if (rblBuySafeEnabled.SelectedIndex == 1)
            {
                var bss = BuySafeController.BuySafeOneClickSignup();
                if (!bss.Sucessful)
                {
                    BuySafeMessage = "buySAFE could not be enabled.{0}";
                    var buysafeResponse = string.IsNullOrEmpty(bss.ErrorMessage) ? "" : " Error message: " + bss.ErrorMessage;
                    ctrlAlertMessage.PushAlertMessage(string.Format(BuySafeMessage, buysafeResponse), AlertMessage.AlertType.Error);
                }
            }

            var errors = new StringBuilder();
            var webMgr = new WebConfigManager();

            if (AppLogic.TrustLevel == AspNetHostingPermissionLevel.Unrestricted)
            {
                if (webMgr.ProtectWebConfig != rblEncrypt.SelectedValue.Equals("true", StringComparison.InvariantCultureIgnoreCase) || rblStaticMachineKey.SelectedValue.Equals("true", StringComparison.InvariantCultureIgnoreCase))
                {
                    webMgr.ProtectWebConfig = rblEncrypt.SelectedValue.Equals("true", StringComparison.InvariantCultureIgnoreCase);

                    if (rblStaticMachineKey.SelectedValue.Equals("true", StringComparison.InvariantCultureIgnoreCase))
                    {
                        webMgr.SetMachineKey          = true;
                        webMgr.ValidationKeyGenMethod = WebConfigManager.KeyGenerationMethod.Auto;
                        webMgr.DecryptKeyGenMethod    = WebConfigManager.KeyGenerationMethod.Auto;
                    }

                    var saveWebConfigExceptions = webMgr.Commit();

                    var webMgrNew = new WebConfigManager();

                    if (saveWebConfigExceptions.Count > 0 && (webMgr.ProtectWebConfig != webMgrNew.ProtectWebConfig || rblStaticMachineKey.SelectedValue.EqualsIgnoreCase("true")))
                    {
                        if (webMgr.ProtectWebConfig != webMgrNew.ProtectWebConfig)
                        {
                            errors.Append("Your web config encryption could not be changed due to the following error(s): <br />");
                        }

                        if (rblStaticMachineKey.SelectedValue.EqualsIgnoreCase("true"))
                        {
                            errors.Append("Could not set static machine key due to the following error(s): <br />");
                        }

                        foreach (var ex in saveWebConfigExceptions)
                        {
                            errors.Append(ex.Message + "<br />");
                        }
                    }
                }
            }

            if (BadSSL)
            {
                errors.AppendFormat("{0}<br />", AppLogic.GetString("admin.wizard.BadSSL", ThisCustomer.LocaleSetting));
            }

            if (!webMgr.WebConfigRequiresReload)
            {
                Response.Redirect("wizard.aspx");
            }

            var errorMessage = errors.ToString();

            if (string.IsNullOrEmpty(errorMessage))
            {
                ctrlAlertMessage.PushAlertMessage(AppLogic.GetString("admin.wizard.success", ThisCustomer.LocaleSetting), AlertMessage.AlertType.Success);
            }
            else
            {
                ctrlAlertMessage.PushAlertMessage(errorMessage, AlertMessage.AlertType.Error);
            }

            loadData();
        }
        protected void btnUpdateEncryptKey_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtSecondaryEncryptKey.Text) &&
                (string.IsNullOrEmpty(txtSecondaryEncryptKeyConfirm.Text)))
            {
                ctlAlertMessage.PushAlertMessage(AppLogic.GetString("admin.changeencrypt.SecondaryEncryptKey.Confirm.Required"), AspDotNetStorefrontControls.AlertMessage.AlertType.Error);
                return;
            }

            var changeEncryptKeySelected = rblChangeEncryptKey.SelectedValue.Equals("true", StringComparison.InvariantCultureIgnoreCase);
            var changeMachineKeySelected = rblChangeMachineKey.SelectedValue.Equals("true", StringComparison.InvariantCultureIgnoreCase);
            var machineKeyAutoGenerate   = rblMachineKeyGenType.SelectedValue.Equals("auto", StringComparison.InvariantCultureIgnoreCase);

            var primaryEncryptKey = txtPrimaryEncryptKey
                                    .Text
                                    .Trim();

            var secondaryEncryptKey = txtSecondaryEncryptKey
                                      .Text
                                      .Trim();

            var combinedEncryptKey = string.Concat(primaryEncryptKey, secondaryEncryptKey);

            var validationKey = txtValidationKey.Text.Trim();
            var decryptKey    = txtDecryptKey.Text.Trim();

            if (changeEncryptKeySelected &&
                (string.IsNullOrWhiteSpace(primaryEncryptKey) ||
                 combinedEncryptKey.Length < 8 ||
                 combinedEncryptKey.Length > 50))
            {
                ctlAlertMessage.PushAlertMessage(AppLogic.GetString("admin.changeencryptkey.AtLeast", SkinID, LocaleSetting), AspDotNetStorefrontControls.AlertMessage.AlertType.Error);
                return;
            }

            if (changeMachineKeySelected)
            {
                if (!machineKeyAutoGenerate && (validationKey.Length < 32 || validationKey.Length > 64))
                {
                    ctlAlertMessage.PushAlertMessage(AppLogic.GetString("admin.changeencryptkey.ValidationKeyAtLeast", SkinID, LocaleSetting), AspDotNetStorefrontControls.AlertMessage.AlertType.Error);
                    return;
                }
                else if (!machineKeyAutoGenerate && decryptKey.Length != 24)
                {
                    ctlAlertMessage.PushAlertMessage(AppLogic.GetString("admin.changeencryptkey.DecryptKeyAtLeast", SkinID, LocaleSetting), AspDotNetStorefrontControls.AlertMessage.AlertType.Error);
                    return;
                }
            }

            try
            {
                var webConfigManager = new WebConfigManager();

                if (changeEncryptKeySelected)
                {
                    webConfigManager.SetEncryptKey       = true;
                    webConfigManager.EncryptKeyGenMethod = WebConfigManager.KeyGenerationMethod.Manual;

                    var encryptIterations    = AppLogic.AppConfigNativeInt("EncryptIterations");
                    var hashAlgorithm        = AppLogic.AppConfig("HashAlgorithm");
                    var initializationVector = AppLogic.AppConfig("InitializationVector");
                    var keySize = AppLogic.AppConfigNativeInt("KeySize");

                    var keyEncryptionKeyConfig = GlobalConfig.GetGlobalConfig(Security.KeyEncryptionKeyName);
                    var tertiaryEncryptionKey  = ConfigurationManager.AppSettings[Security.TertiaryEncryptionKeyName];

                    var keyEncryptionKeyConfigExists = keyEncryptionKeyConfig != null && !string.IsNullOrWhiteSpace(keyEncryptionKeyConfig.ConfigValue);
                    var tertiaryEncryptionKeyExists  = !string.IsNullOrWhiteSpace(tertiaryEncryptionKey);

                    if ((keyEncryptionKeyConfigExists && !tertiaryEncryptionKeyExists) ||
                        (!keyEncryptionKeyConfigExists && tertiaryEncryptionKeyExists))
                    {
                        throw new ArgumentException("Both the key encryption key and tertiary encryption key were expected to be found but one or the other is missing. At this point you cannot recover encrypted data until you restore the original values. You can recover from this error by clearing both encryption keys but you will not be able to recover encrypted data.");
                    }

                    if (string.IsNullOrWhiteSpace(keyEncryptionKeyConfig.ConfigValue))
                    {
                        // No KEK has been created, make one along with a TEK.
                        tertiaryEncryptionKey = Security.CreateRandomKey(64);
                        webConfigManager.TertiaryEncryptionKey = tertiaryEncryptionKey;

                        var keyEncryptionKey = Security.CreateRandomKey(64);
                        webConfigManager.KeyEncryptionKey = keyEncryptionKey;

                        // Encrypt the KEK using the TEK and store it in the database.
                        var encryptedKEK = Security.MungeString(
                            value: keyEncryptionKey,
                            saltKey: string.Empty,
                            securityParams: new Security.SecurityParams
                        {
                            EncryptKey           = tertiaryEncryptionKey,
                            EncryptIterations    = encryptIterations,
                            HashAlgorithm        = hashAlgorithm,
                            InitializationVector = initializationVector,
                            KeySize = keySize
                        });
                        keyEncryptionKeyConfig.ConfigValue = encryptedKEK;
                        keyEncryptionKeyConfig.Save();
                    }
                    else
                    {
                        // A KEK has already been generated, pull the TEK, decrypt the KEK with the TEK and prep
                        //  the WebConfigManager with the decrypted keys to encrypt the EncryptKey.
                        webConfigManager.TertiaryEncryptionKey = ConfigurationManager.AppSettings[Security.TertiaryEncryptionKeyName];
                        webConfigManager.KeyEncryptionKey      = Security.UnmungeString(
                            s: keyEncryptionKeyConfig.ConfigValue,
                            SaltKey: string.Empty,
                            p: new Security.SecurityParams
                        {
                            EncryptKey           = webConfigManager.TertiaryEncryptionKey,
                            EncryptIterations    = encryptIterations,
                            HashAlgorithm        = hashAlgorithm,
                            InitializationVector = initializationVector,
                            KeySize = keySize
                        });;
                    }

                    // If the merchant has specified their encrypt key, set the WebConfigManager's EncryptKey
                    //  property to the plain text value to re-encrypt already encrypted data. The EncryptKey
                    //  will be later encrypted in the AppSettings file. If we're auto-generating an EncryptKey
                    //  then just pass an empty string.
                    if (webConfigManager.EncryptKeyGenMethod == WebConfigManager.KeyGenerationMethod.Manual)
                    {
                        webConfigManager.EncryptKey = combinedEncryptKey;
                    }
                    else
                    {
                        webConfigManager.EncryptKey = string.Empty;
                    }
                }

                if (changeMachineKeySelected)
                {
                    webConfigManager.SetMachineKey          = true;
                    webConfigManager.ValidationKeyGenMethod = (WebConfigManager.KeyGenerationMethod)Enum.Parse(
                        enumType: typeof(WebConfigManager.KeyGenerationMethod),
                        value: rblMachineKeyGenType.SelectedValue,
                        ignoreCase: true);

                    webConfigManager.DecryptKeyGenMethod = webConfigManager.ValidationKeyGenMethod;

                    if (webConfigManager.ValidationKeyGenMethod == WebConfigManager.KeyGenerationMethod.Manual)
                    {
                        webConfigManager.ValidationKey = validationKey;
                        webConfigManager.DecryptKey    = decryptKey;
                    }
                }

                var commitExceptions = webConfigManager.Commit();
                if (commitExceptions.Any())
                {
                    var errorMessage = commitExceptions
                                       .Aggregate(
                        new StringBuilder("Your web.config could not be saved for the following reasons:<br />"),
                        (message, exception) => message.AppendFormat("{0}<br />", exception.Message))
                                       .ToString();

                    ctlAlertMessage.PushAlertMessage(errorMessage, AspDotNetStorefrontControls.AlertMessage.AlertType.Error);
                }
                else
                {
                    ctlAlertMessage.PushAlertMessage(AppLogic.GetString("admin.changeencryptkey.Done", ThisCustomer.LocaleSetting), AspDotNetStorefrontControls.AlertMessage.AlertType.Success);

                    Response.Redirect("changeencryptkey.aspx");
                }
            }
            catch (ThreadAbortException)
            {
                throw;
            }
            catch (Exception exception)
            {
                ctlAlertMessage.PushAlertMessage(CommonLogic.GetExceptionDetail(exception, "<br/>"), AspDotNetStorefrontControls.AlertMessage.AlertType.Error);
            }
        }