Пример #1
0
        public override void CheckPermission()
        {
            if (config.Instance.Site.NeedLogin && ctx.viewer.IsLogin == false)
            {
                echoRedirect(lang("exPlsLogin"), t2(new MainController().Login) + "?returnUrl=" + ctx.url.EncodeUrl);
                return;
            }

            if (config.Instance.Site.BannedIp.Length > 0)
            {
                if (IpUtil.IsAllowedIp(ctx.Ip, config.Instance.Site.BannedIp) == false)
                {
                    echo(config.Instance.Site.BannedIpInfo);
                    return;
                }
            }

            if (ctx.owner.obj is Site)
            {
                checkSitePermission();
            }

            else if (ctx.owner.obj is User)
            {
                checkSpacePermission();
            }

            else if (ctx.owner.obj is Group)
            {
                checkGroupPermission();
            }
        }
Пример #2
0
        public void BandByUtil()
        {
            List <String> list = new List <String>();

            list.Add("88.88.99.99");
            list.Add("192.168.3.2-192.168.3.250");
            list.Add("66.66.66.*");
            list.Add("55.55.*.*");
            list.Add("44.*.*.*");
            list.Add("33.168.10.*-33.168.90.*");
            list.Add("unknow");

            Assert.IsFalse(IpUtil.IsAllowedIp("88.88.99.99", list));
            Assert.IsTrue(IpUtil.IsAllowedIp("88.88.99.100", list));

            Assert.IsFalse(IpUtil.IsAllowedIp("192.168.3.2", list));
            Assert.IsFalse(IpUtil.IsAllowedIp("192.168.3.250", list));
            Assert.IsTrue(IpUtil.IsAllowedIp("192.168.3.1", list));
            Assert.IsTrue(IpUtil.IsAllowedIp("192.168.3.251", list));

            Assert.IsFalse(IpUtil.IsAllowedIp("66.66.66.1", list));
            Assert.IsFalse(IpUtil.IsAllowedIp("66.66.66.2", list));
            Assert.IsFalse(IpUtil.IsAllowedIp("66.66.66.254", list));
            Assert.IsFalse(IpUtil.IsAllowedIp("66.66.66.255", list));

            Assert.IsFalse(IpUtil.IsAllowedIp("55.55.33.33", list));
            Assert.IsFalse(IpUtil.IsAllowedIp("55.55.99.99", list));
            Assert.IsTrue(IpUtil.IsAllowedIp("55.56.33.33", list));

            Assert.IsFalse(IpUtil.IsAllowedIp("44.55.33.33", list));
            Assert.IsFalse(IpUtil.IsAllowedIp("44.99.33.33", list));
            Assert.IsTrue(IpUtil.IsAllowedIp("45.99.33.33", list));

            Assert.IsFalse(IpUtil.IsAllowedIp("33.168.10.1", list));
            Assert.IsFalse(IpUtil.IsAllowedIp("33.168.10.2", list));
            Assert.IsFalse(IpUtil.IsAllowedIp("33.168.10.255", list));
            Assert.IsFalse(IpUtil.IsAllowedIp("33.168.90.1", list));
            Assert.IsFalse(IpUtil.IsAllowedIp("33.168.90.2", list));
            Assert.IsFalse(IpUtil.IsAllowedIp("33.168.90.255", list));

            Assert.IsFalse(IpUtil.IsAllowedIp("", list));
            Assert.IsFalse(IpUtil.IsAllowedIp("unknow", list));
            Assert.IsFalse(IpUtil.IsAllowedIp("abc", list));
            Assert.IsFalse(IpUtil.IsAllowedIp("-", list));

            Assert.IsTrue(IpUtil.IsAllowedIp("68.81.101.87", list));
            Assert.IsTrue(IpUtil.IsAllowedIp("71.85.125.152", list));
            Assert.IsTrue(IpUtil.IsAllowedIp("85.114.137.152", list));
        }