| 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__ |