Exemple #1
1
        public async Task CheckComment_Spam()
        {
            var key = ConfigurationManager.AppSettings["apiKey"];
            var akismet = new Akismet(key, new Uri("http://www.mysite.com"), ApplicationName);
            Assert.True(await akismet.VerifyKeyAsync());

            var comment = akismet.CreateComment();
            comment.UserIp = "127.0.0.1";
            comment.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1";
            comment.Referrer = "http://www.google.com";
            comment.Permalink = "/blog/post_one";
            comment.CommentType = CommentTypes.Comment;
            comment.CommentAuthor = "nike air max bw";
            comment.CommentAuthorEmail = "";
            comment.CommentAuthorUrl = "http://forum.fxdteam.com/profile/RetaWerth";
            comment.CommentContent = "Howdy! I simply would like to offer you a big thumbs up for your excellent info you have here on this post. I will be returning to your site for more soon.";

            var result = await akismet.CheckCommentAsync(comment);

            Assert.Equal(CommentCheck.Spam, result);
        }
Exemple #2
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
        }
Exemple #3
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);
        }
        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);
        }
Exemple #5
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));
        }
Exemple #6
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));
        }
Exemple #7
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
        }
Exemple #8
0
        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();
                    }
                }
            }
        }
Exemple #9
0
        public async Task VerifyKey_Success()
        {
            var key = ConfigurationManager.AppSettings["apiKey"];

            var akismet = new Akismet(key, new Uri("http://www.mysite.com"), ApplicationName);
            var isValid = await akismet.VerifyKeyAsync();

            Assert.True(isValid);
        }
Exemple #10
0
        public async Task VerifyKey_Fail()
        {
            var key = "somefakekeyforunittesting";

            var akismet = new Akismet(key, new Uri("http://www.mysite.com"), ApplicationName);
            var isValid = await akismet.VerifyKeyAsync();

            Assert.False(isValid);
        }
Exemple #11
0
        public static Akismet GetAkismetApi()
        {
            var akismetApi = new Akismet(AkismetApiKey, "http://our.umbraco.org", "OurUmbraco/1.0");

            if (akismetApi.VerifyKey() == false)
            {
                throw new Exception("Akismet API key could not be verified");
            }

            return(akismetApi);
        }
        private Akismet Connect()
        {
            var settings = settingsProvider.GetSettings <FunnelWebSettings>();
            var akismet  = new Akismet(
                settings.AkismetApiKey,
                "http://www.funnelweblog.com",
                "FunnelWeb/1.0"
                );

            akismet.VerifyKey();
            return(akismet);
        }
Exemple #13
0
    public bool Initialize()
    {
        if (!ExtensionManager.ExtensionEnabled("AkismetFilter"))
            return false;

        if (_settings == null) InitSettings();

        _site = _settings.GetSingleValue("SiteURL");
        _key = _settings.GetSingleValue("ApiKey");
        _api = new Akismet(_key, _site, "BlogEngine.net 1.6");

        return _api.VerifyKey();
    }
        /// <summary>
        /// Initializes anti-spam service
        /// </summary>
        /// <returns>
        /// True if service online and credentials validated
        /// </returns>
        public bool Initialize()
        {
            if (!ExtensionManager.ExtensionEnabled("TypePadFilter"))
            {
                return(false);
            }

            site = settings.GetSingleValue("SiteURL");
            key  = settings.GetSingleValue("ApiKey");
            api  = new Akismet(key, site, "BlogEngine.net 1.5", "api.antispam.typepad.com");

            return(api.VerifyKey());
        }
        public CommentsExport()
        {
            namespaces.Add("wp", nsWp);
            namespaces.Add("dsq", nsDSQ);
            namespaces.Add("content", nsContent);
            namespaces.Add("excerpt", nsExcerpt);
            namespaces.Add("wfw", nsWfw);
            namespaces.Add("dc", nsDc);

            api = new Akismet(AkismetApiKey, "http://zasz.me/", "Test/1.0");
            if (!api.VerifyKey())
            {
                throw new Exception("Key not verified");
            }
        }
Exemple #16
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);
        }
Exemple #17
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);
                        }
                    }
                }
            }
        }
Exemple #18
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();
            }
        }
Exemple #19
0
    protected void SettingsSave_Click(object sender, EventArgs e)
    {
        try
        {
            if (!string.IsNullOrEmpty(txtAkismetId.Text.Trim()))
            {
                Macros  m       = new Macros();
                Akismet akismet = new Akismet(txtAkismetId.Text.Trim(), m.FullUrl(new Urls().Home),
                                              SiteSettings.Version);
                if (!akismet.VerifyKey())
                {
                    Message.Text = "Your Akismet key could not be verified. Please check it and re-enter it.";
                    Message.Type = StatusType.Error;
                    return;
                }
            }

            CommentSettings settings = CommentSettings.Get();
            settings.EnableCommentsDefault = EnableComments.Checked;
            settings.CommentDays           = Int32.Parse(CommentDays.SelectedValue);
            settings.Email     = txtEmail.Text;
            settings.SpamScore = Int32.Parse(txtSpamScore.Text);

            if (chkUseAkismet.Checked && String.IsNullOrEmpty(txtAkismetId.Text))
            {
                Message.Text = "Please provide your Akismet Id.";
                Message.Type = StatusType.Error;
                return;
            }

            settings.UseAkismet = chkUseAkismet.Checked;

            settings.AkismetId    = txtAkismetId.Text;
            settings.AkismetScore = Int32.Parse(txtAkismetScore.Text);

            settings.Save();

            Message.Text = "Your Comment & Spam settings have been updated!";
            Message.Type = StatusType.Success;
        }
        catch (Exception ex)
        {
            Message.Text = "Your Comment & Spam settings could not be updated. Reason: " + ex.Message;
            Message.Type = StatusType.Error;
        }
    }
