Exemplo n.º 1
0
        /// <summary>
        /// Verifies the message allowed.
        /// </summary>
        /// <param name="count">The recipients count.</param>
        /// <param name="message">The message.</param>
        /// <returns>
        /// Returns if the user is allowed to send a message or not
        /// </returns>
        private bool VerifyMessageAllowed(int count, string message)
        {
            // Check if SPAM Message first...
            if (!this.PageContext.IsAdmin && !this.PageContext.ForumModeratorAccess && !this.Get <YafBoardSettings>().SpamServiceType.Equals(0))
            {
                var    spamChecker = new YafSpamCheck();
                string spamResult;

                // Check content for spam
                if (spamChecker.CheckPostForSpam(
                        this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName,
                        YafContext.Current.Get <HttpRequestBase>().GetUserRealIPAddress(),
                        message,
                        this.PageContext.User.Email,
                        out spamResult))
                {
                    switch (this.Get <YafBoardSettings>().SpamMessageHandling)
                    {
                    case 0:
                        this.Logger.Log(
                            this.PageContext.PageUserID,
                            "Spam Message Detected",
                            "Spam Check detected possible SPAM ({1}) posted by User: {0}"
                            .FormatWith(
                                this.PageContext.PageUserName,
                                spamResult),
                            EventLogTypes.SpamMessageDetected);
                        break;

                    case 1:
                        this.Logger.Log(
                            this.PageContext.PageUserID,
                            "Spam Message Detected",
                            "Spam Check detected possible SPAM ({1}) posted by User: {0}, it was flagged as unapproved post"
                            .FormatWith(
                                this.PageContext.PageUserName,
                                spamResult),
                            EventLogTypes.SpamMessageDetected);
                        break;

                    case 2:
                        this.Logger.Log(
                            this.PageContext.PageUserID,
                            "Spam Message Detected",
                            "Spam Check detected possible SPAM ({1}) posted by User: {0}, post was rejected"
                            .FormatWith(
                                this.PageContext.PageUserName,
                                spamResult),
                            EventLogTypes.SpamMessageDetected);

                        this.PageContext.AddLoadMessage(this.GetText("SPAM_MESSAGE"), MessageTypes.danger);

                        break;

                    case 3:
                        this.Logger.Log(
                            this.PageContext.PageUserID,
                            "Spam Message Detected",
                            "Spam Check detected possible SPAM ({1}) posted by User: {0}, user was deleted and bannded"
                            .FormatWith(
                                this.PageContext.PageUserName,
                                spamResult),
                            EventLogTypes.SpamMessageDetected);

                        var userIp =
                            new CombinedUserDataHelper(
                                this.PageContext.CurrentUserData.Membership,
                                this.PageContext.PageUserID).LastIP;

                        UserMembershipHelper.DeleteAndBanUser(
                            this.PageContext.PageUserID,
                            this.PageContext.CurrentUserData.Membership,
                            userIp);

                        break;
                    }

                    return(false);
                }

                // Check posts for urls if the user has only x posts
                if (YafContext.Current.CurrentUserData.NumPosts
                    <= YafContext.Current.Get <YafBoardSettings>().IgnoreSpamWordCheckPostCount&&
                    !this.PageContext.IsAdmin && !this.PageContext.ForumModeratorAccess)
                {
                    var urlCount = UrlHelper.CountUrls(message);

                    if (urlCount > this.PageContext.BoardSettings.AllowedNumberOfUrls)
                    {
                        spamResult = "The user posted {0} urls but allowed only {1}".FormatWith(
                            urlCount,
                            this.PageContext.BoardSettings.AllowedNumberOfUrls);

                        switch (this.Get <YafBoardSettings>().SpamMessageHandling)
                        {
                        case 0:
                            this.Logger.Log(
                                this.PageContext.PageUserID,
                                "Spam Message Detected",
                                "Spam Check detected possible SPAM ({1}) posted by User: {0}".FormatWith(
                                    this.PageContext.PageUserName,
                                    spamResult),
                                EventLogTypes.SpamMessageDetected);
                            break;

                        case 1:
                            this.Logger.Log(
                                this.PageContext.PageUserID,
                                "Spam Message Detected",
                                "Spam Check detected possible SPAM ({1}) posted by User: {0}, it was flagged as unapproved post"
                                .FormatWith(
                                    this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName,
                                    spamResult),
                                EventLogTypes.SpamMessageDetected);
                            break;

                        case 2:
                            this.Logger.Log(
                                this.PageContext.PageUserID,
                                "Spam Message Detected",
                                "Spam Check detected possible SPAM ({1}) posted by User: {0}, post was rejected"
                                .FormatWith(
                                    this.PageContext.PageUserName,
                                    spamResult),
                                EventLogTypes.SpamMessageDetected);

                            this.PageContext.AddLoadMessage(this.GetText("SPAM_MESSAGE"), MessageTypes.danger);

                            break;

                        case 3:
                            this.Logger.Log(
                                this.PageContext.PageUserID,
                                "Spam Message Detected",
                                "Spam Check detected possible SPAM ({1}) posted by User: {0}, user was deleted and bannded"
                                .FormatWith(
                                    this.PageContext.PageUserName,
                                    spamResult),
                                EventLogTypes.SpamMessageDetected);

                            var userIp =
                                new CombinedUserDataHelper(
                                    this.PageContext.CurrentUserData.Membership,
                                    this.PageContext.PageUserID).LastIP;

                            UserMembershipHelper.DeleteAndBanUser(
                                this.PageContext.PageUserID,
                                this.PageContext.CurrentUserData.Membership,
                                userIp);

                            break;
                        }

                        return(false);
                    }
                }

                return(true);
            }

            ///////////////////////////////


            // test sending user's PM count
            // get user's name
            var drPMInfo = LegacyDb.user_pmcount(YafContext.Current.PageUserID).Rows[0];

            if ((drPMInfo["NumberTotal"].ToType <int>() + count <= drPMInfo["NumberAllowed"].ToType <int>()) ||
                YafContext.Current.IsAdmin)
            {
                return(true);
            }

            // user has full PM box
            YafContext.Current.AddLoadMessage(
                this.GetTextFormatted("OWN_PMBOX_FULL", drPMInfo["NumberAllowed"]),
                MessageTypes.danger);

            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// The quick reply_ click.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void QuickReplyClick([NotNull] object sender, [NotNull] EventArgs e)
        {
            try
            {
                if (this.quickReplyEditor.Text.Length <= 0)
                {
                    YafContext.Current.PageElements.RegisterJsBlockStartup(
                        "openModalJs",
                        JavaScriptBlocks.OpenModalJs("QuickReplyDialog"));

                    this.PageContext.AddLoadMessage(this.GetText("EMPTY_MESSAGE"), MessageTypes.warning);

                    return;
                }

                // No need to check whitespace if they are actually posting something
                if (this.Get <YafBoardSettings>().MaxPostSize > 0 &&
                    this.quickReplyEditor.Text.Length >= this.Get <YafBoardSettings>().MaxPostSize)
                {
                    YafContext.Current.PageElements.RegisterJsBlockStartup(
                        "openModalJs",
                        JavaScriptBlocks.OpenModalJs("QuickReplyDialog"));

                    this.PageContext.AddLoadMessage(this.GetText("ISEXCEEDED"), MessageTypes.warning);

                    return;
                }

                if (this.EnableCaptcha() && !CaptchaHelper.IsValid(this.tbCaptcha.Text.Trim()))
                {
                    YafContext.Current.PageElements.RegisterJsBlockStartup(
                        "openModalJs",
                        JavaScriptBlocks.OpenModalJs("QuickReplyDialog"));

                    this.PageContext.AddLoadMessage(this.GetText("BAD_CAPTCHA"), MessageTypes.warning);

                    return;
                }

                if (!(this.PageContext.IsAdmin || this.PageContext.ForumModeratorAccess) &&
                    this.Get <YafBoardSettings>().PostFloodDelay > 0)
                {
                    if (YafContext.Current.Get <IYafSession>().LastPost
                        > DateTime.UtcNow.AddSeconds(-this.Get <YafBoardSettings>().PostFloodDelay))
                    {
                        YafContext.Current.PageElements.RegisterJsBlockStartup(
                            "openModalJs",
                            JavaScriptBlocks.OpenModalJs("QuickReplyDialog"));

                        this.PageContext.AddLoadMessage(
                            this.GetTextFormatted(
                                "wait",
                                (YafContext.Current.Get <IYafSession>().LastPost
                                 - DateTime.UtcNow.AddSeconds(-this.Get <YafBoardSettings>().PostFloodDelay)).Seconds),
                            MessageTypes.warning);

                        return;
                    }
                }

                YafContext.Current.Get <IYafSession>().LastPost = DateTime.UtcNow;

                // post message...
                long   messageId = 0;
                object replyTo   = -1;
                var    message   = this.quickReplyEditor.Text;
                long   topicId   = this.PageContext.PageTopicID;

                // SPAM Check

                // Check if Forum is Moderated
                DataRow forumInfo;
                var     isForumModerated = false;

                using (var dt = LegacyDb.forum_list(this.PageContext.PageBoardID, this.PageContext.PageForumID))
                {
                    forumInfo = dt.Rows[0];
                }

                if (forumInfo != null)
                {
                    isForumModerated = this.CheckForumModerateStatus(forumInfo);
                }

                var spamApproved          = true;
                var isPossibleSpamMessage = false;

                // Check for SPAM
                if (!this.PageContext.IsAdmin && !this.PageContext.ForumModeratorAccess &&
                    !this.Get <YafBoardSettings>().SpamServiceType.Equals(0))
                {
                    var    spamChecker = new YafSpamCheck();
                    string spamResult;

                    // Check content for spam
                    if (spamChecker.CheckPostForSpam(
                            this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName,
                            YafContext.Current.Get <HttpRequestBase>().GetUserRealIPAddress(),
                            this.quickReplyEditor.Text,
                            this.PageContext.IsGuest ? null : this.PageContext.User.Email,
                            out spamResult))
                    {
                        switch (this.Get <YafBoardSettings>().SpamMessageHandling)
                        {
                        case 0:
                            this.Logger.Log(
                                this.PageContext.PageUserID,
                                "Spam Message Detected",
                                "Spam Check detected possible SPAM ({1}) posted by User: {0}".FormatWith(
                                    this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName,
                                    spamResult),
                                EventLogTypes.SpamMessageDetected);
                            break;

                        case 1:
                            spamApproved          = false;
                            isPossibleSpamMessage = true;
                            this.Logger.Log(
                                this.PageContext.PageUserID,
                                "Spam Message Detected",
                                "Spam Check detected possible SPAM ({1}) posted by User: {0}, it was flagged as unapproved post"
                                .FormatWith(
                                    this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName,
                                    spamResult),
                                EventLogTypes.SpamMessageDetected);
                            break;

                        case 2:
                            this.Logger.Log(
                                this.PageContext.PageUserID,
                                "Spam Message Detected",
                                "Spam Check detected possible SPAM ({1}) posted by User: {0}, post was rejected"
                                .FormatWith(
                                    this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName,
                                    spamResult),
                                EventLogTypes.SpamMessageDetected);

                            YafContext.Current.PageElements.RegisterJsBlockStartup(
                                "openModalJs",
                                JavaScriptBlocks.OpenModalJs("QuickReplyDialog"));

                            this.PageContext.AddLoadMessage(this.GetText("SPAM_MESSAGE"), MessageTypes.danger);

                            return;

                        case 3:
                            this.Logger.Log(
                                this.PageContext.PageUserID,
                                "Spam Message Detected",
                                "Spam Check detected possible SPAM ({1}) posted by User: {0}, user was deleted and bannded"
                                .FormatWith(
                                    this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName,
                                    spamResult),
                                EventLogTypes.SpamMessageDetected);

                            var userIp = new CombinedUserDataHelper(
                                this.PageContext.CurrentUserData.Membership,
                                this.PageContext.PageUserID).LastIP;

                            UserMembershipHelper.DeleteAndBanUser(
                                this.PageContext.PageUserID,
                                this.PageContext.CurrentUserData.Membership,
                                userIp);

                            return;
                        }
                    }

                    // Check posts for urls if the user has only x posts
                    if (YafContext.Current.CurrentUserData.NumPosts
                        <= YafContext.Current.Get <YafBoardSettings>().IgnoreSpamWordCheckPostCount &&
                        !this.PageContext.IsAdmin && !this.PageContext.ForumModeratorAccess)
                    {
                        var urlCount = UrlHelper.CountUrls(this.quickReplyEditor.Text);

                        if (urlCount > this.PageContext.BoardSettings.AllowedNumberOfUrls)
                        {
                            spamResult = "The user posted {0} urls but allowed only {1}".FormatWith(
                                urlCount,
                                this.PageContext.BoardSettings.AllowedNumberOfUrls);

                            switch (this.Get <YafBoardSettings>().SpamMessageHandling)
                            {
                            case 0:
                                this.Logger.Log(
                                    this.PageContext.PageUserID,
                                    "Spam Message Detected",
                                    "Spam Check detected possible SPAM ({1}) posted by User: {0}".FormatWith(
                                        this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName,
                                        spamResult),
                                    EventLogTypes.SpamMessageDetected);
                                break;

                            case 1:
                                spamApproved          = false;
                                isPossibleSpamMessage = true;
                                this.Logger.Log(
                                    this.PageContext.PageUserID,
                                    "Spam Message Detected",
                                    "Spam Check detected possible SPAM ({1}) posted by User: {0}, it was flagged as unapproved post"
                                    .FormatWith(
                                        this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName,
                                        spamResult),
                                    EventLogTypes.SpamMessageDetected);
                                break;

                            case 2:
                                this.Logger.Log(
                                    this.PageContext.PageUserID,
                                    "Spam Message Detected",
                                    "Spam Check detected possible SPAM ({1}) posted by User: {0}, post was rejected"
                                    .FormatWith(
                                        this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName,
                                        spamResult),
                                    EventLogTypes.SpamMessageDetected);

                                YafContext.Current.PageElements.RegisterJsBlockStartup(
                                    "openModalJs",
                                    JavaScriptBlocks.OpenModalJs("QuickReplyDialog"));

                                this.PageContext.AddLoadMessage(this.GetText("SPAM_MESSAGE"), MessageTypes.danger);

                                return;

                            case 3:
                                this.Logger.Log(
                                    this.PageContext.PageUserID,
                                    "Spam Message Detected",
                                    "Spam Check detected possible SPAM ({1}) posted by User: {0}, user was deleted and bannded"
                                    .FormatWith(
                                        this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName,
                                        spamResult),
                                    EventLogTypes.SpamMessageDetected);

                                var userIp = new CombinedUserDataHelper(
                                    this.PageContext.CurrentUserData.Membership,
                                    this.PageContext.PageUserID).LastIP;

                                UserMembershipHelper.DeleteAndBanUser(
                                    this.PageContext.PageUserID,
                                    this.PageContext.CurrentUserData.Membership,
                                    userIp);

                                return;
                            }
                        }
                    }

                    if (!this.PageContext.IsGuest)
                    {
                        this.UpdateWatchTopic(this.PageContext.PageUserID, this.PageContext.PageTopicID);
                    }
                }

                // If Forum is Moderated
                if (isForumModerated)
                {
                    spamApproved = false;
                }

                // Bypass Approval if Admin or Moderator
                if (this.PageContext.IsAdmin || this.PageContext.ForumModeratorAccess)
                {
                    spamApproved = true;
                }

                var messageFlags = new MessageFlags
                {
                    IsHtml     = this.quickReplyEditor.UsesHTML,
                    IsBBCode   = this.quickReplyEditor.UsesBBCode,
                    IsApproved = spamApproved
                };

                // Bypass Approval if Admin or Moderator.
                LegacyDb.message_save(
                    topicId,
                    this.PageContext.PageUserID,
                    message,
                    null,
                    this.Get <HttpRequestBase>().GetUserRealIPAddress(),
                    null,
                    replyTo,
                    messageFlags.BitValue,
                    ref messageId);

                // Check to see if the user has enabled "auto watch topic" option in his/her profile.
                if (this.PageContext.CurrentUserData.AutoWatchTopics)
                {
                    var watchTopicId = this.GetRepository <WatchTopic>().Check(
                        this.PageContext.PageUserID,
                        this.PageContext.PageTopicID);

                    if (!watchTopicId.HasValue)
                    {
                        // subscribe to this topic
                        this.GetRepository <WatchTopic>().Add(this.PageContext.PageUserID, this.PageContext.PageTopicID);
                    }
                }

                if (messageFlags.IsApproved)
                {
                    // send new post notification to users watching this topic/forum
                    this.Get <ISendNotification>().ToWatchingUsers(messageId.ToType <int>());

                    if (Config.IsDotNetNuke && !this.PageContext.IsGuest)
                    {
                        this.Get <IActivityStream>().AddReplyToStream(
                            this.PageContext.PageForumID,
                            this.PageContext.PageTopicID,
                            messageId.ToType <int>(),
                            this.PageContext.PageTopicName,
                            message);
                    }

                    // redirect to newly posted message
                    YafBuildLink.Redirect(ForumPages.posts, "m={0}&#post{0}", messageId);
                }
                else
                {
                    if (this.Get <YafBoardSettings>().EmailModeratorsOnModeratedPost)
                    {
                        // not approved, notifiy moderators
                        this.Get <ISendNotification>().ToModeratorsThatMessageNeedsApproval(
                            this.PageContext.PageForumID,
                            messageId.ToType <int>(),
                            isPossibleSpamMessage);
                    }

                    var url = YafBuildLink.GetLink(ForumPages.topics, "f={0}", this.PageContext.PageForumID);
                    if (Config.IsRainbow)
                    {
                        YafBuildLink.Redirect(ForumPages.info, "i=1");
                    }
                    else
                    {
                        YafBuildLink.Redirect(ForumPages.info, "i=1&url={0}", this.Server.UrlEncode(url));
                    }
                }
            }
            catch (Exception exception)
            {
                if (exception.GetType() != typeof(ThreadAbortException))
                {
                    this.Logger.Log(this.PageContext.PageUserID, this, exception);
                }
            }
        }