Example #1
0
        private static void SetHash(ISite settings)
        {
            var configSettings = settings.As <ConfigurationSettings>();

            configSettings.SmtpSettingsHash = EncryptSettings(settings);
            settings.Put(configSettings);
        }
Example #2
0
 public static string GetSiteNameValue(this ISite siteSettings)
 {
     return(siteSettings?.As <ContentItem>("LeverFeedSettings")?
            .Get <ContentPart>("LeverFeedSettings")?
            .Get <TextField>("SiteName")?
            .Text);
 }
        private void SetConfiguration(ISite siteSettings)
        {
            var httpsSettings = siteSettings.As <HttpsSettings>();
            var section       = _shellConfiguration.GetSection("StatCan_Https");

            httpsSettings.RequireHttps = section.GetValue("RequireHttps", false);
            httpsSettings.EnableStrictTransportSecurity = section.GetValue("EnableStrictTransportSecurity", false);
            httpsSettings.RequireHttpsPermanent         = section.GetValue("RequireHttpsPermanent", false);
            httpsSettings.SslPort = section.GetValue <int?>("SslPort", null);

            siteSettings.Put(httpsSettings);
        }
Example #4
0
        private void SetConfiguration(ISite siteSettings)
        {
            var smtpSettings = siteSettings.As <SmtpSettings>();
            var section      = _shellConfiguration.GetSection("StatCan_Smtp");

            smtpSettings.DefaultSender = section.GetValue("DefaultSender", string.Empty);

            smtpSettings.PickupDirectoryLocation = section.GetValue("PickupDirectoryLocation", string.Empty);
            smtpSettings.Host = section.GetValue("Host", string.Empty);
            smtpSettings.Port = section.GetValue("Port", 25);

            smtpSettings.AutoSelectEncryption  = section.GetValue("AutoSelectEncryption", false);
            smtpSettings.RequireCredentials    = section.GetValue("RequireCredentials", false);
            smtpSettings.UseDefaultCredentials = section.GetValue("UseDefaultCredentials", false);
            smtpSettings.UserName = section.GetValue("UserName", string.Empty);

            var deliveryMethod = section.GetValue("DeliveryMethod", string.Empty);

            if (!string.IsNullOrEmpty(deliveryMethod))
            {
                if (Enum.TryParse(deliveryMethod, out SmtpDeliveryMethod method))
                {
                    smtpSettings.DeliveryMethod = method;
                }
            }

            var encryptionMethod = section.GetValue("EncryptionMethod", string.Empty);

            if (!string.IsNullOrEmpty(encryptionMethod))
            {
                if (Enum.TryParse(encryptionMethod, out SmtpEncryptionMethod method))
                {
                    smtpSettings.EncryptionMethod = method;
                }
            }

            var password = section.GetValue("Password", string.Empty);

            if (!string.IsNullOrEmpty(password))
            {
                try
                {
                    var protector = _dataProtectionProvider.CreateProtector(nameof(SmtpSettingsConfiguration));
                    smtpSettings.Password = protector.Protect(password);
                }
                catch
                {
                    _logger.LogError("The Smtp password could not be encrypted.");
                }
            }
            siteSettings.Put(smtpSettings);
        }
Example #5
0
        private static bool NeedsUpdate(ISite settings)
        {
            var configSettings = settings.As <ConfigurationSettings>();

            if (!string.IsNullOrEmpty(configSettings.SmtpSettingsHash))
            {
                var encValue = EncryptSettings(settings);
                if (configSettings.SmtpSettingsHash == encValue)
                {
                    return(false);
                }
            }
            return(true);
        }
Example #6
0
        /// <summary>
        /// Verifies if a file is allowed based on its name and the policies defined by the black / white lists.
        /// </summary>
        /// <param name="fileName">The file name of the file to validate.</param>
        /// <param name="allowZip">Boolean value indicating weather zip files are allowed.</param>
        /// <returns>True if the file is allowed; false if otherwise.</returns>
        public bool FileAllowed(string fileName, bool allowZip)
        {
            string localFileName = GetFileName(fileName);
            string extension     = GetExtension(localFileName);

            if (string.IsNullOrEmpty(localFileName) || string.IsNullOrEmpty(extension))
            {
                return(false);
            }

            ISite currentSite = _orchardServices.WorkContext.CurrentSite;
            IUser currentUser = _orchardServices.WorkContext.CurrentUser;

            // zip files at the top level are allowed since this is how you upload multiple files at once.
            if (IsZipFile(extension))
            {
                return(allowZip);
            }

            // whitelist does not apply to the superuser
            if (currentUser == null || !currentSite.SuperUser.Equals(currentUser.UserName, StringComparison.Ordinal))
            {
                // must be in the whitelist
                MediaSettingsPart mediaSettings = currentSite.As <MediaSettingsPart>();

                if (mediaSettings == null)
                {
                    return(false);
                }

                if (String.IsNullOrWhiteSpace(mediaSettings.UploadAllowedFileTypeWhitelist))
                {
                    return(true);
                }

                if (!mediaSettings.UploadAllowedFileTypeWhitelist.ToUpperInvariant().Split(' ').Contains(extension.ToUpperInvariant()))
                {
                    return(false);
                }
            }

            // blacklist always applies
            if (string.Equals(localFileName, "web.config", StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            return(true);
        }
Example #7
0
        private void SetConfiguration(ISite siteSettings)
        {
            var reverseProxySettings = siteSettings.As <ReverseProxySettings>();
            var section = _shellConfiguration.GetSection("StatCan_ReverseProxy");

            reverseProxySettings.ForwardedHeaders = ForwardedHeaders.None;

            if (section.GetValue("EnableXForwardedFor", false))
            {
                reverseProxySettings.ForwardedHeaders |= ForwardedHeaders.XForwardedFor;
            }

            if (section.GetValue("EnableXForwardedHost", false))
            {
                reverseProxySettings.ForwardedHeaders |= ForwardedHeaders.XForwardedHost;
            }
            if (section.GetValue("EnableXForwardedProto", false))
            {
                reverseProxySettings.ForwardedHeaders |= ForwardedHeaders.XForwardedProto;
            }

            siteSettings.Put(reverseProxySettings);
        }
        private async Task <DefaultMetaTags> GetDefaultMetaTagsAsync(ISite siteSettings, MetaTagsPart part)
        {
            var settings = siteSettings.As <ContentItem>("DefaultMetaTags")?.Get <ContentPart>("DefaultMetaTags");

            if (settings == null)
            {
                return(new DefaultMetaTags());
            }

            var imagePath = settings.Get <MediaField>("Image")?.Paths?.FirstOrDefault() ?? string.Empty;
            var values    = new Dictionary <string, FluidValue>()
            {
                ["ContentItem"] = new ObjectValue(part.ContentItem)
            };

            return(new DefaultMetaTags
            {
                Custom = settings.Get <DictionaryField>("Custom")?.Data,
                Description = await _liquidTemplateManager.RenderStringAsync(settings.Get <TextField>("Description")?.Text, NullEncoder.Default, null, values),
                ImagePath = imagePath,
                Title = await _liquidTemplateManager.RenderStringAsync(settings.Get <TextField>("Title")?.Text, NullEncoder.Default, null, values)
            });
        }
Example #9
0
        /// <summary>
        /// Extracts the specified type of property.
        /// </summary>
        /// <typeparam name="T">The type of the property to extract.</typeparam>
        /// <returns>The default value of the requested type if the property was not found.</returns>
        public static T As <T>(this ISite site)
        {
            var typeName = typeof(T).Name;

            return(site.As <T>(typeName));
        }