]> git.zarvox.org Git - shortlog.git/commitdiff
Implement antispam tactics.
authorDrew Fisher <drew.m.fisher@gmail.com>
Fri, 28 Jan 2011 20:23:09 +0000 (14:23 -0600)
committerDrew Fisher <drew.m.fisher@gmail.com>
Fri, 28 Jan 2011 20:23:09 +0000 (14:23 -0600)
I've been getting a bunch of spam comments lately (I knew this day would
come).  This adds a field to the comment-submission page, and verifies
that the field contains a four-digit number.  Hopefully this will stop
most automated bots.

shortlog.py
templates/day.html

index a341b66e0ca85fc095ea7af7ea4c1357851adff3..a2606d3e91f646f5841b26c9e4be1ba12312f5fd 100644 (file)
@@ -147,9 +147,21 @@ class day:
                        web.template.Template.globals['len'] = len
                        print render.noentry("%s-%s-%s" % (year, month, day))
 
+       def verify(self, test):
+               if len(test) != 4:
+                       return False
+               try:
+                       x = int(test,10)
+               except ValueError:
+                       return False
+               return True
 
        def POST(self, year, month, day):
                i = web.input()
+               bottest = i.bottest.strip()
+               if not self.verify(bottest):
+                       web.redirect("http://127.0.0.1/go_away_bot.html")
+                       return
                name = i.name.strip()
                email = i.email.strip()
                website = i.website.strip()
index df4b4fe7353764394939610e608cdc901574ab41..b2a5eac6b17f66eb187fbde3888df6fa52d898f0 100644 (file)
@@ -34,6 +34,7 @@ $for c in comments:
        <p><input name="name" type="text" size="30" aria-required="true" />Name</p>
        <p><input name="email" type="text" size="30" aria-required="true" />Email (required, but won't be posted)</p>
        <p><input name="website" type="text" size="30" aria-required="false" />Website (optional)</p>
+       <p><input name="bottest" type="text" size="30" aria-required="true" />Antispam: enter a four digit number</p>
        <p><textarea name="comment" cols="45" rows="8" aria-required="true"></textarea></p>
        <input name="submit" type="submit" id="submit" value="Post Comment" />
 </form>