Esempio n. 1
0
 public static bool IsSystemDirectory(string directoryName)
 {
     if (StringUtils.EqualsIgnoreCase(directoryName, AspnetClient.DirectoryName) ||
         StringUtils.EqualsIgnoreCase(directoryName, Bin.DirectoryName) ||
         StringUtils.EqualsIgnoreCase(directoryName, SiteFiles.DirectoryName) ||
         StringUtils.EqualsIgnoreCase(directoryName, FileConfigManager.Instance.AdminDirectoryName) ||
         StringUtils.EqualsIgnoreCase(directoryName, SiteTemplates.SiteTemplateMetadata) ||
         StringUtils.EqualsIgnoreCase(directoryName, Api.DirectoryName) ||
         StringUtils.EqualsIgnoreCase(directoryName, "obj") ||
         StringUtils.EqualsIgnoreCase(directoryName, "Properties"))
     {
         return(true);
     }
     return(false);
 }
Esempio n. 2
0
        public static bool IsFileExtenstionNotAllowed(string sNotAllowedExt, string sExt)
        {
            var allow = true;

            if (sExt != null && sExt.StartsWith("."))
            {
                sExt = sExt.Substring(1, sExt.Length - 1);
            }
            sNotAllowedExt = sNotAllowedExt.Replace("|", ",");
            var aExt = sNotAllowedExt.Split(',');

            for (var i = 0; i < aExt.Length; i++)
            {
                if (StringUtils.EqualsIgnoreCase(sExt, aExt[i]))
                {
                    allow = false;
                    break;
                }
            }
            return(allow);
        }
Esempio n. 3
0
        public static string GetAppName(string appId, bool isFullName)
        {
            var retval = string.Empty;

            if (StringUtils.EqualsIgnoreCase(appId, Cms.AppId))
            {
                retval = "SiteServer CMS";
                if (isFullName)
                {
                    retval += " 内容管理系统";
                }
            }
            else if (StringUtils.EqualsIgnoreCase(appId, Wcm.AppId))
            {
                retval = "SiteServer WCM";
                if (isFullName)
                {
                    retval += " 内容协作平台";
                }
            }

            return(retval);
        }
Esempio n. 4
0
 public static bool IsNeedUpgrade()
 {
     return(!StringUtils.EqualsIgnoreCase(Version, BaiRongDataProvider.ConfigDao.GetDatabaseVersion()));
 }
Esempio n. 5
0
        static WebConfigUtils()
        {
            var physicalApplicationPath = string.Empty;
            var applicationPath = string.Empty;
            if (HttpContext.Current != null)
            {
                physicalApplicationPath = HttpContext.Current.Request.PhysicalApplicationPath;
                applicationPath = HttpContext.Current.Request.ApplicationPath;
            }
            else
            {
                physicalApplicationPath = Environment.CurrentDirectory;
            }

            if (string.IsNullOrEmpty(applicationPath))
            {
                applicationPath = "/";
            }

            PhysicalApplicationPath = physicalApplicationPath;
            ApplicationPath = applicationPath;

            var isProtectData = false;
            var databaseType = string.Empty;
            var connectionString = string.Empty;
            try
            {
                var doc = new XmlDocument();

                var configFile = PathUtils.Combine(PhysicalApplicationPath, "web.config");

                doc.Load(configFile);

                var appSettings = doc.SelectSingleNode("configuration/appSettings");
                if (appSettings != null)
                {
                    foreach (XmlNode setting in appSettings)
                    {
                        if (setting.Name == "add")
                        {
                            var attrKey = setting.Attributes?["key"];
                            if (attrKey != null)
                            {
                                if (StringUtils.EqualsIgnoreCase(attrKey.Value, NameIsProtectData))
                                {
                                    var attrValue = setting.Attributes["value"];
                                    if (attrValue != null)
                                    {
                                        isProtectData = TranslateUtils.ToBool(attrValue.Value);
                                    }
                                }
                                else if (StringUtils.EqualsIgnoreCase(attrKey.Value, NameDatabaseType))
                                {
                                    var attrValue = setting.Attributes["value"];
                                    if (attrValue != null)
                                    {
                                        databaseType = attrValue.Value;
                                    }
                                }
                                else if (StringUtils.EqualsIgnoreCase(attrKey.Value, NameConnectionString))
                                {
                                    var attrValue = setting.Attributes["value"];
                                    if (attrValue != null)
                                    {
                                        connectionString = attrValue.Value;
                                    }
                                }
                            }
                        }
                    }

                    if (isProtectData)
                    {
                        databaseType = TranslateUtils.DecryptStringBySecretKey(databaseType);
                        connectionString = TranslateUtils.DecryptStringBySecretKey(connectionString);
                    }
                }
            }
            catch
            {
                // ignored
            }

            IsMySql = StringUtils.EqualsIgnoreCase(databaseType, "MySql");
            ConnectionString = connectionString;
        }
Esempio n. 6
0
        public static void UpdateWebConfig(bool isProtectData, bool isMySql, string connectionString)
        {
            var configFilePath = PathUtils.MapPath("~/web.config");

            var doc = new XmlDocument();
            doc.Load(configFilePath);
            var dirty = false;
            var appSettings = doc.SelectSingleNode("configuration/appSettings");
            if (appSettings != null)
            {
                foreach (XmlNode setting in appSettings)
                {
                    if (setting.Name == "add")
                    {
                        var attrKey = setting.Attributes?["key"];
                        if (attrKey != null)
                        {
                            if (StringUtils.EqualsIgnoreCase(attrKey.Value, NameIsProtectData))
                            {
                                var attrValue = setting.Attributes["value"];
                                if (attrValue != null)
                                {
                                    attrValue.Value = isProtectData.ToString();
                                    dirty = true;
                                }
                            }
                            else if (StringUtils.EqualsIgnoreCase(attrKey.Value, NameDatabaseType))
                            {
                                var attrValue = setting.Attributes["value"];
                                if (attrValue != null)
                                {
                                    attrValue.Value = isMySql ? "MySql" : "SqlServer";
                                    if (isProtectData)
                                    {
                                        attrValue.Value = TranslateUtils.EncryptStringBySecretKey(attrValue.Value);
                                    }
                                    dirty = true;
                                }
                            }
                            else if (StringUtils.EqualsIgnoreCase(attrKey.Value, NameConnectionString))
                            {
                                var attrValue = setting.Attributes["value"];
                                if (attrValue != null)
                                {
                                    attrValue.Value = connectionString;
                                    if (isProtectData)
                                    {
                                        attrValue.Value = TranslateUtils.EncryptStringBySecretKey(attrValue.Value);
                                    }
                                    dirty = true;
                                }
                            }
                        }
                    }
                }
            }

            if (dirty)
            {
                var writer = new XmlTextWriter(configFilePath, System.Text.Encoding.UTF8)
                {
                    Formatting = Formatting.Indented
                };
                doc.Save(writer);
                writer.Flush();
                writer.Close();
            }

            IsMySql = isMySql;
            ConnectionString = connectionString;
            _helper = null;
        }