Spamblocker using Apache rewrites

Applies to

MacroMarket/PageComment2 Version 0.992

Purpose
Intercept spam text and write a mod_rewrite rule
Description

This mod to PageComment2.py blocks spammers at the Apache .htaccess file. The page stops writing and displays no comments. Subsequent POST operations are redirected to an ugly offsite error page. No logging is done in Moin, but the .htaccess file acts as a log.

NOTE: Excessively long rewrite lists can slow down your server. Trim the list from the bottom periodically.

Starting at line 255:

if not missingfields:
    # check input
    import os, fileinput
    badWords=['preteen', ...etc]
    for badWord in badWords:
        if comtext.find(badWord)!=-1:
            for line in fileinput.input('/Library/WebServer/WikiFarm/.htaccess', inplace=1): # OSX path
                print line[:-1]
                if line.startswith("RewriteCond %{REQUEST_METHOD} POST"):
                    print "RewriteCond %%{REMOTE_ADDR} ^%s [OR]" % os.environ.get('REMOTE_ADDR').replace(".", "\.")
            return ""

To set this up, your .htaccess file needs to be redirecting. Use text like this:

# Block page vandals
# Addresses are written by script /Library/WebServer/WikiFarm/plugin/macro/PageComment2.py line 269
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REMOTE_ADDR} ^222
RewriteRule .* http://etc.Gnarlodious.com/Support_Files/BlockedAddress.htm [L]

IP addresses to be blocked will be written after the line
RewriteCond %{REQUEST_METHOD} POST

The great thing about this method is that spammers can't experiment for which words need to be erased since their IP address is blocked from saving any files. My battle with these spammers has taught me that it is a virus that turns an infected computer into a proxy for this spam. There is probably a better way to block using CAPTCHA but its not working for me. I think the PageComment2 macro is a little old for this spam offensive I am warding off.
-- Gnarlodious

Discussion

If that plugin works with at least 1.7 you may want to add the TextCha feature. You have to import from MoinMoin.security.textcha import TextCha and add %(textcha)s to the html form and substitute it by 'textcha': TextCha(self.request).render(),. The rejection is done by adding at the part of the code where you save

if not TextCha(self.request).check_answer_from_form():
            return status, _('TextCha: Wrong answer! Go back and try again...')

-- ReimarBauer 2009-09-13 07:40:08

Format/Stylesheet Patch for PageComment2

Applies to

MacroMarket/PageComment2 version 0.98.1

Purpose
satisfy the "all stylesheet" and "reorder fields" feature requests
Description
see below
Syntax

this is the same as for PageComment2, with two additions:

PageCommentSF(commentformat=taAidDx V{} }}}

