| 1 | package Net::Firewall::BlockerHelper::backends::f5_bigip; | ||||||||||||||||||||||||||||||||||||||||||
| 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::f5_bigip - F5 BIG-IP backend using the iControl REST API. | ||||||||||||||||||||||||||||||||||||||||||
| 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 => 'f5_bigip', | ||||||||||||||||||||||||||||||||||||||||||
| 28 | name => 'ssh', | ||||||||||||||||||||||||||||||||||||||||||
| 29 | options => { | ||||||||||||||||||||||||||||||||||||||||||
| 30 | host => 'bigip.example.org', | ||||||||||||||||||||||||||||||||||||||||||
| 31 | user => 'blocker', | ||||||||||||||||||||||||||||||||||||||||||
| 32 | password => $password, | ||||||||||||||||||||||||||||||||||||||||||
| 33 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | $fw_helper->init_backend; | ||||||||||||||||||||||||||||||||||||||||||
| 37 | $fw_helper->ban( ban => '1.2.3.4' ); | ||||||||||||||||||||||||||||||||||||||||||
| 38 | $fw_helper->unban( ban => '1.2.3.4' ); | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | Blocks IPs on an F5 BIG-IP via its iControl REST API, managing the membership | ||||||||||||||||||||||||||||||||||||||||||
| 43 | of a single firewall address-list. The full membership of the address-list is | ||||||||||||||||||||||||||||||||||||||||||
| 44 | rendered from this backend's internal state on every change, so the address | ||||||||||||||||||||||||||||||||||||||||||
| 45 | list contains exactly the currently banned IPs and nothing else. | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | The managed address-list is identified by its C<name> option (defaulting to | ||||||||||||||||||||||||||||||||||||||||||
| 48 | C<< <prefix>_<name> >>) within a partition (defaulting to C<Common>). The | ||||||||||||||||||||||||||||||||||||||||||
| 49 | address-list object, and any firewall rule referencing it, must already exist | ||||||||||||||||||||||||||||||||||||||||||
| 50 | on the BIG-IP. | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | Blocking is per IP; ports and protocols are not supported and specifying them | ||||||||||||||||||||||||||||||||||||||||||
| 53 | is an error. | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | Auth is via HTTP basic auth using the C<user> and C<password> options. | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | L<LWP::UserAgent> is loaded at run time, so it is only required when this | ||||||||||||||||||||||||||||||||||||||||||
| 58 | backend is actually used. For https, L<LWP::Protocol::https> must be present | ||||||||||||||||||||||||||||||||||||||||||
| 59 | as well. | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | =head2 new | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | Initiates the object. | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | - options :: Backend specific options. See below. | ||||||||||||||||||||||||||||||||||||||||||
| 68 | - prefix :: Prefix to use. Must match /^[a-zA-Z0-9]+$/. Default kur. | ||||||||||||||||||||||||||||||||||||||||||
| 69 | - name :: Name of this instance. Required. | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | Ports and protocols are not supported and specifying either is an error. | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | The options hash accepts the following. | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | - host :: BIG-IP host, optionally host:port. Required. | ||||||||||||||||||||||||||||||||||||||||||
| 76 | - Default :: undef | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | - user :: iControl REST user. Required. | ||||||||||||||||||||||||||||||||||||||||||
| 79 | - Default :: undef | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | - password :: iControl REST password. Required. | ||||||||||||||||||||||||||||||||||||||||||
| 82 | - Default :: undef | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | - name :: The firewall address-list name to manage. | ||||||||||||||||||||||||||||||||||||||||||
| 85 | - Default :: <prefix>_<name> | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | - partition :: The partition the address-list lives in. | ||||||||||||||||||||||||||||||||||||||||||
| 88 | - Default :: Common | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | - insecure :: If true, skip TLS certificate verification (BIG-IP ships a | ||||||||||||||||||||||||||||||||||||||||||
| 91 | self-signed certificate). | ||||||||||||||||||||||||||||||||||||||||||
| 92 | - Default :: 0 | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | - timeout :: HTTP timeout in seconds. | ||||||||||||||||||||||||||||||||||||||||||
| 95 | - Default :: 30 | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | All errors are considered fatal, meaning if new fails it will die. | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 5 | ▶ | my ( $blank, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=27 SCAR=43.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 5 | my $self = { | |||||||||||||||||||||||||||||||||||||||||
| 105 | perror => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 106 | error => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 107 | errorLine => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 108 | errorFilename => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 109 | errorString => "", | ||||||||||||||||||||||||||||||||||||||||||
| 110 | errorExtra => { | ||||||||||||||||||||||||||||||||||||||||||
| 111 | all_errors_fatal => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 112 | # all_fatal is what Error::Helper 2.1.0 actually checks; all_errors_fatal | ||||||||||||||||||||||||||||||||||||||||||
| 113 | # is kept for the name documented in its POD | ||||||||||||||||||||||||||||||||||||||||||
| 114 | all_fatal => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 115 | flags => { | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 => 'notInited', | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 6 => 'invalidPrefixSpecified', | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 7 => 'invalidName', | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 8 => 'optionsNotHash', | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 9 => 'noBanItem', | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 10 => 'banItemNotIP', | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 12 => 'backendInitError', | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 13 => 'banFailed', | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 14 => 'unbanFailed', | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 15 => 'listFailed', | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 16 => 'reInitFailed', | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 17 => 'teardownFailed', | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 18 => 'alreadyInited', | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 23 => 'initFailed', | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 24 => 'checkFailed', | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 25 => 'flushFailed', | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 26 => 'portsNotSupported', | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 27 => 'protocolsNotSupported', | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 30 => 'hostNotDefined', | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 31 => 'userNotDefined', | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 32 => 'passwordNotDefined', | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 33 => 'banCidrFailed', | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 34 => 'unbanCidrFailed', | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 35 => 'cidrItemNotCidr', | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 36 => 'cidrNotSupported', | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 37 => 'listCidrFailed', | ||||||||||||||||||||||||||||||||||||||||||
| 142 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 143 | fatal_flags => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 144 | perror_not_fatal => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 145 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 146 | options => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 147 | ports => [], | ||||||||||||||||||||||||||||||||||||||||||
| 148 | protocols => [], | ||||||||||||||||||||||||||||||||||||||||||
| 149 | testing => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 150 | test_data => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 151 | prefix => 'kur', | ||||||||||||||||||||||||||||||||||||||||||
| 152 | name => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 153 | frontend_obj => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 154 | inited => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 155 | banned => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 156 | banned_cidr => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 157 | cidr_supported => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 158 | ua => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 159 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 5 | bless $self; | |||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | # blocking is per IP; the address-list has no concept of ports or protocols | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 5 | ▶ | 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]
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | $self->{perror} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | $self->{error} = 26; | |||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | $self->{errorString} = 'the f5_bigip backend blocks whole IPs and does not support ports'; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 5 | ▶ | 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]
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | $self->{perror} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | $self->{error} = 27; | |||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | $self->{errorString} = 'the f5_bigip backend blocks whole IPs and does not support protocols'; | |||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | # make sure prefix is sane if defined | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 5 | ▶ | if ( defined( $opts{prefix} ) && $opts{prefix} !~ /^[a-zA-Z0-9]+$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
defined $opts{"prefix"} and not $opts{"prefix"} =~ /^[a-zA-Z0-9]+$/
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 table33%1/3
A and not(B)
A= defined $opts{"prefix"}B= not $opts{"prefix"} =~ /^[a-zA-Z0-9]+$/
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | $self->{perror} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | $self->{error} = 6; | |||||||||||||||||||||||||||||||||||||||||
| 180 | $self->{errorString} | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | = '"' . $opts{prefix} . '" is not a valid prefix as it does not match the regex /^[a-zA-Z0-9]+$/'; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 183 | } elsif ( defined( $opts{prefix} ) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 184 | 5 | $self->{prefix} = $opts{prefix}; | |||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | # make sure we have a name and that it is valid | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 5 | ▶ | if ( !defined( $opts{name} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | $self->{perror} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | $self->{error} = 7; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | $self->{errorString} = 'name is undef'; | |||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 193 | } elsif ( $opts{name} !~ /^[a-zA-Z0-9\-]+$/ ) { | ||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | $self->{perror} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | $self->{error} = 7; | |||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | $self->{errorString} = 'name set to "' . $opts{name} . '" which does not match the regexp /^[a-zA-Z0-9\-]+$/'; | |||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 5 | $self->{name} = $opts{name}; | |||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 5 | ▶ | if ( defined( $opts{testing} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 5 | $self->{testing} = $opts{testing}; | |||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 5 | ▶ | if ( defined( $opts{frontend_obj} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 5 | $self->{frontend_obj} = $opts{frontend_obj}; | |||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | 5 | ▶ | if ( defined( $opts{options} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 5 | ▶ | if ( ref( $opts{options} ) ne 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | $self->{perror} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | $self->{error} = 8; | |||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | $self->{errorString} = 'ref for options is "' . ref( $opts{options} ) . '" and not HASH'; | |||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 5 | $self->{options} = $opts{options}; | |||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | # required connection options | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 5 | ▶ | if ( !defined( $self->{options}{host} ) || $self->{options}{host} eq '' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $self->{"options"}{"host"} or $self->{"options"}{"host"} eq ""
MC/DC50%1/2
not defined $self->{"options"}{"host"} or $self->{"options"}{"host"} eq ""
not defined $self->{"options"}{"host"}
$self->{"options"}{"host"} eq ""
Truth table66%2/3
not(A) or B
A= not defined $self->{"options"}{"host"}B= $self->{"options"}{"host"} eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 1 | $self->{perror} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 221 | 1 | $self->{error} = 30; | |||||||||||||||||||||||||||||||||||||||||
| 222 | 1 | $self->{errorString} = 'the option host is undef or blank'; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 1 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 4 | ▶ | if ( !defined( $self->{options}{user} ) || $self->{options}{user} eq '' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $self->{"options"}{"user"} or $self->{"options"}{"user"} eq ""
MC/DC50%1/2
not defined $self->{"options"}{"user"} or $self->{"options"}{"user"} eq ""
not defined $self->{"options"}{"user"}
$self->{"options"}{"user"} eq ""
Truth table66%2/3
not(A) or B
A= not defined $self->{"options"}{"user"}B= $self->{"options"}{"user"} eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | 1 | $self->{perror} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 227 | 1 | $self->{error} = 31; | |||||||||||||||||||||||||||||||||||||||||
| 228 | 1 | $self->{errorString} = 'the option user is undef or blank'; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 1 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 3 | ▶ | if ( !defined( $self->{options}{password} ) || $self->{options}{password} eq '' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $self->{"options"}{"password"} or $self->{"options"}{"password"} eq ""
MC/DC50%1/2
not defined $self->{"options"}{"password"} or $self->{"options"}{"password"} eq ""
not defined $self->{"options"}{"password"}
$self->{"options"}{"password"} eq ""
Truth table66%2/3
not(A) or B
A= not defined $self->{"options"}{"password"}B= $self->{"options"}{"password"} eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 1 | $self->{perror} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 233 | 1 | $self->{error} = 32; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 1 | $self->{errorString} = 'the option password is undef or blank'; | |||||||||||||||||||||||||||||||||||||||||
| 235 | 1 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | # defaults | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 2 | ▶ | $self->{options}{insecure} = 0 if ( !defined( $self->{options}{insecure} ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 2 | ▶ | $self->{options}{timeout} = 30 if ( !defined( $self->{options}{timeout} ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 2 | ▶ | $self->{options}{partition} = 'Common' if ( !defined( $self->{options}{partition} ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 2 | ▶ | if ( defined( $self->{name} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 2 | ▶ | $self->{options}{name} = $self->{prefix} . '_' . $self->{name} if ( !defined( $self->{options}{name} ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 247 | } ## end sub new | ||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | # Internal helper. Minimal percent encoder so URI::Escape is not needed. | ||||||||||||||||||||||||||||||||||||||||||
| 250 | sub _uri_escape { | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 14 | ▶ | my ( $self, $string ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_uri_escape: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | 14 | $string =~ s/([^A-Za-z0-9\-._~])/sprintf('%%%02X', ord($1))/ge; | |||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 14 | return $string; | |||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | # Internal helper. Returns a canonical JSON::PP encoder/decoder. | ||||||||||||||||||||||||||||||||||||||||||
| 259 | sub _json { | ||||||||||||||||||||||||||||||||||||||||||
| 260 | 6 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_json: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 6 | require JSON::PP; | |||||||||||||||||||||||||||||||||||||||||
| 263 | 6 | return JSON::PP->new->canonical->utf8; | |||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | # Internal helper. Returns the iControl REST URL for the managed address-list | ||||||||||||||||||||||||||||||||||||||||||
| 267 | # object, identified by ~<partition>~<name>, url-escaped. | ||||||||||||||||||||||||||||||||||||||||||
| 268 | sub _obj_url { | ||||||||||||||||||||||||||||||||||||||||||
| 269 | 14 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_obj_url: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 14 | my $id = '~' . $self->{options}{partition} . '~' . $self->{options}{name}; | |||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | return | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 'https://' | ||||||||||||||||||||||||||||||||||||||||||
| 275 | . $self->{options}{host} | ||||||||||||||||||||||||||||||||||||||||||
| 276 | 14 | . '/mgmt/tm/security/firewall/address-list/' | |||||||||||||||||||||||||||||||||||||||||
| 277 | . $self->_uri_escape($id); | ||||||||||||||||||||||||||||||||||||||||||
| 278 | } ## end sub _obj_url | ||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | # Internal helper. Builds the JSON body describing the full desired membership | ||||||||||||||||||||||||||||||||||||||||||
| 281 | # of the address-list, one address entry per currently banned IP, sorted. | ||||||||||||||||||||||||||||||||||||||||||
| 282 | sub _render { | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 6 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_render: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | # the address-list holds both single IPs and CIDR ranges as address entries | ||||||||||||||||||||||||||||||||||||||||||
| 286 | my @addresses | ||||||||||||||||||||||||||||||||||||||||||
| 287 | 6 | = map { { name => $_ } } sort( keys( %{ $self->{banned} } ), keys( %{ $self->{banned_cidr} } ) ); | |||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | 6 | return $self->_json->encode( { addresses => \@addresses } ); | |||||||||||||||||||||||||||||||||||||||||
| 290 | } ## end sub _render | ||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | # Internal helper. Performs a HTTP request via LWP::UserAgent using HTTP basic | ||||||||||||||||||||||||||||||||||||||||||
| 293 | # auth, returning the decoded JSON body (or undef for an empty body) and dying | ||||||||||||||||||||||||||||||||||||||||||
| 294 | # with an explanation on any HTTP level failure. Never called in testing mode. | ||||||||||||||||||||||||||||||||||||||||||
| 295 | sub _request { | ||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | my ( $self, $method, $url, $body ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_request: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | if ( !defined( $self->{ua} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | eval { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | require LWP::UserAgent; | |||||||||||||||||||||||||||||||||||||||||
| 302 | my %args = ( | ||||||||||||||||||||||||||||||||||||||||||
| 303 | agent => 'Net::Firewall::BlockerHelper/' . $VERSION, | ||||||||||||||||||||||||||||||||||||||||||
| 304 | timeout => $self->{options}{timeout}, | ||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | if ( $self->{options}{insecure} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | $args{ssl_opts} = { verify_hostname => 0, SSL_verify_mode => 0 }; | |||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | $self->{ua} = LWP::UserAgent->new(%args); | |||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 311 | } or die( 'failed to load LWP::UserAgent, which the f5_bigip backend requires... ' . $@ ); | ||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | require MIME::Base64; | |||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | my $auth = 'Basic ' . MIME::Base64::encode_base64( $self->{options}{user} . ':' . $self->{options}{password}, '' ); | |||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | my @headers = ( 'Content-Type' => 'application/json', 'Authorization' => $auth ); | |||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | require HTTP::Request; | |||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | my $request = HTTP::Request->new( $method, $url, \@headers, $body ); | |||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | my $response = $self->{ua}->request($request); | |||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | ▶ | if ( !$response->is_success ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | my $detail = $response->decoded_content; | |||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | $detail = defined($detail) ? ( ' body... ' . $detail ) : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | die( $method . ' ' . $url . ' failed... HTTP status... ' . $response->status_line . $detail ); | |||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | my $decoded; | |||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | my $content = $response->decoded_content; | |||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | if ( defined($content) && $content ne '' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $content and $content ne ""
MC/DC0%0/2
defined $content and $content ne ""
defined $content
$content ne ""
Truth table0%0/3
A and B
A= defined $contentB= $content ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | eval { $decoded = $self->_json->decode($content); }; | |||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | return $decoded; | |||||||||||||||||||||||||||||||||||||||||
| 338 | } ## end sub _request | ||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | =head2 init | ||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | Initiates the backend. Verifies the credentials, reachability, and that the | ||||||||||||||||||||||||||||||||||||||||||
| 343 | address-list object exists by fetching it. | ||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | sub init { | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 2 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=4 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | 2 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | 2 | ▶ | if ( $self->{inited} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | $self->{error} = 18; | |||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | $self->{errorString} = 'backend has already been inited'; | |||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | 2 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | 2 | $self->{frontend_obj}->{test_data} = [ { method => 'GET', url => $self->_obj_url } ]; | |||||||||||||||||||||||||||||||||||||||||
| 360 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | eval { $self->_request( 'GET', $self->_obj_url ); 1; } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | $self->{error} = 23; | |||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | $self->{errorString} = 'init failed. probing the address-list object failed... ' . $@; | |||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 366 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | 2 | $self->{inited} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 370 | } ## end sub init | ||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | =head2 ban | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | Bans an IP. The value of ban is validated as being a IPv4 or IPv6 address | ||||||||||||||||||||||||||||||||||||||||||
| 375 | and lowercased, then added to the internal ban list and the full rendered | ||||||||||||||||||||||||||||||||||||||||||
| 376 | membership is pushed to the address-list via a PUT. Banning an already | ||||||||||||||||||||||||||||||||||||||||||
| 377 | banned IP is a noop. If the PUT fails, the IP is removed from the internal | ||||||||||||||||||||||||||||||||||||||||||
| 378 | list again. | ||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||
| 380 | $backend->ban(ban => $ip); | ||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | sub ban { | ||||||||||||||||||||||||||||||||||||||||||
| 385 | 3 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ban: called CC=10 SCAR=38.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | 3 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | 3 | ▶ | if ( !$self->{inited} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | $self->{errorString} = 'backend has not been inited'; | |||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | 3 | ▶ | if ( !defined( $opts{ban} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | $self->{error} = 9; | |||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | $self->{errorString} = 'Nothing specified for the value ban'; | |||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 401 | } elsif ( ref( $opts{ban} ) ne '' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | $self->{error} = 10; | |||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"'; | |||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 406 | ▶ | } elsif ( $opts{ban} !~ /\A$IPv4_re\z/ | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::f5_bigip::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::f5_bigip::IPv6_re\z/
MC/DC0%0/2
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::f5_bigip::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::f5_bigip::IPv6_re\z/
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::f5_bigip::IPv4_re\z/
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::f5_bigip::IPv6_re\z/
Truth table33%1/3
A || B
A= $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::f5_bigip::IPv4_re\z/B= $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::f5_bigip::IPv6_re\z/
| |||||||||||||||||||||||||||||||||||||||||||
| 407 | && $opts{ban} !~ /\A$IPv6_re\z/ ) | ||||||||||||||||||||||||||||||||||||||||||
| 408 | { | ||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | $self->{error} = 10; | |||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 IP'; | |||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | # lowercase so the same IPv6 IP in differing cases can't result in duplicate entries | ||||||||||||||||||||||||||||||||||||||||||
| 416 | 3 | $opts{ban} = lc( $opts{ban} ); | |||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | 3 | ▶ | if ( $self->{banned}{ $opts{ban} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | $self->{frontend_obj}->{test_data} = 'already banned'; | |||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | 3 | $self->{banned}{ $opts{ban} } = 1; | |||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | 3 | my $body = $self->_render; | |||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||
| 429 | 3 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 430 | 3 | $self->{frontend_obj}->{test_data} = [ { method => 'PUT', url => $self->_obj_url, content => $body } ]; | |||||||||||||||||||||||||||||||||||||||||
| 431 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | ▶ | eval { $self->_request( 'PUT', $self->_obj_url, $body ); 1; } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | delete( $self->{banned}{ $opts{ban} } ); | |||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | $self->{error} = 13; | |||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | $self->{errorString} = 'banning "' . $opts{ban} . '" failed... ' . $@; | |||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 439 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||
| 441 | } ## end sub ban | ||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||
| 443 | =head2 unban | ||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||
| 445 | Unbans an IP. The value of ban is validated as being a IPv4 or IPv6 address | ||||||||||||||||||||||||||||||||||||||||||
| 446 | and lowercased, then removed from the internal ban list and the full | ||||||||||||||||||||||||||||||||||||||||||
| 447 | rendered membership is pushed to the address-list via a PUT. Unbanning an | ||||||||||||||||||||||||||||||||||||||||||
| 448 | IP that is not banned is a noop. If the PUT fails, the IP is re-added to | ||||||||||||||||||||||||||||||||||||||||||
| 449 | the internal list. | ||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||
| 451 | $backend->unban(ban => $ip); | ||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||
| 455 | sub unban { | ||||||||||||||||||||||||||||||||||||||||||
| 456 | 1 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unban: called CC=10 SCAR=38.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||
| 458 | 1 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||
| 460 | 1 | ▶ | if ( !$self->{inited} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | $self->{errorString} = 'backend has not been inited'; | |||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | 1 | ▶ | if ( !defined( $opts{ban} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | $self->{error} = 9; | |||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | $self->{errorString} = 'Nothing specified for the value ban'; | |||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 472 | } elsif ( ref( $opts{ban} ) ne '' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | $self->{error} = 10; | |||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"'; | |||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 477 | ▶ | } elsif ( $opts{ban} !~ /\A$IPv4_re\z/ | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::f5_bigip::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::f5_bigip::IPv6_re\z/
MC/DC0%0/2
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::f5_bigip::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::f5_bigip::IPv6_re\z/
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::f5_bigip::IPv4_re\z/
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::f5_bigip::IPv6_re\z/
Truth table33%1/3
A || B
A= $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::f5_bigip::IPv4_re\z/B= $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::f5_bigip::IPv6_re\z/
| |||||||||||||||||||||||||||||||||||||||||||
| 478 | && $opts{ban} !~ /\A$IPv6_re\z/ ) | ||||||||||||||||||||||||||||||||||||||||||
| 479 | { | ||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | $self->{error} = 10; | |||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 IP'; | |||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||
| 486 | # lowercase so the same IPv6 IP in differing cases can't result in duplicate entries | ||||||||||||||||||||||||||||||||||||||||||
| 487 | 1 | $opts{ban} = lc( $opts{ban} ); | |||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||
| 489 | 1 | ▶ | if ( !$self->{banned}{ $opts{ban} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | $self->{frontend_obj}->{test_data} = 'not banned'; | |||||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||
| 496 | 1 | delete( $self->{banned}{ $opts{ban} } ); | |||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||
| 498 | 1 | my $body = $self->_render; | |||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||
| 500 | 1 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 501 | 1 | $self->{frontend_obj}->{test_data} = [ { method => 'PUT', url => $self->_obj_url, content => $body } ]; | |||||||||||||||||||||||||||||||||||||||||
| 502 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | ▶ | eval { $self->_request( 'PUT', $self->_obj_url, $body ); 1; } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | $self->{banned}{ $opts{ban} } = 1; | |||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | $self->{error} = 14; | |||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | $self->{errorString} = 'unbanning "' . $opts{ban} . '" failed... ' . $@; | |||||||||||||||||||||||||||||||||||||||||
| 508 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 510 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||||||||||||||||
| 512 | } ## end sub unban | ||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||
| 514 | # Internal helper. Returns a true value if the passed scalar is a valid IPv4 or | ||||||||||||||||||||||||||||||||||||||||||
| 515 | # IPv6 CIDR range, that is an address followed by "/" and a prefix length that | ||||||||||||||||||||||||||||||||||||||||||
| 516 | # is within the range valid for its family (0 to 32 for IPv4, 0 to 128 for | ||||||||||||||||||||||||||||||||||||||||||
| 517 | # IPv6). Returns false otherwise. | ||||||||||||||||||||||||||||||||||||||||||
| 518 | sub _valid_cidr { | ||||||||||||||||||||||||||||||||||||||||||
| 519 | 2 | ▶ | my ( $self, $cidr ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_valid_cidr: called CC=8 SCAR=30.3
| |||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||
| 521 | 2 | ▶ | return 0 if ( !defined($cidr) || ref($cidr) ne '' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/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 table33%1/3
not(A) or B
A= not defined $cidrB= ref $cidr ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||
| 523 | 2 | ▶ | if ( $cidr =~ m!\A(.+)/([0-9]{1,3})\z! ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 524 | 2 | my ( $addr, $prefix ) = ( $1, $2 ); | |||||||||||||||||||||||||||||||||||||||||
| 525 | 2 | ▶ | return 1 if ( $addr =~ /\A$IPv4_re\z/ && $prefix <= 32 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$addr =~ /\A$Net::Firewall::BlockerHelper::backends::f5_bigip::IPv4_re\z/ and $prefix <= 32
MC/DC0%0/2
$addr =~ /\A$Net::Firewall::BlockerHelper::backends::f5_bigip::IPv4_re\z/ and $prefix <= 32
$addr =~ /\A$Net::Firewall::BlockerHelper::backends::f5_bigip::IPv4_re\z/
$prefix <= 32
Truth table33%1/3
A and B
A= $addr =~ /\A$Net::Firewall::BlockerHelper::backends::f5_bigip::IPv4_re\z/B= $prefix <= 32
| |||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | ▶ | return 1 if ( $addr =~ /\A$IPv6_re\z/ && $prefix <= 128 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$addr =~ /\A$Net::Firewall::BlockerHelper::backends::f5_bigip::IPv6_re\z/ and $prefix <= 128
MC/DC0%0/2
$addr =~ /\A$Net::Firewall::BlockerHelper::backends::f5_bigip::IPv6_re\z/ and $prefix <= 128
$addr =~ /\A$Net::Firewall::BlockerHelper::backends::f5_bigip::IPv6_re\z/
$prefix <= 128
Truth table0%0/3
A and B
A= $addr =~ /\A$Net::Firewall::BlockerHelper::backends::f5_bigip::IPv6_re\z/B= $prefix <= 128
| |||||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 530 | } ## end sub _valid_cidr | ||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||
| 532 | =head2 ban_cidr | ||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||
| 534 | Bans a CIDR range by adding it to the internal list and pushing the full | ||||||||||||||||||||||||||||||||||||||||||
| 535 | rendered membership to the address-list via a PUT. The value of ban is | ||||||||||||||||||||||||||||||||||||||||||
| 536 | validated as being a IPv4 or IPv6 CIDR range and lowercased. Banning an | ||||||||||||||||||||||||||||||||||||||||||
| 537 | already banned range is a noop. | ||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||
| 539 | $backend->ban_cidr(ban => '1.2.3.0/24'); | ||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||
| 541 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||
| 543 | sub ban_cidr { | ||||||||||||||||||||||||||||||||||||||||||
| 544 | 1 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ban_cidr: called CC=9 SCAR=36.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||
| 546 | 1 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||
| 548 | 1 | ▶ | if ( !$self->{inited} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | $self->{errorString} = 'backend has not been inited'; | |||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||
| 555 | 1 | ▶ | if ( !defined( $opts{ban} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | $self->{error} = 9; | |||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | $self->{errorString} = 'Nothing specified for the value ban'; | |||||||||||||||||||||||||||||||||||||||||
| 558 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 560 | } elsif ( ref( $opts{ban} ) ne '' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | $self->{error} = 35; | |||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"'; | |||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 564 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 565 | } elsif ( !$self->_valid_cidr( $opts{ban} ) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | $self->{error} = 35; | |||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 CIDR'; | |||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||
| 572 | # lowercase so the same IPv6 CIDR in differing cases can't result in duplicate entries | ||||||||||||||||||||||||||||||||||||||||||
| 573 | 1 | $opts{ban} = lc( $opts{ban} ); | |||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||
| 575 | 1 | ▶ | if ( $self->{banned_cidr}{ $opts{ban} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | $self->{frontend_obj}->{test_data} = 'already banned'; | |||||||||||||||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||||||
| 582 | 1 | $self->{banned_cidr}{ $opts{ban} } = 1; | |||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||
| 584 | 1 | my $body = $self->_render; | |||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||
| 586 | 1 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 587 | 1 | $self->{frontend_obj}->{test_data} = [ { method => 'PUT', url => $self->_obj_url, content => $body } ]; | |||||||||||||||||||||||||||||||||||||||||
| 588 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | ▶ | eval { $self->_request( 'PUT', $self->_obj_url, $body ); 1; } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | delete( $self->{banned_cidr}{ $opts{ban} } ); | |||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | $self->{error} = 33; | |||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | $self->{errorString} = 'banning "' . $opts{ban} . '" failed... ' . $@; | |||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 596 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||||||||||||
| 598 | } ## end sub ban_cidr | ||||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||||
| 600 | =head2 unban_cidr | ||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||
| 602 | Unbans a CIDR range by removing it from the internal list and pushing the | ||||||||||||||||||||||||||||||||||||||||||
| 603 | full rendered membership to the address-list via a PUT. The value of ban is | ||||||||||||||||||||||||||||||||||||||||||
| 604 | validated as being a IPv4 or IPv6 CIDR range and lowercased. Unbanning a | ||||||||||||||||||||||||||||||||||||||||||
| 605 | range that is not banned is a noop. | ||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||
| 607 | $backend->unban_cidr(ban => '1.2.3.0/24'); | ||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||
| 609 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||
| 611 | sub unban_cidr { | ||||||||||||||||||||||||||||||||||||||||||
| 612 | 1 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unban_cidr: called CC=9 SCAR=36.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||
| 614 | 1 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||
| 616 | 1 | ▶ | if ( !$self->{inited} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 617 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 618 | 0 | $self->{errorString} = 'backend has not been inited'; | |||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||
| 623 | 1 | ▶ | if ( !defined( $opts{ban} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | $self->{error} = 9; | |||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | $self->{errorString} = 'Nothing specified for the value ban'; | |||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 627 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 628 | } elsif ( ref( $opts{ban} ) ne '' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 629 | 0 | $self->{error} = 35; | |||||||||||||||||||||||||||||||||||||||||
| 630 | 0 | $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"'; | |||||||||||||||||||||||||||||||||||||||||
| 631 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 632 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 633 | } elsif ( !$self->_valid_cidr( $opts{ban} ) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | $self->{error} = 35; | |||||||||||||||||||||||||||||||||||||||||
| 635 | 0 | $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 CIDR'; | |||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 638 | } | ||||||||||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||||||||||
| 640 | # lowercase so the same IPv6 CIDR in differing cases can't result in duplicate entries | ||||||||||||||||||||||||||||||||||||||||||
| 641 | 1 | $opts{ban} = lc( $opts{ban} ); | |||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||
| 643 | 1 | ▶ | if ( !$self->{banned_cidr}{ $opts{ban} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 644 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 645 | 0 | $self->{frontend_obj}->{test_data} = 'not banned'; | |||||||||||||||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||||||||||||||||
| 647 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||
| 650 | 1 | delete( $self->{banned_cidr}{ $opts{ban} } ); | |||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||
| 652 | 1 | my $body = $self->_render; | |||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||
| 654 | 1 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 655 | 1 | $self->{frontend_obj}->{test_data} = [ { method => 'PUT', url => $self->_obj_url, content => $body } ]; | |||||||||||||||||||||||||||||||||||||||||
| 656 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 658 | 0 | ▶ | eval { $self->_request( 'PUT', $self->_obj_url, $body ); 1; } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 659 | 0 | $self->{banned_cidr}{ $opts{ban} } = 1; | |||||||||||||||||||||||||||||||||||||||||
| 660 | 0 | $self->{error} = 34; | |||||||||||||||||||||||||||||||||||||||||
| 661 | 0 | $self->{errorString} = 'unbanning "' . $opts{ban} . '" failed... ' . $@; | |||||||||||||||||||||||||||||||||||||||||
| 662 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 663 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 664 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 665 | } | ||||||||||||||||||||||||||||||||||||||||||
| 666 | } ## end sub unban_cidr | ||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||
| 668 | =head2 list_cidr | ||||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||
| 670 | List banned CIDR ranges. Returns an array of the currently banned CIDR | ||||||||||||||||||||||||||||||||||||||||||
| 671 | ranges. Single IPs are not included; for those see L</list>. | ||||||||||||||||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||||||||||||||||
| 673 | my @banned_cidrs = $backend->list_cidr; | ||||||||||||||||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||||||||||||||||
| 675 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||||||||||||
| 677 | sub list_cidr { | ||||||||||||||||||||||||||||||||||||||||||
| 678 | 2 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_cidr: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||||||||||||||||
| 680 | 2 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||
| 682 | 2 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 683 | 2 | $self->{frontend_obj}->{test_data} = 'list_cidr'; | |||||||||||||||||||||||||||||||||||||||||
| 684 | } | ||||||||||||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||||||||||||
| 686 | 2 | return keys( %{ $self->{banned_cidr} } ); | |||||||||||||||||||||||||||||||||||||||||
| 687 | } | ||||||||||||||||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||||||||||||||||
| 689 | =head2 list | ||||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||
| 691 | List banned IPs. Returns an array of the currently banned single IPs. CIDR | ||||||||||||||||||||||||||||||||||||||||||
| 692 | ranges are not included; for those see L</list_cidr>. | ||||||||||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||||||||||
| 694 | my @banned = $backend->list; | ||||||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||||
| 696 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||||||||||||
| 698 | sub list { | ||||||||||||||||||||||||||||||||||||||||||
| 699 | 0 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||||||||||||||||
| 703 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 704 | 0 | $self->{frontend_obj}->{test_data} = 'list'; | |||||||||||||||||||||||||||||||||||||||||
| 705 | } | ||||||||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||||||||
| 707 | 0 | return keys( %{ $self->{banned} } ); | |||||||||||||||||||||||||||||||||||||||||
| 708 | } | ||||||||||||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||||||||||||
| 710 | =head2 re_init | ||||||||||||||||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||||||||||||||||
| 712 | Tears down and re-inits, then re-renders the full membership in a single PUT. | ||||||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||||||
| 714 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||
| 716 | sub re_init { | ||||||||||||||||||||||||||||||||||||||||||
| 717 | 0 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
re_init: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 718 | |||||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||||||||||||||||
| 721 | 0 | ▶ | if ( !$self->{inited} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 723 | 0 | $self->{errorString} = 'backend has not been inited'; | |||||||||||||||||||||||||||||||||||||||||
| 724 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 725 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||||||||||
| 728 | # teardown is best effort here as a partially or fully wiped setup is | ||||||||||||||||||||||||||||||||||||||||||
| 729 | # exactly what re_init needs to recover from | ||||||||||||||||||||||||||||||||||||||||||
| 730 | { | ||||||||||||||||||||||||||||||||||||||||||
| 731 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 732 | 0 | eval { $self->teardown; }; | |||||||||||||||||||||||||||||||||||||||||
| 733 | } | ||||||||||||||||||||||||||||||||||||||||||
| 734 | 0 | $self->init; | |||||||||||||||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||||||||||||||||
| 736 | 0 | my $body = $self->_render; | |||||||||||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||||||||||||
| 738 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 739 | 0 | $self->{frontend_obj}->{test_data} = [ { method => 'PUT', url => $self->_obj_url, content => $body } ]; | |||||||||||||||||||||||||||||||||||||||||
| 740 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 741 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 742 | 0 | ▶ | eval { $self->_request( 'PUT', $self->_obj_url, $body ); 1; } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 743 | 0 | $self->{error} = 13; | |||||||||||||||||||||||||||||||||||||||||
| 744 | 0 | $self->{errorString} = 're_init failed re-rendering the address-list membership... ' . $@; | |||||||||||||||||||||||||||||||||||||||||
| 745 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 746 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 747 | } | ||||||||||||||||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||||||||||||||||
| 749 | 0 | $self->{inited} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 750 | } ## end sub re_init | ||||||||||||||||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||||||||||||||||
| 752 | =head2 teardown | ||||||||||||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||||||||||||
| 754 | Tears down the setup by rendering an empty membership to the address-list. The | ||||||||||||||||||||||||||||||||||||||||||
| 755 | internal list of bans is kept, so a following re_init will re-add them. | ||||||||||||||||||||||||||||||||||||||||||
| 756 | |||||||||||||||||||||||||||||||||||||||||||
| 757 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||||||||||||||||
| 759 | sub teardown { | ||||||||||||||||||||||||||||||||||||||||||
| 760 | 0 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
teardown: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 761 | |||||||||||||||||||||||||||||||||||||||||||
| 762 | 0 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||||||||||||||||
| 764 | 0 | $self->{inited} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||||||
| 766 | # render an empty membership without disturbing the internal ban list | ||||||||||||||||||||||||||||||||||||||||||
| 767 | 0 | my $body = $self->_json->encode( { addresses => [] } ); | |||||||||||||||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||||||||||||||||
| 769 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 770 | 0 | $self->{frontend_obj}->{test_data} = [ { method => 'PUT', url => $self->_obj_url, content => $body } ]; | |||||||||||||||||||||||||||||||||||||||||
| 771 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 772 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 773 | 0 | ▶ | eval { $self->_request( 'PUT', $self->_obj_url, $body ); 1; } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 774 | 0 | $self->{error} = 17; | |||||||||||||||||||||||||||||||||||||||||
| 775 | 0 | $self->{errorString} = 'teardown failed emptying the address-list... ' . $@; | |||||||||||||||||||||||||||||||||||||||||
| 776 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 777 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 778 | } | ||||||||||||||||||||||||||||||||||||||||||
| 779 | } ## end sub teardown | ||||||||||||||||||||||||||||||||||||||||||
| 780 | |||||||||||||||||||||||||||||||||||||||||||
| 781 | =head2 stop | ||||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||
| 783 | Alias for L</teardown>. | ||||||||||||||||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||||||||||||||||
| 785 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||||||||||||||||
| 787 | sub stop { | ||||||||||||||||||||||||||||||||||||||||||
| 788 | 0 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stop: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 789 | |||||||||||||||||||||||||||||||||||||||||||
| 790 | 0 | return $self->teardown(%opts); | |||||||||||||||||||||||||||||||||||||||||
| 791 | } | ||||||||||||||||||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||||||||||||||||
| 793 | =head2 check | ||||||||||||||||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||||||||||||||||
| 795 | Verifies the endpoint and credentials are still usable by fetching the | ||||||||||||||||||||||||||||||||||||||||||
| 796 | address-list object. Returns a true value if so and a false value otherwise. | ||||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||
| 798 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||||||||||||||||
| 800 | sub check { | ||||||||||||||||||||||||||||||||||||||||||
| 801 | 6 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check: called CC=3 SCAR=15.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||||||||||||||||
| 803 | 6 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||||||||||||||||
| 805 | 6 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 806 | 6 | $self->{frontend_obj}->{test_data} = [ { method => 'GET', url => $self->_obj_url } ]; | |||||||||||||||||||||||||||||||||||||||||
| 807 | 6 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 808 | } | ||||||||||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||||||||||
| 810 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 811 | 0 | ▶ | eval { $self->_request( 'GET', $self->_obj_url ); 1; } or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 812 | |||||||||||||||||||||||||||||||||||||||||||
| 813 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 814 | } ## end sub check | ||||||||||||||||||||||||||||||||||||||||||
| 815 | |||||||||||||||||||||||||||||||||||||||||||
| 816 | =head2 flush | ||||||||||||||||||||||||||||||||||||||||||
| 817 | |||||||||||||||||||||||||||||||||||||||||||
| 818 | Removes all currently banned IPs at once by rendering an empty membership to | ||||||||||||||||||||||||||||||||||||||||||
| 819 | the address-list and forgetting them. | ||||||||||||||||||||||||||||||||||||||||||
| 820 | |||||||||||||||||||||||||||||||||||||||||||
| 821 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 822 | |||||||||||||||||||||||||||||||||||||||||||
| 823 | sub flush { | ||||||||||||||||||||||||||||||||||||||||||
| 824 | 0 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
flush: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 825 | |||||||||||||||||||||||||||||||||||||||||||
| 826 | 0 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 827 | |||||||||||||||||||||||||||||||||||||||||||
| 828 | 0 | ▶ | if ( !$self->{inited} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 829 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 830 | 0 | $self->{errorString} = 'backend has not been inited'; | |||||||||||||||||||||||||||||||||||||||||
| 831 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 832 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 833 | } | ||||||||||||||||||||||||||||||||||||||||||
| 834 | |||||||||||||||||||||||||||||||||||||||||||
| 835 | # the rendered empty membership below removes both single IPs and CIDR ranges | ||||||||||||||||||||||||||||||||||||||||||
| 836 | 0 | $self->{banned} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 837 | 0 | $self->{banned_cidr} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 838 | |||||||||||||||||||||||||||||||||||||||||||
| 839 | 0 | my $body = $self->_render; | |||||||||||||||||||||||||||||||||||||||||
| 840 | |||||||||||||||||||||||||||||||||||||||||||
| 841 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 842 | 0 | $self->{frontend_obj}->{test_data} = [ { method => 'PUT', url => $self->_obj_url, content => $body } ]; | |||||||||||||||||||||||||||||||||||||||||
| 843 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 844 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 845 | 0 | ▶ | eval { $self->_request( 'PUT', $self->_obj_url, $body ); 1; } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 846 | 0 | $self->{error} = 25; | |||||||||||||||||||||||||||||||||||||||||
| 847 | 0 | $self->{errorString} = 'flush failed emptying the address-list... ' . $@; | |||||||||||||||||||||||||||||||||||||||||
| 848 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 849 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 850 | } | ||||||||||||||||||||||||||||||||||||||||||
| 851 | } ## end sub flush | ||||||||||||||||||||||||||||||||||||||||||
| 852 | |||||||||||||||||||||||||||||||||||||||||||
| 853 | =head1 ERROR CODES / FLAGS | ||||||||||||||||||||||||||||||||||||||||||
| 854 | |||||||||||||||||||||||||||||||||||||||||||
| 855 | Error handling is provided by L<Error::Helper>. All | ||||||||||||||||||||||||||||||||||||||||||
| 856 | errors are considered fatal. | ||||||||||||||||||||||||||||||||||||||||||
| 857 | |||||||||||||||||||||||||||||||||||||||||||
| 858 | =head2 1, notInited | ||||||||||||||||||||||||||||||||||||||||||
| 859 | |||||||||||||||||||||||||||||||||||||||||||
| 860 | The backend has not been inited yet. | ||||||||||||||||||||||||||||||||||||||||||
| 861 | |||||||||||||||||||||||||||||||||||||||||||
| 862 | =head2 6, invalidPrefixSpecified | ||||||||||||||||||||||||||||||||||||||||||
| 863 | |||||||||||||||||||||||||||||||||||||||||||
| 864 | The specified prefix did not match /^[a-zA-Z0-9]+$/. | ||||||||||||||||||||||||||||||||||||||||||
| 865 | |||||||||||||||||||||||||||||||||||||||||||
| 866 | =head2 7, invalidName | ||||||||||||||||||||||||||||||||||||||||||
| 867 | |||||||||||||||||||||||||||||||||||||||||||
| 868 | The name is either undef or does not match /^[a-zA-Z0-9\-]+$/. | ||||||||||||||||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||||||||||||||||
| 870 | =head2 8, optionsNotHash | ||||||||||||||||||||||||||||||||||||||||||
| 871 | |||||||||||||||||||||||||||||||||||||||||||
| 872 | The item passed to new for options is not a hash. | ||||||||||||||||||||||||||||||||||||||||||
| 873 | |||||||||||||||||||||||||||||||||||||||||||
| 874 | =head2 9, noBanItem | ||||||||||||||||||||||||||||||||||||||||||
| 875 | |||||||||||||||||||||||||||||||||||||||||||
| 876 | No IP or CIDR range specified to ban or unban. | ||||||||||||||||||||||||||||||||||||||||||
| 877 | |||||||||||||||||||||||||||||||||||||||||||
| 878 | =head2 10, banItemNotIP | ||||||||||||||||||||||||||||||||||||||||||
| 879 | |||||||||||||||||||||||||||||||||||||||||||
| 880 | The item to ban is not an IP. Either wrong ref type or regexp | ||||||||||||||||||||||||||||||||||||||||||
| 881 | test using L<Regexp::IPv4> and L<Regexp::IPv6> failed. | ||||||||||||||||||||||||||||||||||||||||||
| 882 | |||||||||||||||||||||||||||||||||||||||||||
| 883 | =head2 12, backendInitError | ||||||||||||||||||||||||||||||||||||||||||
| 884 | |||||||||||||||||||||||||||||||||||||||||||
| 885 | Failed to init the backend. | ||||||||||||||||||||||||||||||||||||||||||
| 886 | |||||||||||||||||||||||||||||||||||||||||||
| 887 | =head2 13, banFailed | ||||||||||||||||||||||||||||||||||||||||||
| 888 | |||||||||||||||||||||||||||||||||||||||||||
| 889 | Failed to ban the item. | ||||||||||||||||||||||||||||||||||||||||||
| 890 | |||||||||||||||||||||||||||||||||||||||||||
| 891 | =head2 14, unbanFailed | ||||||||||||||||||||||||||||||||||||||||||
| 892 | |||||||||||||||||||||||||||||||||||||||||||
| 893 | Failed to unban the item. | ||||||||||||||||||||||||||||||||||||||||||
| 894 | |||||||||||||||||||||||||||||||||||||||||||
| 895 | =head2 15, listFailed | ||||||||||||||||||||||||||||||||||||||||||
| 896 | |||||||||||||||||||||||||||||||||||||||||||
| 897 | Failed to get a list of bans. | ||||||||||||||||||||||||||||||||||||||||||
| 898 | |||||||||||||||||||||||||||||||||||||||||||
| 899 | =head2 16, reInitFailed | ||||||||||||||||||||||||||||||||||||||||||
| 900 | |||||||||||||||||||||||||||||||||||||||||||
| 901 | Failed to re_init the backend. | ||||||||||||||||||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||||||||||||||||
| 903 | =head2 17, teardownFailed | ||||||||||||||||||||||||||||||||||||||||||
| 904 | |||||||||||||||||||||||||||||||||||||||||||
| 905 | Failed to teardown the backend. | ||||||||||||||||||||||||||||||||||||||||||
| 906 | |||||||||||||||||||||||||||||||||||||||||||
| 907 | =head2 18, alreadyInited | ||||||||||||||||||||||||||||||||||||||||||
| 908 | |||||||||||||||||||||||||||||||||||||||||||
| 909 | init called, but the backend has already been inited. | ||||||||||||||||||||||||||||||||||||||||||
| 910 | |||||||||||||||||||||||||||||||||||||||||||
| 911 | =head2 23, initFailed | ||||||||||||||||||||||||||||||||||||||||||
| 912 | |||||||||||||||||||||||||||||||||||||||||||
| 913 | Init failed. Probing the address-list object failed. | ||||||||||||||||||||||||||||||||||||||||||
| 914 | |||||||||||||||||||||||||||||||||||||||||||
| 915 | =head2 24, checkFailed | ||||||||||||||||||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||||||||||||||||
| 917 | The backend check raised an error. | ||||||||||||||||||||||||||||||||||||||||||
| 918 | |||||||||||||||||||||||||||||||||||||||||||
| 919 | =head2 25, flushFailed | ||||||||||||||||||||||||||||||||||||||||||
| 920 | |||||||||||||||||||||||||||||||||||||||||||
| 921 | Failed to flush the bans. | ||||||||||||||||||||||||||||||||||||||||||
| 922 | |||||||||||||||||||||||||||||||||||||||||||
| 923 | =head2 26, portsNotSupported | ||||||||||||||||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||||||||||||||||
| 925 | The f5_bigip backend blocks whole IPs and does not support ports. | ||||||||||||||||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||||||||||||||||
| 927 | =head2 27, protocolsNotSupported | ||||||||||||||||||||||||||||||||||||||||||
| 928 | |||||||||||||||||||||||||||||||||||||||||||
| 929 | The f5_bigip backend blocks whole IPs and does not support protocols. | ||||||||||||||||||||||||||||||||||||||||||
| 930 | |||||||||||||||||||||||||||||||||||||||||||
| 931 | =head2 30, hostNotDefined | ||||||||||||||||||||||||||||||||||||||||||
| 932 | |||||||||||||||||||||||||||||||||||||||||||
| 933 | The option host is undef or blank. | ||||||||||||||||||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||||||||||||||||
| 935 | =head2 31, userNotDefined | ||||||||||||||||||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||||||||||||||||
| 937 | The option user is undef or blank. | ||||||||||||||||||||||||||||||||||||||||||
| 938 | |||||||||||||||||||||||||||||||||||||||||||
| 939 | =head2 32, passwordNotDefined | ||||||||||||||||||||||||||||||||||||||||||
| 940 | |||||||||||||||||||||||||||||||||||||||||||
| 941 | The option password is undef or blank. | ||||||||||||||||||||||||||||||||||||||||||
| 942 | |||||||||||||||||||||||||||||||||||||||||||
| 943 | =head2 33, banCidrFailed | ||||||||||||||||||||||||||||||||||||||||||
| 944 | |||||||||||||||||||||||||||||||||||||||||||
| 945 | Failed to ban the CIDR range. | ||||||||||||||||||||||||||||||||||||||||||
| 946 | |||||||||||||||||||||||||||||||||||||||||||
| 947 | =head2 34, unbanCidrFailed | ||||||||||||||||||||||||||||||||||||||||||
| 948 | |||||||||||||||||||||||||||||||||||||||||||
| 949 | Failed to unban the CIDR range. | ||||||||||||||||||||||||||||||||||||||||||
| 950 | |||||||||||||||||||||||||||||||||||||||||||
| 951 | =head2 35, cidrItemNotCidr | ||||||||||||||||||||||||||||||||||||||||||
| 952 | |||||||||||||||||||||||||||||||||||||||||||
| 953 | The item to ban is not a CIDR range. Either wrong ref type or it is not an | ||||||||||||||||||||||||||||||||||||||||||
| 954 | IPv4 or IPv6 address followed by a prefix length valid for its family. | ||||||||||||||||||||||||||||||||||||||||||
| 955 | |||||||||||||||||||||||||||||||||||||||||||
| 956 | =head2 36, cidrNotSupported | ||||||||||||||||||||||||||||||||||||||||||
| 957 | |||||||||||||||||||||||||||||||||||||||||||
| 958 | The backend does not support CIDR bans. | ||||||||||||||||||||||||||||||||||||||||||
| 959 | |||||||||||||||||||||||||||||||||||||||||||
| 960 | =head2 37, listCidrFailed | ||||||||||||||||||||||||||||||||||||||||||
| 961 | |||||||||||||||||||||||||||||||||||||||||||
| 962 | Failed to get a list of CIDR bans. | ||||||||||||||||||||||||||||||||||||||||||
| 963 | |||||||||||||||||||||||||||||||||||||||||||
| 964 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 965 | |||||||||||||||||||||||||||||||||||||||||||
| 966 | Zane C. Bowers-Hadley, C<< <vvelox at vvelox.ent> >> | ||||||||||||||||||||||||||||||||||||||||||
| 967 | |||||||||||||||||||||||||||||||||||||||||||
| 968 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||
| 969 | |||||||||||||||||||||||||||||||||||||||||||
| 970 | This software is Copyright (c) 2023 by Zane C. Bowers-Hadley. | ||||||||||||||||||||||||||||||||||||||||||
| 971 | |||||||||||||||||||||||||||||||||||||||||||
| 972 | This is free software, licensed under: | ||||||||||||||||||||||||||||||||||||||||||
| 973 | |||||||||||||||||||||||||||||||||||||||||||
| 974 | The GNU Lesser General Public License, Version 2.1, February 1999 | ||||||||||||||||||||||||||||||||||||||||||
| 975 | |||||||||||||||||||||||||||||||||||||||||||
| 976 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 977 | |||||||||||||||||||||||||||||||||||||||||||
| 978 | 1 | 1; # End of Net::Firewall::BlockerHelper::backends::f5_bigip | |||||||||||||||||||||||||||||||||||||||||