Exemple #1
0
    private void Add()
    {
        //添加权限
        ManageHelper.CheckAdminPower("system_memberipblockadd");
        Sys.Common.IP.RestrictionIPResult ip = Sys.Common.IP.BlockIP.GenerateIPList(Name);
        if (!ip.IsChecked)
        {
            err.AddErr("*IP访问规则格式错误");
        }

        Sys.BLL.SysIpBlock bll = new Sys.BLL.SysIpBlock();
        if (bll.CheckName(ID, Name, BlockType, BlockModule))
        {
            err.AddErr("*该IP访问规则已经存在");
        }

        err.ChkErr();

        Sys.Model.SysIpBlock model = new Sys.Model.SysIpBlock();
        model.ID          = 0;
        model.IpStart     = ip.StartIP;
        model.IpEnd       = ip.EndIP;
        model.Name        = Name;
        model.BlockType   = BlockType;
        model.BlockModule = BlockModule;
        int NewID = bll.Add(model);

        ManageHelper.AddLog("system_memberipblockadd", "添加了" + BlockModuleName + BlockTypeName + model.Name);//写日志
        Response.Write("<script>window.parent.location.href=\"ipblocklist.aspx?BlockModule=" + BlockModule + "&BlockType=" + BlockType + "&sucmsg=IP访问规则添加成功。\";</script>");
        Response.End();
    }
Exemple #2
0
        /// <summary>
        /// 输入限制IP地址,生成限制IP地址的256进制IP地址段
        /// </summary>
        /// <param name="ip">要限制的IP地址段,如192.169.4.1,192.169.4.1-192.169.5.1,192.169.*.1,输入值无需判断格式规范</param>
        /// <returns>RestrictionIPResult类,包含输入值是否符合IP地址规范,若符合,则返回256进制的IP地址段,StartIP为起始IP,EndIP为结束IP</returns>
        /// <example>
        /// if(!BlockIP.RestrictionIPResult("inputIP").IsChecked)
        /// {
        ///     页面提示用户输入不正确;
        /// }
        /// else
        /// {
        ///     存储RestrictionIPResult.StartIP
        ///     存储RestrictionIPResult.EndIP
        /// }
        /// </example>
        public static RestrictionIPResult GenerateIPList(string ip)
        {
            RestrictionIPResult result = new RestrictionIPResult(false, 0, 0);

            if (!ip.Contains("-") && !ip.Contains("*")) //精确匹配
            {
                if (!IsIP(ip))
                {
                    return(result);
                }
                result.IsChecked = true;
                result.StartIP   = CalcIP(ip);
                result.EndIP     = CalcIP(ip);
                return(result);
            }
            if (ip.Contains("-") && !ip.Contains("*")) //范围
            {
                string[] argsip = ip.Split('-');
                if (!IsIP(argsip[0]) || !IsIP(argsip[1]))
                {
                    return(result);
                }
                result.IsChecked = true;
                if (CalcIP(argsip[0]) < CalcIP(argsip[1]))
                {
                    result.StartIP = CalcIP(argsip[0]);
                    result.EndIP   = CalcIP(argsip[1]);
                }
                else
                {
                    result.StartIP = CalcIP(argsip[1]);
                    result.EndIP   = CalcIP(argsip[0]);
                }
                return(result);
            }
            if (ip.Contains("*")) //任何匹配
            {
                string[] argsip = new string[2];
                argsip[0] = ip.Replace("*", "0");
                argsip[1] = ip.Replace("*", "254");
                if (!IsIP(argsip[0]) || !IsIP(argsip[1]))
                {
                    return(result);
                }
                result.IsChecked = true;
                if (CalcIP(argsip[0]) < CalcIP(argsip[1]))
                {
                    result.StartIP = CalcIP(argsip[0]);
                    result.EndIP   = CalcIP(argsip[1]);
                }
                else
                {
                    result.StartIP = CalcIP(argsip[1]);
                    result.EndIP   = CalcIP(argsip[0]);
                }
                return(result);
            }
            return(result);
        }
Exemple #3
0
    private void Check()
    {
        Sys.Common.IP.RestrictionIPResult ip = Sys.Common.IP.BlockIP.GenerateIPList(Name);
        if (!ip.IsChecked)
        {
            Response.Write("-1");//IP错误
            Response.End();
        }

        var bllIP = new Sys.BLL.SysIpBlock();

        if (bllIP.CheckName(ID, Name, BlockType, BlockModule))
        {
            Response.Write("-2");//重名
            Response.End();
        }

        Response.Write("1");
        Response.End();
    }