private void btnPostComment_Click(object sender, EventArgs e) { if (!ShouldAllowComments()) { WebUtils.SetupRedirect(this, Request.RawUrl); return; } if (!IsValidComment()) { //SetupInternalCommentSystem(); PopulateControls(); return; } if (news == null) { return; } if (news.AllowCommentsForDays < 0) { WebUtils.SetupRedirect(this, Request.RawUrl); return; } DateTime endDate = news.StartDate.AddDays((double)news.AllowCommentsForDays); if ((endDate < DateTime.UtcNow) && (news.AllowCommentsForDays > 0)) { return; } if (this.chkRememberMe.Checked) { SetCookies(); } News.AddNewsComment( news.NewsID, this.txtName.Text, this.txtCommentTitle.Text, this.txtURL.Text, edComment.Text, DateTime.UtcNow); if (config.NotifyOnComment) { //added this due to news coment spam and need to be able to ban the ip of the spammer StringBuilder message = new StringBuilder(); message.Append(basePage.SiteRoot + news.Url.Replace("~", string.Empty)); message.Append("\n\nHTTP_USER_AGENT: " + Page.Request.ServerVariables["HTTP_USER_AGENT"] + "\n"); message.Append("HTTP_HOST: " + Page.Request.ServerVariables["HTTP_HOST"] + "\n"); message.Append("REMOTE_HOST: " + Page.Request.ServerVariables["REMOTE_HOST"] + "\n"); message.Append("REMOTE_ADDR: " + SiteUtils.GetIP4Address() + "\n"); message.Append("LOCAL_ADDR: " + Page.Request.ServerVariables["LOCAL_ADDR"] + "\n"); message.Append("HTTP_REFERER: " + Page.Request.ServerVariables["HTTP_REFERER"] + "\n"); SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings(); if ((config.NotifyEmail.Length > 0) && (Email.IsValidEmailAddressSyntax(config.NotifyEmail))) { EmailTemplate template = EmailTemplate.Get(siteSettings.SiteId, "NewsCommentNotification"); string fromAddress = siteSettings.DefaultEmailFromAddress; string fromAlias = template.FromName; if (fromAlias.Length == 0) { fromAlias = siteSettings.DefaultFromEmailAlias; } string toEmail = config.NotifyEmail; if (template.ToAddresses.Length > 0) { toEmail += ";" + template.ToAddresses; } NewsHelper.SendCommentNotification( SiteUtils.GetSmtpSettings(), siteSettings.SiteGuid, fromAddress, fromAlias, toEmail, template.ReplyToAddress, template.CcAddresses, template.BccAddresses, template.Subject, template.HtmlBody, siteSettings.SiteName, message.ToString()); } if (config.NotifyEmail != news.UserEmail) { EmailTemplate template = EmailTemplate.Get(siteSettings.SiteId, "NewsCommentNotification"); string fromAddress = siteSettings.DefaultEmailFromAddress; string fromAlias = template.FromName; if (fromAlias.Length == 0) { fromAlias = siteSettings.DefaultFromEmailAlias; } string toEmail = news.UserEmail; if (template.ToAddresses.Length > 0) { toEmail += ";" + template.ToAddresses; } NewsHelper.SendCommentNotification( SiteUtils.GetSmtpSettings(), siteSettings.SiteGuid, fromAddress, fromAlias, toEmail, template.ReplyToAddress, template.CcAddresses, template.BccAddresses, template.Subject, template.HtmlBody, siteSettings.SiteName, message.ToString()); } } WebUtils.SetupRedirect(this, Request.RawUrl); }
private void btnPostComment_Click(object sender, EventArgs e) { if (!IsValidComment()) { return; } if (news == null) { return; } //if (news.AllowCommentsForDays < 0) //{ // WebUtils.SetupRedirect(this, Request.RawUrl); // return; //} //DateTime endDate = news.StartDate.AddDays((double)news.AllowCommentsForDays); //if ((endDate < DateTime.UtcNow) && (news.AllowCommentsForDays > 0)) { return; } string attachFile1 = null; string attachFile2 = null; string attachmentsPath = NewsHelper.AttachmentsPath(siteSettings.SiteId, news.NewsID); if (uplAttachFile1.UploadedFiles.Count > 0 || uplAttachFile2.UploadedFiles.Count > 0) { try { string fileSystemPath = Server.MapPath(attachmentsPath); if (!Directory.Exists(fileSystemPath)) { Directory.CreateDirectory(fileSystemPath); } } catch (Exception ex) { } } if (uplAttachFile1.UploadedFiles.Count > 0) { if (SiteUtils.IsAllowedUploadBrowseFile(uplAttachFile1.UploadedFiles[0].GetExtension(), NewsConfiguration.JobApplyAttachFileExtensions)) { attachFile1 = uplAttachFile1.UploadedFiles[0].FileName.ToCleanFileName(WebConfigSettings.ForceLowerCaseForUploadedFiles); int i = 1; while (File.Exists(VirtualPathUtility.Combine(attachmentsPath, attachFile1))) { attachFile1 = i.ToInvariantString() + attachFile1; i += 1; } } } if (uplAttachFile2.UploadedFiles.Count > 0) { if (SiteUtils.IsAllowedUploadBrowseFile(uplAttachFile2.UploadedFiles[0].GetExtension(), NewsConfiguration.JobApplyAttachFileExtensions)) { attachFile2 = uplAttachFile2.UploadedFiles[0].FileName.ToCleanFileName(WebConfigSettings.ForceLowerCaseForUploadedFiles); int i = 1; while (File.Exists(VirtualPathUtility.Combine(attachmentsPath, attachFile2))) { attachFile2 = i.ToInvariantString() + attachFile2; i += 1; } } } News.AddNewsComment( news.NewsID, txtFullName.Text, txtPosition.Text, url, txtMessage.Text, txtAddress.Text, txtEmail.Text, txtPhone.Text, attachFile1, attachFile2, DateTime.UtcNow); if (!string.IsNullOrEmpty(attachFile1)) { string newAttachmentsPath = VirtualPathUtility.Combine(attachmentsPath, attachFile1); uplAttachFile1.UploadedFiles[0].SaveAs(Server.MapPath(newAttachmentsPath)); } if (!string.IsNullOrEmpty(attachFile2)) { string newAttachmentsPath = VirtualPathUtility.Combine(attachmentsPath, attachFile2); uplAttachFile2.UploadedFiles[0].SaveAs(Server.MapPath(newAttachmentsPath)); } try { StringBuilder message = new StringBuilder(); //message.Append(string.Format("<a target='_blank' href='{0}'>{1}</a>", url, url) + "<br /><br />"); if (!string.IsNullOrEmpty(txtPosition.Text.Trim())) { message.Append("<b>" + NewsResources.JobPositionLabel + ":</b> " + txtPosition.Text.Trim() + "<br />"); } if (!string.IsNullOrEmpty(txtFullName.Text.Trim())) { message.Append("<b>" + NewsResources.JobFullNameLabel + ":</b> " + txtFullName.Text.Trim() + "<br />"); } if (!string.IsNullOrEmpty(txtAddress.Text.Trim())) { message.Append("<b>" + NewsResources.JobAddressLabel + ":</b> " + txtAddress.Text.Trim() + "<br />"); } if (!string.IsNullOrEmpty(txtEmail.Text.Trim())) { message.Append("<b>" + NewsResources.JobEmailLabel + ":</b> " + txtEmail.Text.Trim() + "<br />"); } if (!string.IsNullOrEmpty(txtPhone.Text.Trim())) { message.Append("<b>" + NewsResources.JobPhoneLabel + ":</b> " + txtPhone.Text.Trim() + "<br />"); } if (!string.IsNullOrEmpty(attachFile1)) { string attachFile = string.Format("<a target='_blank' href='{0}'>{1}</a>", basePage.SiteRoot + Page.ResolveUrl(NewsHelper.AttachmentsPath(siteSettings.SiteId, newsId)) + attachFile1, attachFile1); message.Append("<b>" + NewsResources.JobAttachFile1Label + ":</b> " + attachFile + "<br />"); } if (!string.IsNullOrEmpty(attachFile2)) { string attachFile = string.Format("<a target='_blank' href='{0}'>{1}</a>", basePage.SiteRoot + Page.ResolveUrl(NewsHelper.AttachmentsPath(siteSettings.SiteId, newsId)) + attachFile2, attachFile2); message.Append("<b>" + NewsResources.JobAttachFile2Label + ":</b> " + attachFile + "<br />"); } message.Append("<b>" + NewsResources.JobMessageLabel + ":</b><br />" + SiteUtils.ChangeRelativeUrlsToFullyQualifiedUrls(SiteUtils.GetNavigationSiteRoot(), WebUtils.GetSiteRoot(), txtMessage.Text)); message.Append("<br /><br />"); EmailTemplate template = EmailTemplate.Get(siteSettings.SiteId, "JobApplyNotification"); string fromAddress = siteSettings.DefaultEmailFromAddress; string fromAlias = template.FromName; if (fromAlias.Length == 0) { fromAlias = siteSettings.DefaultFromEmailAlias; } NewsHelper.SendCommentNotification( SiteUtils.GetSmtpSettings(), siteSettings.SiteGuid, fromAddress, fromAlias, template.ToAddresses, template.ReplyToAddress, template.CcAddresses, template.BccAddresses, template.Subject, template.HtmlBody, siteSettings.SiteName, message.ToString()); } catch (Exception ex) { log.Error("Error sending email from address was " + siteSettings.DefaultEmailFromAddress + " to address was " + siteSettings.CompanyPublicEmail, ex); } lblMessage.Text = MessageTemplate.GetMessage("JobApplyThankYouMessage", NewsResources.JobApplyThankYouLabel); pnlNewComment.Visible = false; }