2 package IkiWiki
::Plugin
::blogspam
;
8 my $defaulturl='http://test.blogspam.net:8888/';
11 hook
(type
=> "getsetup", id
=> "blogspam", call
=> \
&getsetup
);
12 hook
(type
=> "checkconfig", id
=> "blogspam", call
=> \
&checkconfig
);
13 hook
(type
=> "checkcontent", id
=> "blogspam", call
=> \
&checkcontent
);
23 blogspam_pagespec
=> {
25 example
=> 'postcomment(*)',
26 description
=> 'PageSpec of pages to check for spam',
27 link => 'ikiwiki/PageSpec',
33 example
=> "blacklist=1.2.3.4,blacklist=8.7.6.5,max-links=10",
34 description
=> "options to send to blogspam server",
35 link => "http://blogspam.net/api/testComment.html#options",
41 default => $defaulturl,
42 description
=> "blogspam server XML-RPC url",
49 # This is done at checkconfig time because printing an error
50 # if the module is missing when a spam is posted would not
51 # let the admin know about the problem.
59 sub checkcontent
(@
) {
62 if (exists $config{blogspam_pagespec
}) {
64 if ! pagespec_match
($params{page
}, $config{blogspam_pagespec
},
65 location
=> $params{page
});
69 $url = $config{blogspam_server
} if exists $config{blogspam_server
};
70 my $client = RPC
::XML
::Client
->new($url);
72 my @options = split(",", $config{blogspam_options
})
73 if exists $config{blogspam_options
};
75 # Allow short comments and whitespace-only edits, unless the user
76 # has overridden min-words themselves.
77 push @options, "min-words=0"
78 unless grep /^min-words=/i, @options;
79 # Wiki pages can have a lot of urls, unless the user specifically
80 # wants to limit them.
81 push @options, "exclude=lotsaurls"
82 unless grep /^max-links/i, @options;
83 # Unless the user specified a size check, disable such checking.
84 push @options, "exclude=size"
85 unless grep /^(?:max|min)-size/i, @options;
86 # This test has absurd false positives on words like "alpha"
88 push @options, "exclude=stopwords";
91 ip
=> $ENV{REMOTE_ADDR
},
92 comment
=> defined $params{diff
} ?
$params{diff
} : $params{content
},
93 subject
=> defined $params{subject
} ?
$params{subject
} : "",
94 name
=> defined $params{author
} ?
$params{author
} : "",
95 link => exists $params{url
} ?
$params{url
} : "",
96 options
=> join(",", @options),
98 version
=> "ikiwiki ".$IkiWiki::version
,
100 my $res = $client->send_request('testComment', \
%req);
102 if (! ref $res || ! defined $res->value) {
103 debug
("failed to get response from blogspam server ($url)");
106 elsif ($res->value =~ /^SPAM:(.*)/) {
107 eval q{use Data::Dumper};
108 debug
("blogspam server reports ".$res->value.": ".Dumper
(\
%req));
109 return gettext
("Sorry, but that looks like spam to <a href=\"http://blogspam.net/\">blogspam</a>: ").$1;
111 elsif ($res->value ne 'OK') {
112 debug
("blogspam server failure: ".$res->value);