Exemple #1
0
        public List<IPSecurity> SiteIpSecurityGet(string siteName, out bool isAllowUnlisted)
        {
            Site site = _serverManager.Sites[siteName];
            if (site == null)
            {
                throw new Exception(string.Format("站点{0}不存在!", siteName));
            }

            Configuration applicationHostConfig = _serverManager.GetApplicationHostConfiguration();
            ConfigurationSection ipSecuritySection = applicationHostConfig.GetSection("system.webServer/security/ipSecurity", siteName);
            isAllowUnlisted = Convert.ToBoolean(ipSecuritySection["allowUnlisted"]);

            List<IPSecurity> listIPSecurity = new List<IPSecurity>();
            foreach (ConfigurationElement element in ipSecuritySection.GetCollection())
            {
                IPSecurity ipSecurity = new IPSecurity();
                ipSecurity.IPAddress = element["ipAddress"].ToString();
                ipSecurity.SubNetMask = element["subnetMask"].ToString();
                ipSecurity.IsAllow = Convert.ToBoolean(element["allowed"]);
                listIPSecurity.Add(ipSecurity);
            }

            return listIPSecurity;
        }
Exemple #2
0
        public string SiteIpSecuritySet(DeveloperInfo developerInfo, string siteName, int appId, byte isAllowUnlisted, string ipConfig)
        {
            List<IPSecurity> listIPSecurity = new List<IPSecurity>();
             if (!string.IsNullOrEmpty(ipConfig.Trim()))
             {
                 string[] ipconfigs = ipConfig.Split(new char[] { '|' }, StringSplitOptions.None);
                 foreach (string ipconfig in ipconfigs)
                 {
                     string[] errorRecord = ipconfig.Replace(",", ",").Split(new char[] { ',' }, StringSplitOptions.None);

                     IPSecurity ipSecurity = new IPSecurity();
                     ipSecurity.IPAddress = errorRecord[0].Trim();
                     ipSecurity.SubNetMask = errorRecord[1].Trim();
                     ipSecurity.IsAllow = errorRecord[2] == "1";

                     listIPSecurity.Add(ipSecurity);
                 }
             }

            IISProcess iisProcess = new IISProcess(DeveloperConfig.SystemPhysicalPath, developerInfo.LoginName);
            iisProcess.SiteIpSecuritySet(siteName, Convert.ToBoolean(isAllowUnlisted), listIPSecurity);

            DbCommand cmd = _dataBaseAccess.CreateCommand();
            cmd.CommandText = "Proc_Apps_SiteIpSecurity_Update";

            DbParameter param = _dataBaseAccess.CreateParameter();
            param.ParameterName = "@AppId";
            param.DbType = DbType.Int32;
            param.Value = appId;
            cmd.Parameters.Add(param);

            param = _dataBaseAccess.CreateParameter();
            param.ParameterName = "@IsAllowAccessUnConfig";
            param.DbType = DbType.Byte;
            param.Value = isAllowUnlisted;
            cmd.Parameters.Add(param);

            param = _dataBaseAccess.CreateParameter();
            param.ParameterName = "@IPSecurity";
            param.DbType = DbType.String;
            param.Value = ipConfig;
            cmd.Parameters.Add(param);

            _dataBaseAccess.ExecuteCommand(cmd);

            return string.Empty;
        }