using Castle.ActiveRecord; using NHibernate.Criterion; using System.Text; namespace BizCom { [ActiveRecord("SiteInfo")] public class SiteInfo : ComBase { private string _id = ""; /// /// /// [PrimaryKey(PrimaryKeyType.Assigned)] public string id { get { return _id; } set { _id = value; } } private string _site_title = ""; /// /// /// [Property] public string site_title { get { return _site_title; } set { _site_title = value; } } private string _web_domain = ""; /// /// /// [Property] public string web_domain { get { return _web_domain; } set { _web_domain = value; } } private int _open_ip_white_list = 0; /// /// /// [Property] public int open_ip_white_list { get { return _open_ip_white_list; } set { _open_ip_white_list = value; } } private string _ip_white_list = ""; /// /// /// [Property] public string ip_white_list { get { return _ip_white_list; } set { _ip_white_list = value; } } private string _remark = ""; /// /// /// [Property] public string remark { get { return _remark; } set { _remark = value; } } public void Update(bool isOpenIpWiteList, string ipWiteList, string remark) { SiteInfo siteInfo = new SiteInfo(); siteInfo.id = "1"; siteInfo.open_ip_white_list = isOpenIpWiteList ? 1 : 0; siteInfo.ip_white_list = ipWiteList; siteInfo.remark = remark; _ipWhiteList = null; Update(siteInfo); } public SiteInfo[] GetSiteInfos() { return FindAll(Expression.Eq("open_ip_white_list", 1)); } public SiteInfo GetSiteInfoById(string id) { return FindFirst(Expression.Eq("id", id)); } public override void Update() { base.Update(); _ipWhiteList = null; } private static string[] _ipWhiteList = null; private static string[] getIpWhiteList() { if (_ipWhiteList != null) { return _ipWhiteList; } SiteInfo[] siteInfo = new SiteInfo().GetSiteInfos(); for (int i = 0; i < siteInfo.Length; i++) { string ipWiteList = siteInfo[i].ip_white_list.Replace("\r\n", ",").Replace("\n", ",").Replace(" ", ","); _ipWhiteList = ipWiteList.Split(','); } return _ipWhiteList; } public static bool isPassIp(string ip) { if (string.IsNullOrWhiteSpace(ip)) return false; if (ip.IndexOf("192.168.") != -1 || "127.0.0.1" == ip || "0:0:0:0:0:0:0:1" == ip) return true; //�ж��Ƿ��ڰ������� string[] ipNumList = ip.Split('.'); string newIp = ""; if (ipNumList.Length >= 2) { newIp = ipNumList[0] + "." + ipNumList[1] + ".*.*"; } SiteInfo info = GetSiteInfoByIp(newIp); if (info != null) return true; //if (getIpWhiteList().Length == 0) // return true; //foreach (string matche in getIpWhiteList()) //{ // Match result = Regex.Match(ip, matche); // if (result.Length > 0) // { // return true; // } //} return false; } public static SiteInfo GetSiteInfoByIp(string ip) { return FindFirst(Expression.Sql(string.Format("ip_white_list like '%{0}%'", ip))); } public static void DelById(object id) { StringBuilder sql = new StringBuilder(); sql.AppendFormat("delete from SiteInfo where id='" + id + "'"); ExecuteNonQuery(sql.ToString()); } } }