Example #1
0
        /// <summary>
        /// Handles the PostReply click including: Replying, Editing and New post.
        /// </summary>
        /// <param name="sender">
        /// The Sender Object.
        /// </param>
        /// <param name="e">
        /// The Event Arguments.
        /// </param>
        protected void PostReply_Click([NotNull] object sender, [NotNull] EventArgs e)
        {
            if (!this.IsPostReplyVerified())
            {
                return;
            }

            if (this.IsPostReplyDelay())
            {
                return;
            }

            var isPossibleSpamMessage = false;

            // Check for SPAM
            if (!this.PageContext.IsAdmin && !this.PageContext.ForumModeratorAccess &&
                !this.PageContext.BoardSettings.SpamServiceType.Equals(0))
            {
                // Check content for spam
                if (
                    this.Get <ISpamCheck>().CheckPostForSpam(
                        this.PageContext.IsGuest ? this.From.Text : this.PageContext.User.DisplayOrUserName(),
                        this.Get <HttpRequestBase>().GetUserRealIPAddress(),
                        BBCodeHelper.StripBBCode(
                            HtmlHelper.StripHtml(HtmlHelper.CleanHtmlString(this.forumEditor.Text)))
                        .RemoveMultipleWhitespace(),
                        this.PageContext.IsGuest ? null : this.PageContext.MembershipUser.Email,
                        out var spamResult))
                {
                    var description =
                        $"Spam Check detected possible SPAM ({spamResult}) posted by User: {(this.PageContext.IsGuest ? "Guest" : this.PageContext.User.DisplayOrUserName())}";

                    switch (this.PageContext.BoardSettings.SpamMessageHandling)
                    {
                    case 0:
                        this.Logger.SpamMessageDetected(
                            this.PageContext.PageUserID,
                            description);
                        break;

                    case 1:
                        this.spamApproved     = false;
                        isPossibleSpamMessage = true;
                        this.Logger.SpamMessageDetected(
                            this.PageContext.PageUserID,
                            $"{description}, it was flagged as unapproved post.");
                        break;

                    case 2:
                        this.Logger.SpamMessageDetected(
                            this.PageContext.PageUserID,
                            $"{description}, post was rejected");
                        this.PageContext.AddLoadMessage(this.GetText("SPAM_MESSAGE"), MessageTypes.danger);
                        return;

                    case 3:
                        this.Logger.SpamMessageDetected(
                            this.PageContext.PageUserID,
                            $"{description}, user was deleted and banned");

                        this.Get <IAspNetUsersHelper>().DeleteAndBanUser(
                            this.PageContext.PageUserID,
                            this.PageContext.MembershipUser,
                            this.PageContext.User.IP);

                        return;
                    }
                }
            }

            if (this.Get <ISpamCheck>().ContainsSpamUrls(this.forumEditor.Text))
            {
                return;
            }

            // update the last post time...
            this.Get <ISession>().LastPost = DateTime.UtcNow.AddSeconds(30);

            // Reply to topic
            int?messageId = this.PostReplyHandleReplyToTopic(this.spamApproved);

            var isApproved = this.spamApproved;

            // vzrus^ the poll access controls are enabled and this is a new topic - we add the variables
            var attachPollParameter = string.Empty;
            var returnForum         = string.Empty;

            if (this.PageContext.ForumPollAccess && this.PostOptions1.PollOptionVisible)
            {
                // new topic poll token
                attachPollParameter = $"&t={this.TopicId}";

                // new return forum poll token
                returnForum = $"&f={this.PageContext.PageForumID}";
            }

            // Create notification emails
            if (isApproved)
            {
                this.Get <ISendNotification>().ToWatchingUsers(messageId.Value);

                if (!this.PageContext.IsGuest && this.PageContext.User.Activity)
                {
                    // Handle Mentions
                    BBCodeHelper.FindMentions(this.forumEditor.Text).ForEach(
                        user =>
                    {
                        var userId = this.Get <IUserDisplayName>().FindUserByName(user).ID;

                        if (userId != this.PageContext.PageUserID)
                        {
                            this.Get <IActivityStream>().AddMentionToStream(
                                userId,
                                this.TopicId,
                                messageId.ToType <int>(),
                                this.PageContext.PageUserID);
                        }
                    });

                    // Handle User Quoting
                    BBCodeHelper.FindUserQuoting(this.forumEditor.Text).ForEach(
                        user =>
                    {
                        var userId = this.Get <IUserDisplayName>().FindUserByName(user).ID;

                        if (userId != this.PageContext.PageUserID)
                        {
                            this.Get <IActivityStream>().AddQuotingToStream(
                                userId,
                                this.TopicId,
                                messageId.ToType <int>(),
                                this.PageContext.PageUserID);
                        }
                    });

                    this.Get <IActivityStream>().AddReplyToStream(
                        Config.IsDotNetNuke ? this.PageContext.PageForumID : this.PageContext.PageUserID,
                        this.TopicId,
                        messageId.ToType <int>(),
                        this.PageContext.PageTopicName,
                        this.forumEditor.Text);
                }

                if (attachPollParameter.IsNotSet() || !this.PostOptions1.PollChecked)
                {
                    // regular redirect...
                    this.Get <LinkBuilder>().Redirect(ForumPages.Posts, "m={0}&name={1}#post{0}", messageId, this.PageContext.PageTopicName);
                }
                else
                {
                    // poll edit redirect...
                    this.Get <LinkBuilder>().Redirect(ForumPages.PollEdit, "{0}", attachPollParameter);
                }
            }
            else
            {
                // Not Approved
                if (this.PageContext.BoardSettings.EmailModeratorsOnModeratedPost)
                {
                    // not approved, notify moderators
                    this.Get <ISendNotification>()
                    .ToModeratorsThatMessageNeedsApproval(
                        this.PageContext.PageForumID,
                        messageId.ToType <int>(),
                        isPossibleSpamMessage);
                }

                // 't' variable is required only for poll and this is a attach poll token for attachments page
                if (!this.PostOptions1.PollChecked)
                {
                    attachPollParameter = string.Empty;
                }

                // Tell user that his message will have to be approved by a moderator
                var url = this.Get <LinkBuilder>().GetForumLink(this.PageContext.PageForumID, this.PageContext.PageForumName);

                if (this.PageContext.PageTopicID > 0 && this.topic.NumPosts > 1)
                {
                    url = this.Get <LinkBuilder>().GetTopicLink(this.PageContext.PageTopicID, this.PageContext.PageTopicName);
                }

                if (attachPollParameter.Length <= 0)
                {
                    this.Get <LinkBuilder>().Redirect(ForumPages.Info, "i=1&url={0}", this.Server.UrlEncode(url));
                }
                else
                {
                    this.Get <LinkBuilder>().Redirect(ForumPages.PollEdit, "&ra=1{0}{1}", attachPollParameter, returnForum);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Handles the PostReply click including: Replying, Editing and New post.
        /// </summary>
        /// <param name="sender">
        /// The Sender Object.
        /// </param>
        /// <param name="e">
        /// The Event Arguments.
        /// </param>
        protected void PostReply_Click([NotNull] object sender, [NotNull] EventArgs e)
        {
            if (!this.IsPostReplyVerified())
            {
                return;
            }

            if (this.IsPostReplyDelay())
            {
                return;
            }

            var isPossibleSpamMessage = false;

            // Check for SPAM
            if (!this.PageContext.IsAdmin && !this.PageContext.ForumModeratorAccess &&
                !this.PageContext.BoardSettings.SpamServiceType.Equals(0))
            {
                // Check content for spam
                if (
                    this.Get <ISpamCheck>().CheckPostForSpam(
                        this.PageContext.IsGuest ? this.From.Text : this.PageContext.PageUserName,
                        this.Get <HttpRequestBase>().GetUserRealIPAddress(),
                        BBCodeHelper.StripBBCode(
                            HtmlHelper.StripHtml(HtmlHelper.CleanHtmlString(this.forumEditor.Text)))
                        .RemoveMultipleWhitespace(),
                        this.PageContext.IsGuest ? null : this.PageContext.User.Email,
                        out var spamResult))
                {
                    switch (this.PageContext.BoardSettings.SpamMessageHandling)
                    {
                    case 0:
                        this.Logger.Log(
                            this.PageContext.PageUserID,
                            "Spam Message Detected",
                            $"Spam Check detected possible SPAM posted by User: {(this.PageContext.IsGuest ? this.From.Text : this.PageContext.PageUserName)}",
                            EventLogTypes.SpamMessageDetected);
                        break;

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

                    case 2:
                        this.Logger.Log(
                            this.PageContext.PageUserID,
                            "Spam Message Detected",
                            $"Spam Check detected possible SPAM ({spamResult}) posted by User: {(this.PageContext.IsGuest ? this.From.Text : this.PageContext.PageUserName)}, post was rejected",
                            EventLogTypes.SpamMessageDetected);
                        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 ({spamResult}) posted by User: {(this.PageContext.IsGuest ? this.From.Text : this.PageContext.PageUserName)}, user was deleted and banned",
                            EventLogTypes.SpamMessageDetected);

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

                        this.Get <IAspNetUsersHelper>().DeleteAndBanUser(
                            this.PageContext.PageUserID,
                            this.PageContext.CurrentUserData.Membership,
                            userIp);

                        return;
                    }
                }
            }

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

                if (urlCount > this.PageContext.BoardSettings.AllowedNumberOfUrls)
                {
                    var spamResult =
                        $"The user posted {urlCount} urls but allowed only {this.PageContext.BoardSettings.AllowedNumberOfUrls}";

                    switch (this.PageContext.BoardSettings.SpamMessageHandling)
                    {
                    case 0:
                        this.Logger.Log(
                            this.PageContext.PageUserID,
                            "Spam Message Detected",
                            $"Spam Check detected possible SPAM ({spamResult}) posted by User: {(this.PageContext.IsGuest ? this.From.Text : this.PageContext.PageUserName)}",
                            EventLogTypes.SpamMessageDetected);
                        break;

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

                    case 2:
                        this.Logger.Log(
                            this.PageContext.PageUserID,
                            "Spam Message Detected",
                            $"Spam Check detected possible SPAM ({spamResult}) posted by User: {(this.PageContext.IsGuest ? this.From.Text : this.PageContext.PageUserName)}, post was rejected",
                            EventLogTypes.SpamMessageDetected);
                        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 ({spamResult}) posted by User: {(this.PageContext.IsGuest ? this.From.Text : this.PageContext.PageUserName)}, user was deleted and banned",
                            EventLogTypes.SpamMessageDetected);

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

                        this.Get <IAspNetUsersHelper>().DeleteAndBanUser(
                            this.PageContext.PageUserID,
                            this.PageContext.CurrentUserData.Membership,
                            userIp);

                        return;
                    }
                }
            }

            // update the last post time...
            this.Get <ISession>().LastPost = DateTime.UtcNow.AddSeconds(30);

            // New Topic
            var messageId = this.PostReplyHandleNewPost(out var newTopic);

            // Check if message is approved
            var isApproved = this.GetRepository <Message>().GetById(messageId.ToType <int>()).MessageFlags.IsApproved;

            // vzrus^ the poll access controls are enabled and this is a new topic - we add the variables
            var attachPollParameter = string.Empty;
            var returnForum         = string.Empty;

            if (this.PageContext.ForumPollAccess && this.PostOptions1.PollOptionVisible)
            {
                // new topic poll token
                attachPollParameter = $"&t={newTopic}";

                // new return forum poll token
                returnForum = $"&f={this.PageContext.PageForumID}";
            }

            // Create notification emails
            if (isApproved)
            {
                this.Get <ISendNotification>().ToWatchingUsers(messageId.ToType <int>());

                if (!this.PageContext.IsGuest && this.PageContext.CurrentUserData.Activity)
                {
                    // Handle Mentions
                    BBCodeHelper.FindMentions(this.forumEditor.Text).ForEach(
                        user =>
                    {
                        var userId = this.Get <IUserDisplayName>().GetId(user).Value;

                        if (userId != this.PageContext.PageUserID)
                        {
                            this.Get <IActivityStream>().AddMentionToStream(
                                userId,
                                newTopic.ToType <int>(),
                                messageId.ToType <int>(),
                                this.PageContext.PageUserID);
                        }
                    });

                    // Handle User Quoting
                    BBCodeHelper.FindUserQuoting(this.forumEditor.Text).ForEach(
                        user =>
                    {
                        var userId = this.Get <IUserDisplayName>().GetId(user).Value;

                        if (userId != this.PageContext.PageUserID)
                        {
                            this.Get <IActivityStream>().AddQuotingToStream(
                                userId,
                                newTopic.ToType <int>(),
                                messageId.ToType <int>(),
                                this.PageContext.PageUserID);
                        }
                    });

                    this.Get <IActivityStream>().AddTopicToStream(
                        Config.IsDotNetNuke ? this.PageContext.PageForumID : this.PageContext.PageUserID,
                        newTopic,
                        messageId.ToType <int>(),
                        this.TopicSubjectTextBox.Text,
                        this.forumEditor.Text);

                    // Add tags
                    if (this.Tags.Text.IsSet())
                    {
                        var tags = this.Tags.Text.Split(',');

                        var boardTags = this.GetRepository <Tag>().GetByBoardId();

                        tags.ForEach(
                            tag =>
                        {
                            var existTag = boardTags.FirstOrDefault(t => t.TagName == tag);

                            if (existTag != null)
                            {
                                // add to topic
                                this.GetRepository <TopicTag>().Add(
                                    existTag.ID,
                                    newTopic.ToType <int>());
                            }
                            else
                            {
                                // save new Tag
                                var newTagId = this.GetRepository <Tag>().Add(tag);

                                // add to topic
                                this.GetRepository <TopicTag>().Add(newTagId, newTopic.ToType <int>());
                            }
                        });
                    }
                }

                if (attachPollParameter.IsNotSet() || !this.PostOptions1.PollChecked)
                {
                    // regular redirect...
                    BuildLink.Redirect(ForumPages.Posts, "m={0}#post{0}", messageId);
                }
                else
                {
                    // poll edit redirect...
                    BuildLink.Redirect(ForumPages.PollEdit, "{0}", attachPollParameter);
                }
            }
            else
            {
                // Not Approved
                if (this.PageContext.BoardSettings.EmailModeratorsOnModeratedPost)
                {
                    // not approved, notify moderators
                    this.Get <ISendNotification>()
                    .ToModeratorsThatMessageNeedsApproval(
                        this.PageContext.PageForumID,
                        messageId.ToType <int>(),
                        isPossibleSpamMessage);
                }

                // 't' variable is required only for poll and this is a attach poll token for attachments page
                if (!this.PostOptions1.PollChecked)
                {
                    attachPollParameter = string.Empty;
                }

                // Tell user that his message will have to be approved by a moderator
                var url = BuildLink.GetLink(ForumPages.Topics, "f={0}", this.PageContext.PageForumID);

                if (attachPollParameter.Length <= 0)
                {
                    BuildLink.Redirect(ForumPages.Info, "i=1&url={0}", this.Server.UrlEncode(url));
                }
                else
                {
                    BuildLink.Redirect(ForumPages.PollEdit, "&ra=1{0}{1}", attachPollParameter, returnForum);
                }
            }
        }
