BlockerHelper.pm

filter: Statementstmt 72.2% 273 / 378 Branchbran 79.6% 102 / 128 Conditioncond 75.5% 34 / 45 MC/DCmcdc 62.9% 17 / 27 Subroutinesub 100% 21 / 21 Podpod 100% 13 / 13 totaltotal 75.1% 460 / 612 CC 82 SCAR 25.8
CC
82
Cov
74%
new
27.9
unban_cidr
19.7
ban_cidr
12.0
CRAP 13.3
« BlockerHelper/backends/file_reload.pm ↑ Summary BlockerHelper/backends/shell.pm »
1 package Net::Firewall::BlockerHelper;
2  
3 50 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 50 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 50 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 50 ▶use base 'Error::Helper';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 50 ▶use Regexp::IPv4 qw($IPv4_re);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 50 ▶use Regexp::IPv6 qw($IPv6_re);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 NAME
11  
12 Net::Firewall::BlockerHelper - Helps with managing firewalls for banning IPs.
13  
14 =head1 VERSION
15  
16 Version 0.1.0
17  
18 =cut
19  
20 50 our $VERSION = '0.1.0';
21  
22 =head1 SYNOPSIS
23  
24 use Net::Firewall::BlockerHelper;
25  
26 # create a instance named ssh with a ipfw backend for port 22 tcp
27 my $fw_helper;
28 eval {
29 $fw_helper = Net::Firewall::BlockerHelper->new(
30 backend => 'ipfw',
31 ports => ['22'],
32 protocols => ['tcp'],
33 name => 'ssh',
34 );
35 };
36 if ($@) {
37 print 'Error: '
38 . $Error::Helper::error
39 . "\nError String: "
40 . $Error::Helper::errorString
41 . "\nError Flag: "
42 . $Error::Helper::errorFlag . "\n";
43 }
44  
45 # start the backend
46 $fw_helper->init_backend;
47  
48 # ban some IPs
49 $fw_helper->ban(ban => '1.2.3.4');
50 $fw_helper->ban(ban => '5.6.7.8');
51  
52 # unban a IP
53 $fw_helper->unban(ban => '1.2.3.4');
54  
55 # get a list of banned IPs
56 my @banned = $fw_helper->list;
57 foreach my $ip (@banned) {
58 print 'Banned IP: '.$ip."\n";
59 }
60  
61 # teardown the backend, re-init, and re-ban everything
62 $fw_helper->re_init;
63  
64 # teardown the backend
65 $fw_helper->teardown;
66  
67 =head1 METHODS
68  
69 =head2 new
70  
71 Initiates the the object.
72  
73 - backend :: The backend to use. This must be specified.
74 - Default :: undef
75  
76 - options :: Backend specific options that will be passed to the backend unchecked
77 outside of making sure it is a hash ref if defined.
78 - Default :: {}
79  
80 - ports :: A array of ports to block. Checked to make sure they are ints within
81 the range 1 to 65535 or a valid service name via getservbyname.
82 - Default :: []
83  
84 - protocols :: A array of protocols to block. By default will block all. This
85 is checked against /etc/protocols via the function getprotobyname.
86 - Default :: []
87  
88 - prefix :: Prefix to use. Must match the regex /^[a-zA-Z0-9]+$/
89 - default :: kur
90  
91 - name :: Name of this specific instance.
92 - default :: undef
93  
94 - self_heal :: Before each ban or unban, verify the firewall setup is
95 still present (via the backend's check) and re_init it if it was
96 removed externally. This is the fail2ban actioncheck-before-action
97 behavior. Adds one check probe per ban/unban. Can be overridden per
98 call by passing self_heal to ban/unban.
99 - default :: 1
100  
101 All errors are considered fatal, meaning if new fails it will die.
102  
103 my $fw_helper;
104 eval {
105 $fw_helper = Net::Firewall::BlockerHelper->new(
106 backend => 'ipfw',
107 ports => ['22'],
108 protocols => ['tcp'],
109 name => 'ssh',
110 );
111 };
112 if ($@) {
113 print 'Error: '
114 . $Error::Helper::error
115 . "\nError String: "
116 . $Error::Helper::errorString
117 . "\nError Flag: "
118 . $Error::Helper::errorFlag . "\n";
119 }
120  
121 =cut
122  
123 sub new {
124 185 ▶ my ( $blank, %opts ) = @_;
Subroutine new: called CC=27 SCAR=33.3
Pod documented
125  
126 185 my $self = {
127 perror => undef,
128 error => undef,
129 errorLine => undef,
130 errorFilename => undef,
131 errorString => "",
132 errorExtra => {
133 all_errors_fatal => 1,
134 # all_fatal is what Error::Helper 2.1.0 actually checks; all_errors_fatal
135 # is kept for the name documented in its POD
136 all_fatal => 1,
137 flags => {
138 1 => 'noBackendSpecified',
139 2 => 'invalidPortSpecified',
140 3 => 'portsNotArray',
141 4 => 'protocolsNotArray',
142 5 => 'invalidPortSpecified',
143 6 => 'invalidPrefixSpecified',
144 7 => 'invalidName',
145 8 => 'optionsNotHash',
146 9 => 'noBanItem',
147 10 => 'banItemNotIP',
148 11 => 'invalidBackend',
149 12 => 'backendInitError',
150 13 => 'banFailed',
151 14 => 'unbanFailed',
152 15 => 'listFailed',
153 16 => 'reInitFailed',
154 17 => 'teardownFailed',
155 24 => 'checkFailed',
156 25 => 'flushFailed',
157 26 => 'banCidrFailed',
158 27 => 'unbanCidrFailed',
159 28 => 'cidrItemNotCidr',
160 29 => 'cidrNotSupported',
161 30 => 'listCidrFailed',
162 },
163 fatal_flags => {},
164 perror_not_fatal => 0,
165 },
166 backend => undef,
167 options => {},
168 ports => [],
169 protocols => [],
170 testing => undef,
171 test_data => undef,
172 prefix => 'kur',
173 name => undef,
174 backend_obj => undef,
175 self_heal => 1,
176 };
177 185 bless $self;
178  
179 185 ▶ if ( !defined $opts{backend} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opts{"backend"}) 1 184 185
180 1 $self->{perror} = 1;
181 1 $self->{error} = 1;
182 1 $self->{errorString} = 'backend is undef';
183 1 $self->warn;
184 }
185 184 $self->{backend} = $opts{backend};
186  
187 184 ▶ if ( $self->{backend} !~ /^[a-zA-Z0-9\_]+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"backend"} =~ /^[a-zA-Z0-9\_]+$/) 1 183 184
188 1 $self->{perror} = 1;
189 1 $self->{error} = 11;
190 $self->{errorString}
191 = '"'
192 . $self->{backend}
193 1 . '" does not appear to be valid backend, the regexp /^[a-zA-Z0-9\_]+$/ does not match';
194 1 $self->warn;
195 }
196  
197 183 ▶ if ( defined( $opts{ports} ) && ref( $opts{ports} ) ne 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $opts{'ports'} and ref $opts{'ports'} ne 'ARRAY') { } 1 182 183
elsif (defined $opts{'ports'}) { } 23 159 182
Condition100%3/3
defined $opts{"ports"} and ref $opts{"ports"} ne "ARRAY"
!ll&&!rl&&r
159231
MC/DC100%2/2
defined $opts{"ports"} and ref $opts{"ports"} ne "ARRAY"
defined $opts{"ports"} ref $opts{"ports"} ne "ARRAY"
Truth table100%3/3
A and B
A= defined $opts{"ports"}B= ref $opts{"ports"} ne "ARRAY"
ABresult
0X0
100
111
198 1 $self->{perror} = 1;
199 1 $self->{error} = 3;
200 1 $self->{errorString} = 'ports is defined and type is not array but "' . ref( $opts{ports} ) . '"';
201 1 $self->warn;
202 } elsif ( defined( $opts{ports} ) ) {
203 23 my %ports;
204 23 foreach my $item ( @{ $opts{ports} } ) {
205 29 ▶ if ( $item =~ /^[0-9]+$/ && $item >= 1 && $item <= 65535 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($item =~ /^[0-9]+$/ and $item >= 1 and $item <= 65535) { } 21 8 29
elsif ($item =~ /^[0-9]+$/) { } 2 6 8
Condition100%6/6
$item =~ /^[0-9]+$/ and $item >= 1 and $item <= 65535
!ll&&!rl&&r
7121
$item =~ /^[0-9]+$/ and $item >= 1
!ll&&!rl&&r
6122
MC/DC100%3/3
$item =~ /^[0-9]+$/ and $item >= 1 and $item <= 65535
$item =~ /^[0-9]+$/ $item >= 1 $item <= 65535
Truth table100%4/4
A and B and C
A= $item =~ /^[0-9]+$/B= $item >= 1C= $item <= 65535
ABCresult
0XX0
10X0
1100
1111
206 #push( @{ $self->{ports} }, $item );
207 21 $ports{$item} = 1;
208 } elsif ( $item =~ /^[0-9]+$/ ) {
209 2 $self->{perror} = 1;
210 2 $self->{error} = 2;
211 $self->{errorString}
212 2 = $item . ' is not a valid value for a port as it must be a int within the range 1 to 65535';
213 2 $self->warn;
214 } else {
215 # just using tcp here as protocol must be specified
216 6 my ( $name, $aliases, $port, $proto ) = getservbyname( $item, 'tcp' );
217 6 ▶ if ( !defined($port) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $port) 6 0 6
218 6 $self->{perror} = 1;
219 6 $self->{error} = 2;
220 $self->{errorString}
221 6 = $item . ' could not be resolved to a port name via getservbyname("' . $item . '", "tcp")';
222 6 $self->warn;
223 }
224 0 $ports{$port} = 1;
225 #push( @{ $self->{ports} }, $port );
226 } ## end else [ if ( $item =~ /^[0-9]+$/ && $item >= 1 && ...)]
227 } ## end foreach my $item ( @{ $opts{ports} } )
228 15 my @port_keys = keys(%ports);
229 15 @port_keys = sort { $a <=> $b } @port_keys;
230 15 push( @{ $self->{ports} }, @port_keys );
231 ## end foreach my $item ( @{ $opts{ports} } )
232 } ## end elsif ( defined( $opts{ports} ) )
233  
234 174 ▶ if ( defined( $opts{protocols} ) && ref( $opts{protocols} ) ne 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $opts{'protocols'} and ref $opts{'protocols'} ne 'ARRAY') { } 1 173 174
elsif (defined $opts{'protocols'}) { } 11 162 173
Condition100%3/3
defined $opts{"protocols"} and ref $opts{"protocols"} ne "ARRAY"
!ll&&!rl&&r
162111
MC/DC100%2/2
defined $opts{"protocols"} and ref $opts{"protocols"} ne "ARRAY"
defined $opts{"protocols"} ref $opts{"protocols"} ne "ARRAY"
Truth table100%3/3
A and B
A= defined $opts{"protocols"}B= ref $opts{"protocols"} ne "ARRAY"
ABresult
0X0
100
111
235 1 $self->{perror} = 1;
236 1 $self->{error} = 4;
237 1 $self->{errorString} = 'protocols is defined and type is not array but "' . ref( $opts{protocols} ) . '"';
238 1 $self->warn;
239 } elsif ( defined( $opts{protocols} ) ) {
240 11 my %protocols;
241 11 foreach my $item ( @{ $opts{protocols} } ) {
242 11 my ( $name, $aliases, $proto ) = getprotobyname($item);
243 # if this is undef, it means it is not a known protocol
244 11 ▶ if ( !defined($proto) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $proto) 11 0 11
245 11 $self->{perror} = 1;
246 11 $self->{error} = 5;
247 $self->{errorString}
248 11 = $item . ' could not be resolved to a protocol via getprotobyname("' . $item . '")';
249 11 $self->warn;
250 }
251 0 $protocols{$item} = 1;
252 } ## end foreach my $item ( @{ $opts{protocols} } )
253 0 my @protocols_keys = keys(%protocols);
254 0 @protocols_keys = sort { $a cmp $b } @protocols_keys;
255 0 push( @{ $self->{protocols} }, @protocols_keys );
256 } ## end elsif ( defined( $opts{protocols} ) )
257  
258 # make sure prefix is sane if defiend
259 162 ▶ if ( defined( $opts{prefix} ) && $opts{prefix} !~ /^[a-zA-Z0-9]+$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $opts{'prefix'} and not $opts{'prefix'} =~ /^[a-zA-Z0-9]+$/) { } 1 161 162
elsif (defined $opts{'prefix'}) { } 25 136 161
Condition100%3/3
defined $opts{"prefix"} and not $opts{"prefix"} =~ /^[a-zA-Z0-9]+$/
!ll&&!rl&&r
136251
MC/DC100%2/2
defined $opts{"prefix"} and not $opts{"prefix"} =~ /^[a-zA-Z0-9]+$/
defined $opts{"prefix"} not $opts{"prefix"} =~ /^[a-zA-Z0-9]+$/
Truth table100%3/3
A and not(B)
A= defined $opts{"prefix"}B= not $opts{"prefix"} =~ /^[a-zA-Z0-9]+$/
ABresult
0X0
100
111
260 1 $self->{perror} = 1;
261 1 $self->{error} = 6;
262 $self->{errorString}
263 1 = '"' . $opts{prefix} . '" is not a valid prefix as it does not match the regex /^[a-zA-Z0-9]+$/';
264 1 $self->warn;
265 } elsif ( defined( $opts{prefix} ) ) {
266 25 $self->{prefix} = $opts{prefix};
267 }
268  
269 # make sure we have a name and that it is valid
270 161 ▶ if ( !defined( $opts{name} ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $opts{'name'}) { } 1 160 161
elsif (not $opts{'name'} =~ /^[a-zA-Z0-9\-]+$/) { } 0 160 160
271 1 $self->{perror} = 1;
272 1 $self->{error} = 7;
273 1 $self->{errorString} = 'name is undef';
274 1 $self->warn;
275 } elsif ( $opts{name} !~ /^[a-zA-Z0-9\-]+$/ ) {
276 0 $self->{perror} = 1;
277 0 $self->{error} = 7;
278 0 $self->{errorString} = 'name set to "' . $opts{name} . '" which does not match the regexp /^[a-zA-Z0-9\-]+$/';
279 0 $self->warn;
280 }
281 160 $self->{name} = $opts{name};
282  
283 # used internally for testing
284 160 ▶ if ( defined( $opts{testing} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"testing"}) 145 15 160
285 145 $self->{testing} = $opts{testing};
286 }
287  
288 # check-before-ban self healing, on by default
289 160 ▶ if ( defined( $opts{self_heal} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"self_heal"}) 3 157 160
290 3 ▶ $self->{self_heal} = $opts{self_heal} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$opts{'self_heal'} ? : 0 3 3
291 }
292  
293 160 ▶ if ( defined( $opts{options} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"options"}) 144 16 160
294 144 ▶ if ( ref( $opts{options} ) ne 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $opts{"options"} ne "HASH") 2 142 144
295 2 $self->{perror} = 1;
296 2 $self->{error} = 8;
297 2 $self->{errorString} = 'ref for options is "' . ref( $opts{options} ) . '" and not HASH';
298 2 $self->warn;
299 }
300 142 $self->{options} = $opts{options};
301 }
302  
303 158 return $self;
304 } ## end sub new
305  
306 =head2 init_backend
307  
308 Initiates the backend, creating the backend object and running its init. A
309 failure is raised as backendInitError.
310  
311 No arguments are taken.
312  
313 $fw_helper->init_backend;
314  
315 =cut
316  
317 sub init_backend {
318 148 ▶ my ( $self, %opts ) = @_;
Subroutine init_backend: called CC=6 SCAR=20.7
Pod documented
319  
320 148 $self->errorblank;
321 148 $self->{test_data} = undef;
322  
323 148 my $backend = 'Net::Firewall::BlockerHelper::backends::' . $self->{backend};
324 148 my $backend_obj;
325 eval {
326 # runtime module load: translate Foo::Bar -> Foo/Bar.pm and require it.
327 # $self->{backend} is already validated /^[a-zA-Z0-9_]+$/ in new, so this path is safe.
328 148 ( my $file = $backend ) =~ s{::}{/}g;
329 148 require $file . '.pm';
330  
331 $backend_obj = $backend->new(
332 options => $self->{options},
333 ports => $self->{ports},
334 protocols => $self->{protocols},
335 testing => $self->{testing},
336 prefix => $self->{prefix},
337 name => $self->{name},
338 148 frontend_obj => $self,
339 );
340 79 $backend_obj->init;
341 78 1;
342 148 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { (my $file = $backend) =~ s[::][/]g; require $file . '.pm'; $backend_obj = $backend->new("options", $self->{"options"}, "ports", $self->{"ports"}, "protocols", $self->{"protocols"}, "testing", $self->{"testing"}, "prefix", $self->{"prefix"}, "name", $self->{"name"}, "frontend_obj", $self); $backend_obj->init; 1 } } or do { $self->{"perror"} = 1; $self->{"error"} = 12; $self->{"errorString"} = 'Failed to init backend... ' . $@; $self->warn } 70 78 148
343 70 $self->{perror} = 1;
344 70 $self->{error} = 12;
345 70 $self->{errorString} = 'Failed to init backend... ' . $@;
346 70 $self->warn;
347 };
348 # make sure we got something that is defined and is a object of some sort
349 78 ▶ if ( !defined($backend_obj) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $backend_obj) { } 0 78 78
elsif (ref $backend_obj eq '' or ref $backend_obj eq 'ARRAY' or ref $backend_obj eq 'HASH') { } 0 78 78
350 0 $self->{perror} = 1;
351 0 $self->{error} = 12;
352 0 $self->{errorString} = 'Failed to init backend. Eval did not die, but returned value is undef';
353 0 $self->warn;
354 ▶ } elsif ( ref($backend_obj) eq '' || ref($backend_obj) eq 'ARRAY' || ref($backend_obj) eq 'HASH' ) {
Condition33%2/6
ref $backend_obj eq "" or ref $backend_obj eq "ARRAY" or ref $backend_obj eq "HASH"
l!l&&r!l&&!r
0078
ref $backend_obj eq "" or ref $backend_obj eq "ARRAY"
l!l&&r!l&&!r
0078
MC/DC0%0/3
ref $backend_obj eq "" or ref $backend_obj eq "ARRAY" or ref $backend_obj eq "HASH"
ref $backend_obj eq "" ref $backend_obj eq "ARRAY" ref $backend_obj eq "HASH"
Truth table25%1/4
A or B or C
A= ref $backend_obj eq ""B= ref $backend_obj eq "ARRAY"C= ref $backend_obj eq "HASH"
ABCresult
1XX1
01X1
0011
0000
355 0 $self->{perror} = 1;
356 0 $self->{error} = 12;
357 0 $self->{errorString} = 'ref($backend_obj) is "' . ref($backend_obj) . '"';
358 0 $self->warn;
359 }
360  
361 78 $self->{backend_obj} = $backend_obj;
362 } ## end sub init_backend
363  
364 # Internal helper. If self healing is enabled and the backend is inited, ask
365 # the backend to check that its firewall setup is still present and re_init it
366 # if it is not. This is the fail2ban actioncheck-before-action behavior. Both
367 # the check and re_init are best effort; any failure is left for the following
368 # ban/unban to surface.
369 #
370 # Honors a per-call self_heal override passed via %opts.
371 sub _self_heal {
372 212 ▶ my ( $self, %opts ) = @_;
Subroutine _self_heal: called CC=8 SCAR=20.8
373  
374 212 my $heal = $self->{self_heal};
375 212 ▶ $heal = ( $opts{self_heal} ? 1 : 0 ) if ( exists( $opts{self_heal} ) );
Branch: 2 branches
BranchTrueFalseTotal
if exists $opts{"self_heal"} 3 209 212
$opts{'self_heal'} ? : 1 2 3
376  
377 212 ▶ if ( $heal
Branch: 1 branch
BranchTrueFalseTotal
if ($heal and defined $self->{"backend_obj"} and $self->{"backend_obj"}{"inited"}) 204 8 212
Condition83%5/6
$heal and defined $self->{"backend_obj"} and $self->{"backend_obj"}{"inited"}
!ll&&!rl&&r
71204
$heal and defined $self->{"backend_obj"}
!ll&&!rl&&r
70205
MC/DC66%2/3
$heal and defined $self->{"backend_obj"} and $self->{"backend_obj"}{"inited"}
$heal defined $self->{"backend_obj"} $self->{"backend_obj"}{"inited"}
Truth table75%3/4
A and B and C
A= $healB= defined $self->{"backend_obj"}C= $self->{"backend_obj"}{"inited"}
ABCresult
0XX0
10X0
1100
1111
378 && defined( $self->{backend_obj} )
379 && $self->{backend_obj}->{inited} )
380 {
381 204 my $healthy;
382 204 eval { $healthy = $self->{backend_obj}->check; };
383 204 ▶ if ( !$@ && !$healthy ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@ or $healthy) 5 199 204
Condition66%2/3
$@ or $healthy
l!l&&r!l&&!r
01995
MC/DC50%1/2
$@ or $healthy
$@ $healthy
Truth table66%2/3
A or B
A= $@B= $healthy
ABresult
1X1
011
000
384 # the setup was removed externally, rebuild it and re-add the bans
385 5 eval { $self->{backend_obj}->re_init; };
386 }
387 } ## end if ( $heal && defined( $self->{backend_obj...}))
388  
389 212 return;
390 } ## end sub _self_heal
391  
392 # Internal helper. Returns a true value if the passed scalar is a valid IPv4 or
393 # IPv6 CIDR range, that is an address followed by "/" and a prefix length that
394 # is within the range valid for its family (0 to 32 for IPv4, 0 to 128 for
395 # IPv6). Returns false otherwise.
396 sub _valid_cidr {
397 57 ▶ my ( $self, $cidr ) = @_;
Subroutine _valid_cidr: called CC=8 SCAR=24.3
398  
399 57 ▶ return 0 if ( !defined($cidr) || ref($cidr) ne '' );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $cidr or ref $cidr ne "" 0 57 57
Condition33%1/3
not defined $cidr or ref $cidr ne ""
l!l&&r!l&&!r
0057
MC/DC0%0/2
not defined $cidr or ref $cidr ne ""
not defined $cidr ref $cidr ne ""
Truth table33%1/3
not(A) or B
A= not defined $cidrB= ref $cidr ne ""
ABresult
1X1
011
000
400  
401 57 ▶ if ( $cidr =~ m!\A(.+)/([0-9]{1,3})\z! ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cidr =~ m[\A(.+)/([0-9]{1,3})\z]) 57 0 57
402 57 my ( $addr, $prefix ) = ( $1, $2 );
403 57 ▶ return 1 if ( $addr =~ /\A$IPv4_re\z/ && $prefix <= 32 );
Branch: 1 branch
BranchTrueFalseTotal
if $addr =~ /\A$Net::Firewall::BlockerHelper::IPv4_re\z/ and $prefix <= 32 54 3 57
Condition66%2/3
$addr =~ /\A$Net::Firewall::BlockerHelper::IPv4_re\z/ and $prefix <= 32
!ll&&!rl&&r
3054
MC/DC50%1/2
$addr =~ /\A$Net::Firewall::BlockerHelper::IPv4_re\z/ and $prefix <= 32
$addr =~ /\A$Net::Firewall::BlockerHelper::IPv4_re\z/ $prefix <= 32
Truth table66%2/3
A and B
A= $addr =~ /\A$Net::Firewall::BlockerHelper::IPv4_re\z/B= $prefix <= 32
ABresult
0X0
100
111
404 3 ▶ return 1 if ( $addr =~ /\A$IPv6_re\z/ && $prefix <= 128 );
Branch: 1 branch
BranchTrueFalseTotal
if $addr =~ /\A$Net::Firewall::BlockerHelper::IPv6_re\z/ and $prefix <= 128 3 0 3
Condition33%1/3
$addr =~ /\A$Net::Firewall::BlockerHelper::IPv6_re\z/ and $prefix <= 128
!ll&&!rl&&r
003
MC/DC0%0/2
$addr =~ /\A$Net::Firewall::BlockerHelper::IPv6_re\z/ and $prefix <= 128
$addr =~ /\A$Net::Firewall::BlockerHelper::IPv6_re\z/ $prefix <= 128
Truth table33%1/3
A and B
A= $addr =~ /\A$Net::Firewall::BlockerHelper::IPv6_re\z/B= $prefix <= 128
ABresult
0X0
100
111
405 }
406  
407 0 return 0;
408 } ## end sub _valid_cidr
409  
410 =head2 ban
411  
412 Bans an IP. The value of ban is validated as being a IPv4 or IPv6 address
413 and lowercased, then handed to the backend to ban. If self healing is
414 enabled, the backend setup is checked and restored first. A backend failure
415 is caught and re-raised as banFailed.
416  
417 $fw_helper->ban(ban => $ip);
418  
419 =cut
420  
421 sub ban {
422 130 ▶ my ( $self, %opts ) = @_;
Subroutine ban: called CC=7 SCAR=19.6
Pod documented
423  
424 130 $self->errorblank;
425 130 $self->{test_data} = undef;
426  
427 130 ▶ if ( !defined( $opts{ban} ) ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $opts{'ban'}) { } 1 129 130
elsif (ref $opts{'ban'} ne '') { } 1 128 129
elsif (not $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::IPv6_re\z/) { } 1 127 128
428 1 $self->{error} = 9;
429 1 $self->{errorString} = 'Nothing specified for the value ban';
430 1 $self->warn;
431 0 return;
432 } elsif ( ref( $opts{ban} ) ne '' ) {
433 1 $self->{error} = 10;
434 1 $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"';
435 1 $self->warn;
436 0 return;
437 ▶ } elsif ( $opts{ban} !~ /\A$IPv4_re\z/
Condition100%3/3
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::IPv6_re\z/
l!l&&r!l&&!r
97301
MC/DC100%2/2
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::IPv6_re\z/
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::IPv4_re\z/ $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::IPv6_re\z/
Truth table100%3/3
A || B
A= $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::IPv4_re\z/B= $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::IPv6_re\z/
ABresult
1X1
011
000
438 && $opts{ban} !~ /\A$IPv6_re\z/ )
439 {
440 1 $self->{error} = 10;
441 1 $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 IP';
442 1 $self->warn;
443 0 return;
444 }
445  
446 127 ▶ if ( !defined( $self->{backend_obj} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"backend_obj"}) 1 126 127
447 1 $self->{error} = 13;
448 1 $self->{errorString} = 'No backend object present... init_backend has not been called';
449 1 $self->warn;
450 0 return;
451 }
452  
453 # lowercase so the same IPv6 IP in differing cases can't result in duplicate entries
454 126 $opts{ban} = lc( $opts{ban} );
455  
456 126 $self->_self_heal(%opts);
457  
458 126 eval { $self->{backend_obj}->ban( ban => $opts{ban} ); };
459 126 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 5 121 126
460 5 $self->{error} = 13;
461 5 $self->{errorString} = 'banning item,"' . $opts{ban} . '", failed... ' . $@;
462 5 $self->warn;
463 0 return;
464 }
465 } ## end sub ban
466  
467 =head2 ban_cidr
468  
469 Bans a CIDR range.
470  
471 Only backends whose underlying firewall can match on a network prefix support
472 this. For backends that do not, the cidrNotSupported error is set. See the
473 individual backends for which support it.
474  
475 $fw_helper->ban_cidr(ban => '1.2.3.0/24');
476  
477 =cut
478  
479 sub ban_cidr {
480 34 ▶ my ( $self, %opts ) = @_;
Subroutine ban_cidr: called CC=7 SCAR=24.9
Pod documented
481  
482 34 $self->errorblank;
483 34 $self->{test_data} = undef;
484  
485 34 ▶ if ( !defined( $opts{ban} ) ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $opts{'ban'}) { } 0 34 34
elsif (ref $opts{'ban'} ne '') { } 0 34 34
elsif (not $self->_valid_cidr($opts{'ban'})) { } 0 34 34
486 0 $self->{error} = 9;
487 0 $self->{errorString} = 'Nothing specified for the value ban';
488 0 $self->warn;
489 0 return;
490 } elsif ( ref( $opts{ban} ) ne '' ) {
491 0 $self->{error} = 28;
492 0 $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"';
493 0 $self->warn;
494 0 return;
495 } elsif ( !$self->_valid_cidr( $opts{ban} ) ) {
496 0 $self->{error} = 28;
497 0 $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 CIDR';
498 0 $self->warn;
499 0 return;
500 }
501  
502 34 ▶ if ( !defined( $self->{backend_obj} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"backend_obj"}) 0 34 34
503 0 $self->{error} = 26;
504 0 $self->{errorString} = 'No backend object present... init_backend has not been called';
505 0 $self->warn;
506 0 return;
507 }
508  
509 34 ▶ if ( !$self->{backend_obj}->{cidr_supported} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"backend_obj"}{"cidr_supported"}) 6 28 34
510 6 $self->{error} = 29;
511 6 $self->{errorString} = 'the "' . $self->{backend} . '" backend does not support CIDR bans';
512 6 $self->warn;
513 0 return;
514 }
515  
516 # lowercase so the same IPv6 CIDR in differing cases can't result in duplicate entries
517 28 $opts{ban} = lc( $opts{ban} );
518  
519 28 $self->_self_heal(%opts);
520  
521 28 eval { $self->{backend_obj}->ban_cidr( ban => $opts{ban} ); };
522 28 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 27 28
523 1 $self->{error} = 26;
524 1 $self->{errorString} = 'banning cidr item,"' . $opts{ban} . '", failed... ' . $@;
525 1 $self->warn;
526 0 return;
527 }
528 } ## end sub ban_cidr
529  
530 =head2 unban
531  
532 Unbans an IP. The value of ban is validated as being a IPv4 or IPv6 address
533 and lowercased, then handed to the backend to unban. If self healing is
534 enabled, the backend setup is checked and restored first. A backend failure
535 is caught and re-raised as unbanFailed.
536  
537 $fw_helper->unban(ban => $ip);
538  
539 =cut
540  
541 sub unban {
542 37 ▶ my ( $self, %opts ) = @_;
Subroutine unban: called CC=7 SCAR=21.2
Pod documented
543  
544 37 $self->errorblank;
545 37 $self->{test_data} = undef;
546  
547 37 ▶ if ( !defined( $opts{ban} ) ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $opts{'ban'}) { } 0 37 37
elsif (ref $opts{'ban'} ne '') { } 0 37 37
elsif (not $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::IPv6_re\z/) { } 1 36 37
548 0 $self->{error} = 9;
549 0 $self->{errorString} = 'Nothing specified for the value ban';
550 0 $self->warn;
551 0 return;
552 } elsif ( ref( $opts{ban} ) ne '' ) {
553 0 $self->{error} = 10;
554 0 $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"';
555 0 $self->warn;
556 0 return;
557 ▶ } elsif ( $opts{ban} !~ /\A$IPv4_re\z/
Condition100%3/3
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::IPv6_re\z/
l!l&&r!l&&!r
3331
MC/DC100%2/2
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::IPv6_re\z/
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::IPv4_re\z/ $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::IPv6_re\z/
Truth table100%3/3
A || B
A= $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::IPv4_re\z/B= $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::IPv6_re\z/
ABresult
1X1
011
000
558 && $opts{ban} !~ /\A$IPv6_re\z/ )
559 {
560 1 $self->{error} = 10;
561 1 $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 IP';
562 1 $self->warn;
563 0 return;
564 }
565  
566 36 ▶ if ( !defined( $self->{backend_obj} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"backend_obj"}) 1 35 36
567 1 $self->{error} = 14;
568 1 $self->{errorString} = 'No backend object present... init_backend has not been called';
569 1 $self->warn;
570 0 return;
571 }
572  
573 # lowercase so the same IPv6 IP in differing cases can't result in duplicate entries
574 35 $opts{ban} = lc( $opts{ban} );
575  
576 35 $self->_self_heal(%opts);
577  
578 35 eval { $self->{backend_obj}->unban( ban => $opts{ban} ); };
579 35 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 34 35
580 1 $self->{error} = 14;
581 1 $self->{errorString} = 'unbanning item,"' . $opts{ban} . '", failed... ' . $@;
582 1 $self->warn;
583 0 return;
584 }
585 } ## end sub unban
586  
587 =head2 unban_cidr
588  
589 Unbans a CIDR range.
590  
591 Only backends whose underlying firewall can match on a network prefix support
592 this. For backends that do not, the cidrNotSupported error is set.
593  
594 $fw_helper->unban_cidr(ban => '1.2.3.0/24');
595  
596 =cut
597  
598 sub unban_cidr {
599 23 ▶ my ( $self, %opts ) = @_;
Subroutine unban_cidr: called CC=7 SCAR=29.8
Pod documented
600  
601 23 $self->errorblank;
602 23 $self->{test_data} = undef;
603  
604 23 ▶ if ( !defined( $opts{ban} ) ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $opts{'ban'}) { } 0 23 23
elsif (ref $opts{'ban'} ne '') { } 0 23 23
elsif (not $self->_valid_cidr($opts{'ban'})) { } 0 23 23
605 0 $self->{error} = 9;
606 0 $self->{errorString} = 'Nothing specified for the value ban';
607 0 $self->warn;
608 0 return;
609 } elsif ( ref( $opts{ban} ) ne '' ) {
610 0 $self->{error} = 28;
611 0 $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"';
612 0 $self->warn;
613 0 return;
614 } elsif ( !$self->_valid_cidr( $opts{ban} ) ) {
615 0 $self->{error} = 28;
616 0 $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 CIDR';
617 0 $self->warn;
618 0 return;
619 }
620  
621 23 ▶ if ( !defined( $self->{backend_obj} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"backend_obj"}) 0 23 23
622 0 $self->{error} = 27;
623 0 $self->{errorString} = 'No backend object present... init_backend has not been called';
624 0 $self->warn;
625 0 return;
626 }
627  
628 23 ▶ if ( !$self->{backend_obj}->{cidr_supported} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"backend_obj"}{"cidr_supported"}) 0 23 23
629 0 $self->{error} = 29;
630 0 $self->{errorString} = 'the "' . $self->{backend} . '" backend does not support CIDR bans';
631 0 $self->warn;
632 0 return;
633 }
634  
635 # lowercase so the same IPv6 CIDR in differing cases can't result in duplicate entries
636 23 $opts{ban} = lc( $opts{ban} );
637  
638 23 $self->_self_heal(%opts);
639  
640 23 eval { $self->{backend_obj}->unban_cidr( ban => $opts{ban} ); };
641 23 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 23 23
642 0 $self->{error} = 27;
643 0 $self->{errorString} = 'unbanning cidr item,"' . $opts{ban} . '", failed... ' . $@;
644 0 $self->warn;
645 0 return;
646 }
647 } ## end sub unban_cidr
648  
649 =head2 list
650  
651 List banned IPs. Returns an array of the currently banned single IPs as
652 reported by the backend. CIDR range bans are not included; for those see
653 L</list_cidr>.
654  
655 my @banned = $fw_helper->list;
656  
657 =cut
658  
659 sub list {
660 21 ▶ my ( $self, %opts ) = @_;
Subroutine list: called CC=3 SCAR=11.7
Pod documented
661  
662 21 $self->errorblank;
663 21 $self->{test_data} = undef;
664  
665 21 ▶ if ( !defined( $self->{backend_obj} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"backend_obj"}) 1 20 21
666 1 $self->{error} = 15;
667 1 $self->{errorString} = 'No backend object present... init_backend has not been called';
668 1 $self->warn;
669 0 return;
670 }
671  
672 20 my @banned;
673 20 eval { @banned = $self->{backend_obj}->list; };
674 20 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 20 20
675 0 $self->{error} = 15;
676 0 $self->{errorString} = 'listing bans failed... ' . $@;
677 0 $self->warn;
678 0 return;
679 }
680  
681 20 return @banned;
682 } ## end sub list
683  
684 =head2 list_cidr
685  
686 List banned CIDR ranges. Backends that do not support CIDR bans always return
687 an empty list.
688  
689 my @banned_cidrs = $fw_helper->list_cidr;
690  
691 =cut
692  
693 sub list_cidr {
694 36 ▶ my ( $self, %opts ) = @_;
Subroutine list_cidr: called CC=3 SCAR=13.8
Pod documented
695  
696 36 $self->errorblank;
697 36 $self->{test_data} = undef;
698  
699 36 ▶ if ( !defined( $self->{backend_obj} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"backend_obj"}) 0 36 36
700 0 $self->{error} = 30;
701 0 $self->{errorString} = 'No backend object present... init_backend has not been called';
702 0 $self->warn;
703 0 return;
704 }
705  
706 36 my @banned;
707 36 eval { @banned = $self->{backend_obj}->list_cidr; };
708 36 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 36 36
709 0 $self->{error} = 30;
710 0 $self->{errorString} = 'listing cidr bans failed... ' . $@;
711 0 $self->warn;
712 0 return;
713 }
714  
715 36 return @banned;
716 } ## end sub list_cidr
717  
718 =head2 re_init
719  
720 Tells the backend to re-init itself, rebuilding its firewall setup and
721 re-applying the current ban list. A backend failure is caught and re-raised
722 as reInitFailed.
723  
724 $fw_helper->re_init;
725  
726 =cut
727  
728 sub re_init {
729 8 ▶ my ( $self, %opts ) = @_;
Subroutine re_init: called CC=3 SCAR=11.9
Pod documented
730  
731 8 $self->errorblank;
732 8 $self->{test_data} = undef;
733  
734 8 ▶ if ( !defined( $self->{backend_obj} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"backend_obj"}) 1 7 8
735 1 $self->{error} = 16;
736 1 $self->{errorString} = 'No backend object present... init_backend has not been called';
737 1 $self->warn;
738 0 return;
739 }
740  
741 7 eval { $self->{backend_obj}->re_init; };
742 7 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 7 7
743 0 $self->{error} = 16;
744 0 $self->{errorString} = 'backend re_init failed... ' . $@;
745 0 $self->warn;
746 0 return;
747 }
748 } ## end sub re_init
749  
750 =head2 teardown
751  
752 Tells the backend to tear down its firewall setup, the equivalent of
753 fail2ban's C<actionstop>. The ban list is retained by the backend so a
754 following L</re_init> restores it. A backend failure is caught and re-raised
755 as teardownFailed.
756  
757 $fw_helper->teardown;
758  
759 =cut
760  
761 sub teardown {
762 20 ▶ my ( $self, %opts ) = @_;
Subroutine teardown: called CC=3 SCAR=11.0
Pod documented
763  
764 20 $self->errorblank;
765 20 $self->{test_data} = undef;
766  
767 20 ▶ if ( !defined( $self->{backend_obj} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"backend_obj"}) 1 19 20
768 1 $self->{error} = 17;
769 1 $self->{errorString} = 'No backend object present... init_backend has not been called';
770 1 $self->warn;
771 0 return;
772 }
773  
774 19 eval { $self->{backend_obj}->teardown; };
775 19 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 18 19
776 1 $self->{error} = 17;
777 1 $self->{errorString} = 'backend teardown failed... ' . $@;
778 1 $self->warn;
779 0 return;
780 }
781 } ## end sub teardown
782  
783 =head2 stop
784  
785 Alias for L</teardown>, provided for parity with the fail2ban C<actionstop>
786 concept.
787  
788 $fw_helper->stop;
789  
790 =cut
791  
792 sub stop {
793 1 ▶ my ( $self, %opts ) = @_;
Subroutine stop: called CC=1 SCAR=0.0
Pod documented
794  
795 1 return $self->teardown(%opts);
796 }
797  
798 =head2 check
799  
800 Asks the backend to verify that its firewall setup is still intact. This is
801 the equivalent of fail2ban's C<actioncheck>. Returns a true value if the
802 setup is present and a false value if it appears to have been removed (in
803 which case a L</re_init> is warranted). On an internal error it sets the
804 error and returns undef.
805  
806 if ( !$fw_helper->check ) {
807 $fw_helper->re_init;
808 }
809  
810 =cut
811  
812 sub check {
813 17 ▶ my ( $self, %opts ) = @_;
Subroutine check: called CC=3 SCAR=11.7
Pod documented
814  
815 17 $self->errorblank;
816 17 $self->{test_data} = undef;
817  
818 17 ▶ if ( !defined( $self->{backend_obj} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"backend_obj"}) 1 16 17
819 1 $self->{error} = 24;
820 1 $self->{errorString} = 'No backend object present... init_backend has not been called';
821 1 $self->warn;
822 0 return;
823 }
824  
825 16 my $healthy;
826 16 eval { $healthy = $self->{backend_obj}->check; };
827 16 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 16 16
828 0 $self->{error} = 24;
829 0 $self->{errorString} = 'backend check failed... ' . $@;
830 0 $self->warn;
831 0 return;
832 }
833  
834 16 return $healthy;
835 } ## end sub check
836  
837 =head2 flush
838  
839 Removes all currently banned IPs at once while leaving the firewall rules in
840 place. This is the equivalent of fail2ban's C<actionflush>. Unlike
841 L</teardown>, the blocking rules remain active, so new bans work without a
842 L</re_init>.
843  
844 $fw_helper->flush;
845  
846 =cut
847  
848 sub flush {
849 13 ▶ my ( $self, %opts ) = @_;
Subroutine flush: called CC=3 SCAR=11.0
Pod documented
850  
851 13 $self->errorblank;
852 13 $self->{test_data} = undef;
853  
854 13 ▶ if ( !defined( $self->{backend_obj} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"backend_obj"}) 1 12 13
855 1 $self->{error} = 25;
856 1 $self->{errorString} = 'No backend object present... init_backend has not been called';
857 1 $self->warn;
858 0 return;
859 }
860  
861 12 eval { $self->{backend_obj}->flush; };
862 12 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 11 12
863 1 $self->{error} = 25;
864 1 $self->{errorString} = 'backend flush failed... ' . $@;
865 1 $self->warn;
866 0 return;
867 }
868 } ## end sub flush
869  
870 =head1 ERROR CODES / FLAGS
871  
872 Error handling is provided by L<Error::Helper>. All
873 errors are considered fatal.
874  
875 =head2 1, noBackendSpecified
876  
877 No backend was specified to use.
878  
879 =head2 2, invalidPortSpecified
880  
881 Port is either not an int within the range 1 to 65535 or a name that can be resolved by getservbyname.
882  
883 =head2 3, portsNotArray
884  
885 The data passed to new for ports is not an array.
886  
887 =head2 4, protocolsNotArray
888  
889 The data passed to new for protocols is not an array.
890  
891 =head2 5, invalidPortSpecified
892  
893 Port is either not an int within the range 1 to 65535 or a name that can be resolved by getservbyname.
894  
895 =head2 6, invalidPrefixSpecified
896  
897 The specified prefix did not match /^[a-zA-Z0-9]+$/.
898  
899 =head2 7, invalidName
900  
901 The name is either undef or does not match /^[a-zA-Z0-9\-]+$/.
902  
903 =head2 8, optionsNotHash
904  
905 The item passed to new for options is not a hash.
906  
907 =head2 9, noBanItem
908  
909 No IP specified to ban.
910  
911 =head2 10, banItemNotIP
912  
913 The item to ban is not an IP. Either wrong ref type or regexp
914 test using L<Regexp::IPv4> and L<Regexp::IPv6> failed.
915  
916 =head2 11, invalidBackend
917  
918 The specified backend failed to pass a basic sanity check of making sure it
919 matches the regexp /^[a-zA-Z0-9\_]+$/.
920  
921 =head2 12, backendInitError
922  
923 Failed to init the backend.
924  
925 =head2 13, banFailed
926  
927 Failed to ban the item.
928  
929 =head2 14, unbanFailed
930  
931 Failed to unban the item.
932  
933 =head2 15, listFailed
934  
935 Failed get a list of bans.
936  
937 =head2 16, reInitFailed
938  
939 Failed to re_init the backend.
940  
941 =head2 17, teardownFailed
942  
943 Failed to teardown the backend.
944  
945 =head2 24, checkFailed
946  
947 The backend check raised an error.
948  
949 =head2 25, flushFailed
950  
951 Failed to flush the bans.
952  
953 =head2 26, banCidrFailed
954  
955 Failed to ban the CIDR range.
956  
957 =head2 27, unbanCidrFailed
958  
959 Failed to unban the CIDR range.
960  
961 =head2 28, cidrItemNotCidr
962  
963 The item to ban is not a CIDR range. Either wrong ref type or it is not an
964 IPv4 or IPv6 address followed by a prefix length valid for its family.
965  
966 =head2 29, cidrNotSupported
967  
968 The selected backend does not support CIDR bans.
969  
970 =head2 30, listCidrFailed
971  
972 Failed to get a list of CIDR bans.
973  
974 =head1 AUTHOR
975  
976 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.ent> >>
977  
978 =head1 BUGS
979  
980 Please report any bugs or feature requests to C<bug-net-firewall-blockerhelper at rt.cpan.org>, or through
981 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Firewall-BlockerHelper>. I will be notified, and then you'll
982 automatically be notified of progress on your bug as I make changes.
983  
984  
985  
986  
987 =head1 SUPPORT
988  
989 You can find documentation for this module with the perldoc command.
990  
991 perldoc Net::Firewall::BlockerHelper
992  
993  
994 You can also look for information at:
995  
996 =over 4
997  
998 =item * RT: CPAN's request tracker (report bugs here)
999  
1000 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Firewall-BlockerHelper>
1001  
1002 =item * CPAN Ratings
1003  
1004 L<https://cpanratings.perl.org/d/Net-Firewall-BlockerHelper>
1005  
1006 =item * Search CPAN
1007  
1008 L<https://metacpan.org/release/Net-Firewall-BlockerHelper>
1009  
1010 =back
1011  
1012 =head1 LICENSE AND COPYRIGHT
1013  
1014 This software is Copyright (c) 2026 by Zane C. Bowers-Hadley.
1015  
1016 This is free software, licensed under:
1017  
1018 The GNU Lesser General Public License, Version 2.1, February 1999
1019  
1020 =cut
1021  
1022 50 1; # End of Net::Firewall::BlockerHelper
« BlockerHelper/backends/file_reload.pm ↑ Summary BlockerHelper/backends/shell.pm »