root/trunk/plagger/lib/Plagger/Rule/URLBL.pm

Revision 1679 (checked in by miyagawa, 2 years ago)

Rule::URLBL: fixed URI::_generic calling host bug

Line 
1 package Plagger::Rule::URLBL;
2 use strict;
3 use base qw( Plagger::Rule );
4
5 use Net::DNS::Resolver;
6 use URI;
7
8 sub init {
9     my $self = shift;
10
11     Plagger->context->error("No dnsbl configuration")
12         unless $self->{dnsbl};
13 }
14
15 sub dispatch {
16     my($self, $args) = @_;
17
18     my $url;
19     if ($args->{entry}) {
20         $url = $args->{entry}->permalink;
21     } elsif ($args->{feed}) {
22         $url = $args->{feed}->url;
23     } else {
24         Plagger->context->error("No feed nor entry object in this plugin phase");
25     }
26
27     return unless $url;
28
29     my $uri = URI->new($url);
30     return 1 unless $uri->can('host');
31
32     my $domain = $uri->host;
33     $domain =~ s/^www\.//;
34
35     if (exists $self->{dnscache}->{$domain}) {
36         return $self->{dnscache}->{$domain};
37     }
38
39     my $res = Net::DNS::Resolver->new;
40     my $dnsbl = $self->{dnsbl};
41        $dnsbl = [ $dnsbl ] unless ref $dnsbl;
42
43     for my $dns (@$dnsbl) {
44         Plagger->context->log(debug => "looking up $domain.$dns");
45         my $q = $res->search("$domain.$dns");
46         if ($q && $q->answer) {
47             Plagger->context->log(info => "$domain.$dns found.");
48             return $self->{dnscache}->{$domain} = 0;
49         }
50     }
51
52     return $self->{dnscache}->{$domain} = 1;
53 }
54
55 1;
56
57 __END__
58
59 =head1 NAME
60
61 Plagger::Rule::URLBL - Rule to URLBL for feed url
62
63 =head1 SYNOPSIS
64
65   - module: Aggregator::Xango
66     rule:
67       - module: URLBL
68         dnsbl: rbl.bulkfeeds.jp
69
70 =head1 DESCRIPTION
71
72 The rule is decided by URLBL.
73
74 =head1 CONFIG
75
76 =over 4
77
78 =item C<dnsbl>
79
80   duration: dnsbl domain
81
82 =back
83
84 =head1 AUTHOR
85
86 Kazuhiro Osawa
87
88 inspired by L<Plagger::Plugin::Filter::URLBL>
89
90 =head1 SEE ALSO
91
92 L<Plagger>, L<Plagger::Plugin::Filter::URLBL>
93
94 =cut
Note: See TracBrowser for help on using the browser.