| 1 | package Net::Firewall::BlockerHelper::backends::dns_rpz; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use base 'Error::Helper'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Regexp::IPv4 qw($IPv4_re); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Regexp::IPv6 qw($IPv6_re); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | Net::Firewall::BlockerHelper::backends::dns_rpz - DNS RPZ blocklist backend via nsupdate. | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | Version 0.1.0 | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | our $VERSION = '0.1.0'; | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | use Net::Firewall::BlockerHelper; | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | my $fw_helper = Net::Firewall::BlockerHelper->new( | ||||||||||||||||||||||||||||||||||||||||||
| 27 | backend => 'dns_rpz', | ||||||||||||||||||||||||||||||||||||||||||
| 28 | name => 'resolver', | ||||||||||||||||||||||||||||||||||||||||||
| 29 | options => { | ||||||||||||||||||||||||||||||||||||||||||
| 30 | zone => 'rpz.example.org', | ||||||||||||||||||||||||||||||||||||||||||
| 31 | keyfile => '/etc/rpz.key', | ||||||||||||||||||||||||||||||||||||||||||
| 32 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | $fw_helper->init_backend; | ||||||||||||||||||||||||||||||||||||||||||
| 36 | $fw_helper->ban( ban => '1.2.3.4' ); | ||||||||||||||||||||||||||||||||||||||||||
| 37 | $fw_helper->unban( ban => '1.2.3.4' ); | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | Blocks IPs at the DNS layer using a BIND Response Policy Zone (RPZ). By | ||||||||||||||||||||||||||||||||||||||||||
| 42 | default the C<rpz-client-ip> trigger is used, so a banned IP is prevented from | ||||||||||||||||||||||||||||||||||||||||||
| 43 | resolving anything through the resolver (the policy action is NXDOMAIN via a | ||||||||||||||||||||||||||||||||||||||||||
| 44 | C<CNAME .> record). Set the C<trigger> option to C<ip> to instead use the | ||||||||||||||||||||||||||||||||||||||||||
| 45 | C<rpz-ip> trigger, which rewrites answers that contain the banned IP. | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | Records are added and removed with L<nsupdate(1)> (the DNS update protocol, | ||||||||||||||||||||||||||||||||||||||||||
| 48 | TSIG authenticated), so this backend runs the nsupdate command rather than | ||||||||||||||||||||||||||||||||||||||||||
| 49 | speaking HTTP. The RPZ zone must already exist and be referenced from the | ||||||||||||||||||||||||||||||||||||||||||
| 50 | resolver's C<response-policy> configuration. | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | The owner name is the RPZ IP format: for IPv4 C<1.2.3.4> it is | ||||||||||||||||||||||||||||||||||||||||||
| 53 | C<< 32.4.3.2.1.rpz-client-ip.<zone> >>, and for IPv6 the eight groups are | ||||||||||||||||||||||||||||||||||||||||||
| 54 | reversed with the longest zero run replaced by C<zz>, prefixed with the | ||||||||||||||||||||||||||||||||||||||||||
| 55 | C<128> length. | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | Blocking is per IP; ports and protocols are not supported and specifying | ||||||||||||||||||||||||||||||||||||||||||
| 58 | either is an error. | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | =head2 new | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | Initiates the object. | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | - options :: Backend specific options. See below. | ||||||||||||||||||||||||||||||||||||||||||
| 67 | - name :: Required by Net::Firewall::BlockerHelper, otherwise unused. | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | The options hash accepts the following. zone and keyfile are required. | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | - zone :: The RPZ zone name. | ||||||||||||||||||||||||||||||||||||||||||
| 72 | - Default :: undef | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | - keyfile :: Full path to the TSIG key file authenticating to the server. | ||||||||||||||||||||||||||||||||||||||||||
| 75 | - Default :: undef | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | - trigger :: 'client-ip' (block the querying client) or 'ip' (rewrite | ||||||||||||||||||||||||||||||||||||||||||
| 78 | answers containing the IP). | ||||||||||||||||||||||||||||||||||||||||||
| 79 | - Default :: client-ip | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | - server :: Optional server to send the updates to; adds a server line. | ||||||||||||||||||||||||||||||||||||||||||
| 82 | - Default :: undef | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | - ttl :: TTL in seconds for the created records. | ||||||||||||||||||||||||||||||||||||||||||
| 85 | - Default :: 60 | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | - nsupdate :: The nsupdate command to use. | ||||||||||||||||||||||||||||||||||||||||||
| 88 | - Default :: nsupdate | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | All errors are considered fatal, meaning if new fails it will die. | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 8 | ▶ | my ( $blank, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=29 SCAR=38.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 8 | my $self = { | |||||||||||||||||||||||||||||||||||||||||
| 98 | perror => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 99 | error => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 100 | errorLine => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 101 | errorFilename => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 102 | errorString => "", | ||||||||||||||||||||||||||||||||||||||||||
| 103 | errorExtra => { | ||||||||||||||||||||||||||||||||||||||||||
| 104 | all_errors_fatal => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 105 | # all_fatal is what Error::Helper 2.1.0 actually checks; all_errors_fatal | ||||||||||||||||||||||||||||||||||||||||||
| 106 | # is kept for the name documented in its POD | ||||||||||||||||||||||||||||||||||||||||||
| 107 | all_fatal => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 108 | flags => { | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 1 => 'notInited', | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 8 => 'optionsNotHash', | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 9 => 'noBanItem', | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 10 => 'banItemNotIP', | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 12 => 'backendInitError', | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 13 => 'banFailed', | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 14 => 'unbanFailed', | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 15 => 'listFailed', | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 16 => 'reInitFailed', | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 17 => 'teardownFailed', | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 18 => 'alreadyInited', | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 20 => 'triggerInvalid', | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 23 => 'initFailed', | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 24 => 'checkFailed', | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 25 => 'flushFailed', | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 26 => 'portsNotSupported', | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 27 => 'protocolsNotSupported', | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 30 => 'zoneInvalid', | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 31 => 'keyfileInvalid', | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 32 => 'banCidrFailed', | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 33 => 'unbanCidrFailed', | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 34 => 'cidrItemNotCidr', | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 35 => 'cidrNotSupported', | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 36 => 'listCidrFailed', | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 37 => 'serverInvalid', | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 38 => 'ttlInvalid', | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 39 => 'nsupdateInvalid', | ||||||||||||||||||||||||||||||||||||||||||
| 136 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 137 | fatal_flags => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 138 | perror_not_fatal => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 139 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 140 | options => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 141 | ports => [], | ||||||||||||||||||||||||||||||||||||||||||
| 142 | protocols => [], | ||||||||||||||||||||||||||||||||||||||||||
| 143 | testing => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 144 | test_data => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 145 | prefix => 'kur', | ||||||||||||||||||||||||||||||||||||||||||
| 146 | name => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 147 | frontend_obj => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 148 | inited => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 149 | banned => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 150 | cidr_supported => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 151 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 8 | bless $self; | |||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 8 | ▶ | if ( defined( $opts{ports} ) && ref( $opts{ports} ) eq 'ARRAY' && defined( $opts{ports}[0] ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $opts{"ports"} and ref $opts{"ports"} eq "ARRAY" and defined $opts{"ports"}[0]
defined $opts{"ports"} and ref $opts{"ports"} eq "ARRAY"
MC/DC0%0/3
defined $opts{"ports"} and ref $opts{"ports"} eq "ARRAY" and defined $opts{"ports"}[0]
defined $opts{"ports"}
ref $opts{"ports"} eq "ARRAY"
defined $opts{"ports"}[0]
Truth table25%1/4
A and B and C
A= defined $opts{"ports"}B= ref $opts{"ports"} eq "ARRAY"C= defined $opts{"ports"}[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | $self->{perror} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | $self->{error} = 26; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | $self->{errorString} = 'the dns_rpz backend blocks whole IPs and does not support ports'; | |||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 8 | ▶ | if ( defined( $opts{protocols} ) && ref( $opts{protocols} ) eq 'ARRAY' && defined( $opts{protocols}[0] ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $opts{"protocols"} and ref $opts{"protocols"} eq "ARRAY" and defined $opts{"protocols"}[0]
defined $opts{"protocols"} and ref $opts{"protocols"} eq "ARRAY"
MC/DC0%0/3
defined $opts{"protocols"} and ref $opts{"protocols"} eq "ARRAY" and defined $opts{"protocols"}[0]
defined $opts{"protocols"}
ref $opts{"protocols"} eq "ARRAY"
defined $opts{"protocols"}[0]
Truth table25%1/4
A and B and C
A= defined $opts{"protocols"}B= ref $opts{"protocols"} eq "ARRAY"C= defined $opts{"protocols"}[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | $self->{perror} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | $self->{error} = 27; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $self->{errorString} = 'the dns_rpz backend blocks whole IPs and does not support protocols'; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 8 | ▶ | if ( defined( $opts{testing} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 8 | $self->{testing} = $opts{testing}; | |||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 8 | ▶ | if ( defined( $opts{frontend_obj} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 8 | $self->{frontend_obj} = $opts{frontend_obj}; | |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 8 | ▶ | if ( defined( $opts{name} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 8 | $self->{name} = $opts{name}; | |||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 8 | ▶ | if ( defined( $opts{options} ) && ref( $opts{options} ) ne 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
defined $opts{"options"} and ref $opts{"options"} ne "HASH"
MC/DC0%0/2
defined $opts{"options"} and ref $opts{"options"} ne "HASH"
defined $opts{"options"}
ref $opts{"options"} ne "HASH"
Truth table33%1/3
A and B
A= defined $opts{"options"}B= ref $opts{"options"} ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | $self->{perror} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | $self->{error} = 8; | |||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | $self->{errorString} = 'ref for options is "' . ref( $opts{options} ) . '" and not HASH'; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 182 | } elsif ( defined( $opts{options} ) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 8 | $self->{options} = $opts{options}; | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 8 | ▶ | if ( !defined( $self->{options}{zone} ) || $self->{options}{zone} !~ /^[a-zA-Z0-9.\-]+$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"options"}{"zone"} and $self->{"options"}{"zone"} =~ /^[a-zA-Z0-9.\-]+$/
MC/DC50%1/2
defined $self->{"options"}{"zone"} and $self->{"options"}{"zone"} =~ /^[a-zA-Z0-9.\-]+$/
defined $self->{"options"}{"zone"}
$self->{"options"}{"zone"} =~ /^[a-zA-Z0-9.\-]+$/
Truth table66%2/3
A and B
A= defined $self->{"options"}{"zone"}B= $self->{"options"}{"zone"} =~ /^[a-zA-Z0-9.\-]+$/
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 1 | $self->{perror} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 188 | 1 | $self->{error} = 30; | |||||||||||||||||||||||||||||||||||||||||
| 189 | $self->{errorString} | ||||||||||||||||||||||||||||||||||||||||||
| 190 | = 'the option zone is ' | ||||||||||||||||||||||||||||||||||||||||||
| 191 | 1 | ▶ | . ( defined( $self->{options}{zone} ) ? '"' . $self->{options}{zone} . '" and not a valid zone' : 'undef' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 1 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | # keyfile must be free of whitespace and single quotes so it is safe to embed | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 7 | ▶ | if ( !defined( $self->{options}{keyfile} ) || $self->{options}{keyfile} !~ /^[^'\s]+$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"options"}{"keyfile"} and $self->{"options"}{"keyfile"} =~ /^[^'\s]+$/
MC/DC50%1/2
defined $self->{"options"}{"keyfile"} and $self->{"options"}{"keyfile"} =~ /^[^'\s]+$/
defined $self->{"options"}{"keyfile"}
$self->{"options"}{"keyfile"} =~ /^[^'\s]+$/
Truth table66%2/3
A and B
A= defined $self->{"options"}{"keyfile"}B= $self->{"options"}{"keyfile"} =~ /^[^'\s]+$/
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 1 | $self->{perror} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | $self->{error} = 31; | |||||||||||||||||||||||||||||||||||||||||
| 199 | $self->{errorString} | ||||||||||||||||||||||||||||||||||||||||||
| 200 | = 'the option keyfile is ' | ||||||||||||||||||||||||||||||||||||||||||
| 201 | . ( | ||||||||||||||||||||||||||||||||||||||||||
| 202 | defined( $self->{options}{keyfile} ) | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | ▶ | ? '"' . $self->{options}{keyfile} . '" which contains whitespace or single quotes' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | : 'undef' | ||||||||||||||||||||||||||||||||||||||||||
| 205 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 206 | 1 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 207 | } ## end if ( !defined( $self->{options}{keyfile} )...) | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 6 | ▶ | $self->{options}{trigger} = 'client-ip' if ( !defined( $self->{options}{trigger} ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | # the following are embedded in the shell command _nsupdate_command builds, | ||||||||||||||||||||||||||||||||||||||||||
| 212 | # so limit each to characters safe inside its single quoted printf string | ||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | # '' is treated the same as undef when the command is built | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 6 | ▶ | if ( defined( $self->{options}{server} ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $self->{"options"}{"server"} and $self->{"options"}{"server"} ne "" and not $self->{"options"}{"server"} =~ /^[a-zA-Z0-9.:\-]+$/
defined $self->{"options"}{"server"} and $self->{"options"}{"server"} ne ""
MC/DC66%2/3
defined $self->{"options"}{"server"} and $self->{"options"}{"server"} ne "" and not $self->{"options"}{"server"} =~ /^[a-zA-Z0-9.:\-]+$/
defined $self->{"options"}{"server"}
$self->{"options"}{"server"} ne ""
not $self->{"options"}{"server"} =~ /^[a-zA-Z0-9.:\-]+$/
Truth table75%3/4
A and B and not(C)
A= defined $self->{"options"}{"server"}B= $self->{"options"}{"server"} ne ""C= not $self->{"options"}{"server"} =~ /^[a-zA-Z0-9.:\-]+$/
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | && $self->{options}{server} ne '' | ||||||||||||||||||||||||||||||||||||||||||
| 217 | && $self->{options}{server} !~ /^[a-zA-Z0-9.:\-]+$/ ) | ||||||||||||||||||||||||||||||||||||||||||
| 218 | { | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 1 | $self->{perror} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 220 | 1 | $self->{error} = 37; | |||||||||||||||||||||||||||||||||||||||||
| 221 | $self->{errorString} | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 1 | = 'the option server, "' . $self->{options}{server} . '", does not match /^[a-zA-Z0-9.:\-]+$/'; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 1 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 5 | ▶ | if ( !defined( $self->{options}{ttl} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 4 | $self->{options}{ttl} = 60; | |||||||||||||||||||||||||||||||||||||||||
| 228 | } elsif ( $self->{options}{ttl} !~ /^[0-9]+$/ ) { | ||||||||||||||||||||||||||||||||||||||||||
| 229 | 1 | $self->{perror} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 230 | 1 | $self->{error} = 38; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 1 | $self->{errorString} = 'the option ttl, "' . $self->{options}{ttl} . '", is not an int'; | |||||||||||||||||||||||||||||||||||||||||
| 232 | 1 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | 4 | ▶ | if ( !defined( $self->{options}{nsupdate} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | 3 | $self->{options}{nsupdate} = 'nsupdate'; | |||||||||||||||||||||||||||||||||||||||||
| 237 | } elsif ( $self->{options}{nsupdate} !~ /^[a-zA-Z0-9.\/_\-]+$/ ) { | ||||||||||||||||||||||||||||||||||||||||||
| 238 | 1 | $self->{perror} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 239 | 1 | $self->{error} = 39; | |||||||||||||||||||||||||||||||||||||||||
| 240 | $self->{errorString} | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 1 | = 'the option nsupdate, "' . $self->{options}{nsupdate} . '", does not match /^[a-zA-Z0-9.\/_\-]+$/'; | |||||||||||||||||||||||||||||||||||||||||
| 242 | 1 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 3 | ▶ | if ( $self->{options}{trigger} ne 'client-ip' && $self->{options}{trigger} ne 'ip' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"options"}{"trigger"} ne "client-ip" and $self->{"options"}{"trigger"} ne "ip"
MC/DC100%2/2
$self->{"options"}{"trigger"} ne "client-ip" and $self->{"options"}{"trigger"} ne "ip"
$self->{"options"}{"trigger"} ne "client-ip"
$self->{"options"}{"trigger"} ne "ip"
Truth table100%3/3
A and B
A= $self->{"options"}{"trigger"} ne "client-ip"B= $self->{"options"}{"trigger"} ne "ip"
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 1 | $self->{perror} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 247 | 1 | $self->{error} = 20; | |||||||||||||||||||||||||||||||||||||||||
| 248 | 1 | $self->{errorString} = 'the option trigger is "' . $self->{options}{trigger} . '" and not "client-ip" or "ip"'; | |||||||||||||||||||||||||||||||||||||||||
| 249 | 1 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 253 | } ## end sub new | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | # Internal helper. Returns the RPZ owner name for the passed IP: the reversed | ||||||||||||||||||||||||||||||||||||||||||
| 256 | # address in RPZ IP format under the configured trigger and zone. | ||||||||||||||||||||||||||||||||||||||||||
| 257 | sub _owner { | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 4 | ▶ | my ( $self, $ip ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_owner: called CC=10 SCAR=23.1
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | 4 | my $rpz_ip; | |||||||||||||||||||||||||||||||||||||||||
| 261 | 4 | ▶ | if ( $ip =~ /\A$IPv4_re\z/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 3 | $rpz_ip = '32.' . join( '.', reverse( split( /\./, $ip ) ) ); | |||||||||||||||||||||||||||||||||||||||||
| 263 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 264 | # expand the eight IPv6 groups, reverse them, and replace the longest | ||||||||||||||||||||||||||||||||||||||||||
| 265 | # run of zero groups with zz (the RPZ IPv6 encoding) | ||||||||||||||||||||||||||||||||||||||||||
| 266 | 1 | my @groups = $self->_v6_groups($ip); | |||||||||||||||||||||||||||||||||||||||||
| 267 | 1 | my @rev = reverse(@groups); | |||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | # find the longest run of '0' groups | ||||||||||||||||||||||||||||||||||||||||||
| 270 | 1 | my ( $best_start, $best_len ) = ( -1, 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 271 | 1 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 1 | ▶ | while ( $i < scalar(@rev) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 4 | ▶ | if ( $rev[$i] eq '0' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | 1 | my $j = $i; | |||||||||||||||||||||||||||||||||||||||||
| 275 | 1 | ▶ | $j++ while ( $j < scalar(@rev) && $rev[$j] eq '0' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$j < scalar @rev and $rev[$j] eq 0
MC/DC50%1/2
$j < scalar @rev and $rev[$j] eq 0
$j < scalar @rev
$rev[$j] eq 0
Truth table66%2/3
A and B
A= $j < scalar @revB= $rev[$j] eq 0
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | 1 | ▶ | if ( ( $j - $i ) > $best_len ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | 1 | $best_len = $j - $i; | |||||||||||||||||||||||||||||||||||||||||
| 278 | 1 | $best_start = $i; | |||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||
| 280 | 1 | $i = $j; | |||||||||||||||||||||||||||||||||||||||||
| 281 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 282 | 3 | $i++; | |||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||
| 284 | } ## end while ( $i < scalar(@rev) ) | ||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 1 | my @out; | |||||||||||||||||||||||||||||||||||||||||
| 287 | 1 | $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 288 | 1 | ▶ | while ( $i < scalar(@rev) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | 4 | ▶ | if ( $i == $best_start && $best_len > 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$i == $best_start and $best_len > 0
MC/DC50%1/2
$i == $best_start and $best_len > 0
$i == $best_start
$best_len > 0
Truth table66%2/3
A and B
A= $i == $best_startB= $best_len > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | 1 | push( @out, 'zz' ); | |||||||||||||||||||||||||||||||||||||||||
| 291 | 1 | $i += $best_len; | |||||||||||||||||||||||||||||||||||||||||
| 292 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 293 | 3 | push( @out, $rev[$i] ); | |||||||||||||||||||||||||||||||||||||||||
| 294 | 3 | $i++; | |||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 1 | $rpz_ip = '128.' . join( '.', @out ); | |||||||||||||||||||||||||||||||||||||||||
| 299 | } ## end else [ if ( $ip =~ /\A$IPv4_re\z/)] | ||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | 4 | return $rpz_ip . '.rpz-' . $self->{options}{trigger} . '.' . $self->{options}{zone}; | |||||||||||||||||||||||||||||||||||||||||
| 302 | } ## end sub _owner | ||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | # Internal helper. Expands an IPv6 IP to its eight groups, each hex with leading | ||||||||||||||||||||||||||||||||||||||||||
| 305 | # zeros stripped ('0' for a zero group). | ||||||||||||||||||||||||||||||||||||||||||
| 306 | sub _v6_groups { | ||||||||||||||||||||||||||||||||||||||||||
| 307 | 1 | ▶ | my ( $self, $ip ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_v6_groups: called CC=8 SCAR=23.2
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | 1 | my @groups; | |||||||||||||||||||||||||||||||||||||||||
| 310 | 1 | ▶ | if ( $ip =~ /::/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | 1 | my ( $left, $right ) = split( /::/, $ip, 2 ); | |||||||||||||||||||||||||||||||||||||||||
| 312 | 1 | ▶ | my @l = ( defined($left) && $left ne '' ) ? split( /:/, $left ) : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $left and $left ne ""
MC/DC0%0/2
defined $left and $left ne ""
defined $left
$left ne ""
Truth table33%1/3
A and B
A= defined $leftB= $left ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | 1 | ▶ | my @r = ( defined($right) && $right ne '' ) ? split( /:/, $right ) : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $right and $right ne ""
MC/DC0%0/2
defined $right and $right ne ""
defined $right
$right ne ""
Truth table33%1/3
A and B
A= defined $rightB= $right ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 1 | my $fill = 8 - scalar(@l) - scalar(@r); | |||||||||||||||||||||||||||||||||||||||||
| 315 | 1 | @groups = ( @l, ('0') x $fill, @r ); | |||||||||||||||||||||||||||||||||||||||||
| 316 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | @groups = split( /:/, $ip ); | |||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | # normalize each group: lowercase, strip leading zeros, empty becomes 0 | ||||||||||||||||||||||||||||||||||||||||||
| 321 | 1 | foreach my $g (@groups) { | |||||||||||||||||||||||||||||||||||||||||
| 322 | 8 | $g = lc($g); | |||||||||||||||||||||||||||||||||||||||||
| 323 | 8 | $g =~ s/^0+(?=.)//; | |||||||||||||||||||||||||||||||||||||||||
| 324 | 8 | ▶ | $g = '0' if ( $g eq '' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | 1 | return @groups; | |||||||||||||||||||||||||||||||||||||||||
| 328 | } ## end sub _v6_groups | ||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | # Internal helper. Returns the shell command piping the given update statements | ||||||||||||||||||||||||||||||||||||||||||
| 331 | # into nsupdate, wrapped with the optional server line, zone, and send. | ||||||||||||||||||||||||||||||||||||||||||
| 332 | sub _nsupdate_command { | ||||||||||||||||||||||||||||||||||||||||||
| 333 | 4 | ▶ | my ( $self, @updates ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_nsupdate_command: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | 4 | my @statements; | |||||||||||||||||||||||||||||||||||||||||
| 336 | 4 | ▶ | if ( defined( $self->{options}{server} ) && $self->{options}{server} ne '' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"options"}{"server"} and $self->{"options"}{"server"} ne ""
MC/DC50%1/2
defined $self->{"options"}{"server"} and $self->{"options"}{"server"} ne ""
defined $self->{"options"}{"server"}
$self->{"options"}{"server"} ne ""
Truth table66%2/3
A and B
A= defined $self->{"options"}{"server"}B= $self->{"options"}{"server"} ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | 1 | push( @statements, 'server ' . $self->{options}{server} ); | |||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||
| 339 | 4 | push( @statements, 'zone ' . $self->{options}{zone} ); | |||||||||||||||||||||||||||||||||||||||||
| 340 | 4 | push( @statements, @updates ); | |||||||||||||||||||||||||||||||||||||||||
| 341 | 4 | push( @statements, 'send' ); | |||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | return | ||||||||||||||||||||||||||||||||||||||||||
| 344 | "printf '" | ||||||||||||||||||||||||||||||||||||||||||
| 345 | . join( '\n', @statements ) | ||||||||||||||||||||||||||||||||||||||||||
| 346 | . "\\n' | " | ||||||||||||||||||||||||||||||||||||||||||
| 347 | . $self->{options}{nsupdate} . " -k '" | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 4 | . $self->{options}{keyfile} . "'"; | |||||||||||||||||||||||||||||||||||||||||
| 349 | } ## end sub _nsupdate_command | ||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | # Internal helpers. Return the nsupdate command that adds/removes the RPZ record | ||||||||||||||||||||||||||||||||||||||||||
| 352 | # for the IP. | ||||||||||||||||||||||||||||||||||||||||||
| 353 | sub _ban_command { | ||||||||||||||||||||||||||||||||||||||||||
| 354 | 3 | ▶ | my ( $self, $ip ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ban_command: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | return $self->_nsupdate_command( | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 3 | 'update add ' . $self->_owner($ip) . ' ' . $self->{options}{ttl} . ' IN CNAME .' ); | |||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | sub _unban_command { | ||||||||||||||||||||||||||||||||||||||||||
| 361 | 1 | ▶ | my ( $self, $ip ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unban_command: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | 1 | return $self->_nsupdate_command( 'update delete ' . $self->_owner($ip) . ' IN CNAME .' ); | |||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | =head2 init | ||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | Initiates the backend. Nothing is created on the server; the configured | ||||||||||||||||||||||||||||||||||||||||||
| 369 | keyfile is just verified to exist and be a file. | ||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | sub init { | ||||||||||||||||||||||||||||||||||||||||||
| 374 | 2 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=4 SCAR=19.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | 2 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | 2 | ▶ | if ( $self->{inited} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | $self->{error} = 18; | |||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | $self->{errorString} = 'backend has already been inited'; | |||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | 2 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | 2 | $self->{frontend_obj}->{test_data} = 'inited'; | |||||||||||||||||||||||||||||||||||||||||
| 386 | } elsif ( !-f $self->{options}{keyfile} ) { | ||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | $self->{error} = 23; | |||||||||||||||||||||||||||||||||||||||||
| 388 | $self->{errorString} | ||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | = 'init failed. the keyfile, "' . $self->{options}{keyfile} . '", does not exist or is not a file'; | |||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | 2 | $self->{inited} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 394 | } ## end sub init | ||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | =head2 ban | ||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | Bans an IP. The value of ban is validated as being a IPv4 or IPv6 address | ||||||||||||||||||||||||||||||||||||||||||
| 399 | and lowercased, then a C<CNAME .> record is added at the RPZ owner name for | ||||||||||||||||||||||||||||||||||||||||||
| 400 | the IP by running nsupdate. Banning an already banned IP is a noop. | ||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||
| 402 | $fw_helper->ban( ban => $ip ); | ||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | sub ban { | ||||||||||||||||||||||||||||||||||||||||||
| 407 | 3 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ban: called CC=10 SCAR=36.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||
| 409 | 3 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | 3 | ▶ | if ( !$self->{inited} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | $self->{errorString} = 'backend has not been inited'; | |||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | 3 | ▶ | if ( !defined( $opts{ban} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | $self->{error} = 9; | |||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | $self->{errorString} = 'Nothing specified for the value ban'; | |||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 423 | } elsif ( ref( $opts{ban} ) ne '' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | $self->{error} = 10; | |||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"'; | |||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 428 | ▶ | } elsif ( $opts{ban} !~ /\A$IPv4_re\z/ | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::dns_rpz::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::dns_rpz::IPv6_re\z/
MC/DC0%0/2
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::dns_rpz::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::dns_rpz::IPv6_re\z/
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::dns_rpz::IPv4_re\z/
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::dns_rpz::IPv6_re\z/
Truth table66%2/3
A || B
A= $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::dns_rpz::IPv4_re\z/B= $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::dns_rpz::IPv6_re\z/
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | && $opts{ban} !~ /\A$IPv6_re\z/ ) | ||||||||||||||||||||||||||||||||||||||||||
| 430 | { | ||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | $self->{error} = 10; | |||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 IP'; | |||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||
| 437 | # lowercase so the same IPv6 IP in differing cases can't result in duplicate entries | ||||||||||||||||||||||||||||||||||||||||||
| 438 | 3 | $opts{ban} = lc( $opts{ban} ); | |||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | 3 | ▶ | if ( $self->{banned}{ $opts{ban} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | $self->{frontend_obj}->{test_data} = 'already banned'; | |||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | 3 | my $command = $self->_ban_command( $opts{ban} ); | |||||||||||||||||||||||||||||||||||||||||
| 448 | 3 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | 3 | $self->{frontend_obj}->{test_data} = $command; | |||||||||||||||||||||||||||||||||||||||||
| 450 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | my $output = `$command 2>&1`; | |||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | ▶ | if ( $? != 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | $self->{error} = 13; | |||||||||||||||||||||||||||||||||||||||||
| 454 | $self->{errorString} | ||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | = 'ban failed. non-zero exit code for the command... "' . $command . '"... output... ' . $output; | |||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||
| 460 | 3 | $self->{banned}{ $opts{ban} } = 1; | |||||||||||||||||||||||||||||||||||||||||
| 461 | } ## end sub ban | ||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||
| 463 | =head2 unban | ||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||
| 465 | Unbans an IP. The value of ban is validated as being a IPv4 or IPv6 address | ||||||||||||||||||||||||||||||||||||||||||
| 466 | and lowercased, then the C<CNAME .> record at the RPZ owner name for the IP | ||||||||||||||||||||||||||||||||||||||||||
| 467 | is deleted by running nsupdate. Unbanning an IP that is not banned is a | ||||||||||||||||||||||||||||||||||||||||||
| 468 | noop. | ||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | $fw_helper->unban( ban => $ip ); | ||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||
| 472 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||
| 474 | sub unban { | ||||||||||||||||||||||||||||||||||||||||||
| 475 | 1 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unban: called CC=10 SCAR=37.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||
| 477 | 1 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||
| 479 | 1 | ▶ | if ( !$self->{inited} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | $self->{errorString} = 'backend has not been inited'; | |||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||
| 486 | 1 | ▶ | if ( !defined( $opts{ban} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | $self->{error} = 9; | |||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | $self->{errorString} = 'Nothing specified for the value ban'; | |||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 491 | } elsif ( ref( $opts{ban} ) ne '' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | $self->{error} = 10; | |||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"'; | |||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 496 | ▶ | } elsif ( $opts{ban} !~ /\A$IPv4_re\z/ | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::dns_rpz::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::dns_rpz::IPv6_re\z/
MC/DC0%0/2
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::dns_rpz::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::dns_rpz::IPv6_re\z/
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::dns_rpz::IPv4_re\z/
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::dns_rpz::IPv6_re\z/
Truth table33%1/3
A || B
A= $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::dns_rpz::IPv4_re\z/B= $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::dns_rpz::IPv6_re\z/
| |||||||||||||||||||||||||||||||||||||||||||
| 497 | && $opts{ban} !~ /\A$IPv6_re\z/ ) | ||||||||||||||||||||||||||||||||||||||||||
| 498 | { | ||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | $self->{error} = 10; | |||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 IP'; | |||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||
| 505 | # lowercase so the same IPv6 IP in differing cases can't result in duplicate entries | ||||||||||||||||||||||||||||||||||||||||||
| 506 | 1 | $opts{ban} = lc( $opts{ban} ); | |||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||
| 508 | 1 | ▶ | if ( !$self->{banned}{ $opts{ban} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | $self->{frontend_obj}->{test_data} = 'not banned'; | |||||||||||||||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | 1 | my $command = $self->_unban_command( $opts{ban} ); | |||||||||||||||||||||||||||||||||||||||||
| 516 | 1 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 517 | 1 | $self->{frontend_obj}->{test_data} = $command; | |||||||||||||||||||||||||||||||||||||||||
| 518 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | my $output = `$command 2>&1`; | |||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | ▶ | if ( $? != 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | $self->{error} = 14; | |||||||||||||||||||||||||||||||||||||||||
| 522 | $self->{errorString} | ||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | = 'unban failed. non-zero exit code for the command... "' . $command . '"... output... ' . $output; | |||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||
| 528 | 1 | delete( $self->{banned}{ $opts{ban} } ); | |||||||||||||||||||||||||||||||||||||||||
| 529 | } ## end sub unban | ||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||
| 531 | =head2 list | ||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||
| 533 | List banned IPs. Returns an array of the currently banned IPs. | ||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||
| 535 | my @banned = $fw_helper->list; | ||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||
| 537 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||
| 539 | sub list { | ||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | $self->{frontend_obj}->{test_data} = 'list'; | |||||||||||||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | return keys( %{ $self->{banned} } ); | |||||||||||||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||
| 551 | # Internal helper. Returns a true value if the passed scalar is a valid IPv4 or | ||||||||||||||||||||||||||||||||||||||||||
| 552 | # IPv6 CIDR range, that is an address followed by "/" and a prefix length that | ||||||||||||||||||||||||||||||||||||||||||
| 553 | # is within the range valid for its family (0 to 32 for IPv4, 0 to 128 for | ||||||||||||||||||||||||||||||||||||||||||
| 554 | # IPv6). Returns false otherwise. | ||||||||||||||||||||||||||||||||||||||||||
| 555 | sub _valid_cidr { | ||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | ▶ | my ( $self, $cidr ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_valid_cidr: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||
| 558 | 0 | ▶ | return 0 if ( !defined($cidr) || ref($cidr) ne '' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $cidr or ref $cidr ne ""
MC/DC0%0/2
not defined $cidr or ref $cidr ne ""
not defined $cidr
ref $cidr ne ""
Truth table0%0/3
not(A) or B
A= not defined $cidrB= ref $cidr ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | ▶ | if ( $cidr =~ m!\A(.+)/([0-9]{1,3})\z! ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | my ( $addr, $prefix ) = ( $1, $2 ); | |||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | ▶ | return 1 if ( $addr =~ /\A$IPv4_re\z/ && $prefix <= 32 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$addr =~ /\A$Net::Firewall::BlockerHelper::backends::dns_rpz::IPv4_re\z/ and $prefix <= 32
MC/DC0%0/2
$addr =~ /\A$Net::Firewall::BlockerHelper::backends::dns_rpz::IPv4_re\z/ and $prefix <= 32
$addr =~ /\A$Net::Firewall::BlockerHelper::backends::dns_rpz::IPv4_re\z/
$prefix <= 32
Truth table0%0/3
A and B
A= $addr =~ /\A$Net::Firewall::BlockerHelper::backends::dns_rpz::IPv4_re\z/B= $prefix <= 32
| |||||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | ▶ | return 1 if ( $addr =~ /\A$IPv6_re\z/ && $prefix <= 128 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$addr =~ /\A$Net::Firewall::BlockerHelper::backends::dns_rpz::IPv6_re\z/ and $prefix <= 128
MC/DC0%0/2
$addr =~ /\A$Net::Firewall::BlockerHelper::backends::dns_rpz::IPv6_re\z/ and $prefix <= 128
$addr =~ /\A$Net::Firewall::BlockerHelper::backends::dns_rpz::IPv6_re\z/
$prefix <= 128
Truth table0%0/3
A and B
A= $addr =~ /\A$Net::Firewall::BlockerHelper::backends::dns_rpz::IPv6_re\z/B= $prefix <= 128
| |||||||||||||||||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 567 | } ## end sub _valid_cidr | ||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||
| 569 | =head2 ban_cidr | ||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||
| 571 | CIDR bans are not supported by this backend; this always sets the | ||||||||||||||||||||||||||||||||||||||||||
| 572 | cidrNotSupported error. | ||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||
| 574 | $backend->ban_cidr(ban => '1.2.3.0/24'); | ||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||
| 576 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||
| 578 | sub ban_cidr { | ||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ban_cidr: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | $self->{error} = 35; | |||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | $self->{errorString} = 'the ' . __PACKAGE__ . ' backend does not support CIDR bans'; | |||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 588 | } ## end sub ban_cidr | ||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||
| 590 | =head2 unban_cidr | ||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||
| 592 | CIDR bans are not supported by this backend; this always sets the | ||||||||||||||||||||||||||||||||||||||||||
| 593 | cidrNotSupported error. | ||||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||
| 595 | $backend->unban_cidr(ban => '1.2.3.0/24'); | ||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||
| 597 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||
| 599 | sub unban_cidr { | ||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unban_cidr: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | $self->{error} = 35; | |||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | $self->{errorString} = 'the ' . __PACKAGE__ . ' backend does not support CIDR bans'; | |||||||||||||||||||||||||||||||||||||||||
| 606 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 609 | } ## end sub unban_cidr | ||||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||
| 611 | =head2 list_cidr | ||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||
| 613 | CIDR bans are not supported by this backend, so this always returns an empty | ||||||||||||||||||||||||||||||||||||||||||
| 614 | list. | ||||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||
| 616 | my @banned_cidrs = $backend->list_cidr; | ||||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||
| 618 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||||||||
| 620 | sub list_cidr { | ||||||||||||||||||||||||||||||||||||||||||
| 621 | 0 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_cidr: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||
| 623 | 0 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | return (); | |||||||||||||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||
| 628 | =head2 re_init | ||||||||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||||||
| 630 | Tears down and re-initiates. teardown is called best effort, init is run | ||||||||||||||||||||||||||||||||||||||||||
| 631 | again, and then the RPZ record for every retained banned IP is re-added | ||||||||||||||||||||||||||||||||||||||||||
| 632 | via nsupdate. | ||||||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||||||
| 634 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||
| 636 | sub re_init { | ||||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
re_init: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||||||||||||||||
| 639 | 0 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||
| 641 | 0 | ▶ | if ( !$self->{inited} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 642 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 643 | 0 | $self->{errorString} = 'backend has not been inited'; | |||||||||||||||||||||||||||||||||||||||||
| 644 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 645 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||||||||||||||||
| 648 | { | ||||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | eval { $self->teardown; }; | |||||||||||||||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||||||||||||||||
| 652 | 0 | $self->init; | |||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||
| 654 | 0 | my @commands; | |||||||||||||||||||||||||||||||||||||||||
| 655 | 0 | foreach my $item ( keys( %{ $self->{banned} } ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 656 | 0 | my $command = $self->_ban_command($item); | |||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 658 | 0 | push( @commands, $command ); | |||||||||||||||||||||||||||||||||||||||||
| 659 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 660 | 0 | my $output = `$command 2>&1`; | |||||||||||||||||||||||||||||||||||||||||
| 661 | 0 | ▶ | if ( $? != 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 662 | 0 | $self->{error} = 13; | |||||||||||||||||||||||||||||||||||||||||
| 663 | $self->{errorString} | ||||||||||||||||||||||||||||||||||||||||||
| 664 | 0 | = 'ban failed. non-zero exit code for the command... "' . $command . '"... output... ' . $output; | |||||||||||||||||||||||||||||||||||||||||
| 665 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||||||||||||||
| 667 | } | ||||||||||||||||||||||||||||||||||||||||||
| 668 | } ## end foreach my $item ( keys( %{ ...})) | ||||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||
| 670 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 671 | 0 | $self->{frontend_obj}->{test_data} = \@commands; | |||||||||||||||||||||||||||||||||||||||||
| 672 | } | ||||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||
| 674 | 0 | $self->{inited} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 675 | } ## end sub re_init | ||||||||||||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||||||||||||
| 677 | =head2 teardown | ||||||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||||||
| 679 | Removes the RPZ record for each currently banned IP. The internal ban list is | ||||||||||||||||||||||||||||||||||||||||||
| 680 | kept so a following re_init restores them. | ||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||
| 682 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||
| 684 | sub teardown { | ||||||||||||||||||||||||||||||||||||||||||
| 685 | 0 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
teardown: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||
| 687 | 0 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||||||||||||||||
| 689 | 0 | $self->{inited} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||
| 691 | 0 | my @commands; | |||||||||||||||||||||||||||||||||||||||||
| 692 | 0 | foreach my $item ( sort( keys( %{ $self->{banned} } ) ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 693 | 0 | my $command = $self->_unban_command($item); | |||||||||||||||||||||||||||||||||||||||||
| 694 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 695 | 0 | push( @commands, $command ); | |||||||||||||||||||||||||||||||||||||||||
| 696 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 697 | 0 | my $output = `$command 2>&1`; | |||||||||||||||||||||||||||||||||||||||||
| 698 | 0 | ▶ | if ( $? != 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 699 | 0 | $self->{error} = 17; | |||||||||||||||||||||||||||||||||||||||||
| 700 | $self->{errorString} | ||||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | = 'teardown failed. non-zero exit code for the command... "' . $command . '"... output... ' . $output; | |||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||||||||||||||||
| 704 | } | ||||||||||||||||||||||||||||||||||||||||||
| 705 | } ## end foreach my $item ( sort( keys...)) | ||||||||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||||||||
| 707 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 708 | 0 | $self->{frontend_obj}->{test_data} = \@commands; | |||||||||||||||||||||||||||||||||||||||||
| 709 | } | ||||||||||||||||||||||||||||||||||||||||||
| 710 | } ## end sub teardown | ||||||||||||||||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||||||||||||||||
| 712 | =head2 stop | ||||||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||||||
| 714 | Alias for L</teardown>. | ||||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||
| 716 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||
| 718 | sub stop { | ||||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stop: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||||||||||||||||
| 721 | 0 | return $self->teardown(%opts); | |||||||||||||||||||||||||||||||||||||||||
| 722 | } | ||||||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||||||
| 724 | =head2 check | ||||||||||||||||||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||||||||||||||||
| 726 | Verifies the keyfile still exists and is a file. Returns a true value if so | ||||||||||||||||||||||||||||||||||||||||||
| 727 | and a false value otherwise. | ||||||||||||||||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||||||||||||||||
| 729 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||||||||||||||||
| 731 | sub check { | ||||||||||||||||||||||||||||||||||||||||||
| 732 | 4 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check: called CC=3 SCAR=12.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||||||||||||
| 734 | 4 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||||||||||||||||
| 736 | 4 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 737 | 4 | $self->{frontend_obj}->{test_data} = 'check'; | |||||||||||||||||||||||||||||||||||||||||
| 738 | 4 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 739 | } | ||||||||||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||||||||||
| 741 | 0 | ▶ | return ( -f $self->{options}{keyfile} ) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 742 | } ## end sub check | ||||||||||||||||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||||||||||||||||
| 744 | =head2 flush | ||||||||||||||||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||||||||||||||||
| 746 | Removes all currently banned IPs at once by running a nsupdate delete for | ||||||||||||||||||||||||||||||||||||||||||
| 747 | each RPZ record and clearing the ban list. | ||||||||||||||||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||||||||||||||||
| 749 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||||||||||||||||
| 751 | sub flush { | ||||||||||||||||||||||||||||||||||||||||||
| 752 | 0 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
flush: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||||||||||||
| 754 | 0 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 755 | |||||||||||||||||||||||||||||||||||||||||||
| 756 | 0 | ▶ | if ( !$self->{inited} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 757 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 758 | 0 | $self->{errorString} = 'backend has not been inited'; | |||||||||||||||||||||||||||||||||||||||||
| 759 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 760 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||||||||||||||||
| 763 | 0 | my @commands; | |||||||||||||||||||||||||||||||||||||||||
| 764 | 0 | foreach my $item ( sort( keys( %{ $self->{banned} } ) ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 765 | 0 | my $command = $self->_unban_command($item); | |||||||||||||||||||||||||||||||||||||||||
| 766 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 767 | 0 | push( @commands, $command ); | |||||||||||||||||||||||||||||||||||||||||
| 768 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 769 | 0 | my $output = `$command 2>&1`; | |||||||||||||||||||||||||||||||||||||||||
| 770 | 0 | ▶ | if ( $? != 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 771 | 0 | $self->{error} = 25; | |||||||||||||||||||||||||||||||||||||||||
| 772 | $self->{errorString} | ||||||||||||||||||||||||||||||||||||||||||
| 773 | 0 | = 'flush failed. non-zero exit code for the command... "' . $command . '"... output... ' . $output; | |||||||||||||||||||||||||||||||||||||||||
| 774 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 775 | } | ||||||||||||||||||||||||||||||||||||||||||
| 776 | } | ||||||||||||||||||||||||||||||||||||||||||
| 777 | } ## end foreach my $item ( sort( keys...)) | ||||||||||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||||||||||
| 779 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 780 | 0 | $self->{frontend_obj}->{test_data} = \@commands; | |||||||||||||||||||||||||||||||||||||||||
| 781 | } | ||||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||
| 783 | 0 | $self->{banned} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 784 | } ## end sub flush | ||||||||||||||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||||||||||||
| 786 | =head1 ERROR CODES / FLAGS | ||||||||||||||||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||||||||||||||||
| 788 | Error handling is provided by L<Error::Helper>. All | ||||||||||||||||||||||||||||||||||||||||||
| 789 | errors are considered fatal. | ||||||||||||||||||||||||||||||||||||||||||
| 790 | |||||||||||||||||||||||||||||||||||||||||||
| 791 | =head2 1, notInited | ||||||||||||||||||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||||||||||||||||
| 793 | The backend has not been inited yet. | ||||||||||||||||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||||||||||||||||
| 795 | =head2 8, optionsNotHash | ||||||||||||||||||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||||||||||||||||
| 797 | The item passed to new for options is not a hash. | ||||||||||||||||||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||||||||||||||||
| 799 | =head2 9, noBanItem | ||||||||||||||||||||||||||||||||||||||||||
| 800 | |||||||||||||||||||||||||||||||||||||||||||
| 801 | No IP specified to ban or unban. | ||||||||||||||||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||||||||||||||||
| 803 | =head2 10, banItemNotIP | ||||||||||||||||||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||||||||||||||||
| 805 | The item to ban is not an IP. Either wrong ref type or regexp | ||||||||||||||||||||||||||||||||||||||||||
| 806 | test using L<Regexp::IPv4> and L<Regexp::IPv6> failed. | ||||||||||||||||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||||||||||||||||
| 808 | =head2 12, backendInitError | ||||||||||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||||||||||
| 810 | Failed to init the backend. | ||||||||||||||||||||||||||||||||||||||||||
| 811 | |||||||||||||||||||||||||||||||||||||||||||
| 812 | =head2 13, banFailed | ||||||||||||||||||||||||||||||||||||||||||
| 813 | |||||||||||||||||||||||||||||||||||||||||||
| 814 | Failed to ban the item. | ||||||||||||||||||||||||||||||||||||||||||
| 815 | |||||||||||||||||||||||||||||||||||||||||||
| 816 | =head2 14, unbanFailed | ||||||||||||||||||||||||||||||||||||||||||
| 817 | |||||||||||||||||||||||||||||||||||||||||||
| 818 | Failed to unban the item. | ||||||||||||||||||||||||||||||||||||||||||
| 819 | |||||||||||||||||||||||||||||||||||||||||||
| 820 | =head2 15, listFailed | ||||||||||||||||||||||||||||||||||||||||||
| 821 | |||||||||||||||||||||||||||||||||||||||||||
| 822 | Failed to get a list of bans. | ||||||||||||||||||||||||||||||||||||||||||
| 823 | |||||||||||||||||||||||||||||||||||||||||||
| 824 | =head2 16, reInitFailed | ||||||||||||||||||||||||||||||||||||||||||
| 825 | |||||||||||||||||||||||||||||||||||||||||||
| 826 | Failed to re_init the backend. | ||||||||||||||||||||||||||||||||||||||||||
| 827 | |||||||||||||||||||||||||||||||||||||||||||
| 828 | =head2 17, teardownFailed | ||||||||||||||||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||||||||||||||||
| 830 | Failed to teardown the backend. | ||||||||||||||||||||||||||||||||||||||||||
| 831 | |||||||||||||||||||||||||||||||||||||||||||
| 832 | =head2 18, alreadyInited | ||||||||||||||||||||||||||||||||||||||||||
| 833 | |||||||||||||||||||||||||||||||||||||||||||
| 834 | init called, but the backend has already been inited. | ||||||||||||||||||||||||||||||||||||||||||
| 835 | |||||||||||||||||||||||||||||||||||||||||||
| 836 | =head2 20, triggerInvalid | ||||||||||||||||||||||||||||||||||||||||||
| 837 | |||||||||||||||||||||||||||||||||||||||||||
| 838 | The option trigger is not "client-ip" or "ip". | ||||||||||||||||||||||||||||||||||||||||||
| 839 | |||||||||||||||||||||||||||||||||||||||||||
| 840 | =head2 23, initFailed | ||||||||||||||||||||||||||||||||||||||||||
| 841 | |||||||||||||||||||||||||||||||||||||||||||
| 842 | Init failed. The keyfile does not exist or is not a file. | ||||||||||||||||||||||||||||||||||||||||||
| 843 | |||||||||||||||||||||||||||||||||||||||||||
| 844 | =head2 24, checkFailed | ||||||||||||||||||||||||||||||||||||||||||
| 845 | |||||||||||||||||||||||||||||||||||||||||||
| 846 | The backend check raised an error. | ||||||||||||||||||||||||||||||||||||||||||
| 847 | |||||||||||||||||||||||||||||||||||||||||||
| 848 | =head2 25, flushFailed | ||||||||||||||||||||||||||||||||||||||||||
| 849 | |||||||||||||||||||||||||||||||||||||||||||
| 850 | Failed to flush the bans. | ||||||||||||||||||||||||||||||||||||||||||
| 851 | |||||||||||||||||||||||||||||||||||||||||||
| 852 | =head2 26, portsNotSupported | ||||||||||||||||||||||||||||||||||||||||||
| 853 | |||||||||||||||||||||||||||||||||||||||||||
| 854 | The dns_rpz backend blocks whole IPs and does not support ports. | ||||||||||||||||||||||||||||||||||||||||||
| 855 | |||||||||||||||||||||||||||||||||||||||||||
| 856 | =head2 27, protocolsNotSupported | ||||||||||||||||||||||||||||||||||||||||||
| 857 | |||||||||||||||||||||||||||||||||||||||||||
| 858 | The dns_rpz backend blocks whole IPs and does not support protocols. | ||||||||||||||||||||||||||||||||||||||||||
| 859 | |||||||||||||||||||||||||||||||||||||||||||
| 860 | =head2 30, zoneInvalid | ||||||||||||||||||||||||||||||||||||||||||
| 861 | |||||||||||||||||||||||||||||||||||||||||||
| 862 | The option zone is undef or not a valid zone name. | ||||||||||||||||||||||||||||||||||||||||||
| 863 | |||||||||||||||||||||||||||||||||||||||||||
| 864 | =head2 31, keyfileInvalid | ||||||||||||||||||||||||||||||||||||||||||
| 865 | |||||||||||||||||||||||||||||||||||||||||||
| 866 | The option keyfile is undef or contains whitespace or single quotes. | ||||||||||||||||||||||||||||||||||||||||||
| 867 | |||||||||||||||||||||||||||||||||||||||||||
| 868 | =head2 32, banCidrFailed | ||||||||||||||||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||||||||||||||||
| 870 | Failed to ban the CIDR range. | ||||||||||||||||||||||||||||||||||||||||||
| 871 | |||||||||||||||||||||||||||||||||||||||||||
| 872 | =head2 33, unbanCidrFailed | ||||||||||||||||||||||||||||||||||||||||||
| 873 | |||||||||||||||||||||||||||||||||||||||||||
| 874 | Failed to unban the CIDR range. | ||||||||||||||||||||||||||||||||||||||||||
| 875 | |||||||||||||||||||||||||||||||||||||||||||
| 876 | =head2 34, cidrItemNotCidr | ||||||||||||||||||||||||||||||||||||||||||
| 877 | |||||||||||||||||||||||||||||||||||||||||||
| 878 | The item to ban is not a CIDR range. Either wrong ref type or it is not an | ||||||||||||||||||||||||||||||||||||||||||
| 879 | IPv4 or IPv6 address followed by a prefix length valid for its family. | ||||||||||||||||||||||||||||||||||||||||||
| 880 | |||||||||||||||||||||||||||||||||||||||||||
| 881 | =head2 35, cidrNotSupported | ||||||||||||||||||||||||||||||||||||||||||
| 882 | |||||||||||||||||||||||||||||||||||||||||||
| 883 | The backend does not support CIDR bans. | ||||||||||||||||||||||||||||||||||||||||||
| 884 | |||||||||||||||||||||||||||||||||||||||||||
| 885 | =head2 36, listCidrFailed | ||||||||||||||||||||||||||||||||||||||||||
| 886 | |||||||||||||||||||||||||||||||||||||||||||
| 887 | Failed to get a list of CIDR bans. | ||||||||||||||||||||||||||||||||||||||||||
| 888 | |||||||||||||||||||||||||||||||||||||||||||
| 889 | =head2 37, serverInvalid | ||||||||||||||||||||||||||||||||||||||||||
| 890 | |||||||||||||||||||||||||||||||||||||||||||
| 891 | The option server does not match /^[a-zA-Z0-9.:\-]+$/. | ||||||||||||||||||||||||||||||||||||||||||
| 892 | |||||||||||||||||||||||||||||||||||||||||||
| 893 | =head2 38, ttlInvalid | ||||||||||||||||||||||||||||||||||||||||||
| 894 | |||||||||||||||||||||||||||||||||||||||||||
| 895 | The option ttl is not an int. | ||||||||||||||||||||||||||||||||||||||||||
| 896 | |||||||||||||||||||||||||||||||||||||||||||
| 897 | =head2 39, nsupdateInvalid | ||||||||||||||||||||||||||||||||||||||||||
| 898 | |||||||||||||||||||||||||||||||||||||||||||
| 899 | The option nsupdate does not match /^[a-zA-Z0-9.\/_\-]+$/. | ||||||||||||||||||||||||||||||||||||||||||
| 900 | |||||||||||||||||||||||||||||||||||||||||||
| 901 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||||||||||||||||
| 903 | Zane C. Bowers-Hadley, C<< <vvelox at vvelox.ent> >> | ||||||||||||||||||||||||||||||||||||||||||
| 904 | |||||||||||||||||||||||||||||||||||||||||||
| 905 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||
| 906 | |||||||||||||||||||||||||||||||||||||||||||
| 907 | This software is Copyright (c) 2023 by Zane C. Bowers-Hadley. | ||||||||||||||||||||||||||||||||||||||||||
| 908 | |||||||||||||||||||||||||||||||||||||||||||
| 909 | This is free software, licensed under: | ||||||||||||||||||||||||||||||||||||||||||
| 910 | |||||||||||||||||||||||||||||||||||||||||||
| 911 | The GNU Lesser General Public License, Version 2.1, February 1999 | ||||||||||||||||||||||||||||||||||||||||||
| 912 | |||||||||||||||||||||||||||||||||||||||||||
| 913 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 914 | |||||||||||||||||||||||||||||||||||||||||||
| 915 | 1 | 1; # End of Net::Firewall::BlockerHelper::backends::dns_rpz | |||||||||||||||||||||||||||||||||||||||||