| 1 | package POE::Component::IRC::Plugin::QueryDNSBL; | ||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||
| 3 | 2 | $POE::Component::IRC::Plugin::QueryDNSBL::VERSION = '1.04'; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | #ABSTRACT: A POE::Component::IRC plugin for IRC based DNSBL queries | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use POE; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use POE::Component::Client::DNSBL; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use POE::Component::IRC::Plugin qw[:ALL]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Net::IP::Minimal qw[ip_is_ipv4]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.9
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 1 | my $package = shift; | |||||||||||||||||||||||||||
| 17 | 1 | my %args = @_; | |||||||||||||||||||||||||||
| 18 | 1 | $args{lc $_} = delete $args{$_} for keys %args; | |||||||||||||||||||||||||||
| 19 | delete $args{resolver} | ||||||||||||||||||||||||||||
| 20 | 1 | ▶ | unless ref $args{resolver} and $args{resolver}->isa('POE::Component::Client::DNS'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $args{"resolver"} and $args{"resolver"}->isa("POE::Component::Client::DNS")
MC/DC0%0/2
ref $args{"resolver"} and $args{"resolver"}->isa("POE::Component::Client::DNS")
ref $args{"resolver"}
$args{"resolver"}->isa("POE::Component::Client::DNS")
Truth table33%1/3
A and B
A= ref $args{"resolver"}B= $args{"resolver"}->isa("POE::Component::Client::DNS")
| |||||||||||||||||||||||||||||
| 21 | 1 | bless \%args, $package; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | sub PCI_register { | ||||||||||||||||||||||||||
|
Subroutine
PCI_register: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | 1 | my ($self,$irc) = @_; | |||||||||||||||||||||||||||
| 26 | 1 | $irc->plugin_register( $self, 'SERVER', qw(public msg) ); | |||||||||||||||||||||||||||
| 27 | 1 | $self->{resolver} = $irc->resolver(); | |||||||||||||||||||||||||||
| 28 | $self->{_dnsbl} = POE::Component::Client::DNSBL->spawn( | ||||||||||||||||||||||||||||
| 29 | resolver => $self->{resolver}, | ||||||||||||||||||||||||||||
| 30 | dnsbl => $self->{dnsbl}, | ||||||||||||||||||||||||||||
| 31 | 1 | ); | |||||||||||||||||||||||||||
| 32 | 1 | return 1; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 1 | ▶ | sub PCI_unregister { | ||||||||||||||||||||||||||
|
Subroutine
PCI_unregister: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 36 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 37 | 1 | $self->{_dnsbl}->shutdown(); | |||||||||||||||||||||||||||
| 38 | 1 | return 1; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub S_public { | ||||||||||||||||||||||||||
|
Subroutine
S_public: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 42 | 0 | my ($self,$irc) = splice @_, 0 , 2; | |||||||||||||||||||||||||||
| 43 | 0 | my ($nick,$userhost) = ( split /!/, ${ $_[0] } )[0..1]; | |||||||||||||||||||||||||||
| 44 | 0 | my $channel = ${ $_[1] }->[0]; | |||||||||||||||||||||||||||
| 45 | 0 | my $what = ${ $_[2] }; | |||||||||||||||||||||||||||
| 46 | 0 | my $mynick = $irc->nick_name(); | |||||||||||||||||||||||||||
| 47 | 0 | ▶ | my $cmdstr = $self->{command} || 'dnsbl'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'command'} || 'dnsbl'
MC/DC0%0/1
$self->{'command'} || 'dnsbl'
$self->{'command'}
Truth table0%0/2
A
A= $self->{'command'}
| |||||||||||||||||||||||||||||
| 48 | 0 | my ($command) = $what =~ m/^\s*\Q$mynick\E[\:\,\;\.]?\s*(.*)$/i; | |||||||||||||||||||||||||||
| 49 | 0 | ▶ | return PCI_EAT_NONE unless ( $command and $command =~ /^\Q$cmdstr\E/i ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$command and $command =~ /^\Q$cmdstr\E/i
MC/DC0%0/2
$command and $command =~ /^\Q$cmdstr\E/i
$command
$command =~ /^\Q$cmdstr\E/i
Truth table0%0/3
A and B
A= $commandB= $command =~ /^\Q$cmdstr\E/i
| |||||||||||||||||||||||||||||
| 50 | 0 | $self->_dns_query( $irc, $channel, 'privmsg', split(/\s+/, $command) ); | |||||||||||||||||||||||||||
| 51 | 0 | return PCI_EAT_NONE; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub S_msg { | ||||||||||||||||||||||||||
|
Subroutine
S_msg: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 55 | 0 | my ($self,$irc) = splice @_, 0 , 2; | |||||||||||||||||||||||||||
| 56 | 0 | my ($nick,$userhost) = ( split /!/, ${ $_[0] } )[0..1]; | |||||||||||||||||||||||||||
| 57 | 0 | my $string = ${ $_[2] }; | |||||||||||||||||||||||||||
| 58 | 0 | ▶ | my $cmdstr = $self->{command} || 'dnsbl'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'command'} || 'dnsbl'
MC/DC0%0/1
$self->{'command'} || 'dnsbl'
$self->{'command'}
Truth table0%0/2
A
A= $self->{'command'}
| |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | return PCI_EAT_NONE unless ( $string and $string =~ /^\Q$cmdstr\E\s+/i ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$string and $string =~ /^\Q$cmdstr\E\s+/i
MC/DC0%0/2
$string and $string =~ /^\Q$cmdstr\E\s+/i
$string
$string =~ /^\Q$cmdstr\E\s+/i
Truth table0%0/3
A and B
A= $stringB= $string =~ /^\Q$cmdstr\E\s+/i
| |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | $self->_dns_query( $irc, $nick, ( $self->{privmsg} ? 'privmsg' : 'notice' ), split(/\s+/, $string) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | return PCI_EAT_NONE; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub _dns_query { | ||||||||||||||||||||||||||
|
Subroutine
_dns_query: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 65 | 0 | my ($self,$irc,$target,$method,$cmdstr,$query,$type) = @_; | |||||||||||||||||||||||||||
| 66 | 0 | ▶ | return unless $cmdstr and $query; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$cmdstr and $query
MC/DC0%0/2
$cmdstr and $query
$cmdstr
$query
Truth table0%0/3
A and B
A= $cmdstrB= $query
| |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | unless ( ip_is_ipv4( $query ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 0 | $irc->yield( $method, $target, 'That isn\'t an IPv4 address' ); | |||||||||||||||||||||||||||
| 69 | 0 | return; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | 0 | $poe_kernel->state( '_querydnsbl_response', $self, '_response' ); | |||||||||||||||||||||||||||
| 72 | $self->{_dnsbl}->lookup( | ||||||||||||||||||||||||||||
| 73 | 0 | event => '_querydnsbl_response', | |||||||||||||||||||||||||||
| 74 | address => $query, | ||||||||||||||||||||||||||||
| 75 | _context => { targ => $target, meth => $method, irc => $irc }, | ||||||||||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||||||||||
| 77 | 0 | return 1; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub _response { | ||||||||||||||||||||||||||
|
Subroutine
_response: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 81 | 0 | my $response = $_[ARG0]; | |||||||||||||||||||||||||||
| 82 | 0 | my $target = $response->{_context}->{targ}; | |||||||||||||||||||||||||||
| 83 | 0 | my $method = $response->{_context}->{meth}; | |||||||||||||||||||||||||||
| 84 | 0 | my $irc = $response->{_context}->{irc}; | |||||||||||||||||||||||||||
| 85 | 0 | ▶ | if ( $response->{error} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 0 | $irc->yield( $method, $target, 'Thanks, that generated an error!' ); | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | else { | ||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if ( $response->{response} eq 'NXDOMAIN' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | $irc->yield( $method, $target, 'That address is not blacklisted.' ); | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | else { | ||||||||||||||||||||||||||||
| 93 | 0 | ▶ | $irc->yield( $method, $target, join(' ', $response->{response}, ( $response->{reason} ? "[$response->{reason}]" : '' ) ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | 0 | $poe_kernel->state( '_querydnsbl_response' ); | |||||||||||||||||||||||||||
| 97 | 0 | return; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 2 | 1; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | __END__ | ||||||||||||||||||||||||||||