⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iplockmodule.cs

📁 动易SiteFactory&#8482 网上商店系统1.0源代码
💻 CS
字号:
namespace PowerEasy.Web.HttpModule
{
    using PowerEasy.Common;
    using PowerEasy.Components;
    using PowerEasy.Web;
    using System;
    using System.Web;

    public class IPLockModule : IHttpModule
    {
        private void Application_BeginRequest(object source, EventArgs e)
        {
            HttpApplication application = (HttpApplication) source;
            HttpContext context = application.Context;
            if ((application != null) && (context != null))
            {
                double userIP = StringHelper.EncodeIP(PEContext.Current.UserHostAddress);
                int lockType = DataConverter.CLng(SiteConfig.IPLockConfig.LockIPType);
                string lockIPWhite = SiteConfig.IPLockConfig.LockIPWhite;
                string lockIPBlack = SiteConfig.IPLockConfig.LockIPBlack;
                int lockAdminType = DataConverter.CLng(SiteConfig.IPLockConfig.AdminLockIPType);
                string adminLockIPBlack = SiteConfig.IPLockConfig.AdminLockIPBlack;
                string adminLockIPWhite = SiteConfig.IPLockConfig.AdminLockIPWhite;
                if (CheckIPlock(lockType, lockIPWhite, lockIPBlack, userIP))
                {
                    PowerEasy.Web.Utility.WriteErrMsg(PowerEasy.Web.Utility.GetGlobalErrorString("IPRefusedVisit"), string.Empty);
                }
                else if (IsRefusedVisitAdminPage(context, lockAdminType, adminLockIPWhite, adminLockIPBlack, userIP))
                {
                    PowerEasy.Web.Utility.WriteErrMsg(PowerEasy.Web.Utility.GetGlobalErrorString("IPRefusedVisitAdmin"), string.Empty);
                }
            }
        }

        private static bool CheckIPlock(int lockType, string lockWhiteList, string lockBlackList, double userIP)
        {
            bool flag = false;
            if ((lockType == 0) || (userIP == 0.0))
            {
                return flag;
            }
            if (lockType == 4)
            {
                flag = GetAnalysisResult(lockBlackList, 1, userIP);
                if (flag)
                {
                    flag = GetAnalysisResult(lockWhiteList, 0, userIP);
                }
                return flag;
            }
            if ((lockType == 1) || (lockType == 3))
            {
                flag = GetAnalysisResult(lockWhiteList, 0, userIP);
            }
            if (flag || ((lockType != 2) && (lockType != 3)))
            {
                return flag;
            }
            return GetAnalysisResult(lockBlackList, 1, userIP);
        }

        public void Dispose()
        {
        }

        private static bool GetAnalysisResult(string lockList, int ipType, double userIP)
        {
            bool flag = false;
            if (!string.IsNullOrEmpty(lockList))
            {
                string[] strArray = lockList.Split(new string[] { "$$$" }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < strArray.Length; i++)
                {
                    if (!string.IsNullOrEmpty(strArray[i]))
                    {
                        try
                        {
                            bool flag2;
                            string[] strArray2 = strArray[i].Split(new string[] { "----" }, StringSplitOptions.RemoveEmptyEntries);
                            if (ipType == 0)
                            {
                                flag = true;
                                flag2 = (DataConverter.CDouble(strArray2[0]) <= userIP) && (userIP <= DataConverter.CDouble(strArray2[1]));
                            }
                            else
                            {
                                flag2 = (DataConverter.CDouble(strArray2[0]) <= userIP) && (userIP <= DataConverter.CDouble(strArray2[1]));
                            }
                            if (flag2)
                            {
                                return (ipType == 1);
                            }
                        }
                        catch (IndexOutOfRangeException)
                        {
                            return false;
                        }
                    }
                }
            }
            return flag;
        }

        public void Init(HttpApplication context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            context.BeginRequest += new EventHandler(this.Application_BeginRequest);
        }

        private static bool IsRefusedVisitAdminPage(HttpContext context, int lockAdminType, string lockAdminWhiteList, string lockAdminBlackList, double userIP)
        {
            string absolutePath = context.Request.Url.AbsolutePath;
            string str2 = PowerEasy.Web.Utility.GetBasePath(context.Request) + SiteConfig.SiteOption.ManageDir + "/";
            return (absolutePath.StartsWith(str2, StringComparison.CurrentCultureIgnoreCase) && CheckIPlock(lockAdminType, lockAdminWhiteList, lockAdminBlackList, userIP));
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -