/// <summary> /// 序列化配置信息为XML /// </summary> /// <param name="configinfo">配置信息</param> /// <param name="configFilePath">配置文件完整路径</param> public static GeneralConfigInfo Serialiaze(GeneralConfigInfo configinfo, string configFilePath) { lock(lockHelper) { SerializationHelper.Save(configinfo, configFilePath); } return configinfo; }
/// <summary> /// 静态构造函数初始化相应实例和定时器 /// </summary> static GeneralConfigs() { m_configinfo = GeneralConfigFileManager.LoadConfig(); generalConfigTimer.AutoReset = true; generalConfigTimer.Enabled = true; generalConfigTimer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Elapsed); generalConfigTimer.Start(); }
public void SetOption(GeneralConfigInfo configInfo) { if (configInfo.Maxonlines == 500) size.SelectedValue = "1"; if (configInfo.Maxonlines == 5000) size.SelectedValue = "2"; if (configInfo.Maxonlines == 50000) size.SelectedValue = "3"; if (configInfo.Regctrl == 0) safe.SelectedValue = "1"; if (configInfo.Regctrl == 12) safe.SelectedValue = "2"; if (configInfo.Regctrl == 48) safe.SelectedValue = "3"; if (configInfo.Visitedforums == 0) func.SelectedValue = "1"; if (configInfo.Visitedforums == 10) func.SelectedValue = "2"; if (configInfo.Visitedforums == 20) func.SelectedValue = "3"; }
protected void Page_Load(object sender, EventArgs e) { config = GeneralConfigs.GetConfig(); // 如果IP访问列表有设置则进行判断 if (config.Adminipaccess.Trim() != "") { string[] regctrl = Utils.SplitString(config.Adminipaccess, "\n"); if (!Utils.InIPArray(DNTRequest.GetIP(), regctrl)) { Context.Response.Redirect(BaseConfigs.GetForumPath + "admin/syslogin.aspx"); return; } } //获取当前用户的在线信息 OnlineUserInfo oluserinfo = OnlineUsers.UpdateInfo(config.Passwordkey, config.Onlinetimeout); olid = oluserinfo.Olid; #region 进行权限判断 UserGroupInfo usergroupinfo = AdminUserGroups.AdminGetUserGroupInfo(oluserinfo.Groupid); if (oluserinfo.Userid <= 0 || usergroupinfo.Radminid != 1) { Context.Response.Redirect(BaseConfigs.GetForumPath + "admin/syslogin.aspx"); return; } string secques = Users.GetUserInfo(oluserinfo.Userid).Secques; // 管理员身份验证 if (Context.Request.Cookies["dntadmin"] == null || Context.Request.Cookies["dntadmin"]["key"] == null || ForumUtils.GetCookiePassword(Context.Request.Cookies["dntadmin"]["key"].ToString(), config.Passwordkey) != (oluserinfo.Password + secques + oluserinfo.Userid)) { Context.Response.Redirect(BaseConfigs.GetForumPath + "admin/syslogin.aspx"); return; } else { HttpCookie cookie = HttpContext.Current.Request.Cookies["dntadmin"]; cookie.Values["key"] = ForumUtils.SetCookiePassword(oluserinfo.Password + secques + oluserinfo.Userid.ToString(), config.Passwordkey); cookie.Expires = DateTime.Now.AddMinutes(30); HttpContext.Current.Response.AppendCookie(cookie); } #endregion }
/// <summary> /// 初始化文件修改时间和对象实例 /// </summary> static GeneralConfigFileManager() { m_fileoldchange = System.IO.File.GetLastWriteTime(ConfigFilePath); try { m_configinfo = (GeneralConfigInfo)DefaultConfigFileManager.DeserializeInfo(ConfigFilePath, typeof(GeneralConfigInfo)); } catch { if (File.Exists(ConfigFilePath)) { //ReviseConfig(); m_configinfo = (GeneralConfigInfo)DefaultConfigFileManager.DeserializeInfo(ConfigFilePath, typeof(GeneralConfigInfo)); } } }
protected void Page_Load(object sender, EventArgs e) { configInfo = GeneralConfigs.GetConfig(); dsSrc.ReadXml(Server.MapPath("../../config/forumhot.config")); if (action == "editsave" && id != -1) { EditSave(); //base.RegisterStartupScript("page", "window.location.href='forum_forumhot.aspx';"); Response.Redirect("forum_forumhot.aspx"); } if (action == "closeforumhot") { configInfo.Disableforumhot = TypeConverter.StrToInt(DNTRequest.GetString("forumhot")); GeneralConfigs.Serialiaze(configInfo, Server.MapPath("../../config/general.config")); Response.Redirect("forum_forumhot.aspx"); } }
public ajaxpostinfo() { config = GeneralConfigs.GetConfig(); //是否帖子 if (DNTRequest.GetString("istopic") == "false") { int pid = DNTRequest.GetInt("pid", 0); DataTable dt = DatabaseProvider.GetInstance().GetPost(Posts.GetPostTableName(), pid); GetPostInfo(dt); dt.Dispose(); } //是否是主题 if (DNTRequest.GetString("istopic") == "true") { int tid = DNTRequest.GetInt("tid", 0); DataTable dt = DatabaseProvider.GetInstance().GetMainPostByTid(string.Format("{0}posts{1}", BaseConfigs.GetTablePrefix,Posts.GetPostTableID(tid)), tid); GetPostInfo(dt); dt.Dispose(); } }
protected void Page_Load(object sender, EventArgs e) { //更新在线表相关用户信息 config = GeneralConfigs.GetConfig(); OnlineUserInfo oluserinfo = OnlineUsers.UpdateInfo(config.Passwordkey, config.Onlinetimeout); if(AdminUserGroups.AdminGetUserGroupInfo(oluserinfo.Groupid).Radminid != 1) { HttpContext.Current.Response.Redirect("../"); return; } int olid = oluserinfo.Olid; OnlineUsers.DeleteRows(olid); //清除Cookie ForumUtils.ClearUserCookie(); HttpCookie cookie = new HttpCookie("dntadmin"); HttpContext.Current.Response.AppendCookie(cookie); FormsAuthentication.SignOut(); }
protected void Page_Load(object sender, EventArgs e) { config = GeneralConfigs.GetConfig(); // 如果IP访问列表有设置则进行判断 if (config.Adminipaccess.Trim() != "") { string[] regctrl = Utils.SplitString(config.Adminipaccess, "\n"); if (!Utils.InIPArray(DNTRequest.GetIP(), regctrl)) { Context.Response.Redirect("syslogin.aspx"); return; } } #region 进行权限判断 int userid = Discuz.Forum.Users.GetUserIDFromCookie(); if (userid <= 0) { Context.Response.Redirect("syslogin.aspx"); return; } UserInfo u = Discuz.Forum.Users.GetUserInfo(userid); if (u.Adminid > 0 && u.Groupid > 0) { return; } else { Context.Response.Redirect("syslogin.aspx"); return; } #endregion }
/// <summary> /// BasePage类构造函数 /// </summary> public BaseController() { m_starttick = DateTime.Now; if (recordPageView) PageViewStatistic(pagename); 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(ForumUtils.GetCookie("userid"), -1); //清空当前页面查询统计 #if DEBUG Discuz.Data.DbHelper.QueryCount = 0; Discuz.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 != "forumlist.aspx") && (pagename != "forumindex.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); } } if (config.PostTimeStorageMedia == 1 && Utils.GetCookie("lastposttime") != "")//如果最后发帖时间cookie不为空,则在此修改用户的该属性 oluserinfo.Lastposttime = Utils.GetCookie("lastposttime"); userid = oluserinfo.Userid; usergroupid = oluserinfo.Groupid; username = oluserinfo.Username; password = oluserinfo.Password; userkey = password.Length > 16 ? password.Substring(4, 8).Trim() : ""; lastposttime = oluserinfo.Lastposttime; lastpostpmtime = oluserinfo.Lastpostpmtime; lastsearchtime = oluserinfo.Lastsearchtime; olid = oluserinfo.Olid; isopenconnect = DiscuzCloud.GetCloudServiceEnableStatus("connect"); isbindconnect = isopenconnect ? DiscuzCloud.OnlineUserIsBindConnect(userid) : false; //确保头像可以取到 if (userid > 0) useravatar = Avatars.GetAvatarUrl(userid, AvatarSize.Small); if (Utils.InArray(DNTRequest.GetString("selectedtemplateid"), Templates.GetValidTemplateIDList())) templateid = DNTRequest.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(ForumUtils.GetCookie("pmsound"), 0); //已登录用户检测用户组状态,如果是禁言或禁止访问状态时间到期,则自动解禁 if (usergroupid == 4 || usergroupid == 5) { //int groupExpiry = Users.GetShortUserInfo(userid).Groupexpiry; //if (groupExpiry != 0 && groupExpiry <= Utils.StrToInt(DateTime.Now.ToString("yyyyMMdd"), 0)) //{ // //先改为第一个积分组 // usergroupid = 11; // //usergroupinfo = UserGroups.GetUserGroupInfo(usergroupid); // Users.UpdateUserGroup(userid, 11); //} ShortUserInfo userInfo = Users.GetShortUserInfo(userid); if (userInfo.Groupexpiry != 0 && userInfo.Groupexpiry <= Utils.StrToInt(DateTime.Now.ToString("yyyyMMdd"), 0)) { UserGroupInfo groupInfo = CreditsFacade.GetCreditsUserGroupId(userInfo.Credits); usergroupid = groupInfo.Groupid != 0 ? groupInfo.Groupid : usergroupid; Users.UpdateUserGroup(userid, usergroupid); } } usergroupinfo = UserGroups.GetUserGroupInfo(usergroupid); // 取得用户权限id,1管理员,2超版,3版主,0普通组,-1特殊组 useradminid = usergroupinfo.Radminid; string tips = ForumUtils.GetUserCreditsCookie(userid, usergroupinfo.Grouptitle); if (tips != "") { string[] userinfotipsList = tips.Split(',');//因为考虑到应用程序做单点登录时获取不到userinfotips,封装了此方法 userinfotips = "<p><a class=\"drop\" onmouseover=\"showMenu(this.id);\" href=\"" + BaseConfigs.GetForumPath + "usercpcreditspay.aspx\" id=\"extcreditmenu\">" + userinfotipsList[0] + "</a> "; userinfotips += "<span class=\"pipe\">|</span>用户组: <a class=\"xi2\" id=\"g_upmine\" href=\"" + BaseConfigs.GetForumPath + "usercp.aspx\">" + userinfotipsList[1].Split(':')[1] + "</a></p>"; userinfotips += "<ul id=\"extcreditmenu_menu\" class=\"p_pop\" style=\"display:none;\">"; for (int i = 2; i < userinfotipsList.Length; i++) { userinfotips += string.Format("<li><a> {0}</a></li>", userinfotipsList[i]); } userinfotips += "</ul>"; } 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; } if (!Utils.InArray(pagename, "attachment.aspx"))//加入附件页面判断减少性能消耗 onlineusercount = (userid != -1) ? OnlineUsers.GetOnlineAllUserCount() : OnlineUsers.GetCacheOnlineAllUserCount(); //校验用户是否可以访问论坛 if (!ValidateUserPermission()) return; //更新用户在线时长 if (userid != -1 && !Utils.InArray(pagename, "attachment.aspx"))//加入附件页面判断减少性能消耗 OnlineUsers.UpdateOnlineTime(config.Oltimespan, userid); Discuz.Entity.TemplateInfo templateInfo = Templates.GetTemplateItem(templateid); templatepath = templateInfo.Directory; if (templateInfo.Templateurl.ToLower().StartsWith("http://")) { imagedir = templateInfo.Templateurl.TrimEnd('/') + "/images"; cssdir = templateInfo.Templateurl.TrimEnd('/'); } else { imagedir = forumpath + "templates/" + templateInfo.Directory + "/images"; cssdir = forumpath + "templates/" + templateInfo.Directory; } if (EntLibConfigs.GetConfig() != null && !Utils.StrIsNullOrEmpty(EntLibConfigs.GetConfig().Topicidentifydir)) topicidentifydir = EntLibConfigs.GetConfig().Topicidentifydir.TrimEnd('/'); else topicidentifydir = forumpath + "images/identify"; if (EntLibConfigs.GetConfig() != null && !Utils.StrIsNullOrEmpty(EntLibConfigs.GetConfig().Posticondir)) posticondir = EntLibConfigs.GetConfig().Posticondir.TrimEnd('/'); else posticondir = forumpath + "images/posticons"; if (EntLibConfigs.GetConfig() != null && !Utils.StrIsNullOrEmpty(EntLibConfigs.GetConfig().Jsdir)) jsdir = EntLibConfigs.GetConfig().Jsdir.TrimEnd('/'); else jsdir = rooturl + "javascript"; nowdate = Utils.GetDate(); nowtime = Utils.GetTime(); nowdatetime = Utils.GetDateTime(); ispost = DNTRequest.IsPost(); isget = DNTRequest.IsGet(); link = ""; script = ""; templatelistboxoptions = Caches.GetTemplateListBoxOptionsCache(); string originalTemplate = string.Format("<li><a href=\"###\" onclick=\"window.location.href='{0}showtemplate.aspx?templateid={1}'\">", "", BaseConfigs.GetForumPath, templateid); string newTemplate = string.Format("<li class=\"current\"><a href=\"###\" onclick=\"window.location.href='{0}showtemplate.aspx?templateid={1}'\">", BaseConfigs.GetForumPath, templateid); templatelistboxoptions = templatelistboxoptions.Replace(originalTemplate, newTemplate); isLoginCode = config.Seccodestatus.Contains("login.aspx"); //当该页面设置了验证码检验,并且当前用户的用户组没有给予忽略验证码的权限,则isseccode=true; isseccode = Utils.InArray(pagename, config.Seccodestatus) && usergroupinfo.Ignoreseccode == 0; headerad = Advertisements.GetOneHeaderAd("", 0); footerad = Advertisements.GetOneFooterAd("", 0); //设定当前页面的显示样式 if (config.Allowchangewidth == 0) Utils.WriteCookie("allowchangewidth", ""); if (pagename != "website.aspx") { if (Utils.GetCookie("allowchangewidth") == "0" || (string.IsNullOrEmpty(Utils.GetCookie("allowchangewidth")) && config.Showwidthmode == 1)) isnarrowpage = true; } //校验验证码 if (isseccode && ispost && !ValidateVerifyCode()) return; newtopicminute = config.Viewnewtopicminute; }
/// <summary> /// 构造函数 /// </summary> public ArchiverPage() { config = GeneralConfigs.GetConfig(); if (config.Archiverstatus == 2 && DNTRequest.IsSearchEnginesGet())//启用,但当用户从搜索引擎点击时自动转向动态页面 { string url = OrganizeURL(HttpContext.Current.Request.Url); HttpContext.Current.Response.Redirect(url); } if (config.Archiverstatus == 3 && DNTRequest.IsBrowserGet())//启用,但当用户使用浏览器访问时自动转向动态页面 { string url = OrganizeURL(HttpContext.Current.Request.Url); HttpContext.Current.Response.Redirect(url); } int onlineusercount = OnlineUsers.GetOnlineAllUserCount(); if (onlineusercount >= config.Maxonlines) { ShowError("抱歉,目前访问人数太多,你暂时无法访问论坛.", 0); } if (config.Nocacheheaders == 1) { HttpContext.Current.Response.Buffer = true; HttpContext.Current.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1); HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.AddDays(-1)); HttpContext.Current.Response.Expires = 0; HttpContext.Current.Response.CacheControl = "no-cache"; HttpContext.Current.Response.Cache.SetNoStore(); } OnlineUserInfo oluserinfo = OnlineUsers.UpdateInfo(config.Passwordkey, config.Onlinetimeout); userid = oluserinfo.Userid; useradminid = oluserinfo.Adminid; // 如果论坛关闭且当前用户请求页面不是登录页面且用户非管理员, 则跳转至论坛关闭信息页 if (config.Closed == 1 && oluserinfo.Adminid != 1) { ShowError("", 1); } usergroupinfo = UserGroups.GetUserGroupInfo(oluserinfo.Groupid); // 如果不允许访问论坛则转向到tools/ban.htm if (usergroupinfo.Allowvisit != 1) { ShowError("抱歉, 您所在的用户组不允许访问论坛", 2); } // 如果IP访问列表有设置则进行判断 if (config.Ipaccess.Trim() != "") { string[] regctrl = Utils.SplitString(config.Ipaccess, "\n"); if (!Utils.InIPArray(DNTRequest.GetIP(), regctrl)) { ShowError("抱歉, 系统设置了IP访问列表限制, 您无法访问本论坛", 0); return; } } // 如果IP访问列表有设置则进行判断 if (config.Ipdenyaccess.Trim() != "") { string[] regctrl = Utils.SplitString(config.Ipdenyaccess, "\n"); if (Utils.InIPArray(DNTRequest.GetIP(), regctrl)) { ShowError("由于您严重违反了论坛的相关规定, 已被禁止访问.", 2); return; } } // 如果当前用户请求页面不是登录页面并且当前用户非管理员并且论坛设定了时间段,当时间在其中的一个时间段内,则跳转到论坛登录页面 if (oluserinfo.Adminid != 1 && DNTRequest.GetPageName() != "login.aspx") { if (Scoresets.BetweenTime(config.Visitbanperiods)) { ShowError("在此时间段内不允许访问本论坛", 2); return; } } HttpContext.Current.Response.Write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n<head>\r\n"); if (config.Seokeywords != "") { HttpContext.Current.Response.Write("<meta name=\"keywords\" content=\"" + config.Seokeywords + "\" />\r\n"); } if (config.Seodescription != "") { HttpContext.Current.Response.Write("<meta name=\"description\" content=\"" + config.Seodescription + "\" />\r\n"); } HttpContext.Current.Response.Write(config.Seohead.Trim()); HttpContext.Current.Response.Write("\r\n<link href=\"dntarchiver.css\" rel=\"stylesheet\" type=\"text/css\" />"); if (config.Archiverstatus == 0) { ShowError("系统禁止使用Archiver",3); HttpContext.Current.Response.End(); return; } }
/// <summary> /// BasePage类构造函数 /// </summary> public void PageBaseStart() { config = GeneralConfigs.GetConfig(); LoadUrlConfig(); Issmileyinsert = config.Smileyinsert; userid = Discuz.Forum.Users.GetUserIDFromCookie(); if (userid <= 0) { userid = -1; } #region 为 CPS 商家保存第一次访问的二级域名 new FirstUrl().Save(); #endregion //清空当前页面查询统计 Discuz.Data.DbHelper.QueryCount = 0; #if DEBUG Discuz.Data.DbHelper.QueryDetail = ""; #endif // 如果启用游客页面缓存,则对游客输出缓存页 if (userid == -1 && config.Guestcachepagetimeout > 0) { if (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或focuslist_aspx,可能出现在线并发问题,这时系统会延时2秒 if ((pagename != "forumlist.aspx") && (pagename != "focuslist.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.Userid; usergroupid = oluserinfo.Groupid; username = oluserinfo.Username; password = oluserinfo.Password; if (password.Length > 16) { userkey = password.Substring(4, 8).Trim(); } else { userkey = ""; } lastposttime = oluserinfo.Lastposttime; lastpostpmtime = oluserinfo.Lastpostpmtime; lastsearchtime = oluserinfo.Lastsearchtime; olid = oluserinfo.Olid; //确保头像可以取到 if (userid > 0) { useravatar = Utils.UrlDecode(ForumUtils.GetCookie("avatar")); if (useravatar == string.Empty) { useravatar = Users.GetUserInfo(userid).Avatar; //ForumUtils.WriteCookie("avatar", Utils.UrlEncode(useravatar)); } } if (Utils.InArray(DNTRequest.GetString("selectedtemplateid"), Templates.GetValidTemplateIDList())) { templateid = DNTRequest.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(ForumUtils.GetCookie("pmsound"), 0); usergroupinfo = UserGroups.GetUserGroupInfo(usergroupid); // 根据用户组得到相关联的管理组id useradminid = usergroupinfo.Radminid; // 如果论坛关闭且当前用户请求页面不是登录页面且用户非管理员, 则跳转至论坛关闭信息页 if (config.Closed == 1 && pagename != "login.aspx" && pagename != "logout.aspx" && pagename != "register.aspx" && useradminid != 1) { ShowMessage(1); return; } if (config.Onlinetimeout > 0 && userid != -1) { onlineusercount = OnlineUsers.GetOnlineAllUserCount(); } else { onlineusercount = OnlineUsers.GetCacheOnlineAllUserCount(); } //校验用户是否可以访问论坛 if (!ValidateUserPermission()) return; if (userid != -1) { //更新用户在线时长 OnlineUsers.UpdateOnlineTime(config.Oltimespan, userid); string ignore = DNTRequest.GetString("ignore"); newpmcount = Users.GetUserNewPMCount(userid); realnewpmcount = Math.Abs(newpmcount); if (ignore.ToLower().Equals("yes")) { newpmcount = newpmcount * -1; Users.SetUserNewPMCount(userid, newpmcount); } } templatepath = Templates.GetTemplateItem(templateid).Directory; nowdate = Utils.GetDate(); nowtime = Utils.GetTime(); nowdatetime = Utils.GetDateTime(); ispost = DNTRequest.IsPost(); isget = DNTRequest.IsGet(); link = ""; script = ""; templatelistboxoptions = Caches.GetTemplateListBoxOptionsCache(); isseccode = Utils.InArray(pagename, config.Seccodestatus); headerad = Advertisements.GetOneHeaderAd("", 0); footerad = Advertisements.GetOneFooterAd("", 0); //校验验证码 if ((isseccode) && (ispost)) { if (!ValidateVerifyCode()) return; } newtopicminute = config.Viewnewtopicminute; m_starttick = DateTime.Now; ShowPage(); //m_processtime = //(System.Environment.TickCount - m_starttick) / 1000; m_processtime = DateTime.Now.Subtract(m_starttick).TotalMilliseconds / 1000; querycount = Discuz.Data.DbHelper.QueryCount; Discuz.Data.DbHelper.QueryCount = 0; #if NET1 #else #if DEBUG querydetail = Discuz.Data.DbHelper.QueryDetail; Discuz.Data.DbHelper.QueryDetail = ""; #endif #endif }
protected void Page_Load(object sender, EventArgs e) { UserName.Attributes.Remove("class"); PassWord.Attributes.Remove("class"); UserName.AddAttributes("style", "width:200px"); PassWord.AddAttributes("style", "width:200px"); config = GeneralConfigs.GetConfig(); OnlineUserInfo oluserinfo = Discuz.Forum.OnlineUsers.UpdateInfo(config.Passwordkey, config.Onlinetimeout); olid = oluserinfo.Olid; if (!Page.IsPostBack) { #region 如果IP访问列表有设置则进行判断 if (config.Adminipaccess.Trim() != "") { string[] regctrl = Utils.SplitString(config.Adminipaccess, "\n"); if (!Utils.InIPArray(DNTRequest.GetIP(), regctrl)) { StringBuilder sb = new StringBuilder(); sb.Append("<br /><br /><div style=\"width:100%\" align=\"center\"><div align=\"center\" style=\"width:600px; border:1px dotted #FF6600; background-color:#FFFCEC; margin:auto; padding:20px;\">"); sb.Append("<img src=\"images/hint.gif\" border=\"0\" alt=\"提示:\" align=\"absmiddle\" /> 您的IP地址不在系统允许的范围之内</div></div>"); Response.Write(sb.ToString()); Response.End(); return; } } #endregion #region 用户身份判断 UserGroupInfo usergroupinfo = AdminUserGroups.AdminGetUserGroupInfo(oluserinfo.Groupid); if (oluserinfo.Userid <= 0 || usergroupinfo.Radminid != 1) { string message = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"; message += "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>无法确认您的身份</title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"; message += "<link href=\"styles/default.css\" type=\"text/css\" rel=\"stylesheet\"></head><script type=\"text/javascript\">if(top.location!=self.location){top.location.href = \"syslogin.aspx\";}</script><body><br /><br /><div style=\"width:100%\" align=\"center\">"; message += "<div align=\"center\" style=\"width:600px; border:1px dotted #FF6600; background-color:#FFFCEC; margin:auto; padding:20px;\"><img src=\"images/hint.gif\" border=\"0\" alt=\"提示:\" align=\"absmiddle\" width=\"11\" height=\"13\" /> "; message += "无法确认您的身份, 请<a href=\"../login.aspx\">登录</a></div></div></body></html>"; Response.Write(message); Response.End(); return; } #endregion #region 判断安装目录文件信息 if (IsExistsSetupFile()) { string message = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"; message += "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>请将您的安装目录即install/目录下的文件全部删除, 以免其它用户运行安装该程序!</title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"; message += "<link href=\"styles/default.css\" type=\"text/css\" rel=\"stylesheet\"></head><script type=\"text/javascript\">if(top.location!=self.location){top.location.href = \"syslogin.aspx\";}</script><body><br /><br /><div style=\"width:100%\" align=\"center\">"; message += "<div align=\"center\" style=\"width:660px; border:1px dotted #FF6600; background-color:#FFFCEC; margin:auto; padding:20px;\"><img src=\"images/hint.gif\" border=\"0\" alt=\"提示:\" align=\"absmiddle\" width=\"11\" height=\"13\" /> "; message += "请将您的安装目录(install/)下和升级目录(upgrade/)下的.aspx文件全部删除, 以免其它用户运行安装或升级程序!</div></div></body></html>"; Response.Write(message); Response.End(); return; } #endregion #region 显示相关页面登陆提交信息 if (Context.Request.Cookies["dntadmin"] == null || Context.Request.Cookies["dntadmin"]["key"] == null || ForumUtils.GetCookiePassword(Context.Request.Cookies["dntadmin"]["key"].ToString(), config.Passwordkey) != (oluserinfo.Password + Discuz.Forum.Users.GetUserInfo(oluserinfo.Userid).Secques + oluserinfo.Userid.ToString())) { Msg.Text = "<IMG alt=\"提示:\" src=\"images/warning.gif\" align=\"absMiddle\" border=\"0\" width=\"16\" height=\"16\">请重新进行管理员登录"; } if (oluserinfo.Userid > 0 && usergroupinfo.Radminid == 1 && oluserinfo.Username.Trim() != "") { UserName.Text = oluserinfo.Username; UserName.AddAttributes("readonly", "true"); UserName.CssClass = "nofocus"; UserName.Attributes.Add("onfocus", "this.className='nofocus';"); UserName.Attributes.Add("onblur", "this.className='nofocus';"); } if (DNTRequest.GetString("result") == "1") { Msg.Text = "<IMG alt=\"提示:\" src=\"images/warning.gif\" align=\"absMiddle\" border=\"0\" width=\"16\" height=\"16\"><font color=\"red\">用户不存在或密码错误</font>"; return; } if (DNTRequest.GetString("result") == "2") { Msg.Text = "<IMG alt=\"提示:\" src=\"images/warning.gif\" align=\"absMiddle\" border=\"0\" width=\"16\" height=\"16\"><font color=\"red\">用户不是管理员身分,因此无法登陆后台</font>"; return; } if (DNTRequest.GetString("result") == "3") { Msg.Text = "<IMG alt=\"提示:\" src=\"images/warning.gif\" align=\"absMiddle\" border=\"0\" width=\"16\" height=\"16\"><font color=\"red\">验证码错误,请重新输入</font>"; return; } if (DNTRequest.GetString("result") == "4") { Msg.Text = ""; return; } #endregion } if (Page.IsPostBack) VerifyLoginInf();//对提供的信息进行验证 else Response.Redirect("syslogin.aspx?result=4"); }
/// <summary> /// 附件操作 /// </summary> /// <param name="attachmentinfo">附件信息</param> /// <param name="topicid">主题id</param> /// <param name="postid">帖子id</param> /// <param name="postinfo">帖子信息</param> /// <param name="sb">返回信息</param> /// <param name="userid">当前用户id</param> /// <param name="config">配置信息</param> /// <param name="usergroupinfo">当前用户组信息</param> /// <returns></returns> public static bool UpdateAttachment(AttachmentInfo[] attachmentinfo, int topicid, int postid, PostInfo postinfo, ref StringBuilder sb, int userid, GeneralConfigInfo config, UserGroupInfo usergroupinfo) { if (attachmentinfo != null) { if (attachmentinfo.Length > config.Maxattachments) { sb = new StringBuilder("系统设置为每个帖子附件不得多于" + config.Maxattachments + "个"); return false; } int errorAttachment = Attachments.BindAttachment(attachmentinfo, postid, sb, topicid, userid, usergroupinfo); int[] aid = Attachments.CreateAttachments(attachmentinfo); string tempMessage = Attachments.FilterLocalTags(aid, attachmentinfo, postinfo.Message); if (tempMessage != postinfo.Message) { postinfo.Message = tempMessage; postinfo.Pid = postid; Posts.UpdatePost(postinfo); } UserCredits.UpdateUserCreditsByUploadAttachment(userid, aid.Length - errorAttachment); } Attachments.UpdateSLUploadAttachInfo(topicid, postid, usergroupinfo); return false; }
/// <summary> /// 附件操作 /// </summary> /// <param name="attachmentinfo">附件信息</param> /// <param name="topicId">主题id</param> /// <param name="postId">帖子id</param> /// <param name="postInfo">帖子信息</param> /// <param name="returnMsg">返回信息</param> /// <param name="userId">当前用户id</param> /// <param name="config">配置信息</param> /// <param name="userGroupInfo">当前用户组信息</param> /// <returns></returns> public static bool UpdateAttachment(AttachmentInfo[] attachmentArray, int topicId, int postId, PostInfo postInfo, ref StringBuilder returnMsg, int userId, GeneralConfigInfo config, UserGroupInfo userGroupInfo) { if (attachmentArray == null) return false; if (attachmentArray.Length > config.Maxattachments) { //returnMsg = new StringBuilder("系统设置为每个帖子附件不得多于" + config.Maxattachments + "个"); returnMsg = new StringBuilder(); returnMsg.AppendFormat("您添加了{0}个图片/附件,多于系统设置的{1}个.<br/>请重新编辑该帖并删除多余图片/附件.", attachmentArray.Length, config.Maxattachments); return false; } int newAttachCount = Attachments.BindAttachment(attachmentArray, topicId, postId, userId, userGroupInfo); //int errorAttachment = Attachments.BindAttachment(attachmentinfoarray, postid, sb, topicid, userid, usergroupinfo, out newAttachCount); int[] aid = new int[attachmentArray.Length]; int attType = 0;//普通附件,2为图片附件 for (int i = 0; i < attachmentArray.Length; i++) { //attachmentinfoarray[i].Tid = topicid; //attachmentinfoarray[i].Pid = postid; Attachments.UpdateAttachment(attachmentArray[i]); aid[i] = attachmentArray[i].Aid; attType = attachmentArray[i].Filetype.ToLower().StartsWith("image") ? 2 : 1; } string tempMessage = Attachments.FilterLocalTags(aid, attachmentArray, postInfo.Message); if (tempMessage != postInfo.Message) { postInfo.Message = tempMessage; postInfo.Pid = postId; Posts.UpdatePost(postInfo); } if (newAttachCount > 0) UserCredits.UpdateUserExtCreditsByUploadAttachment(userId, newAttachCount); UpdateTopicAndPostAttachmentType(topicId, postId, attType); return true; }
/// <summary> /// 保存上传的文件 /// </summary> /// <param name="forumid">版块id</param> /// <param name="MaxAllowFileCount">最大允许的上传文件个数</param> /// <param name="MaxSizePerDay">每天允许的附件大小总数</param> /// <param name="MaxFileSize">单个最大允许的文件字节数</param>/// /// <param name="TodayUploadedSize">今天已经上传的附件字节总数</param> /// <param name="AllowFileType">允许的文件类型, 以string[]形式提供</param> /// <param name="config">附件保存方式 0=按年/月/日存入不同目录 1=按年/月/日/论坛存入不同目录 2=按论坛存入不同目录 3=按文件类型存入不同目录</param> /// <param name="watermarkstatus">图片水印位置</param> /// <param name="filekey">File控件的Key(即Name属性)</param> /// <returns>文件信息结构</returns> public static AttachmentInfo[] SaveRequestFiles(int forumid, int MaxAllowFileCount, int MaxSizePerDay, int MaxFileSize, int TodayUploadedSize, string AllowFileType, int watermarkstatus, GeneralConfigInfo config, string filekey, bool isImage) { string[] tmp = Utils.SplitString(AllowFileType, "|"); string[] allowFileExtName = new string[tmp.Length]; int[] maxSize = new int[tmp.Length]; for (int i = 0; i < tmp.Length; i++) { allowFileExtName[i] = Utils.CutString(tmp[i], 0, tmp[i].LastIndexOf(",")); maxSize[i] = Utils.StrToInt(Utils.CutString(tmp[i], tmp[i].LastIndexOf(",") + 1), 0); } int saveFileCount = 0; int fCount = HttpContext.Current.Request.Files.Count; for (int i = 0; i < fCount; i++) { if (!HttpContext.Current.Request.Files[i].FileName.Equals("") && HttpContext.Current.Request.Files.AllKeys[i].Equals(filekey)) { saveFileCount++; } } AttachmentInfo[] attachmentInfo = saveFileCount > 0 ? new AttachmentInfo[saveFileCount] : null; if (saveFileCount > MaxAllowFileCount) return attachmentInfo; saveFileCount = 0; Random random = new Random(unchecked((int)DateTime.Now.Ticks)); for (int i = 0; i < fCount; i++) { if (!HttpContext.Current.Request.Files[i].FileName.Equals("") && HttpContext.Current.Request.Files.AllKeys[i].Equals(filekey)) { string fileName = Path.GetFileName(HttpContext.Current.Request.Files[i].FileName); string fileExtName = Utils.CutString(fileName, fileName.LastIndexOf(".") + 1).ToLower(); string fileType = HttpContext.Current.Request.Files[i].ContentType.ToLower(); int fileSize = HttpContext.Current.Request.Files[i].ContentLength; string newFileName = ""; //flash批量上传时无法获取contenttype if (fileType == "application/octet-stream") fileType = GetContentType(fileExtName); attachmentInfo[saveFileCount] = new AttachmentInfo(); attachmentInfo[saveFileCount].Sys_noupload = ""; // 判断 文件扩展名/文件大小/文件类型 是否符合要求 if (!(Utils.IsImgFilename(fileName) && !fileType.StartsWith("image")) && ValidateImage(fileType, HttpContext.Current.Request.Files[i].InputStream)) { int extnameid = Utils.GetInArrayID(fileExtName, allowFileExtName); if (extnameid >= 0 && (fileSize <= maxSize[extnameid]) && (MaxFileSize >= fileSize /*|| MaxAllSize == 0*/) && (MaxSizePerDay - TodayUploadedSize >= fileSize)) { TodayUploadedSize = TodayUploadedSize + fileSize; string UploadDir = Utils.GetMapPath(BaseConfigs.GetForumPath + "upload/"); string saveDir = GetAttachmentPath(forumid, config, fileExtName); newFileName = string.Format("{0}{1}{2}.{3}", (Environment.TickCount & int.MaxValue).ToString(), i.ToString(), random.Next(1000, 9999).ToString(), fileExtName); //(Environment.TickCount & int.MaxValue).ToString() + i.ToString() + random.Next(1000, 9999).ToString() + "." + fileextname; //临时文件名称变量. 用于当启动远程附件之后,先上传到本地临时文件夹的路径信息 string tempFileName = ""; //当支持FTP上传附件且不保留本地附件时 if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) { // 如果指定目录不存在则建立临时路径 if (!Directory.Exists(UploadDir + "temp\\")) Utils.CreateDir(UploadDir + "temp\\"); tempFileName = "temp\\" + newFileName; } // 如果指定目录不存在则建立 else if (!Directory.Exists(UploadDir + saveDir)) Utils.CreateDir(UploadDir + saveDir); newFileName = saveDir + newFileName; try { // 如果是bmp jpg png图片类型 if ((fileExtName == "bmp" || fileExtName == "jpg" || fileExtName == "jpeg" || fileExtName == "png") && fileType.StartsWith("image")) { Image img = Image.FromStream(HttpContext.Current.Request.Files[i].InputStream); if (config.Attachimgmaxwidth > 0 && img.Width > config.Attachimgmaxwidth) attachmentInfo[saveFileCount].Sys_noupload = "图片宽度为" + img.Width + ", 系统允许的最大宽度为" + config.Attachimgmaxwidth; if (config.Attachimgmaxheight > 0 && img.Height > config.Attachimgmaxheight) attachmentInfo[saveFileCount].Sys_noupload = "图片高度为" + img.Width + ", 系统允许的最大高度为" + config.Attachimgmaxheight; attachmentInfo[saveFileCount].Width = img.Width; attachmentInfo[saveFileCount].Height = img.Height; if (attachmentInfo[saveFileCount].Sys_noupload == "") { if (watermarkstatus == 0) { //当支持FTP上传附件且不保留本地附件模式时,则先上传到临时目录下 if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) HttpContext.Current.Request.Files[i].SaveAs(UploadDir + tempFileName); else HttpContext.Current.Request.Files[i].SaveAs(UploadDir + newFileName); attachmentInfo[saveFileCount].Filesize = fileSize; } else { if (config.Watermarktype == 1 && File.Exists(Utils.GetMapPath(BaseConfigs.GetForumPath + "watermark/" + config.Watermarkpic))) { //当支持FTP上传附件且不保留本地附件模式时,则先上传到临时目录下 if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) AddImageSignPic(img, UploadDir + tempFileName, Utils.GetMapPath(BaseConfigs.GetForumPath + "watermark/" + config.Watermarkpic), config.Watermarkstatus, config.Attachimgquality, config.Watermarktransparency); else AddImageSignPic(img, UploadDir + newFileName, Utils.GetMapPath(BaseConfigs.GetForumPath + "watermark/" + config.Watermarkpic), config.Watermarkstatus, config.Attachimgquality, config.Watermarktransparency); } else { string watermarkText; watermarkText = config.Watermarktext.Replace("{1}", config.Forumtitle); watermarkText = watermarkText.Replace("{2}", "http://" + DNTRequest.GetCurrentFullHost() + "/"); watermarkText = watermarkText.Replace("{3}", Utils.GetDate()); watermarkText = watermarkText.Replace("{4}", Utils.GetTime()); //当支持FTP上传附件且不保留本地附件模式时,则先上传到临时目录下 if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) AddImageSignText(img, UploadDir + tempFileName, watermarkText, config.Watermarkstatus, config.Attachimgquality, config.Watermarkfontname, config.Watermarkfontsize); else AddImageSignText(img, UploadDir + newFileName, watermarkText, config.Watermarkstatus, config.Attachimgquality, config.Watermarkfontname, config.Watermarkfontsize); } //当支持FTP上传附件且不保留本地附件模式时,则读取临时目录下的文件信息 if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) attachmentInfo[saveFileCount].Filesize = new FileInfo(UploadDir + tempFileName).Length; else attachmentInfo[saveFileCount].Filesize = new FileInfo(UploadDir + newFileName).Length; } } } else { attachmentInfo[saveFileCount].Filesize = fileSize; //当支持FTP上传附件且不保留本地附件模式时,则先上传到临时目录下 if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) HttpContext.Current.Request.Files[i].SaveAs(UploadDir + tempFileName); else HttpContext.Current.Request.Files[i].SaveAs(UploadDir + newFileName); } } catch { //当上传目录和临时文件夹都没有上传的文件时 if (!(Utils.FileExists(UploadDir + tempFileName)) && (!(Utils.FileExists(UploadDir + newFileName)))) { attachmentInfo[saveFileCount].Filesize = fileSize; //当支持FTP上传附件且不保留本地附件模式时,则先上传到临时目录下 if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) HttpContext.Current.Request.Files[i].SaveAs(UploadDir + tempFileName); else HttpContext.Current.Request.Files[i].SaveAs(UploadDir + newFileName); } } try { //加载文件预览类指定方法 IPreview preview = PreviewProvider.GetInstance(fileExtName.Trim()); if (preview != null) { preview.UseFTP = (FTPs.GetForumAttachInfo.Allowupload == 1) ? true : false; //当支持FTP上传附件且不保留本地附件模式时 if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) preview.OnSaved(UploadDir + tempFileName); else preview.OnSaved(UploadDir + newFileName); } } catch { } //当支持FTP上传附件时,使用FTP上传远程附件 if (FTPs.GetForumAttachInfo.Allowupload == 1) { FTPs ftps = new FTPs(); //当不保留本地附件模式时,在上传完成之后删除本地tempfilename文件 if (FTPs.GetForumAttachInfo.Reservelocalattach == 0) ftps.UpLoadFile(newFileName.Substring(0, newFileName.LastIndexOf("\\")), UploadDir + tempFileName, FTPs.FTPUploadEnum.ForumAttach); else ftps.UpLoadFile(newFileName.Substring(0, newFileName.LastIndexOf("\\")), UploadDir + newFileName, FTPs.FTPUploadEnum.ForumAttach); } if (EntLibConfigs.GetConfig() != null && EntLibConfigs.GetConfig().Cacheattachfiles.Enable && EntLibConfigs.GetConfig().Cacheattachfiles.Attachpostid > 0) Discuz.Cache.Data.DBCacheService.GetAttachFilesService().UploadFile(UploadDir, newFileName); } else { if (extnameid < 0) attachmentInfo[saveFileCount].Sys_noupload = "文件格式无效"; else if (MaxSizePerDay - TodayUploadedSize < fileSize) attachmentInfo[saveFileCount].Sys_noupload = "文件大于今天允许上传的字节数"; else if (fileSize > maxSize[extnameid]) attachmentInfo[saveFileCount].Sys_noupload = "文件大于该类型附件允许的字节数"; else attachmentInfo[saveFileCount].Sys_noupload = "文件大于单个文件允许上传的字节数"; } } else { attachmentInfo[saveFileCount].Sys_noupload = "文件格式无效"; } //当支持FTP上传附件时 if (FTPs.GetForumAttachInfo.Allowupload == 1) attachmentInfo[saveFileCount].Filename = FTPs.GetForumAttachInfo.Remoteurl + "/" + newFileName.Replace("\\", "/"); else attachmentInfo[saveFileCount].Filename = newFileName; attachmentInfo[saveFileCount].Description = ""; attachmentInfo[saveFileCount].Filetype = fileType; attachmentInfo[saveFileCount].Attachment = fileName; attachmentInfo[saveFileCount].Downloads = 0; attachmentInfo[saveFileCount].Postdatetime = DateTime.Now.ToString(); attachmentInfo[saveFileCount].Sys_index = i; attachmentInfo[saveFileCount].Isimage = isImage ? 1 : 0; saveFileCount++; } } return attachmentInfo; }
/// <summary> /// 获得附件存放目录 /// </summary> /// <param name="forumid"></param> /// <param name="config"></param> /// <param name="fileExtName"></param> /// <returns></returns> private static string GetAttachmentPath(int forumid, GeneralConfigInfo config, string fileExtName) { StringBuilder saveDir = new StringBuilder(""); //附件保存方式 0=按年/月/日存入不同目录 1=按年/月/日/论坛存入不同目录 2=按论坛存入不同目录 3=按文件类型存入不同目录 if (config.Attachsave == 1) { saveDir.Append(DateTime.Now.ToString("yyyy")); saveDir.Append(Path.DirectorySeparatorChar); saveDir.Append(DateTime.Now.ToString("MM")); saveDir.Append(Path.DirectorySeparatorChar); saveDir.Append(DateTime.Now.ToString("dd")); saveDir.Append(Path.DirectorySeparatorChar); saveDir.Append(forumid.ToString()); saveDir.Append(Path.DirectorySeparatorChar); } else if (config.Attachsave == 2) { saveDir.Append(forumid); saveDir.Append(Path.DirectorySeparatorChar); } else if (config.Attachsave == 3) { saveDir.Append(fileExtName); saveDir.Append(Path.DirectorySeparatorChar); } else { saveDir.Append(DateTime.Now.ToString("yyyy")); saveDir.Append(Path.DirectorySeparatorChar); saveDir.Append(DateTime.Now.ToString("MM")); saveDir.Append(Path.DirectorySeparatorChar); saveDir.Append(DateTime.Now.ToString("dd")); saveDir.Append(Path.DirectorySeparatorChar); } return saveDir.ToString(); }
/// <summary> /// ��ø������Ŀ¼ /// </summary> /// <param name="forumid"></param> /// <param name="config"></param> /// <param name="fileExtName"></param> /// <returns></returns> private static string GetAttachmentPath(int forumid, GeneralConfigInfo config, string fileExtName) { StringBuilder saveDir = new StringBuilder(""); //�������淽ʽ 0=����/��/�մ��벻ͬĿ¼ 1=����/��/��/��̳���벻ͬĿ¼ 2=����̳���벻ͬĿ¼ 3=���ļ����ʹ��벻ͬĿ¼ if (config.Attachsave == 1) { saveDir.Append(DateTime.Now.ToString("yyyy")); saveDir.Append(Path.DirectorySeparatorChar); saveDir.Append(DateTime.Now.ToString("MM")); saveDir.Append(Path.DirectorySeparatorChar); saveDir.Append(DateTime.Now.ToString("dd")); saveDir.Append(Path.DirectorySeparatorChar); saveDir.Append(forumid.ToString()); saveDir.Append(Path.DirectorySeparatorChar); } else if (config.Attachsave == 2) { saveDir.Append(forumid); saveDir.Append(Path.DirectorySeparatorChar); } else if (config.Attachsave == 3) { saveDir.Append(fileExtName); saveDir.Append(Path.DirectorySeparatorChar); } else { saveDir.Append(DateTime.Now.ToString("yyyy")); saveDir.Append(Path.DirectorySeparatorChar); saveDir.Append(DateTime.Now.ToString("MM")); saveDir.Append(Path.DirectorySeparatorChar); saveDir.Append(DateTime.Now.ToString("dd")); saveDir.Append(Path.DirectorySeparatorChar); } return saveDir.ToString(); }
/// <summary> /// �����ϴ����ļ� /// </summary> /// <param name="forumid">���id</param> /// <param name="MaxAllowFileCount">���������ϴ��ļ�����</param> /// <param name="MaxSizePerDay">ÿ������ĸ�����С����</param> /// <param name="MaxFileSize">�������������ļ��ֽ���</param>/// /// <param name="TodayUploadedSize">�����Ѿ��ϴ��ĸ����ֽ�����</param> /// <param name="AllowFileType">������ļ�����, ��string[]��ʽ�ṩ</param> /// <param name="config">�������淽ʽ 0=����/��/�մ��벻ͬĿ¼ 1=����/��/��/��̳���벻ͬĿ¼ 2=����̳���벻ͬĿ¼ 3=���ļ����ʹ��벻ͬĿ¼</param> /// <param name="watermarkstatus">ͼƬˮӡλ��</param> /// <param name="filekey">File�ؼ���Key(��Name����)</param> /// <returns>�ļ���Ϣ�ṹ</returns> public static AttachmentInfo[] SaveRequestFiles(int forumid, int MaxAllowFileCount, int MaxSizePerDay, int MaxFileSize, int TodayUploadedSize, string AllowFileType, int watermarkstatus, GeneralConfigInfo config, string filekey,bool isImage) { string[] tmp = Utils.SplitString(AllowFileType, "|"); string[] allowFileExtName = new string[tmp.Length]; int[] maxSize = new int[tmp.Length]; for (int i = 0; i < tmp.Length; i++) { allowFileExtName[i] = Utils.CutString(tmp[i], 0, tmp[i].LastIndexOf(",")); maxSize[i] = Utils.StrToInt(Utils.CutString(tmp[i], tmp[i].LastIndexOf(",") + 1), 0); } int saveFileCount = 0; int fCount = HttpContext.Current.Request.Files.Count; for (int i = 0; i < fCount; i++) { if (!HttpContext.Current.Request.Files[i].FileName.Equals("") && HttpContext.Current.Request.Files.AllKeys[i].Equals(filekey)) { saveFileCount++; } } AttachmentInfo[] attachmentInfo = saveFileCount > 0 ? new AttachmentInfo[saveFileCount] : null; if (saveFileCount > MaxAllowFileCount) return attachmentInfo; saveFileCount = 0; Random random = new Random(unchecked((int)DateTime.Now.Ticks)); for (int i = 0; i < fCount; i++) { if (!HttpContext.Current.Request.Files[i].FileName.Equals("") && HttpContext.Current.Request.Files.AllKeys[i].Equals(filekey)) { string fileName = Path.GetFileName(HttpContext.Current.Request.Files[i].FileName); string fileExtName = Utils.CutString(fileName, fileName.LastIndexOf(".") + 1).ToLower(); string fileType = HttpContext.Current.Request.Files[i].ContentType.ToLower(); int fileSize = HttpContext.Current.Request.Files[i].ContentLength; string newFileName = ""; //flash�����ϴ�ʱ����ȡcontenttype if (fileType == "application/octet-stream") fileType = GetContentType(fileExtName); attachmentInfo[saveFileCount] = new AttachmentInfo(); attachmentInfo[saveFileCount].Sys_noupload = ""; // �ж� �ļ���չ��/�ļ���С/�ļ����� �Ƿ����Ҫ�� if (!(Utils.IsImgFilename(fileName) && !fileType.StartsWith("image"))) { int extnameid = Utils.GetInArrayID(fileExtName, allowFileExtName); if (extnameid >= 0 && (fileSize <= maxSize[extnameid]) && (MaxFileSize >= fileSize /*|| MaxAllSize == 0*/) && (MaxSizePerDay - TodayUploadedSize >= fileSize)) { TodayUploadedSize = TodayUploadedSize + fileSize; string UploadDir = Utils.GetMapPath(BaseConfigs.GetForumPath + "upload/"); string saveDir = GetAttachmentPath(forumid, config, fileExtName); newFileName = string.Format("{0}{1}{2}.{3}", (Environment.TickCount & int.MaxValue).ToString(), i.ToString(), random.Next(1000, 9999).ToString(), fileExtName); //(Environment.TickCount & int.MaxValue).ToString() + i.ToString() + random.Next(1000, 9999).ToString() + "." + fileextname; //��ʱ�ļ����Ʊ���. ���ڵ����Զ�̸���֮��,���ϴ���������ʱ�ļ��е�·����Ϣ string tempFileName = ""; //��֧��FTP�ϴ������Ҳ�������ظ���ʱ if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) { // ���ָ��Ŀ¼������������ʱ·�� if (!Directory.Exists(UploadDir + "temp\\")) Utils.CreateDir(UploadDir + "temp\\"); tempFileName = "temp\\" + newFileName; } // ���ָ��Ŀ¼���������� else if (!Directory.Exists(UploadDir + saveDir)) Utils.CreateDir(UploadDir + saveDir); newFileName = saveDir + newFileName; try { // �����bmp jpg pngͼƬ���� if ((fileExtName == "bmp" || fileExtName == "jpg" || fileExtName == "jpeg" || fileExtName == "png") && fileType.StartsWith("image")) { Image img = Image.FromStream(HttpContext.Current.Request.Files[i].InputStream); if (config.Attachimgmaxwidth > 0 && img.Width > config.Attachimgmaxwidth) attachmentInfo[saveFileCount].Sys_noupload = "ͼƬ���Ϊ" + img.Width + ", ϵͳ����������Ϊ" + config.Attachimgmaxwidth; if (config.Attachimgmaxheight > 0 && img.Height > config.Attachimgmaxheight) attachmentInfo[saveFileCount].Sys_noupload = "ͼƬ�߶�Ϊ" + img.Width + ", ϵͳ��������߶�Ϊ" + config.Attachimgmaxheight; attachmentInfo[saveFileCount].Width = img.Width; attachmentInfo[saveFileCount].Height = img.Height; if (attachmentInfo[saveFileCount].Sys_noupload == "") { if (watermarkstatus == 0) { //��֧��FTP�ϴ������Ҳ�������ظ���ģʽʱ,�����ϴ�����ʱĿ¼�� if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) HttpContext.Current.Request.Files[i].SaveAs(UploadDir + tempFileName); else HttpContext.Current.Request.Files[i].SaveAs(UploadDir + newFileName); attachmentInfo[saveFileCount].Filesize = fileSize; } else { if (config.Watermarktype == 1 && File.Exists(Utils.GetMapPath(BaseConfigs.GetForumPath + "watermark/" + config.Watermarkpic))) { //��֧��FTP�ϴ������Ҳ�������ظ���ģʽʱ,�����ϴ�����ʱĿ¼�� if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) AddImageSignPic(img, UploadDir + tempFileName, Utils.GetMapPath(BaseConfigs.GetForumPath + "watermark/" + config.Watermarkpic), config.Watermarkstatus, config.Attachimgquality, config.Watermarktransparency); else AddImageSignPic(img, UploadDir + newFileName, Utils.GetMapPath(BaseConfigs.GetForumPath + "watermark/" + config.Watermarkpic), config.Watermarkstatus, config.Attachimgquality, config.Watermarktransparency); } else { string watermarkText; watermarkText = config.Watermarktext.Replace("{1}", config.Forumtitle); watermarkText = watermarkText.Replace("{2}", "http://" + DNTRequest.GetCurrentFullHost() + "/"); watermarkText = watermarkText.Replace("{3}", Utils.GetDate()); watermarkText = watermarkText.Replace("{4}", Utils.GetTime()); //��֧��FTP�ϴ������Ҳ�������ظ���ģʽʱ,�����ϴ�����ʱĿ¼�� if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) AddImageSignText(img, UploadDir + tempFileName, watermarkText, config.Watermarkstatus, config.Attachimgquality, config.Watermarkfontname, config.Watermarkfontsize); else AddImageSignText(img, UploadDir + newFileName, watermarkText, config.Watermarkstatus, config.Attachimgquality, config.Watermarkfontname, config.Watermarkfontsize); } //��֧��FTP�ϴ������Ҳ�������ظ���ģʽʱ,���ȡ��ʱĿ¼�µ��ļ���Ϣ if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) attachmentInfo[saveFileCount].Filesize = new FileInfo(UploadDir + tempFileName).Length; else attachmentInfo[saveFileCount].Filesize = new FileInfo(UploadDir + newFileName).Length; } } } else { attachmentInfo[saveFileCount].Filesize = fileSize; //��֧��FTP�ϴ������Ҳ�������ظ���ģʽʱ,�����ϴ�����ʱĿ¼�� if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) HttpContext.Current.Request.Files[i].SaveAs(UploadDir + tempFileName); else HttpContext.Current.Request.Files[i].SaveAs(UploadDir + newFileName); } } catch { //���ϴ�Ŀ¼����ʱ�ļ��ж�û���ϴ����ļ�ʱ if (!(Utils.FileExists(UploadDir + tempFileName)) && (!(Utils.FileExists(UploadDir + newFileName)))) { attachmentInfo[saveFileCount].Filesize = fileSize; //��֧��FTP�ϴ������Ҳ�������ظ���ģʽʱ,�����ϴ�����ʱĿ¼�� if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) HttpContext.Current.Request.Files[i].SaveAs(UploadDir + tempFileName); else HttpContext.Current.Request.Files[i].SaveAs(UploadDir + newFileName); } } try { //�����ļ�Ԥ����ָ������ IPreview preview = PreviewProvider.GetInstance(fileExtName.Trim()); if (preview != null) { preview.UseFTP = (FTPs.GetForumAttachInfo.Allowupload == 1) ? true : false; //��֧��FTP�ϴ������Ҳ�������ظ���ģʽʱ if (FTPs.GetForumAttachInfo.Allowupload == 1 && FTPs.GetForumAttachInfo.Reservelocalattach == 0) preview.OnSaved(UploadDir + tempFileName); else preview.OnSaved(UploadDir + newFileName); } } catch { } //��֧��FTP�ϴ�����ʱ,ʹ��FTP�ϴ�Զ�̸��� if (FTPs.GetForumAttachInfo.Allowupload == 1) { FTPs ftps = new FTPs(); //����������ظ���ģʽʱ,���ϴ����֮��ɾ������tempfilename�ļ� if (FTPs.GetForumAttachInfo.Reservelocalattach == 0) ftps.UpLoadFile(newFileName.Substring(0, newFileName.LastIndexOf("\\")), UploadDir + tempFileName, FTPs.FTPUploadEnum.ForumAttach); else ftps.UpLoadFile(newFileName.Substring(0, newFileName.LastIndexOf("\\")), UploadDir + newFileName, FTPs.FTPUploadEnum.ForumAttach); } if (EntLibConfigs.GetConfig() != null && EntLibConfigs.GetConfig().Cacheattachfiles.Enable && EntLibConfigs.GetConfig().Cacheattachfiles.Attachpostid > 0) Discuz.Cache.Data.DBCacheService.GetAttachFilesService().UploadFile(UploadDir, newFileName); } else { if (extnameid < 0) attachmentInfo[saveFileCount].Sys_noupload = "�ļ���ʽ��Ч"; else if (MaxSizePerDay - TodayUploadedSize < fileSize) attachmentInfo[saveFileCount].Sys_noupload = "�ļ����ڽ��������ϴ����ֽ���"; else if (fileSize > maxSize[extnameid]) attachmentInfo[saveFileCount].Sys_noupload = "�ļ����ڸ�������������ֽ���"; else attachmentInfo[saveFileCount].Sys_noupload = "�ļ����ڵ����ļ������ϴ����ֽ���"; } } else { attachmentInfo[saveFileCount].Sys_noupload = "�ļ���ʽ��Ч"; } //��֧��FTP�ϴ�����ʱ if (FTPs.GetForumAttachInfo.Allowupload == 1) attachmentInfo[saveFileCount].Filename = FTPs.GetForumAttachInfo.Remoteurl + "/" + newFileName.Replace("\\", "/"); else attachmentInfo[saveFileCount].Filename = newFileName; attachmentInfo[saveFileCount].Description = ""; attachmentInfo[saveFileCount].Filetype = fileType; attachmentInfo[saveFileCount].Attachment = fileName; attachmentInfo[saveFileCount].Downloads = 0; attachmentInfo[saveFileCount].Postdatetime = DateTime.Now.ToString(); attachmentInfo[saveFileCount].Sys_index = i; attachmentInfo[saveFileCount].Isimage = isImage ? 1 : 0; saveFileCount++; } } return attachmentInfo; }
/// <summary> /// 保存配置类实例 /// </summary> /// <param name="generalconfiginfo"></param> /// <returns></returns> public static bool SaveConfig(GeneralConfigInfo generalconfiginfo) { GeneralConfigFileManager gcf = new GeneralConfigFileManager(); GeneralConfigFileManager.ConfigInfo = generalconfiginfo; return gcf.SaveConfig(); }
/// <summary> /// 上传店标文件 /// </summary> /// <param name="MaxFileSize">最大文件上传尺寸</param> /// <param name="AllowFileType">允许上传文件类型</param> /// <param name="config">配置对象信息</param> /// <param name="filekey">File控件的Key(即Name属性)</param> /// <returns>文件信息结构</returns> public static string SaveRequestFile(int MaxFileSize, string AllowFileType, GeneralConfigInfo config, string filekey) { string[] tmp = Utils.SplitString(AllowFileType, "\r\n"); Random random = new Random(unchecked((int)DateTime.Now.Ticks)); for (int i = 0; i < HttpContext.Current.Request.Files.Count; i++) { if (!HttpContext.Current.Request.Files[i].FileName.Equals("") && HttpContext.Current.Request.Files.AllKeys[i].Equals(filekey)) { string fileName = Path.GetFileName(HttpContext.Current.Request.Files[i].FileName); string fileExtName = Utils.CutString(fileName, fileName.LastIndexOf(".") + 1).ToLower(); string fileType = HttpContext.Current.Request.Files[i].ContentType.ToLower(); int fileSize = HttpContext.Current.Request.Files[i].ContentLength; string newFileName = ""; // 判断 文件扩展名/文件大小/文件类型 是否符合要求 if (!(Utils.IsImgFilename(fileName) && !fileType.StartsWith("image"))) { int extNameId = Utils.GetInArrayID(fileExtName, tmp); if (extNameId >= 0 && MaxFileSize >= fileSize) { string UploadDir = Utils.GetMapPath(BaseConfigs.GetForumPath + "upload/mall/"); StringBuilder savedir = new StringBuilder(""); savedir.Append(DateTime.Now.ToString("yyyy")); savedir.Append(Path.DirectorySeparatorChar); savedir.Append(DateTime.Now.ToString("MM")); savedir.Append(Path.DirectorySeparatorChar); savedir.Append(DateTime.Now.ToString("dd")); savedir.Append(Path.DirectorySeparatorChar); newFileName = (Environment.TickCount & int.MaxValue).ToString() + i.ToString() + random.Next(1000, 9999).ToString() + "." + fileExtName; //临时文件名称变量. 用于当启动远程附件之后,先上传到本地临时文件夹的路径信息 string tempfilename = ""; //当支持FTP上传附件且不保留本地附件时 if (FTPs.GetMallAttachInfo.Allowupload == 1 && FTPs.GetMallAttachInfo.Reservelocalattach == 0) { // 如果指定目录不存在则建立临时路径 if (!Directory.Exists(UploadDir + "temp\\")) Utils.CreateDir(UploadDir + "temp\\"); tempfilename = "temp\\" + newFileName; } else { // 如果指定目录不存在则建立 if (!Directory.Exists(UploadDir + savedir.ToString())) Utils.CreateDir(UploadDir + savedir.ToString()); } newFileName = savedir.ToString() + newFileName; try { //当上传目录和临时文件夹都没有上传的文件时 if (!(Utils.FileExists(UploadDir + tempfilename)) && (!(Utils.FileExists(UploadDir + newFileName)))) { //当支持FTP上传附件且不保留本地附件模式时,则先上传到临时目录下 if (FTPs.GetMallAttachInfo.Allowupload == 1 && FTPs.GetMallAttachInfo.Reservelocalattach == 0) HttpContext.Current.Request.Files[i].SaveAs(UploadDir + tempfilename); else HttpContext.Current.Request.Files[i].SaveAs(UploadDir + newFileName); } } catch {} //当支持FTP上传附件时,使用FTP上传远程附件 if (FTPs.GetMallAttachInfo.Allowupload == 1) { FTPs ftps = new FTPs(); //当不保留本地附件模式时,在上传完成之后删除本地tempfilename文件 if (FTPs.GetMallAttachInfo.Reservelocalattach == 0) ftps.UpLoadFile(newFileName.Substring(0, newFileName.LastIndexOf("\\")), UploadDir + tempfilename, FTPs.FTPUploadEnum.ForumAttach); else ftps.UpLoadFile(newFileName.Substring(0, newFileName.LastIndexOf("\\")), UploadDir + newFileName, FTPs.FTPUploadEnum.ForumAttach); } } else return (extNameId < 0) ? "文件格式无效" : "文件大于单个文件允许上传的字节数"; } else return "文件格式无效"; //当支持FTP上传附件时 if (FTPs.GetMallAttachInfo.Allowupload == 1) return FTPs.GetMallAttachInfo.Remoteurl + "/" + newFileName.Replace("\\", "/"); else return "mall/" + newFileName; } } return ""; }
/// <summary> /// 检查cookie是否有效 /// </summary> /// <returns></returns> public bool CheckCookie() { string sysloginPage = Shove._Web.Utility.GetUrl() + "/admin/syslogin.aspx"; config = GeneralConfigs.GetConfig(); // 如果IP访问列表有设置则进行判断 if (config.Adminipaccess.Trim() != "") { string[] regctrl = Utils.SplitString(config.Adminipaccess, "\n"); if (!Utils.InIPArray(DNTRequest.GetIP(), regctrl)) { Context.Response.Redirect(sysloginPage); return false; } } #region 进行权限判断 int userid = Discuz.Forum.Users.GetUserIDFromCookie(); if (userid <= 0) { Context.Response.Redirect(sysloginPage); return false; } UserInfo u = Discuz.Forum.Users.GetUserInfo(userid); if (u.Adminid < 1 || u.Groupid < 1) { Context.Response.Redirect(sysloginPage); return false; } UserGroupInfo usergroupinfo = AdminUserGroups.AdminGetUserGroupInfo(u.Groupid); if (usergroupinfo.Radminid != 1) { Context.Response.Redirect(sysloginPage); return false; } this.userid = u.Uid; this.username = u.Username; this.usergroupid = u.Groupid; this.useradminid = (short)usergroupinfo.Radminid; this.grouptitle = usergroupinfo.Grouptitle; this.ip = DNTRequest.GetIP(); #endregion return true; }
/// <summary> /// 保存上传的文件 /// </summary> /// <param name="categoryid">商品分类id</param> /// <param name="MaxAllowFileCount">最大允许的上传文件个数</param> /// <param name="MaxSizePerDay">每天允许的附件大小总数</param> /// <param name="MaxFileSize">单个最大允许的文件字节数</param>/// /// <param name="TodayUploadedSize">今天已经上传的附件字节总数</param> /// <param name="AllowFileType">允许的文件类型, 以string[]形式提供</param> /// <param name="config">附件保存方式 0=按年/月/日存入不同目录 1=按年/月/日/论坛存入不同目录 2=按论坛存入不同目录 3=按文件类型存入不同目录</param> /// <param name="watermarkstatus">图片水印位置</param> /// <param name="filekey">File控件的Key(即Name属性)</param> /// <returns>文件信息结构</returns> public static Goodsattachmentinfo[] SaveRequestFiles(int categoryId, int MaxAllowFileCount, int MaxSizePerDay, int MaxFileSize, int TodayUploadedSize, string AllowFileType, int waterMarkStatus, GeneralConfigInfo config, string fileKey) { string[] tmp = Utils.SplitString(AllowFileType, "\r\n"); string[] AllowFileExtName = new string[tmp.Length]; int[] MaxSize = new int[tmp.Length]; for (int i = 0; i < tmp.Length; i++) { AllowFileExtName[i] = Utils.CutString(tmp[i], 0, tmp[i].LastIndexOf(",")); MaxSize[i] = Utils.StrToInt(Utils.CutString(tmp[i], tmp[i].LastIndexOf(",") + 1), 0); } int saveFileCount = 0; int fCount = HttpContext.Current.Request.Files.Count; for (int i = 0; i < fCount; i++) { if (!HttpContext.Current.Request.Files[i].FileName.Equals("") && HttpContext.Current.Request.Files.AllKeys[i].Equals(fileKey)) saveFileCount++; } Goodsattachmentinfo[] attachmentInfo = new Goodsattachmentinfo[saveFileCount]; if (saveFileCount > MaxAllowFileCount) return attachmentInfo; saveFileCount = 0; Random random = new Random(unchecked((int)DateTime.Now.Ticks)); for (int i = 0; i < fCount; i++) { if (!HttpContext.Current.Request.Files[i].FileName.Equals("") && HttpContext.Current.Request.Files.AllKeys[i].Equals(fileKey)) { string fileName = Path.GetFileName(HttpContext.Current.Request.Files[i].FileName); string fileExtName = Utils.CutString(fileName, fileName.LastIndexOf(".") + 1).ToLower(); string fileType = HttpContext.Current.Request.Files[i].ContentType.ToLower(); int fileSize = HttpContext.Current.Request.Files[i].ContentLength; string newFileName = ""; attachmentInfo[saveFileCount] = new Goodsattachmentinfo(); attachmentInfo[saveFileCount].Sys_noupload = ""; // 判断 文件扩展名/文件大小/文件类型 是否符合要求 if (!(Utils.IsImgFilename(fileName) && !fileType.StartsWith("image"))) { int extNameId = Utils.GetInArrayID(fileExtName, AllowFileExtName); if (extNameId >= 0 && (fileSize <= MaxSize[extNameId]) && (MaxFileSize >= fileSize /*|| MaxAllSize == 0*/) && (MaxSizePerDay - TodayUploadedSize >= fileSize)) { TodayUploadedSize = TodayUploadedSize + fileSize; string UploadDir = Utils.GetMapPath(BaseConfigs.GetForumPath + "upload/mall/"); StringBuilder saveDir = new StringBuilder(""); //附件保存方式 0=按年/月/日存入不同目录 1=按年/月/日/论坛存入不同目录 2=按论坛存入不同目录 3=按文件类型存入不同目录 if (config.Attachsave == 1) { saveDir.Append(DateTime.Now.ToString("yyyy")); saveDir.Append(Path.DirectorySeparatorChar); saveDir.Append(DateTime.Now.ToString("MM")); saveDir.Append(Path.DirectorySeparatorChar); saveDir.Append(DateTime.Now.ToString("dd")); saveDir.Append(Path.DirectorySeparatorChar); saveDir.Append(categoryId.ToString()); saveDir.Append(Path.DirectorySeparatorChar); } else if (config.Attachsave == 2) { saveDir.Append(categoryId); saveDir.Append(Path.DirectorySeparatorChar); } else if (config.Attachsave == 3) { saveDir.Append(fileExtName); saveDir.Append(Path.DirectorySeparatorChar); } else { saveDir.Append(DateTime.Now.ToString("yyyy")); saveDir.Append(Path.DirectorySeparatorChar); saveDir.Append(DateTime.Now.ToString("MM")); saveDir.Append(Path.DirectorySeparatorChar); saveDir.Append(DateTime.Now.ToString("dd")); saveDir.Append(Path.DirectorySeparatorChar); } newFileName = (Environment.TickCount & int.MaxValue).ToString() + i + random.Next(1000, 9999) + "." + fileExtName; //临时文件名称变量. 用于当启动远程附件之后,先上传到本地临时文件夹的路径信息 string tempFileName = ""; //当支持FTP上传附件且不保留本地附件时 if (FTPs.GetMallAttachInfo.Allowupload == 1 && FTPs.GetMallAttachInfo.Reservelocalattach == 0) { // 如果指定目录不存在则建立临时路径 if (!Directory.Exists(UploadDir + "temp\\")) Utils.CreateDir(UploadDir + "temp\\"); tempFileName = "temp\\" + newFileName; } else { // 如果指定目录不存在则建立 if (!Directory.Exists(UploadDir + saveDir.ToString())) Utils.CreateDir(UploadDir + saveDir.ToString()); } newFileName = saveDir.ToString() + newFileName; try { // 如果是bmp jpg png图片类型 if ((fileExtName == "bmp" || fileExtName == "jpg" || fileExtName == "jpeg" || fileExtName == "png") && fileType.StartsWith("image")) { Image img = Image.FromStream(HttpContext.Current.Request.Files[i].InputStream); if (config.Attachimgmaxwidth > 0 && img.Width > config.Attachimgmaxwidth) attachmentInfo[saveFileCount].Sys_noupload = "图片宽度为" + img.Width + ", 系统允许的最大宽度为" + config.Attachimgmaxwidth; if (config.Attachimgmaxheight > 0 && img.Height > config.Attachimgmaxheight) attachmentInfo[saveFileCount].Sys_noupload = "图片高度为" + img.Width + ", 系统允许的最大高度为" + config.Attachimgmaxheight; if (attachmentInfo[saveFileCount].Sys_noupload == "") { if (waterMarkStatus == 0) { //当支持FTP上传附件且不保留本地附件模式时,则先上传到临时目录下 if (FTPs.GetMallAttachInfo.Allowupload == 1 && FTPs.GetMallAttachInfo.Reservelocalattach == 0) HttpContext.Current.Request.Files[i].SaveAs(UploadDir + tempFileName); else HttpContext.Current.Request.Files[i].SaveAs(UploadDir + newFileName); attachmentInfo[saveFileCount].Filesize = fileSize; } else { if (config.Watermarktype == 1 && File.Exists(Utils.GetMapPath(BaseConfigs.GetForumPath + "watermark/" + config.Watermarkpic))) { //当支持FTP上传附件且不保留本地附件模式时,则先上传到临时目录下 if (FTPs.GetMallAttachInfo.Allowupload == 1 && FTPs.GetMallAttachInfo.Reservelocalattach == 0) ForumUtils.AddImageSignPic(img, UploadDir + tempFileName, Utils.GetMapPath(BaseConfigs.GetForumPath + "watermark/" + config.Watermarkpic), config.Watermarkstatus, config.Attachimgquality, config.Watermarktransparency); else ForumUtils.AddImageSignPic(img, UploadDir + newFileName, Utils.GetMapPath(BaseConfigs.GetForumPath + "watermark/" + config.Watermarkpic), config.Watermarkstatus, config.Attachimgquality, config.Watermarktransparency); } else { string watermarkText; watermarkText = config.Watermarktext.Replace("{1}", config.Forumtitle); watermarkText = watermarkText.Replace("{2}", "http://" + DNTRequest.GetCurrentFullHost() + "/"); watermarkText = watermarkText.Replace("{3}", Utils.GetDate()); watermarkText = watermarkText.Replace("{4}", Utils.GetTime()); //当支持FTP上传附件且不保留本地附件模式时,则先上传到临时目录下 if (FTPs.GetMallAttachInfo.Allowupload == 1 && FTPs.GetMallAttachInfo.Reservelocalattach == 0) ForumUtils.AddImageSignText(img, UploadDir + tempFileName, watermarkText, config.Watermarkstatus, config.Attachimgquality, config.Watermarkfontname, config.Watermarkfontsize); else ForumUtils.AddImageSignText(img, UploadDir + newFileName, watermarkText, config.Watermarkstatus, config.Attachimgquality, config.Watermarkfontname, config.Watermarkfontsize); } //当支持FTP上传附件且不保留本地附件模式时,则读取临时目录下的文件信息 if (FTPs.GetMallAttachInfo.Allowupload == 1 && FTPs.GetMallAttachInfo.Reservelocalattach == 0) attachmentInfo[saveFileCount].Filesize = new FileInfo(UploadDir + tempFileName).Length; else attachmentInfo[saveFileCount].Filesize = new FileInfo(UploadDir + newFileName).Length; } } } else { attachmentInfo[saveFileCount].Filesize = fileSize; //当支持FTP上传附件且不保留本地附件模式时,则先上传到临时目录下 if (FTPs.GetMallAttachInfo.Allowupload == 1 && FTPs.GetMallAttachInfo.Reservelocalattach == 0) HttpContext.Current.Request.Files[i].SaveAs(UploadDir + tempFileName); else HttpContext.Current.Request.Files[i].SaveAs(UploadDir + newFileName); } } catch { //当上传目录和临时文件夹都没有上传的文件时 if (!(Utils.FileExists(UploadDir + tempFileName)) && (!(Utils.FileExists(UploadDir + newFileName)))) { attachmentInfo[saveFileCount].Filesize = fileSize; //当支持FTP上传附件且不保留本地附件模式时,则先上传到临时目录下 if (FTPs.GetMallAttachInfo.Allowupload == 1 && FTPs.GetMallAttachInfo.Reservelocalattach == 0) HttpContext.Current.Request.Files[i].SaveAs(UploadDir + tempFileName); else HttpContext.Current.Request.Files[i].SaveAs(UploadDir + newFileName); } } try { //加载文件预览类指定方法 IPreview preview = PreviewProvider.GetInstance(fileExtName.Trim()); if (preview != null) { preview.UseFTP = (FTPs.GetMallAttachInfo.Allowupload == 1) ? true : false; //当支持FTP上传附件且不保留本地附件模式时 if (FTPs.GetMallAttachInfo.Allowupload == 1 && FTPs.GetMallAttachInfo.Reservelocalattach == 0) preview.OnSaved(UploadDir + tempFileName); else preview.OnSaved(UploadDir + newFileName); } } catch { } //当支持FTP上传附件时,使用FTP上传远程附件 if (FTPs.GetMallAttachInfo.Allowupload == 1) { FTPs ftps = new FTPs(); //当不保留本地附件模式时,在上传完成之后删除本地tempfilename文件 if (FTPs.GetMallAttachInfo.Reservelocalattach == 0) ftps.UpLoadFile(newFileName.Substring(0, newFileName.LastIndexOf("\\")), UploadDir + tempFileName, FTPs.FTPUploadEnum.ForumAttach); else ftps.UpLoadFile(newFileName.Substring(0, newFileName.LastIndexOf("\\")), UploadDir + newFileName, FTPs.FTPUploadEnum.ForumAttach); } } else { if (extNameId < 0) attachmentInfo[saveFileCount].Sys_noupload = "文件格式无效"; else if (MaxSizePerDay - TodayUploadedSize < fileSize) attachmentInfo[saveFileCount].Sys_noupload = "文件大于今天允许上传的字节数"; else if (fileSize > MaxSize[extNameId]) attachmentInfo[saveFileCount].Sys_noupload = "文件大于该类型附件允许的字节数"; else attachmentInfo[saveFileCount].Sys_noupload = "文件大于单个文件允许上传的字节数"; } } else attachmentInfo[saveFileCount].Sys_noupload = "文件格式无效"; //当支持FTP上传附件时 if (FTPs.GetMallAttachInfo.Allowupload == 1) attachmentInfo[saveFileCount].Filename = FTPs.GetMallAttachInfo.Remoteurl + "/" + newFileName.Replace("\\", "/"); else attachmentInfo[saveFileCount].Filename = "mall/" + newFileName; attachmentInfo[saveFileCount].Description = fileExtName; attachmentInfo[saveFileCount].Filetype = fileType; attachmentInfo[saveFileCount].Attachment = fileName; attachmentInfo[saveFileCount].Postdatetime = DateTime.Now.ToString(); attachmentInfo[saveFileCount].Sys_index = i; saveFileCount++; } } return attachmentInfo; }
/// <summary> /// BasePage类构造函数 /// </summary> public PageBase() { if (recordPageView) PageViewStatistic(pagename); 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(ForumUtils.GetCookie("userid"), -1); #region == 联合登录 == loginUrl = System.Configuration.ConfigurationManager.AppSettings["LoginUrl"]; registerUrl = System.Configuration.ConfigurationManager.AppSettings["RegisterUrl"]; PlantEng.Login.ILoginAdapter la = new PlantEng.Login.LoginAdapter(); if (la.IsClientLogin()) { PlantEng.Login.LoginUserInfo loginUserInfo = la.GetLoginedUserInfo(); int _loginUserId = loginUserInfo.UserId; var _shortInfo = Users.GetShortUserInfo(_loginUserId); if (_shortInfo != null) { userid = _shortInfo.Uid; } //ShowMessage(string.Format("{0}",userid),0); //return; if (userid <= 0) { //论坛中不存在此用户 //插入用户表 UserInfo newUserInfo = new UserInfo(); newUserInfo.Uid = loginUserInfo.UserId; newUserInfo.Username = loginUserInfo.UserName; newUserInfo.Nickname = loginUserInfo.UserName; newUserInfo.Password = Utils.MD5("123123"); newUserInfo.Secques = string.Empty; newUserInfo.Gender = 0; newUserInfo.Adminid = 0; newUserInfo.Groupexpiry = 0; newUserInfo.Extgroupids = ""; newUserInfo.Regip = DNTRequest.GetIP(); newUserInfo.Joindate = Utils.GetDateTime(); newUserInfo.Lastip = DNTRequest.GetIP(); newUserInfo.Lastvisit = Utils.GetDateTime(); newUserInfo.Lastactivity = Utils.GetDateTime(); newUserInfo.Lastpost = Utils.GetDateTime(); newUserInfo.Lastpostid = 0; newUserInfo.Lastposttitle = ""; newUserInfo.Posts = 0; newUserInfo.Digestposts = 0; newUserInfo.Oltime = 0; newUserInfo.Pageviews = 0; newUserInfo.Credits = 0; newUserInfo.Extcredits1 = Scoresets.GetScoreSet(1).Init; newUserInfo.Extcredits2 = Scoresets.GetScoreSet(2).Init; newUserInfo.Extcredits3 = Scoresets.GetScoreSet(3).Init; newUserInfo.Extcredits4 = Scoresets.GetScoreSet(4).Init; newUserInfo.Extcredits5 = Scoresets.GetScoreSet(5).Init; newUserInfo.Extcredits6 = Scoresets.GetScoreSet(6).Init; newUserInfo.Extcredits7 = Scoresets.GetScoreSet(7).Init; newUserInfo.Extcredits8 = Scoresets.GetScoreSet(8).Init; newUserInfo.Email = loginUserInfo.Email; newUserInfo.Bday = string.Empty; newUserInfo.Sigstatus = 0; newUserInfo.Tpp = 0; newUserInfo.Ppp = 0; newUserInfo.Templateid = 0; newUserInfo.Pmsound = 0; newUserInfo.Showemail = 0; newUserInfo.Salt = "0"; newUserInfo.Invisible = 0; newUserInfo.Newpm = 0; newUserInfo.Medals = ""; newUserInfo.Accessmasks = 0; newUserInfo.Website = string.Empty; newUserInfo.Icq = string.Empty; newUserInfo.Qq = string.Empty; newUserInfo.Yahoo = string.Empty; newUserInfo.Msn = string.Empty; newUserInfo.Skype = string.Empty; newUserInfo.Location = string.Empty; newUserInfo.Customstatus = string.Empty; newUserInfo.Bio = string.Empty; newUserInfo.Signature = string.Empty; newUserInfo.Sightml = string.Empty; newUserInfo.Authtime = Utils.GetDateTime(); newUserInfo.Authstr = ""; newUserInfo.Authflag = 0; newUserInfo.Groupid = UserCredits.GetCreditsUserGroupId(0).Groupid; newUserInfo.Realname = string.Empty; newUserInfo.Idcard = string.Empty; newUserInfo.Mobile = string.Empty; newUserInfo.Phone = string.Empty; userid = Discuz.Forum.Users.CreateUser(newUserInfo); } //ShowMessage(string.Format("{0}|{1}", userid,useradminid), 0); //return; ShortUserInfo userInfo = Users.GetShortUserInfo(userid); usergroupinfo = UserGroups.GetUserGroupInfo(userInfo.Groupid); useradminid = usergroupinfo.Radminid; // 根据用户组得到相关联的管理组id //更新论坛信息 Users.UpdateTrendStat(TrendType.Login); OnlineUsers.UpdateAction(olid, UserAction.Login.ActionID, 0); LoginLogs.DeleteLoginLog(DNTRequest.GetIP()); Users.UpdateUserCreditsAndVisit(userInfo.Uid, DNTRequest.GetIP()); //写Cookie信息 ForumUtils.WriteUserCookie(userid, 30, config.Passwordkey, 0, -1); ForumUtils.WriteUserCreditsCookie(userInfo, usergroupinfo.Grouptitle); } #endregion //清空当前页面查询统计 #if DEBUG Discuz.Data.DbHelper.QueryCount = 0; Discuz.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 != "forumlist.aspx") && (pagename != "forumindex.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.Userid; usergroupid = oluserinfo.Groupid; username = oluserinfo.Username; password = oluserinfo.Password; userkey = password.Length > 16 ? password.Substring(4, 8).Trim() : ""; lastposttime = oluserinfo.Lastposttime; lastpostpmtime = oluserinfo.Lastpostpmtime; lastsearchtime = oluserinfo.Lastsearchtime; olid = oluserinfo.Olid; if (config.PostTimeStorageMedia == 1 && Utils.GetCookie("lastposttime") != "")//如果最后发帖时间cookie不为空,则在此修改用户的该属性 oluserinfo.Lastposttime = Utils.GetCookie("lastposttime"); //确保头像可以取到 if (userid > 0) useravatar = Avatars.GetAvatarUrl(userid, AvatarSize.Small); if (Utils.InArray(DNTRequest.GetString("selectedtemplateid"), Templates.GetValidTemplateIDList())) templateid = DNTRequest.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(ForumUtils.GetCookie("pmsound"), 0); //已登录用户检测用户组状态,如果是禁言或禁止访问状态时间到期,则自动解禁 if (usergroupid == 4 || usergroupid == 5) { //int groupExpiry = Users.GetShortUserInfo(userid).Groupexpiry; //if (groupExpiry != 0 && groupExpiry <= Utils.StrToInt(DateTime.Now.ToString("yyyyMMdd"), 0)) //{ // //先改为第一个积分组 // usergroupid = 11; // //usergroupinfo = UserGroups.GetUserGroupInfo(usergroupid); // Users.UpdateUserGroup(userid, 11); //} ShortUserInfo userInfo = Users.GetShortUserInfo(userid); if (userInfo.Groupexpiry != 0 && userInfo.Groupexpiry <= Utils.StrToInt(DateTime.Now.ToString("yyyyMMdd"), 0)) { UserGroupInfo groupInfo = UserCredits.GetCreditsUserGroupId(userInfo.Credits); usergroupid = groupInfo.Groupid != 0 ? groupInfo.Groupid : usergroupid; Users.UpdateUserGroup(userid, usergroupid); } } usergroupinfo = UserGroups.GetUserGroupInfo(usergroupid); // 取得用户权限id,1管理员,2超版,3版主,0普通组,-1特殊组 useradminid = usergroupinfo.Radminid; string tips = ForumUtils.GetUserCreditsCookie(userid, usergroupinfo.Grouptitle); if (tips != "") { string[] userinfotipsList = tips.Split(',');//因为考虑到应用程序做单点登录时获取不到userinfotips,封装了此方法 userinfotips = "<p><a class=\"drop\" onmouseover=\"showMenu(this.id);\" href=\"" + BaseConfigs.GetForumPath + "usercpcreditspay.aspx\" id=\"extcreditmenu\">" + userinfotipsList[0] + "</a> "; userinfotips += "<span class=\"pipe\">|</span>用户组: <a class=\"xi2\" id=\"g_upmine\" href=\"" + BaseConfigs.GetForumPath + "usercp.aspx\">" + userinfotipsList[1].Split(':')[1] + "</a></p>"; userinfotips += "<ul id=\"extcreditmenu_menu\" class=\"p_pop\" style=\"display:none;\">"; for (int i = 2; i < userinfotipsList.Length; i++) { userinfotips += string.Format("<li><a> {0}</a></li>", userinfotipsList[i]); } userinfotips += "</ul>"; } 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; } if (!Utils.InArray(pagename, "attachment.aspx"))//加入附件页面判断减少性能消耗 onlineusercount = (userid != -1) ? OnlineUsers.GetOnlineAllUserCount() : OnlineUsers.GetCacheOnlineAllUserCount(); //校验用户是否可以访问论坛 if (!ValidateUserPermission()) return; //更新用户在线时长 if (userid != -1 && !Utils.InArray(pagename, "attachment.aspx"))//加入附件页面判断减少性能消耗 OnlineUsers.UpdateOnlineTime(config.Oltimespan, userid); TemplateInfo templateInfo = Templates.GetTemplateItem(templateid); templatepath = templateInfo.Directory; if (templateInfo.Templateurl.ToLower().StartsWith("http://")) { imagedir = templateInfo.Templateurl.TrimEnd('/') + "/images"; cssdir = templateInfo.Templateurl.TrimEnd('/'); } else { imagedir = forumpath + "templates/" + templateInfo.Directory + "/images"; cssdir = forumpath + "templates/" + templateInfo.Directory; } if (EntLibConfigs.GetConfig() != null && !Utils.StrIsNullOrEmpty(EntLibConfigs.GetConfig().Topicidentifydir)) topicidentifydir = EntLibConfigs.GetConfig().Topicidentifydir.TrimEnd('/'); else topicidentifydir = forumpath + "images/identify"; if (EntLibConfigs.GetConfig() != null && !Utils.StrIsNullOrEmpty(EntLibConfigs.GetConfig().Posticondir)) posticondir = EntLibConfigs.GetConfig().Posticondir.TrimEnd('/'); else posticondir = forumpath + "images/posticons"; if (EntLibConfigs.GetConfig() != null && !Utils.StrIsNullOrEmpty(EntLibConfigs.GetConfig().Jsdir)) jsdir = EntLibConfigs.GetConfig().Jsdir.TrimEnd('/'); else jsdir = rooturl + "javascript"; nowdate = Utils.GetDate(); nowtime = Utils.GetTime(); nowdatetime = Utils.GetDateTime(); ispost = DNTRequest.IsPost(); isget = DNTRequest.IsGet(); link = ""; script = ""; templatelistboxoptions = Caches.GetTemplateListBoxOptionsCache(); string originalTemplate = string.Format("<li><a href=\"###\" onclick=\"window.location.href='{0}showtemplate.aspx?templateid={1}'\">", "", BaseConfigs.GetForumPath, templateid); string newTemplate = string.Format("<li class=\"current\"><a href=\"###\" onclick=\"window.location.href='{0}showtemplate.aspx?templateid={1}'\">", BaseConfigs.GetForumPath, templateid); templatelistboxoptions = templatelistboxoptions.Replace(originalTemplate, newTemplate); isLoginCode = config.Seccodestatus.Contains("login.aspx"); //当该页面设置了验证码检验,并且当前用户的用户组没有给予忽略验证码的权限,则isseccode=true; isseccode = Utils.InArray(pagename, config.Seccodestatus) && usergroupinfo.Ignoreseccode == 0; headerad = Advertisements.GetOneHeaderAd("", 0); footerad = Advertisements.GetOneFooterAd("", 0); //设定当前页面的显示样式 if (config.Allowchangewidth == 0) Utils.WriteCookie("allowchangewidth", ""); if (pagename != "website.aspx") { if (Utils.GetCookie("allowchangewidth") == "0" || (string.IsNullOrEmpty(Utils.GetCookie("allowchangewidth")) && config.Showwidthmode == 1)) isnarrowpage = true; } //校验验证码 if (isseccode && ispost && !ValidateVerifyCode()) return; newtopicminute = config.Viewnewtopicminute; m_starttick = DateTime.Now; ShowPage(); m_processtime = DateTime.Now.Subtract(m_starttick).TotalMilliseconds / 1000; querycount = Discuz.Data.DbHelper.QueryCount; Discuz.Data.DbHelper.QueryCount = 0; #if DEBUG querydetail = Discuz.Data.DbHelper.QueryDetail; Discuz.Data.DbHelper.QueryDetail = ""; #endif }
/// <summary> /// 获取原始的缺省论坛设置 /// </summary> /// <returns></returns> public static GeneralConfigInfo GetDefaultConifg() { GeneralConfigInfo __configinfo = new GeneralConfigInfo(); __configinfo.Forumtitle = "论坛名称"; //论坛名称 __configinfo.Forumurl = "/"; //论坛url地址 __configinfo.Webtitle = "网站名称"; //网站名称 __configinfo.Weburl = "/"; //论坛网站url地址 __configinfo.Licensed = 1; //是否显示商业授权链接 __configinfo.Icp = ""; //网站备案信息 __configinfo.Closed = 0; //论坛关闭 __configinfo.Closedreason = "抱歉!论坛暂时关闭,稍后才能访问."; //论坛关闭提示信息 __configinfo.Passwordkey = ForumUtils.CreateAuthStr(16); //用户密码Key __configinfo.Regstatus = 1; //是否允许新用户注册 __configinfo.Regadvance = 1; //注册时候是否显示高级选项 __configinfo.Censoruser = "******"; //用户信息保留关键字 __configinfo.Doublee = 0; //允许同一 Email 注册不同用户 __configinfo.Regverify = 0; //新用户注册验证 0=不验证 1=email验证 2=人工验证 __configinfo.Accessemail = ""; //Email允许地址 __configinfo.Censoremail = ""; //Email禁止地址 __configinfo.Hideprivate = 1; //隐藏无权访问的论坛 __configinfo.Regctrl = 0; //IP 注册间隔限制(小时) __configinfo.Ipregctrl = ""; //特殊 IP 注册限制 __configinfo.Ipaccess = ""; //IP访问列表 __configinfo.Adminipaccess = ""; //管理员后台IP访问列表 __configinfo.Newbiespan = 0; //新手见习期限(单位:小时) __configinfo.Welcomemsg = 1; //发送欢迎短消息 __configinfo.Welcomemsgtxt = "欢迎您注册加入本论坛!"; //欢迎短消息内容 __configinfo.Rules = 1; //是否显示注册许可协议 __configinfo.Rulestxt = ""; //许可协议内容 __configinfo.Templateid = 1; //默认论坛风格 __configinfo.Hottopic = 15; //热门话题最低贴数 __configinfo.Starthreshold = 5; //星星升级阀值 __configinfo.Visitedforums = 10; //显示最近访问论坛数量 __configinfo.Maxsigrows = 20; //最大签名高度(行) __configinfo.Moddisplay = 0; //版主显示方式 0=平面显示 1=下拉菜单 __configinfo.Subforumsindex = 0; //首页是否显示论坛的下级子论坛 __configinfo.Stylejump = 0; //显示风格下拉菜单 __configinfo.Fastpost = 1; //快速发帖 __configinfo.Showsignatures = 1; //是否显示签名 __configinfo.Showavatars = 1; //是否显示头像 __configinfo.Showimages = 1; //是否在帖子中显示图片 __configinfo.Archiverstatus = 1; //启用 Archiver __configinfo.Seotitle = ""; //标题附加字 __configinfo.Seokeywords = ""; //Meta Keywords __configinfo.Seodescription = ""; //Meta Description __configinfo.Seohead = ""; //其他头部信息 __configinfo.Rssstatus = 1; //rssstatus __configinfo.Rssttl = 60; //RSS TTL(分钟) __configinfo.Nocacheheaders = 0; //禁止浏览器缓冲 __configinfo.Fullmytopics = 0; //我的话题全文搜索 0=只搜索用户是主题发表者的主题 1=搜索用户是主题发表者或回复者的主题 __configinfo.Debug = 1; //显示程序运行信息 __configinfo.Rewriteurl = ""; //伪静态url的替换规则 __configinfo.Whosonlinestatus = 3; //显示在线用户 0=不显示 1=仅在首页显示 2=仅在分论坛显示 3=在首页和分论坛显示 __configinfo.Maxonlinelist = 300; //最多显示在线人数 __configinfo.Userstatusby = 2; //衡量并显示用户头衔 __configinfo.Forumjump = 1; //显示论坛跳转菜单 __configinfo.Modworkstatus = 1; //论坛管理工作统计 __configinfo.Maxmodworksmonths = 3; //管理记录保留时间(月) __configinfo.Seccodestatus = "register.aspx"; //使用验证码的页面列表,用","分隔 例如:register.aspx,login.aspx __configinfo.Maxonlines = 9000; //最大在线人数 __configinfo.Postinterval = 20; //发帖灌水预防(秒) __configinfo.Searchctrl = 0; //搜索时间限制(秒) __configinfo.Maxspm = 0; //60 秒最大搜索次数 __configinfo.Visitbanperiods = ""; //禁止访问时间段 __configinfo.Postbanperiods = ""; //禁止发帖时间段 __configinfo.Postmodperiods = ""; //发帖审核时间段 __configinfo.Attachbanperiods = ""; //禁止下载附件时间段 __configinfo.Searchbanperiods = ""; //禁止全文搜索时间段 __configinfo.Memliststatus = 1; //允许查看会员列表 __configinfo.Dupkarmarate = 0; //允许重复评分 __configinfo.Minpostsize = 10; //帖子最小字数(字) __configinfo.Maxpostsize = 500000; //帖子最大字数(字) __configinfo.Tpp = 25; //每页主题数 __configinfo.Ppp = 20; //每页帖子数 __configinfo.Maxfavorites = 100; //收藏夹容量 __configinfo.Maxavatarsize = 20480; //头像最大尺寸(字节) __configinfo.Maxavatarwidth = 120; //头像最大宽度(像素) __configinfo.Maxavatarheight = 120; //头像最大高度(像素); __configinfo.Maxpolloptions = 10; //投票最大选项数 __configinfo.Maxattachments = 10; //最大允许的上传附件数 __configinfo.Attachimgpost = 1; //帖子中显示图片附件 __configinfo.Attachrefcheck = 0; //下载附件来路检查 __configinfo.Attachsave = 3; //附件保存方式 0=全部存入同一目录 1=按论坛存入不同目录 2=按文件类型存入不同目录 3=按年月日存入不同目录 __configinfo.Watermarkstatus = 0; //图片附件添加水印 0=不使用 1=左上 2=中上 3=右上 4=左中 ... 9=右下 __configinfo.Karmaratelimit = 10; //评分时间限制(小时) __configinfo.Losslessdel = 5; //删贴不减积分时间期限(天) __configinfo.Edittimelimit = 0; //编辑帖子时间限制(分钟) __configinfo.Editedby = 1; //编辑帖子附加编辑记录 __configinfo.Defaulteditormode = 1; //默认的编辑器模式 0=ubb代码编辑器 1=可视化编辑器 __configinfo.Allowswitcheditor = 1; //是否允许切换编辑器模式 __configinfo.Smileyinsert = 1; //显示可点击表情 return __configinfo; }
//public AdminPage() //{ // this.RegisterAdminPageClientScriptBlock(); //} public void AdminPageStart() { this.RegisterAdminPageClientScriptBlock(); string sysloginPage = Shove._Web.Utility.GetUrl() + "/admin/syslogin.aspx"; config = GeneralConfigs.GetConfig(); // 如果IP访问列表有设置则进行判断 if (config.Adminipaccess.Trim() != "") { string[] regctrl = Utils.SplitString(config.Adminipaccess, "\n"); if (!Utils.InIPArray(DNTRequest.GetIP(), regctrl)) { Context.Response.Redirect(sysloginPage); return; } } #region 进行权限判断 int userid = Discuz.Forum.Users.GetUserIDFromCookie(); if (userid <= 0) { Context.Response.Redirect(sysloginPage); return; } UserInfo u = Discuz.Forum.Users.GetUserInfo(userid); if (u.Adminid < 1 || u.Groupid < 1) { Context.Response.Redirect(sysloginPage); return; } UserGroupInfo usergroupinfo = AdminUserGroups.AdminGetUserGroupInfo(u.Groupid); if (usergroupinfo.Radminid != 1) { Context.Response.Redirect(sysloginPage); return; } this.userid = u.Uid; this.username = u.Username; this.usergroupid = u.Groupid; this.useradminid = (short)usergroupinfo.Radminid; this.grouptitle = usergroupinfo.Grouptitle; this.ip = DNTRequest.GetIP(); #endregion //当前窗口不在Index.aspx页面上的FRAME中,则重定向到该框架中 //if (DNTRequest.GetPageName() != "runforumstatic.aspx") //{ // Context.Response.Write("<script>if(top.mainFrame==null) top.location.href='/admin/index.aspx?fromurl=" + Context.Request.RawUrl + "';</script>"); // Context.Response.End(); // return; //} }
public static bool CheckEmail(string email, GeneralConfigInfo config) { if (!Utils.IsValidEmail(email) || !Discuz.Forum.Users.ValidateEmail(email)) return false; string emailhost = Utils.GetEmailHostName(email); // 允许名单规则优先于禁止名单规则 if (config.Accessemail.Trim() != "" && !Utils.InArray(emailhost, config.Accessemail.Replace("\r\n", "\n"), "\n")) return false; if (config.Censoremail.Trim() != "" && Utils.InArray(email, config.Censoremail.Replace("\r\n", "\n"), "\n")) return false; return true; }
/// <summary> /// BasePage类构造函数 /// </summary> public PageBase() { 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(ForumUtils.GetCookie("userid"), -1); //清空当前页面查询统计 #if DEBUG Discuz.Data.DbHelper.QueryCount = 0; Discuz.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 != "forumlist.aspx") && (pagename != "forumindex.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.Userid; usergroupid = oluserinfo.Groupid; username = oluserinfo.Username; password = oluserinfo.Password; userkey = password.Length > 16 ? password.Substring(4, 8).Trim() : ""; lastposttime = oluserinfo.Lastposttime; lastpostpmtime = oluserinfo.Lastpostpmtime; lastsearchtime = oluserinfo.Lastsearchtime; olid = oluserinfo.Olid; //确保头像可以取到 if (userid > 0) useravatar = Avatars.GetAvatarUrl(userid, AvatarSize.Small); if (Utils.InArray(DNTRequest.GetString("selectedtemplateid"), Templates.GetValidTemplateIDList())) templateid = DNTRequest.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(ForumUtils.GetCookie("pmsound"), 0); usergroupinfo = UserGroups.GetUserGroupInfo(usergroupid); // 取得用户权限id,1管理员,2超版,3版主,0普通组,-1特殊组 useradminid = usergroupinfo.Radminid; 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 = DNTRequest.IsPost(); isget = DNTRequest.IsGet(); link = ""; script = ""; templatelistboxoptions = Caches.GetTemplateListBoxOptionsCache(); string originalTemplate = string.Format("<li><a href=\"###\" onclick=\"window.location.href='{0}showtemplate.aspx?templateid={1}'\">", "", BaseConfigs.GetForumPath, templateid); string newTemplate = string.Format("<li class=\"current\"><a href=\"###\" onclick=\"window.location.href='{0}showtemplate.aspx?templateid={1}'\">", BaseConfigs.GetForumPath, 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; ShowPage(); m_processtime = DateTime.Now.Subtract(m_starttick).TotalMilliseconds / 1000; querycount = Discuz.Data.DbHelper.QueryCount; Discuz.Data.DbHelper.QueryCount = 0; #if DEBUG querydetail = Discuz.Data.DbHelper.QueryDetail; Discuz.Data.DbHelper.QueryDetail = ""; #endif }
public AdminPage() { if (!Page.IsPostBack) { this.RegisterAdminPageClientScriptBlock(); } config = GeneralConfigs.GetConfig(); // 如果IP访问列表有设置则进行判断 if (config.Adminipaccess.Trim() != "") { string[] regctrl = Utils.SplitString(config.Adminipaccess, "\n"); if (!Utils.InIPArray(DNTRequest.GetIP(), regctrl)) { Context.Response.Redirect(BaseConfigs.GetForumPath + "admin/syslogin.aspx"); return; } } // 获取用户信息 OnlineUserInfo oluserinfo = OnlineUsers.UpdateInfo(config.Passwordkey, config.Onlinetimeout); UserGroupInfo usergroupinfo = AdminUserGroups.AdminGetUserGroupInfo(oluserinfo.Groupid); if (oluserinfo.Userid <= 0 || usergroupinfo.Radminid != 1) { Context.Response.Redirect(BaseConfigs.GetForumPath + "admin/syslogin.aspx"); return; } string secques = Users.GetUserInfo(oluserinfo.Userid).Secques; // 管理员身份验证 if (Context.Request.Cookies["dntadmin"] == null || Context.Request.Cookies["dntadmin"]["key"] == null || ForumUtils.GetCookiePassword(Context.Request.Cookies["dntadmin"]["key"].ToString(), config.Passwordkey) != (oluserinfo.Password + secques + oluserinfo.Userid.ToString())) { Context.Response.Redirect(BaseConfigs.GetForumPath + "admin/syslogin.aspx"); return; } else { HttpCookie cookie = HttpContext.Current.Request.Cookies["dntadmin"]; cookie.Values["key"] = ForumUtils.SetCookiePassword(oluserinfo.Password + secques + oluserinfo.Userid.ToString(), config.Passwordkey); cookie.Values["userid"] = oluserinfo.Userid.ToString(); cookie.Expires = DateTime.Now.AddMinutes(30); HttpContext.Current.Response.AppendCookie(cookie); } this.userid = oluserinfo.Userid; this.username = oluserinfo.Username; this.usergroupid = oluserinfo.Groupid; this.useradminid = (short)usergroupinfo.Radminid; this.grouptitle = usergroupinfo.Grouptitle; this.ip = DNTRequest.GetIP(); //当前窗口不在Index.aspx页面上的FRAME中,则重定向到该框架中 //if (DNTRequest.GetPageName() != "runforumstatic.aspx") //{ // Context.Response.Write("<script>if(top.mainFrame==null) top.location.href='/admin/index.aspx?fromurl=" + Context.Request.RawUrl + "';</script>"); // Context.Response.End(); // return; //} }
/// <summary> /// 重设配置类实例 /// </summary> public static void ResetConfig() { m_configinfo = GeneralConfigFileManager.LoadConfig(); }