BlockerHelper/backends/netscaler.pm

filter: Statementstmt 47.7% 147 / 308 Branchbran 45.6% 52 / 114 Conditioncond 66.6% 28 / 42 MC/DCmcdc 25.0% 6 / 24 Subroutinesub 77.2% 17 / 22 Podpod 100% 13 / 13 totaltotal 50.2% 263 / 523 CC 75 SCAR 38.0
CC
75
Cov
49%
new
95.2
_request
42.0
unban
41.2
CRAP 44.8
« BlockerHelper/backends/fortigate.pm ↑ Summary BlockerHelper/backends/pfsense.pm »
1 package Net::Firewall::BlockerHelper::backends::netscaler;
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 qw( Error::Helper Net::Firewall::BlockerHelper::Util );
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::netscaler - Citrix NetScaler/ADC backend for Net::Firewall::BlockerHelper.
13  
14 =head1 VERSION
15  
16 Version 0.2.0
17  
18 =cut
19  
20 1 our $VERSION = '0.2.0';
21  
22 =head1 SYNOPSIS
23  
24 use Net::Firewall::BlockerHelper;
25  
26 my $fw_helper = Net::Firewall::BlockerHelper->new(
27 backend => 'netscaler',
28 name => 'ssh',
29 options => {
30 host => 'netscaler.foo.bar',
31 user => 'nsroot',
32 pass => $password,
33 dataset => 'fail2ban',
34 },
35 );
36  
37 $fw_helper->init_backend;
38 $fw_helper->ban(ban => '1.2.3.4');
39 $fw_helper->unban(ban => '1.2.3.4');
40  
41 =head1 DESCRIPTION
42  
43 Blocks IPs remotely by binding them into a policy dataset on a Citrix
44 NetScaler/ADC via the NITRO REST API, equivalent to the fail2ban netscaler
45 action, but using L<LWP::UserAgent> rather than curl. The dataset can then
46 be used to block the IPs via responder policies at a vserver or global
47 level.
48  
49 The dataset must already exist on the NetScaler, as must a responder or
50 similar policy referencing it, as binding IPs into the dataset does nothing
51 by itself; init and check only verify the API is reachable and auth works.
52  
53 Blocking is per IP; ports and protocols are not supported and specifying
54 them is an error.
55  
56 L<LWP::UserAgent> is only loaded at run time, so it is only required if
57 this backend is actually used. For https, L<LWP::Protocol::https> must be
58 present as well.
59  
60 =head1 METHODS
61  
62 =head2 new
63  
64 Initiates the the object.
65  
66 - options :: Backend specific options. See below.
67 - Default :: {}
68  
69 - prefix :: Prefix to use. Must match the regex /^[a-zA-Z0-9]+$/
70 - default :: kur
71  
72 - name :: Name of this specific instance. This must be specified.
73 - default :: undef
74  
75 Ports and protocols are not supported by this backend and specifying either
76 is an error.
77  
78 The options hash accepts the following. host must be specified, as must
79 either auth or both user and pass.
80  
81 - host :: Hostname or IP of the NetScaler appliance.
82 - Default :: undef
83  
84 - user :: Username for basic auth.
85 - Default :: undef
86  
87 - pass :: Password for basic auth.
88 - Default :: undef
89  
90 - auth :: Pre-base64ed basic auth value to use instead of user/pass,
91 for parity with the fail2ban ns_auth option.
92 - Default :: undef
93  
94 - dataset :: The policy dataset holding the blocked IPs.
95 - Default :: <prefix>_<name>
96  
97 - scheme :: http or https.
98 - Default :: https
99  
100 - ssl_verify :: Verify the TLS certificate. The fail2ban action uses
101 curl -k, so this defaults to off; set to 1 if the appliance has
102 a valid certificate.
103 - Default :: 0
104  
105 - timeout :: HTTP timeout in seconds.
106 - Default :: 30
107  
108 All errors are considered fatal, meaning if new fails it will die.
109  
110 =cut
111  
112 5 ▶sub new {
Subroutine new: called CC=33 SCAR=45.6
Pod documented
113 5 my ( $blank, %opts ) = @_;
114  
115 5 my $self = {
116 perror => undef,
117 error => undef,
118 errorLine => undef,
119 errorFilename => undef,
120 errorString => "",
121 errorExtra => {
122 all_errors_fatal => 1,
123 # all_fatal is what Error::Helper 2.1.0 actually checks; all_errors_fatal
124 # is kept for the name documented in its POD
125 all_fatal => 1,
126 flags => {
127 1 => 'notInited',
128 6 => 'invalidPrefixSpecified',
129 7 => 'invalidName',
130 8 => 'optionsNotHash',
131 9 => 'noBanItem',
132 10 => 'banItemNotIP',
133 12 => 'backendInitError',
134 13 => 'banFailed',
135 14 => 'unbanFailed',
136 15 => 'listFailed',
137 16 => 'reInitFailed',
138 17 => 'teardownFailed',
139 18 => 'alreadyInited',
140 23 => 'initFailed',
141 24 => 'checkFailed',
142 25 => 'flushFailed',
143 26 => 'portsNotSupported',
144 27 => 'protocolsNotSupported',
145 28 => 'optionInvalid',
146 29 => 'banCidrFailed',
147 30 => 'unbanCidrFailed',
148 31 => 'cidrItemNotCidr',
149 32 => 'cidrNotSupported',
150 33 => 'listCidrFailed',
151 },
152 fatal_flags => {},
153 perror_not_fatal => 0,
154 },
155 options => {},
156 ports => [],
157 protocols => [],
158 testing => undef,
159 test_data => undef,
160 prefix => 'kur',
161 frontend_obj => undef,
162 inited => 0,
163 banned => {},
164 cidr_supported => 0,
165 ua => undef,
166 };
167 5 bless $self;
168  
169 # blocking is per IP; the dataset has no concept of ports or protocols
170 5 ▶ if ( defined( $opts{ports} ) && ref( $opts{ports} ) eq 'ARRAY' && defined( $opts{ports}[0] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"ports"} and ref $opts{"ports"} eq "ARRAY" and defined $opts{"ports"}[0]) 1 4 5
Condition83%5/6
defined $opts{"ports"} and ref $opts{"ports"} eq "ARRAY" and defined $opts{"ports"}[0]
!ll&&!rl&&r
221
defined $opts{"ports"} and ref $opts{"ports"} eq "ARRAY"
!ll&&!rl&&r
203
MC/DC66%2/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 table75%3/4
A and B and C
A= defined $opts{"ports"}B= ref $opts{"ports"} eq "ARRAY"C= defined $opts{"ports"}[0]
ABCresult
0XX0
10X0
1100
1111
171 1 $self->{perror} = 1;
172 1 $self->{error} = 26;
173 1 $self->{errorString} = 'the netscaler backend blocks whole IPs and does not support ports';
174 1 $self->warn;
175 }
176 4 ▶ if ( defined( $opts{protocols} ) && ref( $opts{protocols} ) eq 'ARRAY' && defined( $opts{protocols}[0] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"protocols"} and ref $opts{"protocols"} eq "ARRAY" and defined $opts{"protocols"}[0]) 0 4 4
Condition66%4/6
defined $opts{"protocols"} and ref $opts{"protocols"} eq "ARRAY" and defined $opts{"protocols"}[0]
!ll&&!rl&&r
220
defined $opts{"protocols"} and ref $opts{"protocols"} eq "ARRAY"
!ll&&!rl&&r
202
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 table50%2/4
A and B and C
A= defined $opts{"protocols"}B= ref $opts{"protocols"} eq "ARRAY"C= defined $opts{"protocols"}[0]
ABCresult
0XX0
10X0
1100
1111
177 0 $self->{perror} = 1;
178 0 $self->{error} = 27;
179 0 $self->{errorString} = 'the netscaler backend blocks whole IPs and does not support protocols';
180 0 $self->warn;
181 }
182  
183 # make sure prefix is sane if defiend
184 4 ▶ 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]+$/) { } 0 4 4
elsif (defined $opts{'prefix'}) { } 2 2 4
Condition66%2/3
defined $opts{"prefix"} and not $opts{"prefix"} =~ /^[a-zA-Z0-9]+$/
!ll&&!rl&&r
220
MC/DC0%0/2
defined $opts{"prefix"} and not $opts{"prefix"} =~ /^[a-zA-Z0-9]+$/
defined $opts{"prefix"} not $opts{"prefix"} =~ /^[a-zA-Z0-9]+$/
Truth table66%2/3
A and not(B)
A= defined $opts{"prefix"}B= not $opts{"prefix"} =~ /^[a-zA-Z0-9]+$/
ABresult
0X0
100
111
185 0 $self->{perror} = 1;
186 0 $self->{error} = 6;
187 $self->{errorString}
188 0 = '"' . $opts{prefix} . '" is not a valid prefix as it does not match the regex /^[a-zA-Z0-9]+$/';
189 0 $self->warn;
190 } elsif ( defined( $opts{prefix} ) ) {
191 2 $self->{prefix} = $opts{prefix};
192 }
193  
194 # make sure we have a name and that it is valid
195 4 ▶ if ( !defined( $opts{name} ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $opts{'name'}) { } 0 4 4
elsif (not $opts{'name'} =~ /^[a-zA-Z0-9\-]+$/) { } 0 4 4
196 0 $self->{perror} = 1;
197 0 $self->{error} = 7;
198 0 $self->{errorString} = 'name is undef';
199 0 $self->warn;
200 } elsif ( $opts{name} !~ /^[a-zA-Z0-9\-]+$/ ) {
201 0 $self->{perror} = 1;
202 0 $self->{error} = 7;
203 0 $self->{errorString} = 'name set to "' . $opts{name} . '" which does not match the regexp /^[a-zA-Z0-9\-]+$/';
204 0 $self->warn;
205 }
206 4 $self->{name} = $opts{name};
207  
208 # used internally for testing
209 4 ▶ if ( defined( $opts{testing} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"testing"}) 2 2 4
210 2 $self->{testing} = $opts{testing};
211 }
212 4 ▶ if ( defined( $opts{frontend_obj} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"frontend_obj"}) 2 2 4
213 2 $self->{frontend_obj} = $opts{frontend_obj};
214 }
215  
216 4 ▶ if ( defined( $opts{options} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"options"}) 4 0 4
217 4 ▶ if ( ref( $opts{options} ) ne 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $opts{"options"} ne "HASH") 0 4 4
218 0 $self->{perror} = 1;
219 0 $self->{error} = 8;
220 0 $self->{errorString} = 'ref for options is "' . ref( $opts{options} ) . '" and not HASH';
221 0 $self->warn;
222 }
223 4 $self->{options} = $opts{options};
224 }
225  
226 4 ▶ if ( !defined( $self->{options}{host} ) || $self->{options}{host} !~ /^[a-zA-Z0-9.\-\[\]:]+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"options"}{"host"} and $self->{"options"}{"host"} =~ /^[a-zA-Z0-9.\-\[\]:]+$/) 1 3 4
Condition66%2/3
defined $self->{"options"}{"host"} and $self->{"options"}{"host"} =~ /^[a-zA-Z0-9.\-\[\]:]+$/
!ll&&!rl&&r
103
MC/DC50%1/2
defined $self->{"options"}{"host"} and $self->{"options"}{"host"} =~ /^[a-zA-Z0-9.\-\[\]:]+$/
defined $self->{"options"}{"host"} $self->{"options"}{"host"} =~ /^[a-zA-Z0-9.\-\[\]:]+$/
Truth table66%2/3
A and B
A= defined $self->{"options"}{"host"}B= $self->{"options"}{"host"} =~ /^[a-zA-Z0-9.\-\[\]:]+$/
ABresult
0X0
100
111
227 1 $self->{perror} = 1;
228 1 $self->{error} = 28;
229 $self->{errorString}
230 = 'the option host is '
231 1 ▶ . ( defined( $self->{options}{host} ) ? '"' . $self->{options}{host} . '" and not a valid host' : 'undef' );
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'options'}{'host'} ? : 0 1 1
232 1 $self->warn;
233 }
234  
235 3 ▶ if ( !defined( $self->{options}{auth} )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"options"}{"auth"} or defined $self->{"options"}{"user"} and defined $self->{"options"}{"pass"}) 1 2 3
Condition83%5/6
defined $self->{"options"}{"auth"} or defined $self->{"options"}{"user"} and defined $self->{"options"}{"pass"}
l!l&&r!l&&!r
111
defined $self->{"options"}{"user"} and defined $self->{"options"}{"pass"}
!ll&&!rl&&r
101
MC/DC66%2/3
defined $self->{"options"}{"auth"} or defined $self->{"options"}{"user"} and defined $self->{"options"}{"pass"}
defined $self->{"options"}{"auth"} defined $self->{"options"}{"user"} defined $self->{"options"}{"pass"}
Truth table75%3/4
A or B and C
A= defined $self->{"options"}{"auth"}B= defined $self->{"options"}{"user"}C= defined $self->{"options"}{"pass"}
ABCresult
1XX1
0111
00X0
0100
236 && ( !defined( $self->{options}{user} ) || !defined( $self->{options}{pass} ) ) )
237 {
238 1 $self->{perror} = 1;
239 1 $self->{error} = 28;
240 $self->{errorString}
241 1 = 'either the option auth, or both the options user and pass, must be specified for auth';
242 1 $self->warn;
243 }
244  
245 2 ▶ if ( !defined( $self->{options}{dataset} ) && defined( $self->{name} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{"options"}{"dataset"} and defined $self->{"name"}) 1 1 2
Condition66%2/3
not defined $self->{"options"}{"dataset"} and defined $self->{"name"}
!ll&&!rl&&r
101
MC/DC50%1/2
not defined $self->{"options"}{"dataset"} and defined $self->{"name"}
not defined $self->{"options"}{"dataset"} defined $self->{"name"}
Truth table66%2/3
not(A) and B
A= not defined $self->{"options"}{"dataset"}B= defined $self->{"name"}
ABresult
0X0
100
111
246 1 $self->{options}{dataset} = $self->{prefix} . '_' . $self->{name};
247 }
248 2 ▶ if ( defined( $self->{options}{dataset} ) && $self->{options}{dataset} !~ /^[a-zA-Z0-9_\-]+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"options"}{"dataset"} and not $self->{"options"}{"dataset"} =~ /^[a-zA-Z0-9_\-]+$/) 0 2 2
Condition33%1/3
defined $self->{"options"}{"dataset"} and not $self->{"options"}{"dataset"} =~ /^[a-zA-Z0-9_\-]+$/
!ll&&!rl&&r
020
MC/DC0%0/2
defined $self->{"options"}{"dataset"} and not $self->{"options"}{"dataset"} =~ /^[a-zA-Z0-9_\-]+$/
defined $self->{"options"}{"dataset"} not $self->{"options"}{"dataset"} =~ /^[a-zA-Z0-9_\-]+$/
Truth table33%1/3
A and not(B)
A= defined $self->{"options"}{"dataset"}B= not $self->{"options"}{"dataset"} =~ /^[a-zA-Z0-9_\-]+$/
ABresult
0X0
100
111
249 0 $self->{perror} = 1;
250 0 $self->{error} = 28;
251 $self->{errorString}
252 0 = 'the option dataset, "' . $self->{options}{dataset} . '", does not match /^[a-zA-Z0-9_\-]+$/';
253 0 $self->warn;
254 }
255  
256 2 ▶ if ( defined( $self->{options}{scheme} )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{'options'}{'scheme'} and $self->{'options'}{'scheme'} ne 'http' and $self->{'options'}{'scheme'} ne 'https') { } 0 2 2
elsif (not defined $self->{'options'}{'scheme'}) { } 1 1 2
Condition50%3/6
defined $self->{"options"}{"scheme"} and $self->{"options"}{"scheme"} ne "http" and $self->{"options"}{"scheme"} ne "https"
!ll&&!rl&&r
200
defined $self->{"options"}{"scheme"} and $self->{"options"}{"scheme"} ne "http"
!ll&&!rl&&r
110
MC/DC0%0/3
defined $self->{"options"}{"scheme"} and $self->{"options"}{"scheme"} ne "http" and $self->{"options"}{"scheme"} ne "https"
defined $self->{"options"}{"scheme"} $self->{"options"}{"scheme"} ne "http" $self->{"options"}{"scheme"} ne "https"
Truth table50%2/4
A and B and C
A= defined $self->{"options"}{"scheme"}B= $self->{"options"}{"scheme"} ne "http"C= $self->{"options"}{"scheme"} ne "https"
ABCresult
0XX0
10X0
1100
1111
257 && $self->{options}{scheme} ne 'http'
258 && $self->{options}{scheme} ne 'https' )
259 {
260 0 $self->{perror} = 1;
261 0 $self->{error} = 28;
262 0 $self->{errorString} = 'the option scheme, "' . $self->{options}{scheme} . '", is not "http" or "https"';
263 0 $self->warn;
264 } elsif ( !defined( $self->{options}{scheme} ) ) {
265 1 $self->{options}{scheme} = 'https';
266 }
267  
268 2 ▶ if ( !defined( $self->{options}{ssl_verify} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"options"}{"ssl_verify"}) 2 0 2
269 2 $self->{options}{ssl_verify} = 0;
270 }
271  
272 2 ▶ if ( !defined( $self->{options}{timeout} ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $self->{'options'}{'timeout'}) { } 2 0 2
elsif (not $self->{'options'}{'timeout'} =~ /^[0-9]+$/) { } 0 0 0
273 2 $self->{options}{timeout} = 30;
274 } elsif ( $self->{options}{timeout} !~ /^[0-9]+$/ ) {
275 0 $self->{perror} = 1;
276 0 $self->{error} = 28;
277 0 $self->{errorString} = 'the option timeout, "' . $self->{options}{timeout} . '", is not an int';
278 0 $self->warn;
279 }
280  
281 2 return $self;
282 } ## end sub new
283  
284 # Internal helper. Returns the base URL of the NITRO configuration API, which
285 # every request is built on.
286 #
287 # NITRO splits its API into config and stat trees; everything this backend
288 # does is configuration, so the config half is baked in here rather than being
289 # a per call decision.
290 #
291 # Takes no arguments; the scheme and host come from the options.
292 #
293 # Returns the base URL as a string, with no trailing slash.
294 #
295 # $self->_base_url; # https://ns.example.org/nitro/v1/config
296 22 ▶sub _base_url {
Subroutine _base_url: called CC=1 SCAR=0.0
297 22 my ($self) = @_;
298  
299 22 return $self->{options}{scheme} . '://' . $self->{options}{host} . '/nitro/v1/config';
300 }
301  
302 # Internal helper. Performs one HTTP request against the NITRO API. Every call
303 # this backend makes to the appliance goes through here.
304 #
305 # The user agent is built on first use and cached on the object, so a run of
306 # requests shares one agent. LWP::UserAgent is loaded with require at that
307 # point rather than at compile time, since only the HTTP backends need it;
308 # failing to load it dies with an explanation naming this backend.
309 #
310 # Note the certificate verification switch here is the ssl_verify option and
311 # is the inverse of the insecure option the other HTTP backends use:
312 # verification is turned off when ssl_verify is false, rather than when
313 # insecure is true.
314 #
315 # Any HTTP level failure dies rather than setting an error. The callers wrap
316 # this in eval and turn the exception into the appropriate error code, which
317 # is what lets one helper serve paths that report ban, unban, and teardown
318 # failures differently.
319 #
320 # Never called in testing mode; those paths record the request instead.
321 #
322 # Args:
323 #
324 # method - The HTTP method, as a plain string, such as 'POST' for adding a
325 # binding or 'DELETE' for removing one.
326 #
327 # url - The full URL to request, as a plain string, built on
328 # _base_url.
329 #
330 # body - Optional request body, as an already encoded JSON string. undef
331 # for methods that carry no body, such as the unban DELETE, which
332 # identifies its target entirely through the URL.
333 #
334 # Returns nothing useful; it is called for its success or failure rather than
335 # its result. Dies on any non success HTTP status.
336 #
337 # $self->_request( 'DELETE', $self->_unban_url($ip) );
338 #
339 # # the usual shape at the call sites
340 # eval { $self->_request( 'POST', $url, $body ); };
341 # if ($@) { ... raise banFailed ... }
342 0 ▶sub _request {
Subroutine _request: not called CC=6 SCAR=37.4
343 0 my ( $self, $method, $url, $body ) = @_;
344  
345 0 ▶ if ( !defined( $self->{ua} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"ua"}) 0 0 0
346 0 local $@;
347 0 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require LWP::UserAgent; my(%new_opts) = ("agent", 'Net::Firewall::BlockerHelper/' . $Net::Firewall::BlockerHelper::backends::netscaler::VERSION, "timeout", $self->{"options"}{"timeout"}); unless ($self->{"options"}{"ssl_verify"}) { $new_opts{"ssl_opts"} = {"verify_hostname", 0, "SSL_verify_mode", 0}; } ; $self->{"ua"} = "LWP::UserAgent"->new(%new_opts); 1 } } or die 'failed to load LWP::UserAgent, which the netscaler backend requires... ' . $@ 0 0 0
348 0 require LWP::UserAgent;
349 my %new_opts = (
350 agent => 'Net::Firewall::BlockerHelper/' . $VERSION,
351 timeout => $self->{options}{timeout},
352 0 );
353 0 ▶ if ( !$self->{options}{ssl_verify} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"options"}{"ssl_verify"}) 0 0 0
354 0 $new_opts{ssl_opts} = { verify_hostname => 0, SSL_verify_mode => 0 };
355 }
356 0 $self->{ua} = LWP::UserAgent->new(%new_opts);
357 0 1;
358 } or die( 'failed to load LWP::UserAgent, which the netscaler backend requires... ' . $@ );
359 } ## end if ( !defined( $self->{ua} ) )
360  
361 0 my $auth = $self->{options}{auth};
362 0 ▶ if ( !defined($auth) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $auth) 0 0 0
363 0 require MIME::Base64;
364 0 $auth = MIME::Base64::encode_base64( $self->{options}{user} . ':' . $self->{options}{pass}, '' );
365 }
366  
367 0 my @headers = (
368 'Content-Type' => 'application/json',
369 'Authorization' => 'Basic ' . $auth,
370 );
371  
372 0 require HTTP::Request;
373 0 my $request = HTTP::Request->new( $method, $url, \@headers, $body );
374 0 my $response = $self->{ua}->request($request);
375  
376 0 ▶ if ( !$response->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->is_success) 0 0 0
377 0 die( $method . ' '
378 . $url
379 . ' failed... HTTP status... '
380 . $response->status_line
381 . '... content... '
382 . $response->decoded_content );
383 }
384  
385 0 return $response;
386 } ## end sub _request
387  
388 =head2 init
389  
390 Initiates the backend. Verifies the NITRO API is reachable and auth works
391 via a GET of C</nitro/v1/config>. Nothing is created on the NetScaler; the
392 dataset is expected to already exist.
393  
394 $backend->init;
395  
396 =cut
397  
398 4 ▶sub init {
Subroutine init: called CC=4 SCAR=20.3
Pod documented
399 4 my ( $self, %opts ) = @_;
400  
401 4 $self->errorblank;
402  
403 4 ▶ if ( $self->{inited} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"inited"}) 0 4 4
404 0 $self->{error} = 18;
405 0 $self->{errorString} = 'backend has already been inited';
406 0 $self->warn;
407 }
408  
409 4 my $url = $self->_base_url;
410  
411 4 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'testing'}) { } 4 0 4
412 4 $self->{frontend_obj}->{test_data} = { requests => [ { method => 'GET', url => $url } ] };
413 } else {
414 0 local $@;
415 0 ▶ eval { $self->_request( 'GET', $url ); 1; } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->_request("GET", $url); 1 } } or do { $self->{"error"} = 23; $self->{"errorString"} = 'init failed. probing the NITRO API failed... ' . $@; $self->warn } 0 0 0
416 0 $self->{error} = 23;
417 0 $self->{errorString} = 'init failed. probing the NITRO API failed... ' . $@;
418 0 $self->warn;
419 };
420 }
421  
422 4 $self->{inited} = 1;
423 } ## end sub init
424  
425 =head2 ban
426  
427 Bans an IP. The value of ban is validated as being a IPv4 or IPv6 address
428 and lowercased, then bound into the policy dataset via a PUT to
429 C</nitro/v1/config/policydataset_value_binding>. Banning an already banned
430 IP is a noop.
431  
432 $backend->ban(ban => $ip);
433  
434 =cut
435  
436 5 ▶sub ban {
Subroutine ban: called CC=10 SCAR=33.8
Pod documented
437 5 my ( $self, %opts ) = @_;
438  
439 5 $self->errorblank;
440  
441 5 ▶ if ( !$self->{inited} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"inited"}) 0 5 5
442 0 $self->{error} = 1;
443 0 $self->{errorString} = 'backend has not been inited';
444 0 $self->warn;
445 0 return;
446 }
447  
448 5 ▶ if ( !defined( $opts{ban} ) ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $opts{'ban'}) { } 0 5 5
elsif (ref $opts{'ban'} ne '') { } 0 5 5
elsif (not $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::netscaler::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::netscaler::IPv6_re\z/) { } 0 5 5
449 0 $self->{error} = 9;
450 0 $self->{errorString} = 'Nothing specified for the value ban';
451 0 $self->warn;
452 0 return;
453 } elsif ( ref( $opts{ban} ) ne '' ) {
454 0 $self->{error} = 10;
455 0 $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"';
456 0 $self->warn;
457 0 return;
458 ▶ } elsif ( $opts{ban} !~ /\A$IPv4_re\z/
Condition66%2/3
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::netscaler::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::netscaler::IPv6_re\z/
l!l&&r!l&&!r
410
MC/DC0%0/2
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::netscaler::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::netscaler::IPv6_re\z/
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::netscaler::IPv4_re\z/ $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::netscaler::IPv6_re\z/
Truth table66%2/3
A || B
A= $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::netscaler::IPv4_re\z/B= $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::netscaler::IPv6_re\z/
ABresult
1X1
011
000
459 && $opts{ban} !~ /\A$IPv6_re\z/ )
460 {
461 0 $self->{error} = 10;
462 0 $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 IP';
463 0 $self->warn;
464 0 return;
465 }
466  
467 # lowercase so the same IPv6 IP in differing cases can't result in duplicate entries
468 5 $opts{ban} = lc( $opts{ban} );
469  
470 5 ▶ if ( $self->{banned}{ $opts{ban} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"banned"}{$opts{"ban"}}) 1 4 5
471 1 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"testing"}) 1 0 1
472 1 $self->{frontend_obj}->{test_data} = 'already banned';
473 }
474 1 return;
475 }
476  
477 4 my $url = $self->_base_url . '/policydataset_value_binding';
478 my $body
479 = '{"policydataset_value_binding":{"name":"'
480 . $self->{options}{dataset}
481 . '","value":"'
482 4 . $opts{ban} . '"}}';
483  
484 4 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'testing'}) { } 4 0 4
485 4 $self->{frontend_obj}->{test_data} = [ { method => 'PUT', url => $url, content => $body } ];
486 } else {
487 0 local $@;
488 0 ▶ eval { $self->_request( 'PUT', $url, $body ); 1; } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->_request("PUT", $url, $body); 1 } } or do { $self->{"error"} = 13; $self->{"errorString"} = 'banning "' . $opts{"ban"} . '" failed... ' . $@; $self->warn; return } 0 0 0
489 0 $self->{error} = 13;
490 0 $self->{errorString} = 'banning "' . $opts{ban} . '" failed... ' . $@;
491 0 $self->warn;
492 0 return;
493 };
494 }
495  
496 4 $self->{banned}{ $opts{ban} } = 1;
497 } ## end sub ban
498  
499 # Internal helper. Returns the URL that removes one address's binding from the
500 # policy dataset.
501 #
502 # NITRO models dataset membership as a binding object rather than as a field
503 # on the dataset, so removing an address means deleting a binding rather than
504 # rewriting a list. That makes this backend incremental, unlike the
505 # replace-in-full ones, and it is why an unban needs a URL of its own while a
506 # ban does not: the ban POSTs a body, the unban carries everything in the URL.
507 #
508 # Which binding to delete is given through the args query parameter, NITRO's
509 # way of identifying a specific binding. The address is percent encoded, which
510 # matters for IPv6, whose colons would otherwise sit raw in the query string.
511 #
512 # Args:
513 #
514 # ip - The address whose binding should be removed, as a plain string.
515 # Expected to be an already validated and lowercased IPv4 or IPv6
516 # address, spelled the same way it was when banned.
517 #
518 # Returns the URL as a string, for a DELETE that carries no body.
519 #
520 # $self->_unban_url('10.0.0.1');
521 # # https://ns.example.org/nitro/v1/config/policydataset_value_binding/blocklist?args=value:10.0.0.1
522 #
523 # $self->_unban_url('2001:db8::1');
524 # # https://ns.example.org/nitro/v1/config/policydataset_value_binding/blocklist?args=value:2001%3Adb8%3A%3A1
525 5 ▶sub _unban_url {
Subroutine _unban_url: called CC=1 SCAR=0.0
526 5 my ( $self, $ip ) = @_;
527  
528 return
529 $self->_base_url
530 . '/policydataset_value_binding/'
531 . $self->{options}{dataset}
532 5 . '?args=value:'
533 . $self->_uri_escape($ip);
534 } ## end sub _unban_url
535  
536 =head2 unban
537  
538 Unbans an IP. The value of ban is validated as being a IPv4 or IPv6 address
539 and lowercased, then its binding is removed from the policy dataset via a
540 DELETE of C</nitro/v1/config/policydataset_value_binding/E<lt>datasetE<gt>?args=value:E<lt>ipE<gt>>.
541 Unbanning an IP that is not banned is a noop.
542  
543 $backend->unban(ban => $ip);
544  
545 =cut
546  
547 2 ▶sub unban {
Subroutine unban: called CC=10 SCAR=37.2
Pod documented
548 2 my ( $self, %opts ) = @_;
549  
550 2 $self->errorblank;
551  
552 2 ▶ if ( !$self->{inited} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"inited"}) 0 2 2
553 0 $self->{error} = 1;
554 0 $self->{errorString} = 'backend has not been inited';
555 0 $self->warn;
556 0 return;
557 }
558  
559 2 ▶ if ( !defined( $opts{ban} ) ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $opts{'ban'}) { } 0 2 2
elsif (ref $opts{'ban'} ne '') { } 0 2 2
elsif (not $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::netscaler::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::netscaler::IPv6_re\z/) { } 0 2 2
560 0 $self->{error} = 9;
561 0 $self->{errorString} = 'Nothing specified for the value ban';
562 0 $self->warn;
563 0 return;
564 } elsif ( ref( $opts{ban} ) ne '' ) {
565 0 $self->{error} = 10;
566 0 $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"';
567 0 $self->warn;
568 0 return;
569 ▶ } elsif ( $opts{ban} !~ /\A$IPv4_re\z/
Condition66%2/3
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::netscaler::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::netscaler::IPv6_re\z/
l!l&&r!l&&!r
110
MC/DC0%0/2
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::netscaler::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::netscaler::IPv6_re\z/
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::netscaler::IPv4_re\z/ $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::netscaler::IPv6_re\z/
Truth table66%2/3
A || B
A= $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::netscaler::IPv4_re\z/B= $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::netscaler::IPv6_re\z/
ABresult
1X1
011
000
570 && $opts{ban} !~ /\A$IPv6_re\z/ )
571 {
572 0 $self->{error} = 10;
573 0 $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 IP';
574 0 $self->warn;
575 0 return;
576 }
577  
578 # lowercase so the same IPv6 IP in differing cases can't result in duplicate entries
579 2 $opts{ban} = lc( $opts{ban} );
580  
581 2 ▶ if ( !$self->{banned}{ $opts{ban} } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"banned"}{$opts{"ban"}}) 0 2 2
582 0 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"testing"}) 0 0 0
583 0 $self->{frontend_obj}->{test_data} = 'not banned';
584 }
585 0 return;
586 }
587  
588 2 my $url = $self->_unban_url( $opts{ban} );
589  
590 2 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'testing'}) { } 2 0 2
591 2 $self->{frontend_obj}->{test_data} = [ { method => 'DELETE', url => $url } ];
592 } else {
593 0 local $@;
594 0 ▶ eval { $self->_request( 'DELETE', $url ); 1; } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->_request("DELETE", $url); 1 } } or do { $self->{"error"} = 14; $self->{"errorString"} = 'unbanning "' . $opts{"ban"} . '" failed... ' . $@; $self->warn; return } 0 0 0
595 0 $self->{error} = 14;
596 0 $self->{errorString} = 'unbanning "' . $opts{ban} . '" failed... ' . $@;
597 0 $self->warn;
598 0 return;
599 };
600 }
601  
602 2 delete( $self->{banned}{ $opts{ban} } );
603 } ## end sub unban
604  
605 =head2 ban_cidr
606  
607 CIDR bans are not supported by this backend; this always sets the
608 cidrNotSupported error.
609  
610 $backend->ban_cidr(ban => '1.2.3.0/24');
611  
612 =cut
613  
614 0 ▶sub ban_cidr {
Subroutine ban_cidr: not called CC=1 SCAR=6.9
Pod documented
615 0 my ( $self, %opts ) = @_;
616  
617 0 $self->errorblank;
618  
619 0 $self->{error} = 32;
620 0 $self->{errorString} = 'the ' . __PACKAGE__ . ' backend does not support CIDR bans';
621 0 $self->warn;
622  
623 0 return;
624 } ## end sub ban_cidr
625  
626 =head2 unban_cidr
627  
628 CIDR bans are not supported by this backend; this always sets the
629 cidrNotSupported error.
630  
631 $backend->unban_cidr(ban => '1.2.3.0/24');
632  
633 =cut
634  
635 0 ▶sub unban_cidr {
Subroutine unban_cidr: not called CC=1 SCAR=6.9
Pod documented
636 0 my ( $self, %opts ) = @_;
637  
638 0 $self->errorblank;
639  
640 0 $self->{error} = 32;
641 0 $self->{errorString} = 'the ' . __PACKAGE__ . ' backend does not support CIDR bans';
642 0 $self->warn;
643  
644 0 return;
645 } ## end sub unban_cidr
646  
647 =head2 list_cidr
648  
649 CIDR bans are not supported by this backend, so this always returns an empty
650 list.
651  
652 my @banned_cidrs = $backend->list_cidr;
653  
654 =cut
655  
656 0 ▶sub list_cidr {
Subroutine list_cidr: not called CC=1 SCAR=6.9
Pod documented
657 0 my ( $self, %opts ) = @_;
658  
659 0 $self->errorblank;
660  
661 0 return ();
662 }
663  
664 =head2 list
665  
666 List banned IPs. Returns an array of the currently banned IPs from the
667 internal ban list; the NetScaler is not queried.
668  
669 my @banned = $backend->list;
670  
671 =cut
672  
673 2 ▶sub list {
Subroutine list: called CC=2 SCAR=7.0
Pod documented
674 2 my ( $self, %opts ) = @_;
675  
676 2 $self->errorblank;
677  
678 2 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"testing"}) 2 0 2
679 2 $self->{frontend_obj}->{test_data} = 'list';
680 }
681  
682 2 return keys( %{ $self->{banned} } );
683 }
684  
685 =head2 re_init
686  
687 Tells the backend to re-init it's self.
688  
689 This will call teardown, best effort as a partially wiped setup is what it
690 is recovering from, then init again. After that every IP in the retained
691 ban list is re-banned by PUTing its dataset binding back.
692  
693 $backend->re_init;
694  
695 =cut
696  
697 1 ▶sub re_init {
Subroutine re_init: called CC=5 SCAR=18.1
Pod documented
698 1 my ( $self, %opts ) = @_;
699  
700 1 $self->errorblank;
701  
702 # teardown is best effort here as a partially or fully wiped setup is
703 # exactly what re_init needs to recover from; init cleans up any remnants
704 {
705 1 local $@;
706 1 eval { $self->teardown; };
707 }
708 1 $self->init;
709  
710 1 my @to_ban = keys( %{ $self->{banned} } );
711  
712 1 my @re_init_test_data;
713 1 foreach my $item (@to_ban) {
714 1 my $url = $self->_base_url . '/policydataset_value_binding';
715 my $body
716 1 = '{"policydataset_value_binding":{"name":"' . $self->{options}{dataset} . '","value":"' . $item . '"}}';
717  
718 1 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'testing'}) { } 1 0 1
719 1 push( @re_init_test_data, { method => 'PUT', url => $url, content => $body } );
720 } else {
721 0 local $@;
722 0 ▶ eval { $self->_request( 'PUT', $url, $body ); 1; } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->_request("PUT", $url, $body); 1 } } or do { $self->{"error"} = 13; $self->{"errorString"} = 'banning "' . $item . '" failed... ' . $@; $self->warn } 0 0 0
723 0 $self->{error} = 13;
724 0 $self->{errorString} = 'banning "' . $item . '" failed... ' . $@;
725 0 $self->warn;
726 };
727 }
728 } ## end foreach my $item (@to_ban)
729  
730 1 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"testing"}) 1 0 1
731 1 $self->{frontend_obj}->{test_data} = \@re_init_test_data;
732 }
733  
734 1 $self->{inited} = 1;
735 } ## end sub re_init
736  
737 =head2 teardown
738  
739 Tears down the setup for the backend by removing the binding for each
740 currently banned IP. The internal list of bans is kept, so a following
741 re_init will re-add them.
742  
743 $backend->teardown;
744  
745 =cut
746  
747 2 ▶sub teardown {
Subroutine teardown: called CC=5 SCAR=20.0
Pod documented
748 2 my ( $self, %opts ) = @_;
749  
750 2 $self->errorblank;
751  
752 2 $self->{inited} = 0;
753  
754 2 my @requests;
755 2 foreach my $item ( sort( keys( %{ $self->{banned} } ) ) ) {
756 2 my $url = $self->_unban_url($item);
757 2 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'testing'}) { } 2 0 2
758 2 push( @requests, { method => 'DELETE', url => $url } );
759 } else {
760 0 local $@;
761 0 ▶ eval { $self->_request( 'DELETE', $url ); 1; } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->_request("DELETE", $url); 1 } } or do { $self->{"error"} = 17; $self->{"errorString"} = 'teardown failed removing the binding for "' . $item . '"... ' . $@; $self->warn } 0 0 0
762 0 $self->{error} = 17;
763 0 $self->{errorString} = 'teardown failed removing the binding for "' . $item . '"... ' . $@;
764 0 $self->warn;
765 };
766 }
767 } ## end foreach my $item ( sort( keys( %{ $self->{banned...})))
768  
769 2 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"testing"}) 2 0 2
770 2 $self->{frontend_obj}->{test_data} = \@requests;
771 }
772 } ## end sub teardown
773  
774 =head2 stop
775  
776 Alias for L</teardown>, provided for parity with the fail2ban C<actionstop>
777 concept.
778  
779 $backend->stop;
780  
781 =cut
782  
783 0 ▶sub stop {
Subroutine stop: not called CC=1 SCAR=6.9
Pod documented
784 0 my ( $self, %opts ) = @_;
785  
786 0 return $self->teardown(%opts);
787 }
788  
789 =head2 check
790  
791 Verifies the NITRO API is still reachable and auth still works. Returns a
792 true value if so and a false value otherwise. This is the equivalent of
793 fail2ban's C<actioncheck>.
794  
795 if ( !$backend->check ) {
796 $backend->re_init;
797 }
798  
799 =cut
800  
801 8 ▶sub check {
Subroutine check: called CC=3 SCAR=14.7
Pod documented
802 8 my ( $self, %opts ) = @_;
803  
804 8 $self->errorblank;
805  
806 8 my $url = $self->_base_url;
807  
808 8 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"testing"}) 8 0 8
809 8 $self->{frontend_obj}->{test_data} = [ { method => 'GET', url => $url } ];
810 8 return 1;
811 }
812  
813 0 local $@;
814 0 ▶ eval { $self->_request( 'GET', $url ); 1; } or return 0;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->_request("GET", $url); 1 } } or return 0 0 0 0
815  
816 0 return 1;
817 } ## end sub check
818  
819 =head2 flush
820  
821 Removes all currently banned IPs at once by removing their bindings and
822 forgetting them. This is the equivalent of fail2ban's C<actionflush>.
823  
824 $backend->flush;
825  
826 =cut
827  
828 1 ▶sub flush {
Subroutine flush: called CC=6 SCAR=23.9
Pod documented
829 1 my ( $self, %opts ) = @_;
830  
831 1 $self->errorblank;
832  
833 1 ▶ if ( !$self->{inited} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"inited"}) 0 1 1
834 0 $self->{error} = 1;
835 0 $self->{errorString} = 'backend has not been inited';
836 0 $self->warn;
837 0 return;
838 }
839  
840 1 my @requests;
841 1 foreach my $item ( sort( keys( %{ $self->{banned} } ) ) ) {
842 1 my $url = $self->_unban_url($item);
843 1 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'testing'}) { } 1 0 1
844 1 push( @requests, { method => 'DELETE', url => $url } );
845 } else {
846 0 local $@;
847 0 ▶ eval { $self->_request( 'DELETE', $url ); 1; } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->_request("DELETE", $url); 1 } } or do { $self->{"error"} = 25; $self->{"errorString"} = 'flush failed removing the binding for "' . $item . '"... ' . $@; $self->warn } 0 0 0
848 0 $self->{error} = 25;
849 0 $self->{errorString} = 'flush failed removing the binding for "' . $item . '"... ' . $@;
850 0 $self->warn;
851 };
852 }
853 } ## end foreach my $item ( sort( keys( %{ $self->{banned...})))
854  
855 1 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"testing"}) 1 0 1
856 1 $self->{frontend_obj}->{test_data} = \@requests;
857 }
858  
859 1 $self->{banned} = {};
860 } ## end sub flush
861  
862 =head1 ERROR CODES / FLAGS
863  
864 Error handling is provided by L<Error::Helper>. All
865 errors are considered fatal.
866  
867 =head2 1, notInited
868  
869 The backend has not been inited yet.
870  
871 =head2 6, invalidPrefixSpecified
872  
873 The specified prefix did not match /^[a-zA-Z0-9]+$/.
874  
875 =head2 7, invalidName
876  
877 The name is either undef or does not match /^[a-zA-Z0-9\-]+$/.
878  
879 =head2 8, optionsNotHash
880  
881 The item passed to new for options is not a hash.
882  
883 =head2 9, noBanItem
884  
885 No IP specified to ban or unban.
886  
887 =head2 10, banItemNotIP
888  
889 The item to ban is not an IP. Either wrong ref type or regexp
890 test using L<Regexp::IPv4> and L<Regexp::IPv6> failed.
891  
892 =head2 12, backendInitError
893  
894 Failed to init the backend.
895  
896 =head2 13, banFailed
897  
898 Failed to ban the item.
899  
900 =head2 14, unbanFailed
901  
902 Failed to unban the item.
903  
904 =head2 15, listFailed
905  
906 Failed to get a list of bans.
907  
908 =head2 16, reInitFailed
909  
910 Failed to re_init the backend.
911  
912 =head2 17, teardownFailed
913  
914 Failed to teardown the backend.
915  
916 =head2 18, alreadyInited
917  
918 init called, but the backend has already been inited.
919  
920 =head2 23, initFailed
921  
922 Probing the NITRO API during init failed.
923  
924 =head2 24, checkFailed
925  
926 The backend check raised an error.
927  
928 =head2 25, flushFailed
929  
930 Failed to flush the bans.
931  
932 =head2 26, portsNotSupported
933  
934 The netscaler backend blocks whole IPs and does not support ports.
935  
936 =head2 27, protocolsNotSupported
937  
938 The netscaler backend blocks whole IPs and does not support protocols.
939  
940 =head2 28, optionInvalid
941  
942 One of the options, such as host, auth, dataset, scheme, or timeout, is
943 invalid or missing.
944  
945 =head2 29, banCidrFailed
946  
947 Failed to ban the CIDR range.
948  
949 =head2 30, unbanCidrFailed
950  
951 Failed to unban the CIDR range.
952  
953 =head2 31, cidrItemNotCidr
954  
955 The item to ban is not a CIDR range. Either wrong ref type or it is not an
956 IPv4 or IPv6 address followed by a prefix length valid for its family.
957  
958 =head2 32, cidrNotSupported
959  
960 The backend does not support CIDR bans.
961  
962 =head2 33, listCidrFailed
963  
964 Failed to get a list of CIDR bans.
965  
966 =head1 AUTHOR
967  
968 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.ent> >>
969  
970 =head1 BUGS
971  
972 Please report any bugs or feature requests to C<bug-net-firewall-blockerhelper at rt.cpan.org>, or through
973 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Firewall-BlockerHelper>.
974  
975 =head1 LICENSE AND COPYRIGHT
976  
977 This software is Copyright (c) 2023 by Zane C. Bowers-Hadley.
978  
979 This is free software, licensed under:
980  
981 The GNU Lesser General Public License, Version 2.1, February 1999
982  
983  
984 =cut
985  
986 1 1; # End of Net::Firewall::BlockerHelper
« BlockerHelper/backends/fortigate.pm ↑ Summary BlockerHelper/backends/pfsense.pm »