File Coverage

lib/Kwiki/DNSBL.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package Kwiki::DNSBL;
2 1     1   22264 use Kwiki::Plugin '-Base';
  0            
  0            
3             use Kwiki::Installer '-base';
4             use Net::DNSBLLookup;
5              
6             const class_id => 'dnsbl';
7             const class_title => 'DNS Blackhole List';
8             our $VERSION = '0.01';
9              
10             sub register {
11             my $registry = shift;
12             $registry->add(hook => 'edit:save', pre => 'dnsbl_hook');
13             $registry->add(action => 'blocked_ip');
14             }
15              
16             sub dnsbl_hook {
17             my $hook = pop;
18             my $edit_address = $self->pages->current->metadata->get_edit_address;
19             if ($self->hub->dnsbl->check_dnsbl($edit_address)) {
20             $hook->cancel();
21             return $self->redirect("action=blocked_ip");
22             }
23             }
24              
25             sub check_dnsbl {
26             my ($ip) = @_;
27             my $dnsbl = Net::DNSBLLookup->new(timeout => 5);
28             my $res = $dnsbl->lookup($ip);
29             my ($proxy, $spam, $unknown) = $res->breakdown;
30             if ($proxy || $spam || $unknown) {
31             return 1;
32             } else {
33             return 0;
34             }
35             }
36              
37             sub blocked_ip {
38             return $self->render_screen(
39             content_pane => 'blocked_ip.html',
40             );
41             }
42              
43             __DATA__