/// <summary> /// Called when page is loaded /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ForumPage_Load( object sender, System.EventArgs e ) { if ( m_bNoDataBase ) return; #if DEBUG QueryCounter.Reset(); #endif // basic Request Checking (can be easily spoofed) CheckRequestValidity( Request ); // setup the culture based on the browser... InitCulture(); try { string key = string.Format( "BannedIP.{0}", PageBoardID ); DataTable banip = ( DataTable ) HttpContext.Current.Cache [key]; if ( banip == null ) { banip = DB.bannedip_list( PageBoardID, null ); HttpContext.Current.Cache [key] = banip; } foreach ( DataRow row in banip.Rows ) if ( Utils.IsBanned( ( string ) row ["Mask"], HttpContext.Current.Request.ServerVariables ["REMOTE_ADDR"] ) ) HttpContext.Current.Response.End(); } catch ( Exception ) { // If the above fails chances are that this is a new install Response.Redirect( Data.ForumRoot + "install/" ); } // Find user name AuthType authType = Data.GetAuthType; string typeUser; switch ( authType ) { case AuthType.Guest: typeUser = "******"; break; case AuthType.Rainbow: typeUser = "******"; break; case AuthType.DotNetNuke: typeUser = "******"; break; case AuthType.Windows: typeUser = "******"; break; case AuthType.Portal: typeUser = "******"; break; case AuthType.Custom: string assembly = Config.yafSection ["CustomUserAssembly"]; if ( assembly.Contains( ".dll" ) ) { assembly = assembly.Replace( ".dll", "" ); } typeUser = String.Format( "{0},{1}", Config.yafSection ["CustomUserClass"], assembly ); break; default: typeUser = "******"; break; } m_forumUser = ( IForumUser ) Activator.CreateInstance( Type.GetType( typeUser ) ); string browser = String.Format( "{0} {1}", HttpContext.Current.Request.Browser.Browser, HttpContext.Current.Request.Browser.Version ); string platform = HttpContext.Current.Request.Browser.Platform; if ( HttpContext.Current.Request.UserAgent != null ) { if ( HttpContext.Current.Request.UserAgent.IndexOf( "Windows NT 5.2" ) >= 0 ) platform = "Win2003"; if ( HttpContext.Current.Request.UserAgent.IndexOf( "Windows NT 6.0" ) >= 0 ) platform = "Vista"; } object categoryID = ValidInt( HttpContext.Current.Request.QueryString ["c"] ); object forumID = ValidInt( HttpContext.Current.Request.QueryString ["f"] ); object topicID = ValidInt( HttpContext.Current.Request.QueryString ["t"] ); object messageID = ValidInt( HttpContext.Current.Request.QueryString ["m"] ); if ( ForumControl.CategoryID != 0 ) categoryID = ForumControl.CategoryID; m_pageinfo = DB.pageload( HttpContext.Current.Session.SessionID, PageBoardID, User.Name, HttpContext.Current.Request.UserHostAddress, HttpContext.Current.Request.FilePath, browser, platform, categoryID, forumID, topicID, messageID ); // If user wasn't found and we have foreign // authorization, try to register the user. if ( m_pageinfo == null && authType != AuthType.Forms && User.IsAuthenticated ) { if ( !DB.user_register( this, PageBoardID, User.Name, "ext", User.Email, User.Location, User.HomePage, 0, false ) ) throw new ApplicationException( "User registration failed." ); m_pageinfo = DB.pageload( HttpContext.Current.Session.SessionID, PageBoardID, User.Name, HttpContext.Current.Request.UserHostAddress, HttpContext.Current.Request.FilePath, HttpContext.Current.Request.Browser.Browser, HttpContext.Current.Request.Browser.Platform, HttpContext.Current.Request.QueryString ["c"], HttpContext.Current.Request.QueryString ["f"], HttpContext.Current.Request.QueryString ["t"], HttpContext.Current.Request.QueryString ["m"] ); } if ( m_pageinfo == null ) { if ( User.IsAuthenticated ) throw new ApplicationException( string.Format( "User '{0}' isn't registered.", User.Name ) ); else throw new ApplicationException( "Failed to find guest user." ); } if ( m_checkSuspended && IsSuspended ) { if ( SuspendedTo < DateTime.Now ) { DB.user_suspend( PageUserID, null ); HttpContext.Current.Response.Redirect( Utils.GetSafeRawUrl() ); } Forum.Redirect( Pages.info, "i=2" ); } // This happens when user logs in if ( Mession.LastVisit == DateTime.MinValue ) { // Only important for portals like Rainbow or DotNetNuke if ( User.IsAuthenticated ) User.UpdateUserInfo( PageUserID ); if ( ( int ) m_pageinfo ["Incoming"] > 0 ) AddLoadMessage( String.Format( GetText( "UNREAD_MSG" ), m_pageinfo ["Incoming"] ) ); } if ( !IsGuest && m_pageinfo ["PreviousVisit"] != DBNull.Value && !Mession.HasLastVisit ) { //if(Mession.LastVisit == DateTime.MinValue || (DateTime)m_pageinfo["PreviousVisit"]<Mession.LastVisit) Mession.LastVisit = ( DateTime ) m_pageinfo ["PreviousVisit"]; Mession.HasLastVisit = true; } else if ( Mession.LastVisit == DateTime.MinValue ) { Mession.LastVisit = DateTime.Now; } // Check if pending mails, and send 10 of them if possible if ( ( int ) m_pageinfo ["MailsPending"] > 0 ) { SendMailThread(); } // compute page title.. System.Text.StringBuilder title = new StringBuilder(); if ( this.PageTopicID != 0 ) title.AppendFormat( "{0} - ", Utils.BadWordReplace( this.PageTopicName ) ); // Tack on the topic we're viewing if ( this.PageForumName != string.Empty ) title.AppendFormat( "{0} - ", Server.HtmlEncode( this.PageForumName ) ); // Tack on the forum we're viewing title.Append( Server.HtmlEncode( BoardSettings.Name ) ); // and lastly, tack on the board's name _forumPageTitle = title.ToString(); if ( PageTitleSet != null ) PageTitleSet( this, new ForumPageArgs( _forumPageTitle ) ); }
/// <summary> /// Called when page is loaded /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ForumPage_Load(object sender, System.EventArgs e) { if(m_bNoDataBase) return; #if DEBUG QueryCounter.Reset(); #endif // Set the culture and UI culture to the browser's accept language try { string sCulture = ""; string [] sTmp = HttpContext.Current.Request.UserLanguages; if (sTmp != null) { sCulture = sTmp[0]; if(sCulture.IndexOf(';')>=0) { sCulture = sCulture.Substring(0, sCulture.IndexOf(';')); } } else { sCulture = "en-US"; } Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(sCulture); Thread.CurrentThread.CurrentUICulture = new CultureInfo(sCulture); } #if DEBUG catch(Exception ex) { throw new ApplicationException("Error getting User Language." + Environment.NewLine + ex.ToString()); } #else catch(Exception) { } #endif //Response.Expires = -1000; /* HttpContext.Current.Response.AddHeader("Cache-control", "private, no-cache, must-revalidate"); HttpContext.Current.Response.AddHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); // Past date HttpContext.Current.Response.AddHeader("Pragma", "no-cache"); */ try { string key = string.Format("BannedIP.{0}",PageBoardID); DataTable banip = (DataTable)HttpContext.Current.Cache[key]; if(banip == null) { banip = DB.bannedip_list(PageBoardID,null); HttpContext.Current.Cache[key] = banip; } foreach(DataRow row in banip.Rows) if(Utils.IsBanned((string)row["Mask"], HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"])) HttpContext.Current.Response.End(); } catch(Exception) { // If the above fails chances are that this is a new install Response.Redirect(Data.ForumRoot + "install/"); } if( HttpContext.Current.User is User ) { m_forumUser = (IForumUser)HttpContext.Current.User; }else { GenericIdentity identity = new GenericIdentity(""); m_forumUser = new User( identity, OrionApplication.defaultRoles); } string browser = String.Format("{0} {1}",HttpContext.Current.Request.Browser.Browser,HttpContext.Current.Request.Browser.Version); string platform = HttpContext.Current.Request.Browser.Platform; if (HttpContext.Current.Request.UserAgent != null) { if(HttpContext.Current.Request.UserAgent.IndexOf("Windows NT 5.2")>=0) platform = "Win2003"; } object categoryID = ValidInt(HttpContext.Current.Request.QueryString["c"]); object forumID = ValidInt(HttpContext.Current.Request.QueryString["f"]); object topicID = ValidInt(HttpContext.Current.Request.QueryString["t"]); object messageID = ValidInt(HttpContext.Current.Request.QueryString["m"]); if(ForumControl.CategoryID!=null) categoryID = ForumControl.CategoryID; m_pageinfo = DB.pageload( HttpContext.Current.Session.SessionID, PageBoardID, User.Email, HttpContext.Current.Request.UserHostAddress, HttpContext.Current.Request.FilePath, browser, platform, categoryID, forumID, topicID, messageID); // If user wasn't found and we have foreign // authorization, try to register the user. /*if(m_pageinfo==null && authType!=AuthType.Forms && User.IsAuthenticated) { if(!DB.user_register(this,PageBoardID,User.Name,"ext",User.Email,User.Location,User.HomePage,0,false)) throw new ApplicationException("User registration failed."); m_pageinfo = DB.pageload( HttpContext.Current.Session.SessionID, PageBoardID, User.Name, HttpContext.Current.Request.UserHostAddress, HttpContext.Current.Request.FilePath, HttpContext.Current.Request.Browser.Browser, Hhttp://localhost/alnitak/Web.configttpContext.Current.Request.Browser.Platform, HttpContext.Current.Request.QueryString["c"], HttpContext.Current.Request.QueryString["f"], HttpContext.Current.Request.QueryString["t"], HttpContext.Current.Request.QueryString["m"]); }*/ if(m_pageinfo==null) { if(User.IsAuthenticated) throw new ApplicationException(string.Format("User '{0}' isn't registered.",User.Name)); else throw new ApplicationException("Failed to find guest user."); } /*if(m_checkSuspended && IsSuspended) { if(SuspendedTo < DateTime.Now) { DB.user_suspend(PageUserID,null); HttpContext.Current.Response.Redirect(Utils.GetSafeRawUrl()); } Forum.Redirect(Pages.info,"i=2"); }*/ if(HttpContext.Current.Request.Cookies["yaf"]!=null) { HttpContext.Current.Response.Cookies.Add(HttpContext.Current.Request.Cookies["yaf"]); HttpContext.Current.Response.Cookies["yaf"].Expires = DateTime.Now.AddYears(1); } // This happens when user logs in if(Mession.LastVisit == DateTime.MinValue) { // Only important for portals like Rainbow or DotNetNuke if(User.IsAuthenticated) User.UpdateUserInfo(PageUserID); if((int)m_pageinfo["Incoming"]>0) AddLoadMessage(String.Format(GetText("UNREAD_MSG"),m_pageinfo["Incoming"])); } if(Mession.LastVisit == DateTime.MinValue && HttpContext.Current.Request.Cookies["yaf"] != null && HttpContext.Current.Request.Cookies["yaf"]["lastvisit"] != null) { try { Mession.LastVisit = DateTime.Parse(HttpContext.Current.Request.Cookies["yaf"]["lastvisit"]); } catch(Exception) { Mession.LastVisit = DateTime.Now; } HttpContext.Current.Response.Cookies["yaf"]["lastvisit"] = DateTime.Now.ToString(); HttpContext.Current.Response.Cookies["yaf"].Expires = DateTime.Now.AddYears(1); } else if(Mession.LastVisit == DateTime.MinValue) { Mession.LastVisit = DateTime.Now; } if(HttpContext.Current.Request.Cookies["yaf"] != null && HttpContext.Current.Request.Cookies["yaf"]["lastvisit"] != null) { try { if(DateTime.Parse(HttpContext.Current.Request.Cookies["yaf"]["lastvisit"]) < DateTime.Now - TimeSpan.FromMinutes(5)) { HttpContext.Current.Response.Cookies["yaf"]["lastvisit"] = DateTime.Now.ToString(); HttpContext.Current.Response.Cookies["yaf"].Expires = DateTime.Now.AddYears(1); } } catch(Exception) { HttpContext.Current.Response.Cookies["yaf"]["lastvisit"] = DateTime.Now.ToString(); HttpContext.Current.Response.Cookies["yaf"].Expires = DateTime.Now.AddYears(1); } } else { HttpContext.Current.Response.Cookies["yaf"]["lastvisit"] = DateTime.Now.ToString(); HttpContext.Current.Response.Cookies["yaf"].Expires = DateTime.Now.AddYears(1); } // Check if pending mails, and send 10 of them if possible if((int)m_pageinfo["MailsPending"]>0) { try { using(DataTable dt = DB.mail_list()) { for(int i=0;i<dt.Rows.Count;i++) { // Build a MailMessage if (dt.Rows[i]["ToUser"].ToString().Trim() != String.Empty) { Utils.SendMail(this,BoardSettings.ForumEmail,(string)dt.Rows[i]["ToUser"],(string)dt.Rows[i]["Subject"],(string)dt.Rows[i]["Body"]); } DB.mail_delete(dt.Rows[i]["MailID"]); } if(IsAdmin) AddLoadMessage(String.Format("Sent {0} mails.",dt.Rows.Count)); } } catch(Exception x) { if(IsAdmin) { AddLoadMessage(x.Message); } } } }