/// <summary> /// 执行在线用户向表及缓存中添加的操作。 /// </summary> /// <param name="onlineuserinfo">在组用户信息内容</param> /// <param name="timeout">系统设置用户多少时间即算做离线</param> /// <param name="deletingfrequency">删除过期用户频率(单位:分钟)</param> /// <returns>添加成功则返回刚刚添加的olid,失败则返回0</returns> public int AddOnlineUser(OnlineUserInfo onlineUserInfo, int timeOut, int deletingFrequency) { //标识需要更新用户在线状态,0表示需要更新 int onlinestate = 1; // 如果timeout为负数则代表不需要精确更新用户是否在线的状态 if (timeOut > 0) { if (onlineUserInfo.Ol_ps_id > 0) onlinestate = 0; } else timeOut = timeOut * -1; if (timeOut > 9999) timeOut = 9999; DbParameter[] parms = { DbHelper.MakeInParam("@onlinestate",(DbType)SqlDbType.Int,4,onlinestate), DbHelper.MakeInParam("@ol_ps_id",(DbType)SqlDbType.Int,4,onlineUserInfo.Ol_ps_id), DbHelper.MakeInParam("@ol_ip",(DbType)SqlDbType.VarChar,50,onlineUserInfo.Ol_ip), DbHelper.MakeInParam("@ol_name",(DbType)SqlDbType.VarChar,50,onlineUserInfo.Ol_name), DbHelper.MakeInParam("@ol_nickName",(DbType)SqlDbType.VarChar,50,onlineUserInfo.Ol_nickName), DbHelper.MakeInParam("@ol_password",(DbType)SqlDbType.VarChar,200,onlineUserInfo.Ol_password), DbHelper.MakeInParam("@ol_ug_id",(DbType)SqlDbType.Int,4,onlineUserInfo.Ol_ug_id), DbHelper.MakeInParam("@ol_img",(DbType)SqlDbType.VarChar,200,onlineUserInfo.Ol_img), DbHelper.MakeInParam("@ol_pg_id",(DbType)SqlDbType.Int,4,onlineUserInfo.Ol_pg_id), DbHelper.MakeInParam("@ol_invisible",(DbType)SqlDbType.SmallInt,2,onlineUserInfo.Ol_invisible), DbHelper.MakeInParam("@ol_action",(DbType)SqlDbType.Int,4,onlineUserInfo.Ol_action), DbHelper.MakeInParam("@ol_lastactivity",(DbType)SqlDbType.Int,4,onlineUserInfo.Ol_lastactivity), DbHelper.MakeInParam("@ol_lastpostpmtime",(DbType)SqlDbType.DateTime,8,DateTime.Parse(onlineUserInfo.Ol_lastpostpmtime)), DbHelper.MakeInParam("@ol_lastsearchtime",(DbType)SqlDbType.DateTime,8,DateTime.Parse(onlineUserInfo.Ol_lastsearchtime)), DbHelper.MakeInParam("@ol_lastupdatetime",(DbType)SqlDbType.DateTime,8,DateTime.Parse(onlineUserInfo.Ol_lastupdatetime)), DbHelper.MakeInParam("@ol_pm_id",(DbType)SqlDbType.Int,4,onlineUserInfo.Ol_pm_id), DbHelper.MakeInParam("@ol_pm_name",(DbType)SqlDbType.VarChar,200,""), DbHelper.MakeInParam("@ol_verifycode",(DbType)SqlDbType.VarChar,50,onlineUserInfo.Ol_verifycode), DbHelper.MakeInParam("@ol_newpms",(DbType)SqlDbType.Int,4,onlineUserInfo.Ol_newpms), DbHelper.MakeInParam("@ol_newnotices",(DbType)SqlDbType.Int,4,onlineUserInfo.Ol_newnotices) }; int olid = TypeConverter.ObjectToInt(DbHelper.ExecuteScalar(CommandType.StoredProcedure, string.Format("{0}createonlineuser", BaseConfigs.GetTablePrefix), parms)); //按照系统设置频率(默认5分钟)清除过期用户 if (_lastRemoveTimeout == 0 || (System.Environment.TickCount - _lastRemoveTimeout) > 60000 * deletingFrequency) { DeleteExpiredOnlineUsers(timeOut); _lastRemoveTimeout = System.Environment.TickCount; } // 如果id值太大则重建在线表 if (olid > 2147483000) { CreateOnlineTable(); DbHelper.ExecuteNonQuery(CommandType.StoredProcedure, string.Format("{0}createonlineuser", BaseConfigs.GetTablePrefix), parms); return 1; } return 0; }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { config = GeneralConfigs.GetConfig(); // 如果IP访问列表有设置则进行判断 if (config.Adminipaccess.Trim() != "") { string[] regctrl = Utils.SplitString(config.Adminipaccess, "\n"); if (!Utils.InIPArray(SASRequest.GetIP(), regctrl)) { Context.Response.Redirect(BaseConfigs.GetSitePath + "ManagePage/syslogin.aspx"); return; } } //获取当前用户的在线否? OnlineUserInfo oluserinfo = new OnlineUserInfo(); try { oluserinfo = OnlineUsers.UpdateInfo(config.Passwordkey, config.Onlinetimeout); } catch { Thread.Sleep(2000); oluserinfo = OnlineUsers.UpdateInfo(config.Passwordkey, config.Onlinetimeout); } #region 进行权限判断 UserGroupInfo usergroupinfo = AdminUserGroups.AdminGetUserGroupInfo(oluserinfo.Ol_ug_id); if (oluserinfo.Ol_ps_id <= 0 || usergroupinfo.ug_pg_id != 1) { Context.Response.Redirect(BaseConfigs.GetSitePath + "ManagePage/syslogin.aspx"); return; } string secques = Users.GetUserInfo(oluserinfo.Ol_ps_id).Ps_secques; // 管理员身份验? if (Context.Request.Cookies["sasadmin"] == null || Context.Request.Cookies["sasadmin"]["key"] == null || LogicUtils.GetCookiePassword(Context.Request.Cookies["sasadmin"]["key"].ToString(), config.Passwordkey) != (oluserinfo.Ol_password + secques + oluserinfo.Ol_ps_id.ToString())) { Context.Response.Redirect(BaseConfigs.GetSitePath + "ManagePage/syslogin.aspx"); return; } else { HttpCookie cookie = HttpContext.Current.Request.Cookies["sasadmin"]; cookie.Values["key"] = LogicUtils.SetCookiePassword(oluserinfo.Ol_password + secques + oluserinfo.Ol_ps_id.ToString(), config.Passwordkey); cookie.Expires = DateTime.Now.AddMinutes(30); HttpContext.Current.Response.AppendCookie(cookie); } #endregion } }
/// <summary> /// Cookie中没有用户ID或则存的的用户ID无效时在在线表中增加一个游客. /// </summary> public static OnlineUserInfo CreateGuestUser(int timeout) { OnlineUserInfo onlineuserinfo = new OnlineUserInfo(); onlineuserinfo.Ol_ps_id = -1; onlineuserinfo.Ol_name = "游客"; onlineuserinfo.Ol_nickName = "游客"; onlineuserinfo.Ol_password = ""; onlineuserinfo.Ol_ug_id = 7; onlineuserinfo.Ol_img = GetGroupImg(7); onlineuserinfo.Ol_pg_id = 0; onlineuserinfo.Ol_invisible = 0; onlineuserinfo.Ol_ip = SASRequest.GetIP(); onlineuserinfo.Ol_lastpostpmtime = "1900-1-1 00:00:00"; onlineuserinfo.Ol_lastsearchtime = "1900-1-1 00:00:00"; onlineuserinfo.Ol_lastupdatetime = "1900-1-1 00:00:00"; onlineuserinfo.Ol_action = 0; onlineuserinfo.Ol_lastactivity = 0; onlineuserinfo.Ol_verifycode = LogicUtils.CreateAuthStr(5, false); onlineuserinfo.Ol_id = SAS.Data.DataProvider.OnlineUsers.CreateOnlineUserInfo(onlineuserinfo, timeout); return onlineuserinfo; }
/// <summary> /// 增加一个会员信息到在线列表中。用户login.aspx或在线用户信息超时,但用户仍在线的情况下重新生成用户在线列表 /// </summary> /// <param name="uid"></param> private static OnlineUserInfo CreateUser(int uid, int timeout) { OnlineUserInfo onlineuserinfo = new OnlineUserInfo(); if (uid > 0) { ShortUserInfo ui = Users.GetShortUserInfo(uid); if (ui != null) { onlineuserinfo.Ol_ps_id = uid; onlineuserinfo.Ol_name = ui.Ps_name.Trim(); onlineuserinfo.Ol_nickName = ui.Ps_nickName.Trim(); onlineuserinfo.Ol_password = ui.Ps_password.Trim(); onlineuserinfo.Ol_ug_id = short.Parse(ui.Ps_ug_id.ToString()); onlineuserinfo.Ol_img = GetGroupImg(short.Parse(ui.Ps_ug_id.ToString())); onlineuserinfo.Ol_pg_id = short.Parse(ui.Ps_pg_id.ToString()); onlineuserinfo.Ol_invisible = short.Parse(ui.Ps_invisible.ToString()); onlineuserinfo.Ol_ip = SASRequest.GetIP(); onlineuserinfo.Ol_lastpostpmtime = "1900-1-1 00:00:00"; onlineuserinfo.Ol_lastsearchtime = "1900-1-1 00:00:00"; onlineuserinfo.Ol_lastupdatetime = "1900-1-1 00:00:00"; onlineuserinfo.Ol_action = 0; onlineuserinfo.Ol_lastactivity = 0; onlineuserinfo.Ol_verifycode = LogicUtils.CreateAuthStr(5, false); onlineuserinfo.Ol_newpms = short.Parse(PrivateMessages.GetPrivateMessageCount(uid, 0, 1).ToString()); onlineuserinfo.Ol_newnotices = short.Parse(Notices.GetNewNoticeCountByUid(uid).ToString()); onlineuserinfo.Ol_id = SAS.Data.DataProvider.OnlineUsers.CreateOnlineUserInfo(onlineuserinfo, timeout); //给管理人员发送关注通知 if (ui.Ps_pg_id > 0 && ui.Ps_pg_id < 4) { if (SAS.Data.DataProvider.Notices.ReNewNotice((int)Noticetype.AttentionNotice, ui.Ps_id) == 0) { NoticeInfo ni = new NoticeInfo(); ni.New = 1; ni.Note = "请及时查看<a href=\"modcp.aspx?operation=attention&forumid=0\">需要关注的主题</a>"; ni.Postdatetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); ni.Type = Noticetype.AttentionNotice; ni.Poster = ""; ni.Posterid = 0; ni.Uid = ui.Ps_id; Notices.CreateNoticeInfo(ni); } } SAS.Data.DataProvider.OnlineUsers.SetUserOnlineState(uid, 1); HttpCookie cookie = HttpContext.Current.Request.Cookies["sas"]; if (cookie != null) { //cookie.Values["tpp"] = ui.Tpp.ToString(); //cookie.Values["ppp"] = ui.Ppp.ToString(); if (HttpContext.Current.Request.Cookies["sas"]["expires"] != null) { int expires = TypeConverter.StrToInt(HttpContext.Current.Request.Cookies["sas"]["expires"].ToString(), 0); if (expires > 0) { cookie.Expires = DateTime.Now.AddMinutes(TypeConverter.StrToInt(HttpContext.Current.Request.Cookies["sas"]["expires"].ToString(), 0)); } } } string cookieDomain = GeneralConfigs.GetConfig().CookieDomain.Trim(); if (!Utils.StrIsNullOrEmpty(cookieDomain) && HttpContext.Current.Request.Url.Host.IndexOf(cookieDomain) > -1 && LogicUtils.IsValidDomain(HttpContext.Current.Request.Url.Host)) cookie.Domain = cookieDomain; HttpContext.Current.Response.AppendCookie(cookie); } else { onlineuserinfo = CreateGuestUser(timeout); } } else { onlineuserinfo = CreateGuestUser(timeout); } return onlineuserinfo; }
/// <summary> /// 用户在线信息维护。判断当前用户的身份(会员还是游客),是否在在线列表中存在,如果存在则更新会员的当前动,不存在则建立. /// </summary> /// <param name="passwordkey">论坛passwordkey</param> /// <param name="timeout">在线超时时间</param> /// <param name="passwd">用户密码</param> public static OnlineUserInfo UpdateInfo(string passwordkey, int timeout, int uid, string passwd) { lock (SynObject) { OnlineUserInfo onlineuser = new OnlineUserInfo(); string ip = SASRequest.GetIP(); int userid = TypeConverter.StrToInt(LogicUtils.GetCookie("userid"), uid); string password = (Utils.StrIsNullOrEmpty(passwd) ? LogicUtils.GetCookiePassword(passwordkey) : LogicUtils.GetCookiePassword(passwd, passwordkey)); // 如果密码非Base64编码字符串则怀疑被非法篡改, 直接置身份为游客 if (password.Length == 0 || !Utils.IsBase64String(password)) userid = -1; if (userid != -1) { onlineuser = GetOnlineUser(userid, password); //更新流量统计 if (!SASRequest.GetPageName().EndsWith("ajax.aspx") && GeneralConfigs.GetConfig().Statstatus == 1) Stats.UpdateStatCount(false, onlineuser != null); if (onlineuser != null) { if (onlineuser.Ol_ip != ip) { UpdateIP(onlineuser.Ol_id, ip); onlineuser.Ol_ip = ip; return onlineuser; } } else { // 判断密码是否正确 userid = Users.CheckPassword(userid, password, false); if (userid != -1) { SAS.Data.DataProvider.OnlineUsers.DeleteRowsByIP(ip); CheckIp(ip); return CreateUser(userid, timeout); } else { CheckIp(ip); // 如密码错误则在在线表中创建游客 onlineuser = GetOnlineUserByIP(-1, ip); if (onlineuser == null) return CreateGuestUser(timeout); } } } else { onlineuser = GetOnlineUserByIP(-1, ip); //更新流量统计 if (!SASRequest.GetPageName().EndsWith("ajax.aspx") && GeneralConfigs.GetConfig().Statstatus == 1) Stats.UpdateStatCount(true, onlineuser != null); if (onlineuser == null) return CreateGuestUser(timeout); } onlineuser.Ol_lastupdatetime = Utils.GetDateTime(); return onlineuser; } }
/// <summary> /// BasePage类构造函数 /// </summary> public BasePage() { config = GeneralConfigs.GetConfig(); //if (SpacePluginProvider.GetInstance() == null) // config.Enablespace = 0; if (AlbumPluginProvider.GetInstance() == null) config.Enablealbum = 0; //if (MallPluginProvider.GetInstance() == null) // config.Enablemall = 0; LoadUrlConfig(); userid = Utils.StrToInt(LogicUtils.GetCookie("userid"), -1); //清空当前页面查询统计 #if DEBUG SAS.Data.DbHelper.QueryCount = 0; SAS.Data.DbHelper.QueryDetail = ""; #endif // 如果启用游客页面缓存,则对游客输出缓存页 if (userid == -1 && config.Guestcachepagetimeout > 0 && GetUserCachePage(pagename)) return; AddMetaInfo(config.Seokeywords, config.Seodescription, config.Seohead); if (config.Nocacheheaders == 1) { System.Web.HttpContext.Current.Response.BufferOutput = false; System.Web.HttpContext.Current.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1); System.Web.HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.AddDays(-1)); System.Web.HttpContext.Current.Response.Expires = 0; System.Web.HttpContext.Current.Response.CacheControl = "no-cache"; System.Web.HttpContext.Current.Response.Cache.SetNoStore(); } //当为forumlist.aspx或forumindex.aspx,可能出现在线并发问题,这时系统会延时2秒 if ((pagename != "zshy.aspx") && (pagename != "index.aspx")) oluserinfo = OnlineUsers.UpdateInfo(config.Passwordkey, config.Onlinetimeout); else { try { oluserinfo = OnlineUsers.UpdateInfo(config.Passwordkey, config.Onlinetimeout); } catch { System.Threading.Thread.Sleep(2000); oluserinfo = OnlineUsers.UpdateInfo(config.Passwordkey, config.Onlinetimeout); } } userid = oluserinfo.Ol_ps_id; usergroupid = oluserinfo.Ol_ug_id; username = oluserinfo.Ol_name; password = oluserinfo.Ol_password; userkey = password.Length > 16 ? password.Substring(4, 8).Trim() : ""; //lastposttime = oluserinfo.Lastposttime; lastpostpmtime = oluserinfo.Ol_lastpostpmtime; lastsearchtime = oluserinfo.Ol_lastsearchtime; olid = oluserinfo.Ol_id; //确保头像可以取到 //if (userid > 0) // useravatar = Avatars.GetAvatarUrl(userid.ToString(), AvatarSize.Small); if (Utils.InArray(SASRequest.GetString("selectedtemplateid"), Templates.GetValidTemplateIDList())) templateid = SASRequest.GetInt("selectedtemplateid", 0); else if (Utils.InArray(Utils.GetCookie(Utils.GetTemplateCookieName()), Templates.GetValidTemplateIDList())) templateid = Utils.StrToInt(Utils.GetCookie(Utils.GetTemplateCookieName()), config.Templateid); if (templateid == 0) templateid = config.Templateid; pmsound = Utils.StrToInt(LogicUtils.GetCookie("pmsound"), 0); usergroupinfo = UserGroups.GetUserGroupInfo(usergroupid); // 取得用户权限id,1管理员,2超版,3版主,0普通组,-1特殊组 useradminid = usergroupinfo.ug_pg_id; mainnavigation = Navs.GetNavigationString(userid, useradminid); subnavigation = Navs.GetSubNavigation(); mainnavigationhassub = Navs.GetMainNavigationHasSub(); // 如果论坛关闭且当前用户请求页面不是登录页面且用户非管理员, 则跳转至论坛关闭信息页 if (config.Closed == 1 && pagename != "login.aspx" && pagename != "logout.aspx" && pagename != "register.aspx" && useradminid != 1) { ShowMessage(1); return; } onlineusercount = (userid != -1) ? OnlineUsers.GetOnlineAllUserCount() : OnlineUsers.GetCacheOnlineAllUserCount(); //校验用户是否可以访问站点 if (!ValidateUserPermission()) return; //更新用户在线时长 if (userid != -1) OnlineUsers.UpdateOnlineTime(config.Oltimespan, userid); templatepath = Templates.GetTemplateItem(templateid).Directory; nowdate = Utils.GetDate(); nowtime = Utils.GetTime(); nowdatetime = Utils.GetDateTime(); ispost = SASRequest.IsPost(); isget = SASRequest.IsGet(); link = ""; script = ""; templatelistboxoptions = Caches.GetTemplateListBoxOptionsCache(); string originalTemplate = string.Format("<li><a href=\"###\" onclick=\"window.location.href='{0}showtemplate.aspx?templateid={1}'\">", "", BaseConfigs.GetSitePath, templateid); string newTemplate = string.Format("<li class=\"current\"><a href=\"###\" onclick=\"window.location.href='{0}showtemplate.aspx?templateid={1}'\">", BaseConfigs.GetSitePath, templateid); templatelistboxoptions = templatelistboxoptions.Replace(originalTemplate, newTemplate); isseccode = Utils.InArray(pagename, config.Seccodestatus); //headerad = Advertisements.GetOneHeaderAd("", 0); //footerad = Advertisements.GetOneFooterAd("", 0); //校验验证码 if (isseccode && ispost && !ValidateVerifyCode()) return; //newtopicminute = config.Viewnewtopicminute; m_starttick = DateTime.Now; Companies.GetCompanyCountSum(out allcount, out passcount, out todaycount, out waitcount); ShowPage(); m_processtime = DateTime.Now.Subtract(m_starttick).TotalMilliseconds / 1000; querycount = SAS.Data.DbHelper.QueryCount; SAS.Data.DbHelper.QueryCount = 0; #if DEBUG querydetail = SAS.Data.DbHelper.QueryDetail; SAS.Data.DbHelper.QueryDetail = ""; #endif }
/// <summary> /// 执行在线用户向表及缓存中添加的操作。 /// </summary> /// <param name="onlineuserinfo">在组用户信息内容</param> /// <returns>添加成功则返回刚刚添加的olid,失败则返回0</returns> public static int CreateOnlineUserInfo(OnlineUserInfo onlineuserinfo, int timeout) { return DatabaseProvider.GetInstance().AddOnlineUser(onlineuserinfo, timeout, GeneralConfigs.GetConfig().Deletingexpireduserfrequency); }
private static OnlineUserInfo LoadSingleOnlineUser(DataRow dr) { OnlineUserInfo info = new OnlineUserInfo(); info.Ol_id = TypeConverter.ObjectToInt(dr["ol_id"]); info.Ol_ps_id = TypeConverter.ObjectToInt(dr["ol_ps_id"]); info.Ol_ip = dr["ol_ip"].ToString(); info.Ol_name = dr["ol_name"].ToString(); info.Ol_nickName = dr["ol_nickName"].ToString(); info.Ol_password = dr["ol_password"].ToString(); info.Ol_ug_id = Int16.Parse(dr["ol_ug_id"].ToString()); info.Ol_img = dr["ol_img"].ToString(); info.Ol_pg_id = Int16.Parse(dr["ol_pg_id"].ToString()); info.Ol_invisible = Int16.Parse(dr["ol_invisible"].ToString()); info.Ol_action = Int16.Parse(dr["ol_action"].ToString()); info.Ol_actionname = ""; info.Ol_lastactivity = Int16.Parse(dr["ol_lastactivity"].ToString()); info.Ol_lastpostpmtime = dr["ol_lastpostpmtime"].ToString(); info.Ol_lastsearchtime = dr["ol_lastsearchtime"].ToString(); info.Ol_lastupdatetime = dr["ol_lastupdatetime"].ToString(); info.Ol_pm_id = TypeConverter.ObjectToInt(dr["ol_pm_id"]); if (dr["ol_pm_name"] != DBNull.Value) info.Ol_pm_name = dr["ol_pm_name"].ToString(); info.Ol_verifycode = dr["ol_verifycode"].ToString(); if (dr["ol_newpms"] != DBNull.Value) info.Ol_newpms = Int16.Parse(dr["ol_newpms"].ToString()); if (dr["ol_newnotices"] != DBNull.Value) info.Ol_newnotices = Int16.Parse(dr["ol_newnotices"].ToString()); return info; }