public override void OnActionExecuting(ActionExecutingContext filterContext) { //Create a new instance of the Akismet API and verify your key is valid. Akismet api = new Akismet(ConfigurationManager.AppSettings["AkismetApiKey"], UrlUtility.VADomain, filterContext.HttpContext.Request.UserAgent); if (!api.VerifyKey()) { throw new Exception("Akismet API key invalid."); } //Now create an instance of AkismetComment, populating it with values //from the POSTed form collection. AkismetComment akismetComment = new AkismetComment { Blog = UrlUtility.VADomain, UserIp = filterContext.HttpContext.Request.UserHostAddress, UserAgent = filterContext.HttpContext.Request.UserAgent, CommentContent = filterContext.HttpContext.Request[this.CommentField], CommentType = "comment", CommentAuthor = filterContext.HttpContext.Request[this.AuthorField], CommentAuthorEmail = filterContext.HttpContext.Request[this.EmailField], CommentAuthorUrl = filterContext.HttpContext.Request[this.WebsiteField] }; //Check if Akismet thinks this comment is spam. Returns TRUE if spam. if (api.CommentCheck(akismetComment)) { //Comment is spam, add error to model state. filterContext.Controller.ViewData.ModelState.AddModelError("spam", "Comment identified as spam."); } base.OnActionExecuting(filterContext); }
public void Process(CreateCommentArgs args) { Assert.IsNotNull(args.CommentItem, "Comment Item cannot be null"); if (!string.IsNullOrEmpty(Settings.AkismetAPIKey) && !string.IsNullOrEmpty(Settings.CommentWorkflowCommandSpam)) { var workflow = args.Database.WorkflowProvider.GetWorkflow(args.CommentItem); if (workflow != null) { var api = new Akismet(Settings.AkismetAPIKey, ManagerFactory.BlogManagerInstance.GetCurrentBlog().SafeGet(x => x.Url), "WeBlog/2.1"); var isSpam = api.CommentCheck(args.CommentItem); if (isSpam) { //Need to switch to shell website to execute workflow using (new SiteContextSwitcher(SiteContextFactory.GetSiteContext(Sitecore.Constants.ShellSiteName))) { workflow.Execute(Settings.CommentWorkflowCommandSpam, args.CommentItem, "Akismet classified this comment as spam", false, new object[0]); } args.AbortPipeline(); } } } }
private bool ContattoIsSpam(string tipo, string testo, string email, HttpContext context) { bool result = false; Akismet api = new Akismet(ConfigurationManager.AppSettings["AkismetApiKey"], UrlUtility.VADomain, context.Request.UserAgent); if (!api.VerifyKey()) { throw new Exception("Akismet API key invalid."); } //Now create an instance of AkismetComment, populating it with values //from the POSTed form collection. AkismetComment akismetComment = new AkismetComment { Blog = UrlUtility.VADomain, UserIp = context.Request.UserHostAddress, UserAgent = context.Request.UserAgent, CommentContent = testo, CommentType = "comment", CommentAuthor = tipo, CommentAuthorEmail = email, CommentAuthorUrl = "" }; //Check if Akismet thinks this comment is spam. Returns TRUE if spam. result = api.CommentCheck(akismetComment); return(result); }
public bool CheckForSpam(PostComments.Comment comment) { //Create a new instance of the Akismet API and verify your key is valid. string blog = ConfigurationManager.AppSettings["MainUrl"]; var api = new Akismet(akismetKey, blog, comment.UserAgent); if (!api.VerifyKey()) { throw new Exception("Akismet API key invalid."); } var akismetComment = new AkismetComment { Blog = blog, UserIp = comment.UserHostAddress, UserAgent = comment.UserAgent, CommentContent = comment.Body, CommentType = "comment", CommentAuthor = comment.Author, CommentAuthorEmail = comment.Email, CommentAuthorUrl = comment.Url, }; //Check if Akismet thinks this comment is spam. Returns TRUE if spam. return(api.CommentCheck(akismetComment)); }
public static bool CheckForSpam(PostComments.Comment comment) { #if DEBUG return(false); #endif var api = new Akismet(AkismetKey, BlogUrl, comment.UserAgent); if (!api.VerifyKey()) { throw new Exception("Akismet API key invalid."); } var akismetComment = new AkismetComment { Blog = BlogUrl, UserIp = comment.UserHostAddress, UserAgent = comment.UserAgent, CommentContent = comment.Body, CommentType = "comment", CommentAuthor = comment.Author, CommentAuthorEmail = comment.Email, CommentAuthorUrl = comment.Url, }; //Check if Akismet thinks this comment is spam. Returns TRUE if spam. return(api.CommentCheck(akismetComment)); }
/// <summary> /// Determines whether the specified comment is spam. /// </summary> /// <param name="comment">The comment.</param> /// <returns> /// <c>true</c> if the specified comment is spam; otherwise, <c>false</c>. /// </returns> public bool IsSpam(CheckCommentForSpam comment) { if (VerifyKey) { AkismetComment akismetComment = ConvertCommentToAkismetComment(comment); return(Service.CommentCheck(akismetComment)); } return(false); }
/// <summary> /// Check if comment is spam /// </summary> /// <param name="comment">BlogEngine comment</param> /// <returns>True if comment is spam</returns> public bool Check(Comment comment) { if (api == null) { this.Initialize(); } var typePadComment = GetAkismetComment(comment); var isspam = api.CommentCheck(typePadComment); fallThrough = !isspam; return(isspam); }
public bool Check(Comment comment) { if (_api == null) { Initialize(); } AkismetComment typePadComment = GetAkismetComment(comment); bool isspam = _api.CommentCheck(typePadComment); _fallThrough = !isspam; return(isspam); }
public static int ScoreComment(Comment comment, Post p) { int score = 0; CommentSettings cs = Get(); if (string.IsNullOrEmpty(comment.Body)) { throw new Exception("No comment body found"); } if (!cs.EnableCommentOnPost(p)) { throw new Exception("No new comments are allowed on this post"); } if (comment.Body.Trim().Length < 20) { score += (-1 * (comment.Body.Trim().Length - 20)); } score += Regex.Matches(comment.Body, @"(http|ftp|https):\/\/[\w]+(.[\w]+)([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])", RegexOptions.IgnoreCase).Count; score += CountWords(comment); if (!String.IsNullOrEmpty(cs.AkismetId)) { try { AkismetComment akComment = GetComment(comment); Akismet akismet = new Akismet(cs.AkismetId, akComment.Blog, SiteSettings.Version); if (akismet.CommentCheck(akComment)) { score += cs.AkismetScore; } } catch (Exception ex) { Log.Error("Spam - Akismet", "Akismet scoring failed.\n\nReason: {0}", ex); } } return(score); }
public bool Check(Comment comment) { if (_api == null) { Initialize(); } if (_settings == null) { InitSettings(); } AkismetComment akismetComment = GetAkismetComment(comment); return(_api.CommentCheck(akismetComment)); }
private void ValidateCreatingComment(Comment comment) { var catchSpamInComments = Config.Get <AkismetModuleConfig>().ProtectComments; if (catchSpamInComments) { Akismet akismetApiClient = new Akismet(Config.Get <AkismetModuleConfig>().ApiKey, "http://www.sitefinity.com", "SitefinityAkismetModule"); if (!akismetApiClient.VerifyKey()) { return; } var newAkismetData = new AkismetData() { AkismetDataId = Guid.NewGuid(), ContentItemId = comment.Id, ItemType = typeof(Comment).FullName, UserIP = HttpContext.Current.Request.UserHostAddress, UserAgent = HttpContext.Current.Request.UserAgent, Referrer = HttpContext.Current.Request.UrlReferrer.OriginalString, }; var newComment = new AkismetComment() { Blog = "http://www.sitefinity.com", CommentContent = comment.Content, CommentType = "comment", Referrer = newAkismetData.Referrer, UserAgent = newAkismetData.UserAgent, UserIp = newAkismetData.UserIP, CommentAuthor = comment.AuthorName, CommentAuthorEmail = comment.Email, CommentAuthorUrl = comment.Website }; var isSpam = akismetApiClient.CommentCheck(newComment); if (isSpam) { comment.CommentStatus = CommentStatus.Spam; } var akismetDbContext = new AkismetEntityContext(); akismetDbContext.AkismetDataList.Add(newAkismetData); akismetDbContext.SaveChanges(); } }
public bool Check(Comment comment) { if (_api == null) { Initialize(); } if (_settings == null) { InitSettings(); } AkismetComment akismetComment = GetAkismetComment(comment); bool isSpam = _api.CommentCheck(akismetComment); _fallThrough = !isSpam; return(isSpam); }
/// <summary> /// Check if comment is spam /// </summary> /// <param name="comment"> /// BlogEngine comment /// </param> /// <returns> /// True if comment is spam /// </returns> public bool Check(Comment comment) { if (api == null) { this.Initialize(); } if (settings == null) { this.InitSettings(); } var akismetComment = GetAkismetComment(comment); var spam = api.CommentCheck(akismetComment); this.FallThrough = !spam; return(spam); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { if (String.IsNullOrEmpty(BgResources.Akismet_API_key)) { return; } if (CodeFirstSecurity.IsAuthenticated) { return; } //Create a new instance of the Akismet API and verify your key is valid. Akismet api = new Akismet(BgResources.Akismet_API_key, filterContext.HttpContext.Request.Url.AbsoluteUri, filterContext.HttpContext.Request.UserAgent); if (!api.VerifyKey()) { filterContext.Controller.ViewData.ModelState.AddModelError("akismetkey", Resources.AppMessages.AkismetApikeyInvalid); return; } //Now create an instance of AkismetComment, populating it with values //from the POSTed form collection. AkismetComment akismetComment = new AkismetComment { Blog = filterContext.HttpContext.Request.Url.Scheme + "://" + filterContext.HttpContext.Request.Url.Host, UserIp = filterContext.HttpContext.Request.UserHostAddress, UserAgent = filterContext.HttpContext.Request.UserAgent, CommentContent = filterContext.HttpContext.Request.Unvalidated()[this.CommentField], CommentType = "comment", CommentAuthor = filterContext.HttpContext.Request[this.AuthorField], CommentAuthorEmail = filterContext.HttpContext.Request[this.EmailField], CommentAuthorUrl = filterContext.HttpContext.Request[this.WebsiteField] }; //Check if Akismet thinks this comment is spam. Returns TRUE if spam. if (api.CommentCheck(akismetComment)) { filterContext.Controller.ViewData.ModelState.AddModelError("isspam", Resources.AppMessages.SpamDetected); } base.OnActionExecuting(filterContext); }
private void ValidateCreatingForumPost(ForumPost post) { var catchSpamInForums = Config.Get <AkismetModuleConfig>().ProtectForums; if (catchSpamInForums) { Akismet akismetApiClient = new Akismet(Config.Get <AkismetModuleConfig>().ApiKey, "http://www.sitefinity.com", "SitefinityAkismetModule"); if (!akismetApiClient.VerifyKey()) { return; } var newAkismetData = new AkismetData() { AkismetDataId = Guid.NewGuid(), ContentItemId = post.Id, ItemType = typeof(ForumPost).FullName, UserIP = HttpContext.Current.Request.UserHostAddress, UserAgent = HttpContext.Current.Request.UserAgent, Referrer = HttpContext.Current.Request.UrlReferrer.OriginalString }; var newForumPost = new AkismetComment() { Blog = "http://www.sitefinity.com", CommentContent = post.Content, CommentType = "comment", Referrer = newAkismetData.Referrer, UserAgent = newAkismetData.UserAgent, UserIp = newAkismetData.UserIP, }; var isSpam = akismetApiClient.CommentCheck(newForumPost); post.IsMarkedSpam = isSpam; if (isSpam) { post.IsPublished = false; } var akismetDbContext = new AkismetEntityContext(); akismetDbContext.AkismetDataList.Add(newAkismetData); akismetDbContext.SaveChanges(); } }
public bool ValidateComment(CommentPart commentPart) { CommentSettingsPartRecord commentSettingsPartRecord = _orchardServices.WorkContext.CurrentSite.As <CommentSettingsPart>().Record; string akismetKey = commentSettingsPartRecord.AkismetKey; string akismetUrl = commentSettingsPartRecord.AkismetUrl; bool enableSpamProtection = commentSettingsPartRecord.EnableSpamProtection; if (enableSpamProtection == false) { return(true); } if (String.IsNullOrEmpty(akismetKey)) { _notifer.Information(T("Please configure your Akismet key for spam protection")); return(true); } if (String.IsNullOrEmpty(akismetUrl)) { akismetUrl = "http://www.orchardproject.net"; } Akismet akismetApi = new Akismet(akismetKey, akismetUrl, null); AkismetComment akismetComment = new AkismetComment { CommentAuthor = commentPart.Record.Author, CommentAuthorEmail = commentPart.Record.Email, Blog = akismetUrl, CommentAuthorUrl = commentPart.Record.SiteName, CommentContent = commentPart.Record.CommentText, UserAgent = HttpContext.Current.Request.UserAgent, }; if (akismetApi.VerifyKey()) { return(!akismetApi.CommentCheck(akismetComment)); // CommentCheck returning true == spam } return(false); }
/// <summary> /// Gets Comments out of XML files, which follow the BlogEngine.NET format. /// </summary> /// <param name = "folderSystemPath">Folder where XML files are located</param> public void ExportToWxr(string folderSystemPath) { Action <string> die = dieLog => { Debug.WriteLine(dieLog); throw new Exception(dieLog); }; if (String.IsNullOrEmpty(folderSystemPath)) { die("Null Path"); } var files = Directory.GetFiles(folderSystemPath); var xmlFiles = (from file in files where file.EndsWith(".xml") select file).ToList(); if (!xmlFiles.Any()) { die("No XML Files found"); } wxr = new XmlDocument(); wxr.AppendChild(wxr.CreateNode(XmlNodeType.XmlDeclaration, null, null)); var rss = XElement("rss"); foreach (var ns in namespaces) { rss.SetAttribute("xmlns:" + ns.Key, ns.Value); } wxr.AppendChild(rss); var root = XElement("channel"); rss.AppendChild(root); foreach (var postFile in xmlFiles) { Log("Working on file : " + postFile); var postDoc = new XmlDocument(); postDoc.Load(postFile); var title = Get(postDoc, "post/title"); var slug = Get(postDoc, "post/slug"); Log("Title : " + title); var item = XElement("item"); root.AppendChild(item); item.AppendChild(XElement("title", title)); item.AppendChild(XElement("link", Get(postDoc, "WHAT TO DO HERE?"))); item.AppendChild(XElement("dsq:thread_identifier", slug)); item.AppendChild(XElement("wp:post_date_gmt", Get(postDoc, "pubDate"))); item.AppendChild(XElement("content:encoded", wxr.CreateCDataSection(Get(postDoc, "content")))); item.AppendChild(XElement("wp:post_id", slug)); item.AppendChild(XElement("wp:comment_status", "open")); item.AppendChild(XElement("wp:ping_status", "open")); item.AppendChild(XElement("wp:post_type", "post")); foreach (XmlNode node in postDoc.SelectNodes("post/comments/comment")) { var comment = new AkismetComment(); comment.Blog = "http://zasz.me/Blog"; comment.UserIp = Get(node, "ip"); comment.CommentContent = Get(node, "content"); comment.CommentAuthor = Get(node, "author"); comment.CommentAuthorEmail = Get(node, "email"); comment.CommentAuthorUrl = Get(node, "website"); comment.CommentType = "comment"; if (api.CommentCheck(comment)) { continue; } var cmt = XElement("wp:comment"); cmt.AppendChild(XElement("wp:comment_id", (++commentCount).ToString())); cmt.AppendChild(XElement("wp:comment_author", wxr.CreateCDataSection(comment.CommentAuthor))); cmt.AppendChild(XElement("wp:comment_author_email", comment.CommentAuthorEmail)); cmt.AppendChild(XElement("wp:comment_author_url", comment.CommentAuthorUrl)); cmt.AppendChild(XElement("wp:comment_author_IP", comment.UserIp)); var date = DateTime.Parse(Get(node, "date")).ToString(dateFormat); cmt.AppendChild(XElement("wp:comment_date", date)); cmt.AppendChild(XElement("wp:comment_date_gmt", date)); cmt.AppendChild(XElement("wp:comment_content", wxr.CreateCDataSection(comment.CommentContent))); cmt.AppendChild(XElement("wp:comment_approved", "1")); item.AppendChild(cmt); } } wxr.Save(folderSystemPath + @"\Comments\CommentsWXRAksimetFiltered.xml"); }