| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- using Castle.ActiveRecord;
- using NHibernate.Criterion;
- using System.Text;
- namespace BizCom
- {
- [ActiveRecord("SiteInfo")]
- public class SiteInfo : ComBase<SiteInfo>
- {
- private string _id = "";
- /// <summary>
- ///
- /// </summary>
- [PrimaryKey(PrimaryKeyType.Assigned)]
- public string id
- {
- get { return _id; }
- set { _id = value; }
- }
- private string _site_title = "";
- /// <summary>
- ///
- /// </summary>
- [Property]
- public string site_title
- {
- get { return _site_title; }
- set { _site_title = value; }
- }
- private string _web_domain = "";
- /// <summary>
- ///
- /// </summary>
- [Property]
- public string web_domain
- {
- get { return _web_domain; }
- set { _web_domain = value; }
- }
- private int _open_ip_white_list = 0;
- /// <summary>
- ///
- /// </summary>
- [Property]
- public int open_ip_white_list
- {
- get { return _open_ip_white_list; }
- set { _open_ip_white_list = value; }
- }
- private string _ip_white_list = "";
- /// <summary>
- ///
- /// </summary>
- [Property]
- public string ip_white_list
- {
- get { return _ip_white_list; }
- set { _ip_white_list = value; }
- }
- private string _remark = "";
- /// <summary>
- ///
- /// </summary>
- [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());
- }
- }
- }
|