示例#1
0
        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));
        }
示例#2
0
        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));
        }
示例#3
0
        public void MarkSpam(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,
            };

#if !DEBUG
            api.SubmitSpam(akismetComment);
#endif
        }
示例#4
0
    public void Report(Comment comment)
    {
        if (_api == null)
        {
            Initialize();
        }

        if (_settings == null)
        {
            InitSettings();
        }

        AkismetComment akismetComment = GetAkismetComment(comment);

        if (comment.IsApproved)
        {
            Utils.Log(string.Format("Akismet: Reporting NOT spam from \"{0}\" at \"{1}\"", comment.Author, comment.IP));
            _api.SubmitHam(akismetComment);
        }
        else
        {
            Utils.Log(string.Format("Akismet: Reporting SPAM from \"{0}\" at \"{1}\"", comment.Author, comment.IP));
            _api.SubmitSpam(akismetComment);
        }
    }
示例#5
0
        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);
        }
示例#6
0
        public static void MarkSpam(PostComments.Comment comment)
        {
            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,
            };

#if !DEBUG
            api.SubmitSpam(akismetComment);
#endif
        }
        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);
        }
示例#8
0
        public void ImplicitOperatorToAkismetComment_NullItem_ReturnsNull()
        {
            // arrange, act
            AkismetComment comment = (CommentItem)null;

            // assert
            Assert.That(comment, Is.Null);
        }
 /// <summary>
 /// This call is for submitting comments that weren't marked as spam but should've been.
 /// </summary>
 /// <param name="comment">The comment.</param>
 public void SubmitSpam(CheckCommentForSpam comment)
 {
     if (VerifyKey)
     {
         AkismetComment akismetComment = ConvertCommentToAkismetComment(comment);
         Service.SubmitSpam(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);
        }
示例#11
0
        public void Verify(Pingback pingback)
        {
            var akismet        = Connect();
            var akismetComment = new AkismetComment();

            akismetComment.Blog             = "http://www.funnelweblog.com";
            akismetComment.CommentAuthorUrl = pingback.TargetUri;
            akismetComment.CommentContent   = pingback.TargetUri;
            akismetComment.CommentType      = "pingback";

            pingback.IsSpam = akismet.CommentCheck(akismetComment);
        }
示例#12
0
    public bool Check(Comment comment)
    {
        if (_api == null)
        {
            Initialize();
        }

        AkismetComment typePadComment = GetAkismetComment(comment);
        bool           isspam         = _api.CommentCheck(typePadComment);

        _fallThrough = !isspam;
        return(isspam);
    }
示例#13
0
        private static AkismetComment GetComment(Comment zComment)
        {
            AkismetComment comment = new AkismetComment();

            comment.Blog             = new Macros().FullUrl(new Urls().Home);
            comment.CommentAuthor    = zComment.Name;
            comment.CommentAuthorUrl = zComment.WebSite;
            comment.CommentContent   = zComment.Body;
            comment.CommentType      = "comment";
            comment.UserAgent        = HttpContext.Current.Request.UserAgent;
            comment.UserIp           = zComment.IPAddress;

            return(comment);
        }
示例#14
0
        public bool CommentCheck(AkismetComment comment)
        {
            var isSpam = false;

            SpamQualifiers.ForEach(spam =>
            {
                if (!isSpam && comment.CommentContent.Contains(spam))
                {
                    isSpam = true;
                }
            });

            return(isSpam);
        }
示例#15
0
        public async Task <IActionResult> AddComment(AddCommentViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction(nameof(BlogPostBySlug), new { slug = model.Slug }));
            }

            if (model.Text != null)
            {
                model.Text = model.Text.Replace("<", "&lt;");
                model.Text = model.Text.Replace(">", "&gt;");
            }

            // validate comment isn't spam
            var comment = new AkismetComment
            {
                UserIp      = Request.HttpContext.Connection.RemoteIpAddress.ToString(),
                UserAgent   = Request.Headers["User-Agent"].ToString(),
                Author      = model.Name,
                AuthorEmail = model.Email,
                AuthorUrl   = model.Website,
                CommentType = "comment",
                Content     = model.Text,
                Permalink   = _akismetClient.BlogUrl + Url.Action(nameof(BlogPostBySlug), new { slug = model.Slug })
            };

            if (await _akismetClient.IsCommentSpam(comment))
            {
                return(RedirectToAction(nameof(BlogPostBySlug), new { slug = model.Slug }));
            }

            var addComment = new AddCommentCommand
            {
                Name       = model.Name,
                Email      = model.Email,
                Website    = model.Website,
                Text       = model.Text,
                BlogPostId = model.Id
            };

            var result = await _cp.ProcessAsync(addComment);

            if (result.Succeeded)
            {
                return(RedirectToAction(nameof(BlogPostBySlug), new { slug = model.Slug }));
            }
            _logger.LogError("Error adding comment...");

            return(RedirectToAction(nameof(BlogPostBySlug), new { slug = model.Slug }));
        }
