Exemple #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));
        }
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 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 #4
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
        }
        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 #6
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);
        }
Exemple #7
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);
        }
        /// <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());
        }
Exemple #10
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();
    }
        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 #12
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 #13
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 #14
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 #15
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 #16
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 #17
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 #18
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 #20
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 #21
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();
 }