Syntax Notes
  • CLASS is the css class definition you wish to apply to the comments.
  • The format string can include the following:
    • 't': The text of the comment (cell has class commenttext)
    • 'a': The author of the comment (class commentauthor)
    • 'A': author in verbose "Posted by <author>" (class commentauthorverbose)

    • 'i': smiley (class commenticon)
    • 'd': date/time (class commentdate)
    • 'D': verbose date/time (class commentdate)
    • 'x': link to delete the comment
    • ' ': bit o' horizontal whitespace
    • '{': break line, start a right-justified group of fields (class commentcontinuation)
    • '}': Close group started by { - note this is mandatory when '{' is used
    • 'V': bit o' vertical whitespace, produced by a cell spanning the entire entry of style commentblankline. Probably only really works at the end of the format string.

Patch

sf.patch (took out the inline since it's so big)

Alternatively, I have also attached the complete text of the patched version, since the diff is pretty big.

PageCommentSF.py

You will also need to put the following stylesheet someplace where it will be included in your wiki's stylesheet. You can either append it to your favorite theme/common.css; or I prefer to put it in htdocs/common/PageComment2.css and add to the stylesheets config variable in wikiconfig.py, that way this is visible in all themes1.

    # Content options ------------------------------

    stylesheets = [ ('all', '/wiki/common/css/PageComment2.css'),
                    ('all', '/wiki/common/css/SF.css')
                  ]

And here's the contents of PageComment2.css:

   1 /* PageComment css */
   2 
   3 /* these first four styles govern the cell styles in classic table view and in article view,
   4    in ordinary and preview mode
   5  */
   6 
   7 .commentclassic td, .commentclassicpreview td {
   8     border-width: 0px; border-top-width: 1px; 
   9     vertical-align: top; 
  10     font-size: 9pt;
  11 }
  12 
  13 .commentclassicpreview td {
  14     background-color: #ffeeee;
  15 }
  16 
  17 .commentarticle td, .commentarticlepreview td {
  18     font-size: 9pt; 
  19     background-color: #eeeeee;
  20     vertical-align: top;
  21 }
  22 
  23 .commentarticle td {
  24     border-width: 0px;
  25 }
  26 
  27 
  28 .commentarticlepreview td {
  29     border-width: 1px;
  30     border-color: #ff7777;
  31 }
  32 
  33     
  34 td.commentblankline {
  35     border-width: 0px;
  36     height: 10px;
  37 }
  38 
  39 /* The remaining styles are modifiers placed on the basic cell style for
  40    each of the types of fields. Note that several of these by default don't 
  41    change the basic cell type at all.
  42  */
  43 
  44 td.commenticon, td.commentauthor, td.commenttext {
  45 }
  46 
  47 td.commentcontinuation,.commentcontinuation td {
  48     background-color: white;
  49     margin-top: 0px;
  50     padding-top: 0px;
  51     border-width: 0px;
  52 }
  53 
  54 td.commentauthorverbose, td.commentdate {
  55     text-align: right;
  56     font-size: 8pt; color: #999999;
  57 }
  58 
  59 td.commentauthorverbose {
  60     border-width: 0pt
  61 }
PageCommentSF.css

  1. Of course,then there's no way one theme can override these styles. IMHO, MoinMoin needs a stylesheets_before config parameter as well, for common bits that themes can mostly share, but might need to override parts of. (1)

Discussion

PageComment2 was a wonderful addition to the MoinMoin wiki I'm working on (especially since the WYSIWYG editor is not supported by Safari). But I found the availability of just two styles (articleview=0 or 1) a bit limiting, even though they are quite nice. Browsing the comments here, I saw that I was not alone - Matthew Miller recently in the WishList on the PageComment2 page wanted to rearrange fields and JureKodzoman in ../Ideas wanted the style control moved into the CSS. Those both were along the lines I was thinking, and the implementation of the two dovetailed pretty nicely and streamlined the code in PageComment2 a bit to boot. So here it is.

New parameters:

commentclass
the name of the stylesheet class for the rows of the table. Note that in preview mode this gets appended with preview
commentformat

a string with a bunch of mnemonic characters listing the desired fields in order. Has stuff like 't' for the text of the comment, 'a' for the author, 'd' for the DateTime, etc. See the file for the full list.

[Note 20070108: uploaded slight modification to the patch; the original version used > and < as special characters in the format, which seemed to break GUI editing. Switched to { and }, and now things seem smooth. -- gtw]

Plan

Optional username and password for PageComment2

Applies to

MacroMarket/PageComment2 version 0.98.1

Purpose
make username and password optional
Description
see below

Patch

Thanks for the macro, it was exactly what I needed for the Wiki I am just working on! I made several messages translatable and added userorip parameter - when set, the macro never asks for username and password (this was confusing as hell for uninitiated users), but rather uses user's IP address in case of anonymous users. Download PageComment2-099-rg.py and PageComment2-981-099-rg.diff.gz -- 147.213.138.3 2007-05-01 15:58:23

Logged in User only

Applies to

MacroMarket/PageComment2 version 0.98.1 File::PageComment2-0.981-only_logged_in_user.py

Purpose
Do not allow anonymous write to the page. Only logged in users.
Description

Trying to fight spam. Because the PageCommentData doesn't follow acl, there is no way to block users that are not registered. I have commented out lines 624 which contain java script for adding ip/password, add changed comment on line 279 to tell user to log in.

Added to CSS when using Mandarin theme

Append the following to your mandarin/styles.css.

/* DC RemcoBoerma: added to enable PageComment2 macro to have the textarea a width of more then only a few chars wide */
table.addcommentform tbody tr td textarea { width:50em; }
/* DC RemcoBoerma: margin: 0.5em auto; - auto element was removed to not auto center all tables */
#content table { border-collapse: collapse; font-size: 80%; margin: 0.5em; } 

See also: ThemeMarket/Mandarin - a theme favored by a lot of non-wiki users.

This patch is now incorporated in ThemeMarket/Mandarin, except for the non-centered tables, which are left as an option (one has to remove the comments). Thanks a lot.


MoinMoin: MacroMarket/PageComment2/Patches (last edited 2009-09-13 07:42:15 by ReimarBauer)