示例#16
0
 private static AkismetComment GetAkismetComment(Comment comment)
 {
     AkismetComment akismetComment = new AkismetComment();
     akismetComment.Blog = _settings.GetSingleValue("SiteURL");
     akismetComment.UserIp = comment.IP;
     akismetComment.CommentContent = comment.Content;
     akismetComment.CommentType = "comment";
     akismetComment.CommentAuthor = comment.Author;
     akismetComment.CommentAuthorEmail = comment.Email;
     if (comment.Website != null)
     {
         akismetComment.CommentAuthorUrl = comment.Website.OriginalString;
     }
     return akismetComment;
 }
示例#17
0
    private static AkismetComment GetAkismetComment(Comment comment)
    {
        AkismetComment akismetComment = new AkismetComment();

        akismetComment.Blog               = _settings.GetSingleValue("SiteURL");
        akismetComment.UserIp             = comment.IP;
        akismetComment.CommentContent     = comment.Content;
        akismetComment.CommentAuthor      = comment.Author;
        akismetComment.CommentAuthorEmail = comment.Email;
        if (comment.Website != null)
        {
            akismetComment.CommentAuthorUrl = comment.Website.OriginalString;
        }
        return(akismetComment);
    }
示例#18
0
        public static AkismetComment ConstructAkismetComment(Member member, string commentType, string body)
        {
            var comment = new AkismetComment
            {
                Blog               = "http://our.umbraco.org",
                UserIp             = HttpContext.Current.Request.UserHostAddress,
                CommentAuthor      = member.Text,
                CommentAuthorEmail = member.Email,
                CommentType        = commentType,
                CommentContent     = body,
                UserAgent          = HttpContext.Current.Request.UserAgent
            };

            return(comment);
        }
示例#19
0
        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\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])",
                              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);
        }