Example #3
0
    /// <summary>
    /// Handles the PostReply click including: Replying, Editing and New post.
    /// </summary>
    /// <param name="sender">
    /// The Sender Object.
    /// </param>
    /// <param name="e">
    /// The Event Arguments.
    /// </param>
    protected void PostReply_Click([NotNull] object sender, [NotNull] EventArgs e)
    {
        if (!this.IsPostReplyVerified())
        {
            return;
        }

        if (this.IsPostReplyDelay())
        {
            return;
        }

        var isPossibleSpamMessage = false;

        var message = HtmlHelper.StripHtml(this.forumEditor.Text);

        // Check for SPAM
        if (!this.PageBoardContext.IsAdmin && !this.PageBoardContext.ForumModeratorAccess)
        {
            // Check content for spam
            if (
                this.Get <ISpamCheck>().CheckPostForSpam(
                    this.PageBoardContext.IsGuest ? this.From.Text : this.PageBoardContext.PageUser.DisplayOrUserName(),
                    this.Get <HttpRequestBase>().GetUserRealIPAddress(),
                    BBCodeHelper.StripBBCode(
                        HtmlHelper.StripHtml(HtmlHelper.CleanHtmlString(this.forumEditor.Text)))
                    .RemoveMultipleWhitespace(),
                    this.PageBoardContext.IsGuest ? null : this.PageBoardContext.MembershipUser.Email,
                    out var spamResult))
            {
                var description =
                    $@"Spam Check detected possible SPAM ({spamResult})
                           posted by PageUser: {(this.PageBoardContext.IsGuest ? "Guest" : this.PageBoardContext.PageUser.DisplayOrUserName())}";

                switch (this.PageBoardContext.BoardSettings.SpamPostHandling)
                {
                case SpamPostHandling.DoNothing:
                    this.Logger.SpamMessageDetected(
                        this.PageBoardContext.PageUserID,
                        description);
                    break;

                case SpamPostHandling.FlagMessageUnapproved:
                    this.spamApproved     = false;
                    isPossibleSpamMessage = true;
                    this.Logger.SpamMessageDetected(
                        this.PageBoardContext.PageUserID,
                        $"{description}, it was flagged as unapproved post.");
                    break;

                case SpamPostHandling.RejectMessage:
                    this.Logger.SpamMessageDetected(
                        this.PageBoardContext.PageUserID,
                        $"S{description}, post was rejected");
                    this.PageBoardContext.Notify(this.GetText("SPAM_MESSAGE"), MessageTypes.danger);
                    return;

                case SpamPostHandling.DeleteBanUser:
                    this.Logger.SpamMessageDetected(
                        this.PageBoardContext.PageUserID,
                        $"{description}, user was deleted and banned");

                    this.Get <IAspNetUsersHelper>().DeleteAndBanUser(
                        this.PageBoardContext.PageUserID,
                        this.PageBoardContext.MembershipUser,
                        this.PageBoardContext.PageUser.IP);

                    return;
                }
            }
        }

        // update the last post time...
        this.Get <ISession>().LastPost = DateTime.UtcNow.AddSeconds(30);

        // New Topic
        var newMessage = this.PostReplyHandleNewTopic();

        // Check if message is approved
        var isApproved = newMessage.MessageFlags.IsApproved;

        // vzrus^ the poll access controls are enabled and this is a new topic - we add the variables
        var attachPollParameter = this.PageBoardContext.ForumPollAccess && this.PostOptions1.PollOptionVisible;

        // Create notification emails
        if (isApproved)
        {
            this.Get <ISendNotification>().ToWatchingUsers(newMessage, true);

            if (!this.PageBoardContext.IsGuest && this.PageBoardContext.PageUser.Activity)
            {
                // Handle Mentions
                BBCodeHelper.FindMentions(message).ForEach(
                    user =>
                {
                    var userId = this.Get <IUserDisplayName>().FindUserByName(user).ID;

                    if (userId != this.PageBoardContext.PageUserID)
                    {
                        this.Get <IActivityStream>().AddMentionToStream(
                            userId,
                            newMessage.TopicID,
                            newMessage.ID,
                            this.PageBoardContext.PageUserID);
                    }
                });

                // Handle User Quoting
                BBCodeHelper.FindUserQuoting(message).ForEach(
                    user =>
                {
                    var userId = this.Get <IUserDisplayName>().FindUserByName(user).ID;

                    if (userId != this.PageBoardContext.PageUserID)
                    {
                        this.Get <IActivityStream>().AddQuotingToStream(
                            userId,
                            newMessage.TopicID,
                            newMessage.ID,
                            this.PageBoardContext.PageUserID);
                    }
                });

                this.Get <IActivityStream>().AddTopicToStream(
                    Config.IsDotNetNuke ? this.PageBoardContext.PageForumID : this.PageBoardContext.PageUserID,
                    newMessage.TopicID,
                    newMessage.ID,
                    HtmlHelper.StripHtml(this.TopicSubjectTextBox.Text),
                    message);

                // Add tags
                if (this.TagsValue.Value.IsSet())
                {
                    this.GetRepository <TopicTag>().AddTagsToTopic(this.TagsValue.Value, newMessage.TopicID);
                }
            }

            if (!attachPollParameter || !this.PostOptions1.PollChecked)
            {
                // regular redirect...
                this.Get <LinkBuilder>().Redirect(ForumPages.Posts, new { m = newMessage.ID, name = newMessage.Topic.TopicName });
            }
            else
            {
                // poll edit redirect...
                this.Get <LinkBuilder>().Redirect(ForumPages.PollEdit, new { t = newMessage.TopicID });
            }
        }
        else
        {
            // Not Approved
            if (this.PageBoardContext.BoardSettings.EmailModeratorsOnModeratedPost)
            {
                // not approved, notify moderators
                this.Get <ISendNotification>()
                .ToModeratorsThatMessageNeedsApproval(
                    this.PageBoardContext.PageForumID,
                    newMessage.ID,
                    isPossibleSpamMessage);
            }

            // 't' variable is required only for poll and this is a attach poll token for attachments page
            if (!this.PostOptions1.PollChecked)
            {
                attachPollParameter = false;
            }

            // Tell user that his message will have to be approved by a moderator
            var url = this.Get <LinkBuilder>().GetForumLink(this.PageBoardContext.PageForum);

            if (!attachPollParameter)
            {
                this.Get <LinkBuilder>().Redirect(ForumPages.Info, new { i = 1, url = this.Server.UrlEncode(url) });
            }
            else
            {
                this.Get <LinkBuilder>().Redirect(
                    ForumPages.PollEdit,
                    new { ra = 1, t = newMessage.TopicID, f = this.PageBoardContext.PageForumID });
            }
        }
    }