Пример #1
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();
                    }
                }
            }
        }
Пример #2
0
        public bool ValidateComment(Comment comment) {
            CommentSettingsRecord commentSettingsRecord = CurrentSite.As<CommentSettings>().Record;
            string akismetKey = commentSettingsRecord.AkismetKey;
            string akismetUrl = commentSettingsRecord.AkismetUrl;
            bool enableSpamProtection = commentSettingsRecord.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 = comment.Record.Author,
                CommentAuthorEmail = comment.Record.Email,
                Blog = comment.Record.SiteName,
                CommentAuthorUrl = comment.Record.SiteName,
                CommentContent = comment.Record.CommentText,
                UserAgent = HttpContext.Current.Request.UserAgent,
            };

            if (akismetApi.VerifyKey()) {
                return akismetApi.CommentCheck(akismetComment);
            }

            return false;
        }
Пример #3
0
    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();
    }
 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;
 }
Пример #5
0
        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");
        }
Пример #6
0
    protected void SettingsSave_Click(object sender, EventArgs e)
    {
        try
        {
            if (!string.IsNullOrEmpty(txtAkismetId.Text.Trim()))
            {
                Macros m = new Macros();
                Joel.Net.Akismet akismet = new Joel.Net.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;
        }
    }
Пример #7
0
    protected void SettingsSave_Click(object sender, EventArgs e)
    {
        try
        {
            if (!string.IsNullOrEmpty(txtAkismetId.Text.Trim()))
            {
                Macros           m       = new Macros();
                Joel.Net.Akismet akismet = new Joel.Net.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;
        }
    }
Пример #8
0
		public static void MarkHam(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.SubmitHam(akismetComment);
#endif
		}
Пример #9
0
        public static bool CheckForSpam(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,
            };

            //Check if Akismet thinks this comment is spam. Returns TRUE if spam.
            return api.CommentCheck(akismetComment);
        }
Пример #10
0
        public void MarkHam(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.SubmitHam(akismetComment);
            #endif
        }
Пример #11
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);
        }
Пример #12
0
        internal static bool CheckCommentForSpamUsingAkismet(HttpRequest request, string name, 
                        string email, string webSite, string feedbackText)
        {
            //Test spam username: viagra-test-123
            Akismet akismetAPI = new Akismet(CacheHandler.GetBlogConfig().AkismetApiKey,
                "http://www." + CacheHandler.GetBlogConfig().Host, "Test/1.0");
            if (!akismetAPI.VerifyKey())
            {
                throw new Exception("Akismet key could not be verified.");
            }
            AkismetComment comment = new AkismetComment();
            comment.Blog = "http://www." + CacheHandler.GetBlogConfig().Host;
            comment.UserIp = request.UserHostAddress;
            comment.UserAgent = request.UserAgent;
            comment.CommentContent = feedbackText;
            comment.CommentType = "comment";
            comment.CommentAuthor = name;
            comment.CommentAuthorEmail = email;
            comment.CommentAuthorUrl = webSite;

            bool spamCheck = akismetAPI.CommentCheck(comment);
            return spamCheck;
        }
Пример #13
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, string.Format("BlogEngine.NET {0}", BlogSettings.Instance.Version()));

            return Api.VerifyKey();
        }
Пример #14
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;
        }
Пример #15
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 1.6");

            return api.VerifyKey();
        }
Пример #16
0
        private Akismet Initialize(int nodeid)
        {
             umbraco.presentation.nodeFactory.Node blog = 
                new umbraco.presentation.nodeFactory.Node(nodeid);

            while (blog.NodeTypeAlias != "Blog")
            {
                blog = blog.Parent;
            }

            if (blog.GetProperty("akismetAPIKey").Value != string.Empty)
            {
                Akismet api = new Joel.Net.Akismet(
                    blog.GetProperty("akismetAPIKey").Value,
                    "http://" + HttpContext.Current.Request.ServerVariables["HTTP_HOST"] + blog.Url,
                    "Blog4Umbraco2");

                if (!api.VerifyKey())
                {
                    umbraco.BusinessLogic.Log.Add(
                        umbraco.BusinessLogic.LogTypes.Error,
                        -1,
                        "Akismet Key could not be verified, please check if you have a valid Akismet API Key");

                    return null;
                }
                else
                {
                    return api;
                }
            }
            else
            {
                return null;
            }
        }
Пример #17
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;
        }
Пример #18
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);
        }
Пример #19
0
        /// <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();
        }
 /// <summary>
 /// Initializes the <see cref="CommentSpamService"/> class.
 /// </summary>
 static CommentSpamService()
 {
     Service = new Akismet("key", "http://www.momntz.com", "Momntz/2.0");
     VerifyKey = Service.VerifyKey();
 }