示例#20
0
        private void ValidateUpdatingComment(Comment comment)
        {
            var catchSpamInComments = Config.Get <AkismetModuleConfig>().ProtectComments;

            if (catchSpamInComments)
            {
                var blogsMan        = BlogsManager.GetManager(string.Empty, "DummyTransaction");
                var existingComment = SystemManager.GetCommentsService().GetComment(comment.Id.ToString());

                if (existingComment != null && existingComment.Status != comment.Status.ToString())
                {
                    Akismet akismetApiClient = new Akismet(Config.Get <AkismetModuleConfig>().ApiKey, "http://www.sitefinity.com", "SitefinityAkismetModule");
                    if (!akismetApiClient.VerifyKey())
                    {
                        return;
                    }

                    var akismetDbContext    = new AkismetEntityContext();
                    var existingAkismetData = akismetDbContext.AkismetDataList.SingleOrDefault(a => a.ContentItemId == comment.Id);
                    if (existingAkismetData != null)
                    {
                        var updatedComment = new AkismetComment()
                        {
                            Blog               = "http://www.sitefinity.com",
                            CommentContent     = comment.Content,
                            CommentType        = "comment",
                            Referrer           = existingAkismetData.Referrer,
                            UserAgent          = existingAkismetData.UserAgent,
                            UserIp             = existingAkismetData.UserIP,
                            CommentAuthor      = comment.AuthorName,
                            CommentAuthorEmail = comment.Email,
                            CommentAuthorUrl   = comment.Website
                        };

                        if (comment.CommentStatus.ToString() == Telerik.Sitefinity.Services.Comments.StatusConstants.Spam)
                        {
                            // the item has been marked as spam
                            akismetApiClient.SubmitSpam(updatedComment);
                        }
                        else
                        {
                            // the item has been marked as ham
                            akismetApiClient.SubmitHam(updatedComment);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Converts the comment to akismet comment.
        /// </summary>
        /// <param name="comment">The comment.</param>
        /// <returns></returns>
        private AkismetComment ConvertCommentToAkismetComment(CheckCommentForSpam comment)
        {
            AkismetComment akismet = new AkismetComment
            {
                Blog               = "http://momntz.com",
                CommentAuthor      = comment.Author,
                CommentAuthorEmail = comment.AuthorEmail,
                CommentAuthorUrl   = comment.AuthorUrl,
                CommentContent     = comment.Body,
                CommentType        = "comment",
                UserAgent          = comment.UserAgent,
                UserIp             = comment.UserIP
            };

            return(akismet);
        }
示例#22
0
    public bool Check(Comment comment)
    {
        if (_api == null)
        {
            Initialize();
        }

        if (_settings == null)
        {
            InitSettings();
        }

        AkismetComment akismetComment = GetAkismetComment(comment);

        return(_api.CommentCheck(akismetComment));
    }
示例#23
0
        public void SubmitHam()
        {
            var comment = new AkismetComment
            {
                Blog      = blog,
                UserIp    = "127.0.0.1",
                UserAgent =
                    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
                CommentContent     = "Hey, I'm testing out the Akismet API!",
                CommentType        = "blog",
                CommentAuthor      = "Joel",
                CommentAuthorEmail = "",
                CommentAuthorUrl   = ""
            };

            api.SubmitHam(comment);
        }
示例#24
0
        public void SubmitSpam()
        {
            var comment = new AkismetComment
            {
                Blog           = blog,
                UserIp         = "147.202.45.202",
                UserAgent      = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)",
                CommentContent =
                    "A friend of mine told me about this place. I'm just wondering if this thing works.   You check this posts everyday incase <a href=\"http://someone.finderinn.com\">find someone</a> needs some help?  I think this is a great job! Really nice place http://someone.finderinn.com here.   I found a lot of interesting stuff all around.  I enjoy beeing here and i'll come back soon. Many greetings.",
                CommentType        = "blog",
                CommentAuthor      = "someone",
                CommentAuthorEmail = "*****@*****.**",
                CommentAuthorUrl   = "http://someone.finderinn.com"
            };

            api.SubmitSpam(comment);
        }
示例#25
0
        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();
            }
        }
示例#26
0
        private void ValidateUpdatingForumPost(ForumPost post, string origin, Guid userId)
        {
            var catchSpamInForums = Config.Get <AkismetModuleConfig>().ProtectForums;

            if (catchSpamInForums)
            {
                var forumsMan = ForumsManager.GetManager(string.Empty, "DummyTransaction");

                var existingPost = forumsMan.GetPost(post.Id);
                if (existingPost != null && existingPost.IsMarkedSpam != post.IsMarkedSpam)
                {
                    Akismet akismetApiClient = new Akismet(Config.Get <AkismetModuleConfig>().ApiKey, "http://www.sitefinity.com", "SitefinityAkismetModule");
                    if (!akismetApiClient.VerifyKey())
                    {
                        return;
                    }

                    var akismetDbContext    = new AkismetEntityContext();
                    var existingAkismetData = akismetDbContext.AkismetDataList.SingleOrDefault(a => a.ContentItemId == post.Id);
                    if (existingAkismetData != null)
                    {
                        var updatedForumPost = new AkismetComment()
                        {
                            Blog           = "http://www.sitefinity.com",
                            CommentContent = post.Content,
                            CommentType    = "comment",
                            Referrer       = existingAkismetData.Referrer,
                            UserAgent      = existingAkismetData.UserAgent,
                            UserIp         = existingAkismetData.UserIP,
                        };

                        if (post.IsMarkedSpam)
                        {
                            // the item has been marked as spam
                            akismetApiClient.SubmitSpam(updatedForumPost);
                        }
                        else
                        {
                            // the item has been marked as ham
                            akismetApiClient.SubmitHam(updatedForumPost);
                        }
                    }
                }
            }
        }
示例#27
0
    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>
        /// Gets the akismet comment.
        /// </summary>
        /// <param name="comment">The comment.</param>
        /// <returns>An Akismet Comment.</returns>
        private static AkismetComment GetAkismetComment(Comment comment)
        {
            var akismetComment = new AkismetComment
            {
                Blog               = settings.GetSingleValue("SiteURL"),
                UserIp             = comment.IP,
                CommentContent     = comment.Content,
                CommentAuthor      = comment.Author,
                CommentAuthorEmail = comment.Email
            };

            if (comment.Website != null)
            {
                akismetComment.CommentAuthorUrl = comment.Website.OriginalString;
            }

            return(akismetComment);
        }
示例#29
0
        public void NonSpamTest()
        {
            var comment = new AkismetComment
            {
                Blog      = blog,
                UserIp    = "127.0.0.1",
                UserAgent =
                    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
                CommentContent     = "Hey, I'm testing out the Akismet API!",
                CommentType        = "blog",
                CommentAuthor      = "Joel",
                CommentAuthorEmail = "",
                CommentAuthorUrl   = ""
            };

            bool result = api.CommentCheck(comment);

            Assert.IsFalse(result, "API was expected to return 'False' when 'True' was returned instead.");
        }
示例#30
0
        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();
            }
        }