Exemple #20
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);
                        }
                    }
                }
            }
        }
Exemple #21
0
    public bool Initialize()
    {
        if (!ExtensionManager.ExtensionEnabled("AkismetFilter"))
        {
            return(false);
        }

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

        _site = _settings.GetSingleValue("SiteURL");
        _key  = _settings.GetSingleValue("ApiKey");
        _api  = new Akismet(_key, _site, "BlogEngine.net 1.6");

        return(_api.VerifyKey());
    }
Exemple #22
0
        /// <summary>
        /// Initializes anti-spam service
        /// </summary>
        /// <returns>
        /// True if service online and credentials validated
        /// </returns>
        public bool Initialize()
        {
            if (!ExtensionManager.ExtensionEnabled("AkismetFilter"))
            {
                return(false);
            }

            if (Settings == null)
            {
                this.InitSettings();
            }

            Site = Settings.GetSingleValue("SiteURL");
            Key  = Settings.GetSingleValue("ApiKey");
            Api  = new Akismet(Key, Site, $"BlogEngine.NET {BlogSettings.Instance.Version()}");

            return(Api.VerifyKey());
        }
Exemple #23
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();
            }
        }
        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);
        }
Exemple #25
0
        public JsonResult ChangeSpamMark(int id)
        {
            Comment comment = CommentServices.FindEntityByIdentity(id);

            //Create a new instance of the Akismet API and verify your key is valid.
            Akismet api = new Akismet(BgResources.Akismet_API_key, Request.Url.AbsoluteUri, HttpContext.Request.UserAgent);

            if (!api.VerifyKey())
            {
                return(Json(new { result = "error", text = Resources.AppMessages.AkismetApikeyInvalid }));
            }

            //Now create an instance of AkismetComment, populating it with values
            //from the POSTed form collection.
            AkismetComment akismetComment = new AkismetComment
            {
                Blog               = Request.Url.Scheme + "://" + Request.Url.Host,
                UserIp             = comment.Ip,
                UserAgent          = comment.UserAgent,
                CommentContent     = comment.Message,
                CommentType        = "comment",
                CommentAuthor      = comment.AnonymousUser != null ? comment.AnonymousUser.Username : comment.User.Username,
                CommentAuthorEmail = comment.AnonymousUser != null ? comment.AnonymousUser.Email : comment.User.Email,
                CommentAuthorUrl   = comment.AnonymousUser != null ? comment.AnonymousUser.Web : String.Empty
            };

            if (comment.IsSpam)
            {
                comment.IsSpam = false;
                api.SubmitHam(akismetComment);
            }
            else
            {
                comment.IsSpam = true;
                api.SubmitSpam(akismetComment);
            }

            BlogServices.SaveComment(comment);

            return(Json(new { result = "ok" }));
        }
Exemple #26
0
        public void Process(CreateCommentArgs args)
        {
            Assert.IsNotNull(args.CommentItem, "Comment Item cannot be null");

            if (!string.IsNullOrEmpty(_commentSettings.AkismetAPIKey) && !string.IsNullOrEmpty(_commentSettings.CommentWorkflowCommandSpam))
            {
                var workflow = args.Database.WorkflowProvider.GetWorkflow(args.CommentItem);

                if (workflow != null)
                {
                    var api = _akismetApi;
                    if (api == null)
                    {
                        api = new Akismet();
                    }

                    var version = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;

                    var blogItem = _blogManager.GetCurrentBlog(args.CommentItem);
                    var url      = _linkManager.GetAbsoluteItemUrl(blogItem);

                    api.Init(_commentSettings.AkismetAPIKey, url, "WeBlog/" + version);

                    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(_commentSettings.CommentWorkflowCommandSpam, args.CommentItem, "Akismet classified this comment as spam", false, new object[0]);
                        }

                        args.AbortPipeline();
                    }
                }
            }
        }
Exemple #27
0
        public static void MarkAsHam(int memberId, string body, string commentType)
        {
            var akismetApi = new Akismet(AkismetApiKey, "http://our.umbraco.org", "Test/1.0");

            if (akismetApi.VerifyKey() == false)
            {
                throw new Exception("Akismet API key could not be verified");
            }

            var member = new Member(memberId);

            var comment = new AkismetComment
            {
                Blog               = "http://our.umbraco.org",
                UserIp             = member.getProperty("ip").Value.ToString(),
                CommentAuthor      = member.Text,
                CommentAuthorEmail = member.Email,
                CommentType        = commentType,
                CommentContent     = body
            };

            akismetApi.SubmitHam(comment);
        }
        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>
 /// Initializes the <see cref="CommentSpamService"/> class.
 /// </summary>
 static CommentSpamService()
 {
     Service   = new Akismet("key", "http://www.momntz.com", "Momntz/2.0");
     VerifyKey = Service.VerifyKey();
 }