Exemplo n.º 1
0
        public static ListItem GetListItem(ERestrictionType type, bool selected)
        {
            var item = new ListItem(GetText(type), GetValue(type));

            if (selected)
            {
                item.Selected = true;
            }
            return(item);
        }
Exemplo n.º 2
0
 public static bool Equals(ERestrictionType type, string typeStr)
 {
     if (string.IsNullOrEmpty(typeStr))
     {
         return(false);
     }
     if (string.Equals(GetValue(type).ToLower(), typeStr.ToLower()))
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 3
0
 public static string GetText(ERestrictionType type)
 {
     if (type == ERestrictionType.BlackList)
     {
         return("启用黑名单,禁止黑名单中的IP进行访问,其余允许访问");
     }
     if (type == ERestrictionType.WhiteList)
     {
         return("启用白名单,允许白名单中的IP进行访问,其余禁止访问");
     }
     return("无访问限制");
 }
Exemplo n.º 4
0
 public static string GetValue(ERestrictionType type)
 {
     if (type == ERestrictionType.BlackList)
     {
         return("BlackList");
     }
     if (type == ERestrictionType.WhiteList)
     {
         return("WhiteList");
     }
     return("None");
 }
Exemplo n.º 5
0
        public static bool IsVisitAllowed(ERestrictionType restrictionType, StringCollection restrictionBlackList, StringCollection restrictionWhiteList)
        {
            if (restrictionType == ERestrictionType.NoRestriction)
            {
                return(true);
            }
            var restrictionList = new StringCollection();

            if (restrictionType == ERestrictionType.BlackList)
            {
                restrictionList = restrictionBlackList;
            }
            else if (restrictionType == ERestrictionType.WhiteList)
            {
                restrictionList = restrictionWhiteList;
            }
            return(IsVisitAllowed(restrictionType, restrictionList));
        }
Exemplo n.º 6
0
 public static string GetShortText(ERestrictionType type)
 {
     if (type == ERestrictionType.NoRestriction)
     {
         return("无");
     }
     else if (type == ERestrictionType.BlackList)
     {
         return("启用黑名单");
     }
     else if (type == ERestrictionType.WhiteList)
     {
         return("启用白名单");
     }
     else
     {
         throw new Exception();
     }
 }
Exemplo n.º 7
0
 public static string GetText(ERestrictionType type)
 {
     if (type == ERestrictionType.NoRestriction)
     {
         return("无访问限制");
     }
     else if (type == ERestrictionType.BlackList)
     {
         return("启用黑名单,禁止黑名单中的IP进行访问,其余允许访问");
     }
     else if (type == ERestrictionType.WhiteList)
     {
         return("启用白名单,允许白名单中的IP进行访问,其余禁止访问");
     }
     else
     {
         throw new Exception();
     }
 }
Exemplo n.º 8
0
 public static string GetValue(ERestrictionType type)
 {
     if (type == ERestrictionType.NoRestriction)
     {
         return("NoRestriction");
     }
     else if (type == ERestrictionType.BlackList)
     {
         return("BlackList");
     }
     else if (type == ERestrictionType.WhiteList)
     {
         return("WhiteList");
     }
     else
     {
         throw new Exception();
     }
 }
Exemplo n.º 9
0
        private static bool IsVisitAllowed(ERestrictionType restrictionType, StringCollection restrictionList)
        {
            var isAllowed = true;

            if (restrictionType != ERestrictionType.NoRestriction)
            {
                var userIP = PageUtils.GetIpAddress();
                if (restrictionType == ERestrictionType.BlackList)
                {
                    var list = new IPList();
                    foreach (var restriction in restrictionList)
                    {
                        AddRestrictionToIPList(list, restriction);
                    }
                    if (list.CheckNumber(userIP))
                    {
                        isAllowed = false;
                    }
                }
                else if (restrictionType == ERestrictionType.WhiteList)
                {
                    if (restrictionList.Count > 0)
                    {
                        isAllowed = false;
                        var list = new IPList();
                        foreach (var restriction in restrictionList)
                        {
                            AddRestrictionToIPList(list, restriction);
                        }
                        if (list.CheckNumber(userIP))
                        {
                            isAllowed = true;
                        }
                    }
                }
            }
            return(isAllowed);
        }
Exemplo n.º 10
0
 public static bool Equals(string typeStr, ERestrictionType type)
 {
     return(Equals(type, typeStr));
 }