示例#31
0
        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);
        }
示例#32
0
        public static bool IsSpam(string ApiKey, string domain, PostComments.Comment comment)
        {
            #if DEBUG
            return false;
            #endif
            var validator = new AkismetValidator(ApiKey);
            if (!validator.VerifyKey(domain)) throw new Exception("Akismet API key invalid.");

            var akismetComment = new AkismetComment
            {
                blog = domain,
                user_ip= comment.UserHostAddress,
                user_agent = comment.UserAgent,
                comment_content= comment.Content,
                comment_type= "comment",
                comment_author = comment.Author,
                comment_author_email = comment.Email,
                comment_author_url= comment.Website,
            };

            //Check if Akismet thinks this comment is spam. Returns TRUE if spam.
            return validator.IsSpam(akismetComment);
        }
示例#33
0
        /// <summary>
        /// Prepare request parameters based on the input comment.
        /// </summary>
        /// <param name="comment">The input comment.</param>
        /// <returns>The prepared parameters if any.</returns>
        protected virtual NameValueCollection PreparePars(AkismetComment comment)
        {
            // check the input parameters
            if ((null != comment) && (!comment.IsValid))
                return null;

            // initialize result
            NameValueCollection result = new NameValueCollection();

            // add required information
            result["blog"] = HttpUtility.UrlEncode(comment.blog);
            result["user_ip"] = HttpUtility.UrlEncode(comment.user_ip);
            result["user_agent"] = HttpUtility.UrlEncode(comment.user_agent);
            // add optional information
            result["referrer"] = String.IsNullOrEmpty(comment.referrer) ? String.Empty : HttpUtility.UrlEncode(comment.referrer);
            result["permalink"] = String.IsNullOrEmpty(comment.permalink) ? String.Empty : HttpUtility.UrlEncode(comment.permalink);
            result["comment_type"] = String.IsNullOrEmpty(comment.comment_type) ? String.Empty : HttpUtility.UrlEncode(comment.comment_type);
            result["comment_author"] = String.IsNullOrEmpty(comment.comment_author) ? String.Empty : HttpUtility.UrlEncode(comment.comment_author);
            result["comment_author_email"] = String.IsNullOrEmpty(comment.comment_author_email) ? String.Empty : HttpUtility.UrlEncode(comment.comment_author_email);
            result["comment_author_url"] = String.IsNullOrEmpty(comment.comment_author_url) ? String.Empty : HttpUtility.UrlEncode(comment.comment_author_url);
            result["comment_content"] = String.IsNullOrEmpty(comment.comment_content) ? String.Empty : HttpUtility.UrlEncode(comment.comment_content);

            // return result
            return result;
        }
示例#34
0
        /// <summary>
        /// Check if the input comment is valid or not.
        /// </summary>
        /// <param name="comment">The input comment to be checked.</param>
        /// <returns>True if the comment is valid, false otherwise.</returns>
        public Boolean IsSpam(AkismetComment comment)
        {
            // prepare pars for the request
            NameValueCollection pars = PreparePars(comment);
            if (null != pars)
            {
                // extract result from the request
                return ExtractResult(PostRequest(String.Format("http://{0}.rest.akismet.com/1.1/comment-check", m_key), pars));
            }

            // return no spam
            return false;
        }
示例#35
0
 public AkismetStatus(AkismetComment comment)
 {
     Comment = comment;
 }
示例#36
0
 /// <summary>
 /// This call is for submitting comments that weren't marked as spam but should've been.
 /// </summary>
 /// <param name="comment">The input comment to be sent as spam.</param>
 /// <returns>True if the comment was successfully sent, false otherwise.</returns>
 public void SubmitSpam(AkismetComment comment)
 {
     // prepare pars for the request
     NameValueCollection pars = PreparePars(comment);
     if (null != pars)
     {
         PostRequest(String.Format("http://{0}.rest.akismet.com/1.1/submit-spam", m_key), pars);
     }
 }