1 So I have enabled the [[plugins/moderatedcomments]] plugin on my wiki. and good thing that! around 1000 spammy comments showed up in the last 3 months! Awful!
3 It's pretty hard to figure out the ham and the spam in there. One thing I was hoping was to use the power of the commandline to filter through all that stuff. Now, it seems there's only a "ikiwiki-comment" tool now, and nothing to examine the moderated comments.
5 It seems to me it would be great to have some tool to filter through that...
8 So it turns out it was over 3000 comments. The vast majority of those (every one but 42 comments) were from the IP `46.161.41.34` which i recommend null-routing everywhere. I used the following shell magic to figure that out:
15 cd .ikiwiki/transient || {
16 echo could not find comments, make sure you are in a ikiwiki source directory.
19 # count the number of comments
20 echo found $(find . -name '*._comment_pending' | wc -l) pending comments
21 # number of comments per IP
23 find . -name '*._comment_pending' | xargs grep -h ip= | sort | uniq -c | sort -n
24 # generate a banlist for insertion in `banusers`, assuming all the
25 # pending comments are spam
26 echo banlist would look like:
27 find . -name '*._comment_pending' | xargs grep -h ip= | sort -u| sed 's/ ip="//;s/"//;s/^/- ip(/;s/$/)/'
29 echo to remove comments from a specific IP, use one of those:
30 find . -name '*._comment_pending' | xargs grep -h ip= | sort -u \
31 | sed 's/ ip="//;s/"//;' \
33 echo "find . -name '*._comment_pending' | xargs grep -l 'ip=\"$ip\"'| xargs rm"
35 echo to flush all pending comments, use:
36 echo "find . -name '*._comment_pending' -delete"
39 The remaining 42 comments I reviewed throught the web interface, then flushed using the above command. My final addition to the banlist is:
60 Update: i made a script, above. And the banlist is much larger now so the above list is pretty much out of date now... --[[anarcat]]
62 Another update, 2020: I rewrote the script to support interactive batch approval and running from a cron job. I have published the [script in my own repo](https://gitlab.com/anarcat/scripts/blob/master/ikiwiki-comment-moderation) since it's python (and not perl), but I would be happy to provide it as a patch here if that's acceptable.
64 The basic usage is as follows. First, you add the script in a cron job:
66 9 * * * * /home/anarcat/bin/ikiwiki-comment-moderation --source-dir=$HOME/source/
68 This will run every hour. When there are no comments to moderate, the script is silent and you will not get mail. Otherwise you will get something like this:
70 date ip user subject content
71 2020-05-27T03:42:05Z 192.168.0.116 spammer name subject spammy comment
72 1 comments pending moderation
74 Then you can either go through the web interface to approve/deny the
75 comments, or call the script by hand, interactively, for example:
77 w-anarcat@marcos:~/source$ ~anarcat/bin/ikiwiki-comment-moderation --source-dir=$HOME/source -i --verbose
78 Date : 2020-05-27T04:00:23Z
80 Claimedauthor : spammer name
82 Content : spammy comment
83 approve, delete, ignore? [a/d/I] a
84 moving /home/w-anarcat/source/.ikiwiki/transient/blog/2020-04-27-drowning-camera/comment_1_07f43231a14d0ee6e78d1030aa6a7985._comment_pending to /home/w-anarcat/source/blog/2020-04-27-drowning-camera/comment_1_07f43231a14d0ee6e78d1030aa6a7985._comment
86 [master 8f5cb10f] approve comment
87 1 file changed, 9 insertions(+)
88 create mode 100644 blog/2020-04-27-drowning-camera/comment_1_07f43231a14d0ee6e78d1030aa6a7985._comment
89 Énumération des objets: 8, fait.
90 Décompte des objets: 100% (8/8), fait.
91 Compression par delta en utilisant jusqu'à 12 fils d'exécution
92 Compression des objets: 100% (5/5), fait.
93 Écriture des objets: 100% (5/5), 566 bytes | 566.00 KiB/s, fait.
94 Total 5 (delta 3), réutilisés 0 (delta 0)
95 To /home/w-anarcat/source.git
96 91669038..8f5cb10f master -> master
99 And you're done! In the above case, the test comment was actually
100 approved (by pressing `a`), but you can also hit `d` to just delete
101 the comment. The default (`i`) is to ignore the comment.
103 I find that this is generally faster than going through a web browser, although to be as fast as the CGI interface, there would need to be a final dialog that says "delete all ignored comments" like in the CGI. Exercise for the reader or, I guess, myself when I got too many junk comments to process...
105 Feedback, as usual, welcome. -- [[anarcat]]