line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Akismet; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Net::Akismet - Perl interface to Akismet - comment and trackback spam fighter |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=cut |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
79974
|
use 5.006; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
48
|
|
10
|
1
|
|
|
1
|
|
8
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
38
|
|
11
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
12
|
1
|
|
|
1
|
|
1218
|
use integer; |
|
1
|
|
|
|
|
13
|
|
|
1
|
|
|
|
|
5
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
3284
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
104989
|
|
|
1
|
|
|
|
|
40
|
|
15
|
1
|
|
|
1
|
|
2270
|
use HTTP::Request::Common; |
|
1
|
|
|
|
|
2910
|
|
|
1
|
|
|
|
|
9482
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $UA_SUFFIX = "Perl-Net-Akismet/$VERSION"; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $akismet = Net::Akismet->new( |
24
|
|
|
|
|
|
|
KEY => 'secret-baba-API-key', |
25
|
|
|
|
|
|
|
URL => 'http://example.blog.net/', |
26
|
|
|
|
|
|
|
) or die('Key verification failure!'); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $verdict = $akismet->check( |
29
|
|
|
|
|
|
|
USER_IP => '10.10.10.11', |
30
|
|
|
|
|
|
|
COMMENT_USER_AGENT => 'Mozilla/5.0', |
31
|
|
|
|
|
|
|
COMMENT_CONTENT => 'Run, Lola, Run, the spam will catch you!', |
32
|
|
|
|
|
|
|
COMMENT_AUTHOR => 'dosser', |
33
|
|
|
|
|
|
|
COMMENT_AUTHOR_EMAIL => 'dosser@subway.de', |
34
|
|
|
|
|
|
|
REFERRER => 'http://lola.home/', |
35
|
|
|
|
|
|
|
) or die('Is the server here?'); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
if ('true' eq $verdict) { |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
print "I found spam. I am a spam-founder!\n"; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 METHODS |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=over 8 |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=item B |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Net::Akismet->new(PARAM => ...); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Acceptable parameters: |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=over 4 |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=item KEY |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
The API key being verified for use with the API. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=item URL |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
The front page or home URL of the instance making the request. For a blog or wiki this would be the front page. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=item USER_AGENT |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
If supplied the value is prepended to this module's identification string to become something like: |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
your-killer-app/0.042 Perl-Net-Akismet/0.01 libwww-perl/5.8 |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Otherwise just Akismet Perl's user agent string will be sent. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=item SERVICE_HOST |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
If supplied, the host of the service API. The default is rest.akismet.com |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item SERVICE_VERSION |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
If supplied, the API version. The default is 1.1 |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=back |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
If verification of the key was unsuccessful C returns C. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub new { |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
0
|
1
|
|
my $that = shift; |
87
|
0
|
|
0
|
|
|
|
my $class = ref $that || $that; |
88
|
0
|
|
|
|
|
|
my %params = @_; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
my $self = \%params; |
91
|
|
|
|
|
|
|
|
92
|
0
|
0
|
|
|
|
|
$self->{ua} = LWP::UserAgent->new() or return undef; |
93
|
|
|
|
|
|
|
|
94
|
0
|
0
|
|
|
|
|
my $key = $self->{KEY} or return undef; |
95
|
0
|
0
|
|
|
|
|
my $url = $self->{URL} or return undef; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# NOTE: trailing space leaves LWP::UserAgent agent string in place |
98
|
0
|
|
|
|
|
|
my $agent = "$UA_SUFFIX "; |
99
|
0
|
0
|
|
|
|
|
$agent = "$params{USER_AGENT} $agent" if $params{USER_AGENT}; |
100
|
0
|
|
|
|
|
|
$self->{ua}->agent($agent); |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
0
|
|
|
|
$self->{SERVICE_HOST} = $params{SERVICE_HOST} || 'rest.akismet.com'; |
103
|
0
|
|
0
|
|
|
|
$self->{SERVICE_VERSION} = $params{SERVICE_VERSION} || '1.1'; |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
bless $self, $class; |
106
|
|
|
|
|
|
|
|
107
|
0
|
0
|
|
|
|
|
return $self->_verify_key()? $self : undef; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub _verify_key { |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
0
|
|
|
my $self = shift; |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
my $response = $self->{ua}->request( |
115
|
|
|
|
|
|
|
POST "http://$self->{SERVICE_HOST}/$self->{SERVICE_VERSION}/verify-key", |
116
|
|
|
|
|
|
|
[ |
117
|
|
|
|
|
|
|
key => $self->{KEY}, |
118
|
|
|
|
|
|
|
blog => $self->{URL}, |
119
|
|
|
|
|
|
|
] |
120
|
|
|
|
|
|
|
); |
121
|
|
|
|
|
|
|
|
122
|
0
|
0
|
0
|
|
|
|
($response && $response->is_success() && 'valid' eq $response->content()) or return undef; |
|
|
|
0
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
return 1; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item B |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
$akismet->check(USER_IP => ..., COMMENT_CONTENT => ..., ...) |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
To be or not to be... C is meant to tell you. Give it enough details about the comment and expect C<'true'>, C<'false'> or C as a result. C<'true'> means B, C<'false'> means B, C is returned on errror in submission of the comment. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Acceptable comment characteristics: |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=over 4 |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item USER_IP |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
B Represents the IP address of the comment submitter. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item COMMENT_USER_AGENT |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
B User agent string from the comment submitter's request. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item COMMENT_CONTENT |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Comment text. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item REFERRER |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
HTTP C header. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item PERMALINK |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Permanent link to the subject of the comment. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item COMMENT_TYPE |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
May be blank, 'comment', 'trackback', 'pingback', or a made up value like 'registration'. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=item COMMENT_AUTHOR |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Name of submitter. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=item COMMENT_AUTHOR_EMAIL |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Submitter e-mail. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item COMMENT_AUTHOR_URL |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Submitter web page. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=back |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=cut |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub check { |
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
181
|
|
|
|
|
|
|
|
182
|
0
|
0
|
|
|
|
|
$self->_submit('comment-check', {@_}) or return undef; |
183
|
|
|
|
|
|
|
|
184
|
0
|
0
|
0
|
|
|
|
('true' eq $self->{response} || 'false' eq $self->{response}) or return undef; |
185
|
|
|
|
|
|
|
|
186
|
0
|
|
|
|
|
|
return $self->{response}; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item B |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Reports a certain comment as spam. Accepts the same arguments as C. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
In case of failed submission returns C, otherwise - a perl-known truth. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=cut |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub spam { |
198
|
|
|
|
|
|
|
|
199
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
200
|
|
|
|
|
|
|
|
201
|
0
|
|
|
|
|
|
return $self->_submit('submit-spam', {@_}); |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=item B |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
This call is intended for the marking of false positives, things that were incorrectly marked as spam. It takes identical arguments as C and C. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
In case of failed submission returns C, otherwise - a perl-known truth. |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=cut |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
sub ham { |
213
|
|
|
|
|
|
|
|
214
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
215
|
|
|
|
|
|
|
|
216
|
0
|
|
|
|
|
|
return $self->_submit('submit-ham', {@_}); |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
sub _submit { |
220
|
|
|
|
|
|
|
|
221
|
0
|
|
|
0
|
|
|
my $self = shift; |
222
|
|
|
|
|
|
|
|
223
|
0
|
|
0
|
|
|
|
my $action = shift || 'comment-check'; |
224
|
|
|
|
|
|
|
|
225
|
0
|
|
|
|
|
|
my $comment = shift; |
226
|
|
|
|
|
|
|
|
227
|
0
|
0
|
0
|
|
|
|
$comment->{USER_IP} && $comment->{COMMENT_USER_AGENT} || return undef; |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
# accomodate common misspelling |
230
|
0
|
0
|
0
|
|
|
|
$comment->{REFERRER} = $comment->{REFERER} if !$comment->{REFERRER} && $comment->{REFERER}; |
231
|
|
|
|
|
|
|
|
232
|
0
|
|
|
|
|
|
my $response = $self->{ua}->request( |
233
|
|
|
|
|
|
|
POST "http://$self->{KEY}.$self->{SERVICE_HOST}/$self->{SERVICE_VERSION}/$action", |
234
|
|
|
|
|
|
|
[ |
235
|
|
|
|
|
|
|
blog => $self->{URL}, |
236
|
|
|
|
|
|
|
user_ip => $comment->{USER_IP}, |
237
|
|
|
|
|
|
|
user_agent => $comment->{COMMENT_USER_AGENT}, |
238
|
|
|
|
|
|
|
referrer => $comment->{REFERRER}, |
239
|
|
|
|
|
|
|
permalink => $comment->{PERMALINK}, |
240
|
|
|
|
|
|
|
comment_type => $comment->{COMMENT_TYPE}, |
241
|
|
|
|
|
|
|
comment_author => $comment->{COMMENT_AUTHOR}, |
242
|
|
|
|
|
|
|
comment_author_email => $comment->{COMMENT_AUTHOR_EMAIL}, |
243
|
|
|
|
|
|
|
comment_author_url => $comment->{COMMENT_AUTHOR_URL}, |
244
|
|
|
|
|
|
|
comment_content => $comment->{COMMENT_CONTENT}, |
245
|
|
|
|
|
|
|
] |
246
|
|
|
|
|
|
|
); |
247
|
|
|
|
|
|
|
|
248
|
0
|
0
|
0
|
|
|
|
($response && $response->is_success()) or return undef; |
249
|
|
|
|
|
|
|
|
250
|
0
|
|
|
|
|
|
$self->{response} = $response->content(); |
251
|
|
|
|
|
|
|
|
252
|
0
|
|
|
|
|
|
return 1; |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
1; |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=back |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=head1 NOTES |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
Although almost all comment characteristics are optional, performance can drop dramatically if you exclude certain elements. So please, supply as much comment detail as possible. |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=head1 SEE ALSO |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=over 4 |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=item * http://akismet.com/ |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=item * http://akismet.com/development/api/ |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=back |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=head1 AUTHOR |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
Nikolay Bachiyski Enb@nikolay.bgE |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=head2 Help, modifications and bugfixes from: |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=over 4 |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=item * Peter Pentchev |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
=item * John Belmonte |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=back |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
Copyright (C) 2006, 2007, 2008 by Nikolay Bachiyski |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.7 or, at your option, any later version of Perl 5 you may have available. |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
$Id: Akismet.pm 38 2008-06-05 17:15:12Z humperdink $ |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=cut |