Andreas Jellinghaus <[EMAIL PROTECTED]> writes:
> I'm still using trac 0.8.1 (debian sarge), but I'm getting lots of
> wiki spam, and deleting those pages all the time is getting on my
> nerve.
>
> What can I do about it?
I run Trac 0.8.1 on Debian sarge too and I made a small patch that
rejects Wiki pages that match a regular expression. I have to refine
the regexp once in a while, but that's much less work than having to
delete spammy page versions.
Here is the patch:
--- Wiki.py.orig 2006-04-02 15:03:16.000000000 +0200
+++ Wiki.py 2006-04-04 13:16:21.000000000 +0200
@@ -20,6 +20,7 @@
# Author: Jonas Borgström <[EMAIL PROTECTED]>
import os
+import re
import time
import urllib
import difflib
@@ -51,6 +52,35 @@
class WikiPage:
"""WikiPage: Represents a wiki page (new or existing).
"""
+
+ _spam_re = re.compile(
+ r"""
+ style.*=.*display.*:.*none
+
+ | alprazolam
+ | black.jack
+ | breast\ enhance
+ | breast\ augment
+ | business\ opportunity
+ | casino
+ | cellulite
+ | drug\ test
+ | free\ work.*home
+ | los[es]\ weight
+ | levitra
+ | phentermine
+ | poker
+ | rolex
+ | texas.holdem
+ | viagra
+ | vicodin
+ | weight\ loss
+ | xanax
+
+ | prohosting\.com
+ """,
+ re.IGNORECASE | re.VERBOSE)
+
def __init__(self, name, version, perm, db):
self.db = db
self.name = name
@@ -95,6 +125,14 @@
if self.readonly:
self.perm.assert_permission (perm.WIKI_ADMIN)
+ if self._spam_re.search(self.text):
+ spamlog = open("/path/to/spam.log", "a")
+ spamlog.write("%s Spam detected from %s on %s\n" % (
+ time.strftime("%Y-%m-%d %H:%M:%S"),
+ author,
+ self.name))
+ raise perm.PermissionError("Spam")
+
cursor = self.db.cursor ()
if not self.modified and self.readonly != self.old_readonly:
cursor.execute ('UPDATE wiki SET readonly=%s WHERE name=%s and
VERSION=%s',
--
Regards,
Joel Rosdahl <[EMAIL PROTECTED]>
Key BB845E97; fingerprint 9F4B D780 6EF4 5700 778D 8B22 0064 F9FF BB84 5E97
_______________________________________________
Trac mailing list
[email protected]
http://lists.edgewall.com/mailman/listinfo/trac