| 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 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::f5_bigip - F5 BIG-IP backend using the iControl REST API. | ||||||||||||||||||||||||||||||||||||||||||
| 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 => '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 | 5 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=27 SCAR=43.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 5 | my ( $blank, %opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 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. Returns the iControl REST URL of the address-list this | ||||||||||||||||||||||||||||||||||||||||||
| 250 | # instance manages. | ||||||||||||||||||||||||||||||||||||||||||
| 251 | # | ||||||||||||||||||||||||||||||||||||||||||
| 252 | # BIG-IP identifies configuration objects by a partition qualified path, which | ||||||||||||||||||||||||||||||||||||||||||
| 253 | # in iControl REST is written with tildes in place of slashes: | ||||||||||||||||||||||||||||||||||||||||||
| 254 | # ~<partition>~<name>. The whole identifier is then percent encoded so the | ||||||||||||||||||||||||||||||||||||||||||
| 255 | # tildes and any awkward characters in the name survive being placed in the | ||||||||||||||||||||||||||||||||||||||||||
| 256 | # URL path. | ||||||||||||||||||||||||||||||||||||||||||
| 257 | # | ||||||||||||||||||||||||||||||||||||||||||
| 258 | # This backend does not create the address-list. It is expected to already | ||||||||||||||||||||||||||||||||||||||||||
| 259 | # exist and be referenced by a firewall policy; all this does is rewrite its | ||||||||||||||||||||||||||||||||||||||||||
| 260 | # contents. | ||||||||||||||||||||||||||||||||||||||||||
| 261 | # | ||||||||||||||||||||||||||||||||||||||||||
| 262 | # Takes no arguments; the host, partition, and name come from the options. | ||||||||||||||||||||||||||||||||||||||||||
| 263 | # | ||||||||||||||||||||||||||||||||||||||||||
| 264 | # Returns the URL as a string, used for both the read and the replace. | ||||||||||||||||||||||||||||||||||||||||||
| 265 | # | ||||||||||||||||||||||||||||||||||||||||||
| 266 | # # partition Common, name blocklist | ||||||||||||||||||||||||||||||||||||||||||
| 267 | # $self->_obj_url; | ||||||||||||||||||||||||||||||||||||||||||
| 268 | # # https://f5.example.org/mgmt/tm/security/firewall/address-list/~Common~blocklist | ||||||||||||||||||||||||||||||||||||||||||
| 269 | 14 | ▶ | sub _obj_url { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_obj_url: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | 14 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | 14 | my $id = '~' . $self->{options}{partition} . '~' . $self->{options}{name}; | |||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | return | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 'https://' | ||||||||||||||||||||||||||||||||||||||||||
| 276 | . $self->{options}{host} | ||||||||||||||||||||||||||||||||||||||||||
| 277 | 14 | . '/mgmt/tm/security/firewall/address-list/' | |||||||||||||||||||||||||||||||||||||||||
| 278 | . $self->_uri_escape($id); | ||||||||||||||||||||||||||||||||||||||||||
| 279 | } ## end sub _obj_url | ||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | # Internal helper. Renders the complete desired contents of the address-list | ||||||||||||||||||||||||||||||||||||||||||
| 282 | # from the current bans, which is what gets pushed to replace it. | ||||||||||||||||||||||||||||||||||||||||||
| 283 | # | ||||||||||||||||||||||||||||||||||||||||||
| 284 | # The address-list is replace-in-full: there is no add or remove one entry | ||||||||||||||||||||||||||||||||||||||||||
| 285 | # call, so every ban and unban rewrites the whole membership from the internal | ||||||||||||||||||||||||||||||||||||||||||
| 286 | # state. | ||||||||||||||||||||||||||||||||||||||||||
| 287 | # | ||||||||||||||||||||||||||||||||||||||||||
| 288 | # Each entry is an object with a name key rather than a bare string, which is | ||||||||||||||||||||||||||||||||||||||||||
| 289 | # the shape iControl REST expects. Single addresses and CIDR ranges are held | ||||||||||||||||||||||||||||||||||||||||||
| 290 | # in two separate internal lists but go into the same list, merged and sorted | ||||||||||||||||||||||||||||||||||||||||||
| 291 | # together into one run, since BIG-IP accepts both as address entries and does | ||||||||||||||||||||||||||||||||||||||||||
| 292 | # not distinguish them. | ||||||||||||||||||||||||||||||||||||||||||
| 293 | # | ||||||||||||||||||||||||||||||||||||||||||
| 294 | # Takes no arguments; the bans come from the object's banned and banned_cidr | ||||||||||||||||||||||||||||||||||||||||||
| 295 | # hashes. | ||||||||||||||||||||||||||||||||||||||||||
| 296 | # | ||||||||||||||||||||||||||||||||||||||||||
| 297 | # Returns the body as a JSON string, ready to be the content of the replace | ||||||||||||||||||||||||||||||||||||||||||
| 298 | # request. With nothing banned the addresses array is empty, which is how | ||||||||||||||||||||||||||||||||||||||||||
| 299 | # teardown and flush clear the list. | ||||||||||||||||||||||||||||||||||||||||||
| 300 | # | ||||||||||||||||||||||||||||||||||||||||||
| 301 | # # with 10.0.0.1 and 10.0.0.0/8 banned | ||||||||||||||||||||||||||||||||||||||||||
| 302 | # $self->_render; | ||||||||||||||||||||||||||||||||||||||||||
| 303 | # # {"addresses":[{"name":"10.0.0.0/8"},{"name":"10.0.0.1"}]} | ||||||||||||||||||||||||||||||||||||||||||
| 304 | # | ||||||||||||||||||||||||||||||||||||||||||
| 305 | # # with nothing banned | ||||||||||||||||||||||||||||||||||||||||||
| 306 | # # {"addresses":[]} | ||||||||||||||||||||||||||||||||||||||||||
| 307 | 6 | ▶ | sub _render { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_render: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | # the address-list holds both single IPs and CIDR ranges as address entries | ||||||||||||||||||||||||||||||||||||||||||
| 311 | my @addresses | ||||||||||||||||||||||||||||||||||||||||||
| 312 | 6 | = map { { name => $_ } } sort( keys( %{ $self->{banned} } ), keys( %{ $self->{banned_cidr} } ) ); | |||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 6 | return $self->_json->encode( { addresses => \@addresses } ); | |||||||||||||||||||||||||||||||||||||||||
| 315 | } ## end sub _render | ||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | # Internal helper. Performs one HTTP request against the BIG-IP iControl REST | ||||||||||||||||||||||||||||||||||||||||||
| 318 | # API. Every call this backend makes to the appliance goes through here. | ||||||||||||||||||||||||||||||||||||||||||
| 319 | # | ||||||||||||||||||||||||||||||||||||||||||
| 320 | # The user agent is built on first use and cached on the object, so a run of | ||||||||||||||||||||||||||||||||||||||||||
| 321 | # requests shares one agent. LWP::UserAgent is loaded with require at that | ||||||||||||||||||||||||||||||||||||||||||
| 322 | # point rather than at compile time, since only the HTTP backends need it; | ||||||||||||||||||||||||||||||||||||||||||
| 323 | # failing to load it dies with an explanation naming this backend. The | ||||||||||||||||||||||||||||||||||||||||||
| 324 | # insecure option turns off certificate verification, which is there because a | ||||||||||||||||||||||||||||||||||||||||||
| 325 | # BIG-IP commonly presents a self signed certificate. | ||||||||||||||||||||||||||||||||||||||||||
| 326 | # | ||||||||||||||||||||||||||||||||||||||||||
| 327 | # Authentication is HTTP basic, encoded per request; there is no session or | ||||||||||||||||||||||||||||||||||||||||||
| 328 | # token to establish. MIME::Base64 is required at call time for the same | ||||||||||||||||||||||||||||||||||||||||||
| 329 | # reason LWP is. Note the second argument to encode_base64 is an empty string, | ||||||||||||||||||||||||||||||||||||||||||
| 330 | # which suppresses the line wrapping it would otherwise insert and which would | ||||||||||||||||||||||||||||||||||||||||||
| 331 | # corrupt the header. | ||||||||||||||||||||||||||||||||||||||||||
| 332 | # | ||||||||||||||||||||||||||||||||||||||||||
| 333 | # Any HTTP level failure dies rather than setting an error. The callers wrap | ||||||||||||||||||||||||||||||||||||||||||
| 334 | # this in eval and turn the exception into the appropriate error code. | ||||||||||||||||||||||||||||||||||||||||||
| 335 | # | ||||||||||||||||||||||||||||||||||||||||||
| 336 | # A body that fails to decode as JSON is not fatal; the decode runs inside its | ||||||||||||||||||||||||||||||||||||||||||
| 337 | # own eval and leaves the result undef. | ||||||||||||||||||||||||||||||||||||||||||
| 338 | # | ||||||||||||||||||||||||||||||||||||||||||
| 339 | # Never called in testing mode; those paths record the request instead. | ||||||||||||||||||||||||||||||||||||||||||
| 340 | # | ||||||||||||||||||||||||||||||||||||||||||
| 341 | # Args: | ||||||||||||||||||||||||||||||||||||||||||
| 342 | # | ||||||||||||||||||||||||||||||||||||||||||
| 343 | # method - The HTTP method, as a plain string, such as 'GET' or 'PATCH'. | ||||||||||||||||||||||||||||||||||||||||||
| 344 | # | ||||||||||||||||||||||||||||||||||||||||||
| 345 | # url - The full URL to request, as a plain string, normally | ||||||||||||||||||||||||||||||||||||||||||
| 346 | # _obj_url. | ||||||||||||||||||||||||||||||||||||||||||
| 347 | # | ||||||||||||||||||||||||||||||||||||||||||
| 348 | # body - Optional request body, as an already encoded JSON string, | ||||||||||||||||||||||||||||||||||||||||||
| 349 | # normally from _render. undef for methods that carry no body. | ||||||||||||||||||||||||||||||||||||||||||
| 350 | # | ||||||||||||||||||||||||||||||||||||||||||
| 351 | # Returns the decoded response body as whatever structure the JSON held, | ||||||||||||||||||||||||||||||||||||||||||
| 352 | # normally a hashref, or undef when the response body was empty or did not | ||||||||||||||||||||||||||||||||||||||||||
| 353 | # parse. Dies on any non success HTTP status. | ||||||||||||||||||||||||||||||||||||||||||
| 354 | # | ||||||||||||||||||||||||||||||||||||||||||
| 355 | # $self->_request( 'GET', $self->_obj_url ); | ||||||||||||||||||||||||||||||||||||||||||
| 356 | # | ||||||||||||||||||||||||||||||||||||||||||
| 357 | # # the usual shape at the call sites | ||||||||||||||||||||||||||||||||||||||||||
| 358 | # eval { $self->_request( 'PATCH', $self->_obj_url, $self->_render ); }; | ||||||||||||||||||||||||||||||||||||||||||
| 359 | # if ($@) { ... raise banFailed ... } | ||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | sub _request { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_request: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | my ( $self, $method, $url, $body ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | if ( !defined( $self->{ua} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | eval { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | require LWP::UserAgent; | |||||||||||||||||||||||||||||||||||||||||
| 367 | my %args = ( | ||||||||||||||||||||||||||||||||||||||||||
| 368 | agent => 'Net::Firewall::BlockerHelper/' . $VERSION, | ||||||||||||||||||||||||||||||||||||||||||
| 369 | timeout => $self->{options}{timeout}, | ||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | if ( $self->{options}{insecure} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | $args{ssl_opts} = { verify_hostname => 0, SSL_verify_mode => 0 }; | |||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | $self->{ua} = LWP::UserAgent->new(%args); | |||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 376 | } or die( 'failed to load LWP::UserAgent, which the f5_bigip backend requires... ' . $@ ); | ||||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | require MIME::Base64; | |||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | my $auth = 'Basic ' . MIME::Base64::encode_base64( $self->{options}{user} . ':' . $self->{options}{password}, '' ); | |||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | my @headers = ( 'Content-Type' => 'application/json', 'Authorization' => $auth ); | |||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | require HTTP::Request; | |||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | my $request = HTTP::Request->new( $method, $url, \@headers, $body ); | |||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | my $response = $self->{ua}->request($request); | |||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | if ( !$response->is_success ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | my $detail = $response->decoded_content; | |||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | $detail = defined($detail) ? ( ' body... ' . $detail ) : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | die( $method . ' ' . $url . ' failed... HTTP status... ' . $response->status_line . $detail ); | |||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | my $decoded; | |||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | my $content = $response->decoded_content; | |||||||||||||||||||||||||||||||||||||||||
| 397 | 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 ""
| |||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | eval { $decoded = $self->_json->decode($content); }; | |||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | return $decoded; | |||||||||||||||||||||||||||||||||||||||||
| 403 | } ## end sub _request | ||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | =head2 init | ||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | Initiates the backend. Verifies the credentials, reachability, and that the | ||||||||||||||||||||||||||||||||||||||||||
| 408 | address-list object exists by fetching it. | ||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||
| 412 | 2 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=4 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 413 | 2 | my ( $self, %opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | 2 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | 2 | ▶ | if ( $self->{inited} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | $self->{error} = 18; | |||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | $self->{errorString} = 'backend has already been inited'; | |||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | 2 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | 2 | $self->{frontend_obj}->{test_data} = [ { method => 'GET', url => $self->_obj_url } ]; | |||||||||||||||||||||||||||||||||||||||||
| 425 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | ▶ | eval { $self->_request( 'GET', $self->_obj_url ); 1; } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | $self->{error} = 23; | |||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | $self->{errorString} = 'init failed. probing the address-list object failed... ' . $@; | |||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 431 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | 2 | $self->{inited} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 435 | } ## end sub init | ||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||
| 437 | =head2 ban | ||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | Bans an IP. The value of ban is validated as being a IPv4 or IPv6 address | ||||||||||||||||||||||||||||||||||||||||||
| 440 | and lowercased, then added to the internal ban list and the full rendered | ||||||||||||||||||||||||||||||||||||||||||
| 441 | membership is pushed to the address-list via a PUT. Banning an already | ||||||||||||||||||||||||||||||||||||||||||
| 442 | banned IP is a noop. If the PUT fails, the IP is removed from the internal | ||||||||||||||||||||||||||||||||||||||||||
| 443 | list again. | ||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||
| 445 | $backend->ban(ban => $ip); | ||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||
| 449 | 3 | ▶ | sub ban { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ban: called CC=10 SCAR=38.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 450 | 3 | my ( $self, %opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | 3 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||
| 454 | 3 | ▶ | if ( !$self->{inited} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | $self->{errorString} = 'backend has not been inited'; | |||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||
| 461 | 3 | ▶ | if ( !defined( $opts{ban} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | $self->{error} = 9; | |||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | $self->{errorString} = 'Nothing specified for the value ban'; | |||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 466 | } elsif ( ref( $opts{ban} ) ne '' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | $self->{error} = 10; | |||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"'; | |||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 471 | ▶ | } 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/
| |||||||||||||||||||||||||||||||||||||||||||
| 472 | && $opts{ban} !~ /\A$IPv6_re\z/ ) | ||||||||||||||||||||||||||||||||||||||||||
| 473 | { | ||||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | $self->{error} = 10; | |||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 IP'; | |||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | # lowercase so the same IPv6 IP in differing cases can't result in duplicate entries | ||||||||||||||||||||||||||||||||||||||||||
| 481 | 3 | $opts{ban} = lc( $opts{ban} ); | |||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||
| 483 | 3 | ▶ | if ( $self->{banned}{ $opts{ban} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | $self->{frontend_obj}->{test_data} = 'already banned'; | |||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||
| 490 | 3 | $self->{banned}{ $opts{ban} } = 1; | |||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||
| 492 | 3 | my $body = $self->_render; | |||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | 3 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 495 | 3 | $self->{frontend_obj}->{test_data} = [ { method => 'PUT', url => $self->_obj_url, content => $body } ]; | |||||||||||||||||||||||||||||||||||||||||
| 496 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | ▶ | eval { $self->_request( 'PUT', $self->_obj_url, $body ); 1; } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | delete( $self->{banned}{ $opts{ban} } ); | |||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | $self->{error} = 13; | |||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | $self->{errorString} = 'banning "' . $opts{ban} . '" failed... ' . $@; | |||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 504 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||||||||||
| 506 | } ## end sub ban | ||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||
| 508 | =head2 unban | ||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||
| 510 | Unbans an IP. The value of ban is validated as being a IPv4 or IPv6 address | ||||||||||||||||||||||||||||||||||||||||||
| 511 | and lowercased, then removed from the internal ban list and the full | ||||||||||||||||||||||||||||||||||||||||||
| 512 | rendered membership is pushed to the address-list via a PUT. Unbanning an | ||||||||||||||||||||||||||||||||||||||||||
| 513 | IP that is not banned is a noop. If the PUT fails, the IP is re-added to | ||||||||||||||||||||||||||||||||||||||||||
| 514 | the internal list. | ||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||
| 516 | $backend->unban(ban => $ip); | ||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||
| 518 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||
| 520 | 1 | ▶ | sub unban { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unban: called CC=10 SCAR=38.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 521 | 1 | my ( $self, %opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||
| 523 | 1 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||
| 525 | 1 | ▶ | if ( !$self->{inited} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | $self->{errorString} = 'backend has not been inited'; | |||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||
| 532 | 1 | ▶ | if ( !defined( $opts{ban} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | $self->{error} = 9; | |||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | $self->{errorString} = 'Nothing specified for the value ban'; | |||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 537 | } elsif ( ref( $opts{ban} ) ne '' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | $self->{error} = 10; | |||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"'; | |||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 542 | ▶ | } 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/
| |||||||||||||||||||||||||||||||||||||||||||
| 543 | && $opts{ban} !~ /\A$IPv6_re\z/ ) | ||||||||||||||||||||||||||||||||||||||||||
| 544 | { | ||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | $self->{error} = 10; | |||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 IP'; | |||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||
| 551 | # lowercase so the same IPv6 IP in differing cases can't result in duplicate entries | ||||||||||||||||||||||||||||||||||||||||||
| 552 | 1 | $opts{ban} = lc( $opts{ban} ); | |||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||
| 554 | 1 | ▶ | if ( !$self->{banned}{ $opts{ban} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | $self->{frontend_obj}->{test_data} = 'not banned'; | |||||||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||||||
| 558 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||
| 561 | 1 | delete( $self->{banned}{ $opts{ban} } ); | |||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||
| 563 | 1 | my $body = $self->_render; | |||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||
| 565 | 1 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 566 | 1 | $self->{frontend_obj}->{test_data} = [ { method => 'PUT', url => $self->_obj_url, content => $body } ]; | |||||||||||||||||||||||||||||||||||||||||
| 567 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | ▶ | eval { $self->_request( 'PUT', $self->_obj_url, $body ); 1; } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | $self->{banned}{ $opts{ban} } = 1; | |||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | $self->{error} = 14; | |||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | $self->{errorString} = 'unbanning "' . $opts{ban} . '" failed... ' . $@; | |||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 574 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 575 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||
| 577 | } ## end sub unban | ||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||
| 579 | =head2 ban_cidr | ||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||
| 581 | Bans a CIDR range by adding it to the internal list and pushing the full | ||||||||||||||||||||||||||||||||||||||||||
| 582 | rendered membership to the address-list via a PUT. The value of ban is | ||||||||||||||||||||||||||||||||||||||||||
| 583 | validated as being a IPv4 or IPv6 CIDR range and lowercased. Banning an | ||||||||||||||||||||||||||||||||||||||||||
| 584 | already banned range is a noop. | ||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||
| 586 | $backend->ban_cidr(ban => '1.2.3.0/24'); | ||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||
| 588 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||
| 590 | 1 | ▶ | sub ban_cidr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ban_cidr: called CC=9 SCAR=36.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 591 | 1 | my ( $self, %opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||
| 593 | 1 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||
| 595 | 1 | ▶ | if ( !$self->{inited} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 597 | 0 | $self->{errorString} = 'backend has not been inited'; | |||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||
| 602 | 1 | ▶ | if ( !defined( $opts{ban} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | $self->{error} = 9; | |||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | $self->{errorString} = 'Nothing specified for the value ban'; | |||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 606 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 607 | } elsif ( ref( $opts{ban} ) ne '' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | $self->{error} = 35; | |||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"'; | |||||||||||||||||||||||||||||||||||||||||
| 610 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 611 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 612 | } elsif ( !$self->_valid_cidr( $opts{ban} ) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | $self->{error} = 35; | |||||||||||||||||||||||||||||||||||||||||
| 614 | 0 | $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 CIDR'; | |||||||||||||||||||||||||||||||||||||||||
| 615 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||
| 619 | # lowercase so the same IPv6 CIDR in differing cases can't result in duplicate entries | ||||||||||||||||||||||||||||||||||||||||||
| 620 | 1 | $opts{ban} = lc( $opts{ban} ); | |||||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||||
| 622 | 1 | ▶ | if ( $self->{banned_cidr}{ $opts{ban} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 623 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | $self->{frontend_obj}->{test_data} = 'already banned'; | |||||||||||||||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 627 | } | ||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||
| 629 | 1 | $self->{banned_cidr}{ $opts{ban} } = 1; | |||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||
| 631 | 1 | my $body = $self->_render; | |||||||||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||||||||||
| 633 | 1 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 634 | 1 | $self->{frontend_obj}->{test_data} = [ { method => 'PUT', url => $self->_obj_url, content => $body } ]; | |||||||||||||||||||||||||||||||||||||||||
| 635 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | ▶ | eval { $self->_request( 'PUT', $self->_obj_url, $body ); 1; } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 638 | 0 | delete( $self->{banned_cidr}{ $opts{ban} } ); | |||||||||||||||||||||||||||||||||||||||||
| 639 | 0 | $self->{error} = 33; | |||||||||||||||||||||||||||||||||||||||||
| 640 | 0 | $self->{errorString} = 'banning "' . $opts{ban} . '" failed... ' . $@; | |||||||||||||||||||||||||||||||||||||||||
| 641 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 642 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 643 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 644 | } | ||||||||||||||||||||||||||||||||||||||||||
| 645 | } ## end sub ban_cidr | ||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||
| 647 | =head2 unban_cidr | ||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||
| 649 | Unbans a CIDR range by removing it from the internal list and pushing the | ||||||||||||||||||||||||||||||||||||||||||
| 650 | full rendered membership to the address-list via a PUT. The value of ban is | ||||||||||||||||||||||||||||||||||||||||||
| 651 | validated as being a IPv4 or IPv6 CIDR range and lowercased. Unbanning a | ||||||||||||||||||||||||||||||||||||||||||
| 652 | range that is not banned is a noop. | ||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||
| 654 | $backend->unban_cidr(ban => '1.2.3.0/24'); | ||||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||
| 656 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||
| 658 | 1 | ▶ | sub unban_cidr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unban_cidr: called CC=9 SCAR=36.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 659 | 1 | my ( $self, %opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||||||||||||
| 661 | 1 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||
| 663 | 1 | ▶ | if ( !$self->{inited} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 664 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 665 | 0 | $self->{errorString} = 'backend has not been inited'; | |||||||||||||||||||||||||||||||||||||||||
| 666 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 668 | } | ||||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||
| 670 | 1 | ▶ | if ( !defined( $opts{ban} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 671 | 0 | $self->{error} = 9; | |||||||||||||||||||||||||||||||||||||||||
| 672 | 0 | $self->{errorString} = 'Nothing specified for the value ban'; | |||||||||||||||||||||||||||||||||||||||||
| 673 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 674 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 675 | } elsif ( ref( $opts{ban} ) ne '' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 676 | 0 | $self->{error} = 35; | |||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"'; | |||||||||||||||||||||||||||||||||||||||||
| 678 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 680 | } elsif ( !$self->_valid_cidr( $opts{ban} ) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 681 | 0 | $self->{error} = 35; | |||||||||||||||||||||||||||||||||||||||||
| 682 | 0 | $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 CIDR'; | |||||||||||||||||||||||||||||||||||||||||
| 683 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||
| 687 | # lowercase so the same IPv6 CIDR in differing cases can't result in duplicate entries | ||||||||||||||||||||||||||||||||||||||||||
| 688 | 1 | $opts{ban} = lc( $opts{ban} ); | |||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||||
| 690 | 1 | ▶ | if ( !$self->{banned_cidr}{ $opts{ban} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 691 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 692 | 0 | $self->{frontend_obj}->{test_data} = 'not banned'; | |||||||||||||||||||||||||||||||||||||||||
| 693 | } | ||||||||||||||||||||||||||||||||||||||||||
| 694 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 695 | } | ||||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||
| 697 | 1 | delete( $self->{banned_cidr}{ $opts{ban} } ); | |||||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||||||
| 699 | 1 | my $body = $self->_render; | |||||||||||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||||||||||||
| 701 | 1 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 702 | 1 | $self->{frontend_obj}->{test_data} = [ { method => 'PUT', url => $self->_obj_url, content => $body } ]; | |||||||||||||||||||||||||||||||||||||||||
| 703 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 704 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 705 | 0 | ▶ | eval { $self->_request( 'PUT', $self->_obj_url, $body ); 1; } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 706 | 0 | $self->{banned_cidr}{ $opts{ban} } = 1; | |||||||||||||||||||||||||||||||||||||||||
| 707 | 0 | $self->{error} = 34; | |||||||||||||||||||||||||||||||||||||||||
| 708 | 0 | $self->{errorString} = 'unbanning "' . $opts{ban} . '" failed... ' . $@; | |||||||||||||||||||||||||||||||||||||||||
| 709 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 710 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 711 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||||||||||||||||
| 713 | } ## end sub unban_cidr | ||||||||||||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||||||||||||
| 715 | =head2 list_cidr | ||||||||||||||||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||||||||||||||||
| 717 | List banned CIDR ranges. Returns an array of the currently banned CIDR | ||||||||||||||||||||||||||||||||||||||||||
| 718 | ranges. Single IPs are not included; for those see L</list>. | ||||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||
| 720 | my @banned_cidrs = $backend->list_cidr; | ||||||||||||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||||||||||||
| 722 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||||||
| 724 | 2 | ▶ | sub list_cidr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_cidr: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 725 | 2 | my ( $self, %opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||
| 727 | 2 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||||||||||||||||
| 729 | 2 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 730 | 2 | $self->{frontend_obj}->{test_data} = 'list_cidr'; | |||||||||||||||||||||||||||||||||||||||||
| 731 | } | ||||||||||||||||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||||||||||||||||
| 733 | 2 | return keys( %{ $self->{banned_cidr} } ); | |||||||||||||||||||||||||||||||||||||||||
| 734 | } | ||||||||||||||||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||||||||||||||||
| 736 | =head2 list | ||||||||||||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||||||||||||
| 738 | List banned IPs. Returns an array of the currently banned single IPs. CIDR | ||||||||||||||||||||||||||||||||||||||||||
| 739 | ranges are not included; for those see L</list_cidr>. | ||||||||||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||||||||||
| 741 | my @banned = $backend->list; | ||||||||||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||||||||||
| 743 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||||||||||||
| 745 | 0 | ▶ | sub list { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 746 | 0 | my ( $self, %opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||||||||||||||||
| 748 | 0 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 749 | |||||||||||||||||||||||||||||||||||||||||||
| 750 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 751 | 0 | $self->{frontend_obj}->{test_data} = 'list'; | |||||||||||||||||||||||||||||||||||||||||
| 752 | } | ||||||||||||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||||||||||||
| 754 | 0 | return keys( %{ $self->{banned} } ); | |||||||||||||||||||||||||||||||||||||||||
| 755 | } | ||||||||||||||||||||||||||||||||||||||||||
| 756 | |||||||||||||||||||||||||||||||||||||||||||
| 757 | =head2 re_init | ||||||||||||||||||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||||||||||||||||
| 759 | Tears down and re-inits, then re-renders the full membership in a single PUT. | ||||||||||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||||||||||
| 761 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||||||||||||||||
| 763 | 0 | ▶ | sub re_init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
re_init: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 764 | 0 | my ( $self, %opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||||||
| 766 | 0 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||||||||||||||||
| 768 | # teardown is best effort here as a partially or fully wiped setup is | ||||||||||||||||||||||||||||||||||||||||||
| 769 | # exactly what re_init needs to recover from | ||||||||||||||||||||||||||||||||||||||||||
| 770 | { | ||||||||||||||||||||||||||||||||||||||||||
| 771 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 772 | 0 | eval { $self->teardown; }; | |||||||||||||||||||||||||||||||||||||||||
| 773 | } | ||||||||||||||||||||||||||||||||||||||||||
| 774 | 0 | $self->init; | |||||||||||||||||||||||||||||||||||||||||
| 775 | |||||||||||||||||||||||||||||||||||||||||||
| 776 | 0 | my $body = $self->_render; | |||||||||||||||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||||||||||||||||
| 778 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 779 | 0 | $self->{frontend_obj}->{test_data} = [ { method => 'PUT', url => $self->_obj_url, content => $body } ]; | |||||||||||||||||||||||||||||||||||||||||
| 780 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 781 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 782 | 0 | ▶ | eval { $self->_request( 'PUT', $self->_obj_url, $body ); 1; } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 783 | 0 | $self->{error} = 13; | |||||||||||||||||||||||||||||||||||||||||
| 784 | 0 | $self->{errorString} = 're_init failed re-rendering the address-list membership... ' . $@; | |||||||||||||||||||||||||||||||||||||||||
| 785 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 786 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 787 | } | ||||||||||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||||||||||
| 789 | 0 | $self->{inited} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 790 | } ## end sub re_init | ||||||||||||||||||||||||||||||||||||||||||
| 791 | |||||||||||||||||||||||||||||||||||||||||||
| 792 | =head2 teardown | ||||||||||||||||||||||||||||||||||||||||||
| 793 | |||||||||||||||||||||||||||||||||||||||||||
| 794 | Tears down the setup by rendering an empty membership to the address-list. The | ||||||||||||||||||||||||||||||||||||||||||
| 795 | internal list of bans is kept, so a following re_init will re-add them. | ||||||||||||||||||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||||||||||||||||
| 797 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||||||||||||||||
| 799 | 0 | ▶ | sub teardown { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
teardown: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 800 | 0 | my ( $self, %opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||||||||||||
| 802 | 0 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||||||||||||||||
| 804 | 0 | $self->{inited} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||||||||||||||||
| 806 | # render an empty membership without disturbing the internal ban list | ||||||||||||||||||||||||||||||||||||||||||
| 807 | 0 | my $body = $self->_json->encode( { addresses => [] } ); | |||||||||||||||||||||||||||||||||||||||||
| 808 | |||||||||||||||||||||||||||||||||||||||||||
| 809 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 810 | 0 | $self->{frontend_obj}->{test_data} = [ { method => 'PUT', url => $self->_obj_url, content => $body } ]; | |||||||||||||||||||||||||||||||||||||||||
| 811 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 812 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 813 | 0 | ▶ | eval { $self->_request( 'PUT', $self->_obj_url, $body ); 1; } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 814 | 0 | $self->{error} = 17; | |||||||||||||||||||||||||||||||||||||||||
| 815 | 0 | $self->{errorString} = 'teardown failed emptying the address-list... ' . $@; | |||||||||||||||||||||||||||||||||||||||||
| 816 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 817 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 818 | } | ||||||||||||||||||||||||||||||||||||||||||
| 819 | } ## end sub teardown | ||||||||||||||||||||||||||||||||||||||||||
| 820 | |||||||||||||||||||||||||||||||||||||||||||
| 821 | =head2 stop | ||||||||||||||||||||||||||||||||||||||||||
| 822 | |||||||||||||||||||||||||||||||||||||||||||
| 823 | Alias for L</teardown>. | ||||||||||||||||||||||||||||||||||||||||||
| 824 | |||||||||||||||||||||||||||||||||||||||||||
| 825 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||||||||||||||||
| 827 | 0 | ▶ | sub stop { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stop: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 828 | 0 | my ( $self, %opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||||||||||||||||
| 830 | 0 | return $self->teardown(%opts); | |||||||||||||||||||||||||||||||||||||||||
| 831 | } | ||||||||||||||||||||||||||||||||||||||||||
| 832 | |||||||||||||||||||||||||||||||||||||||||||
| 833 | =head2 check | ||||||||||||||||||||||||||||||||||||||||||
| 834 | |||||||||||||||||||||||||||||||||||||||||||
| 835 | Verifies the endpoint and credentials are still usable by fetching the | ||||||||||||||||||||||||||||||||||||||||||
| 836 | address-list object. Returns a true value if so and a false value otherwise. | ||||||||||||||||||||||||||||||||||||||||||
| 837 | |||||||||||||||||||||||||||||||||||||||||||
| 838 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 839 | |||||||||||||||||||||||||||||||||||||||||||
| 840 | 6 | ▶ | sub check { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check: called CC=3 SCAR=15.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 841 | 6 | my ( $self, %opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 842 | |||||||||||||||||||||||||||||||||||||||||||
| 843 | 6 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 844 | |||||||||||||||||||||||||||||||||||||||||||
| 845 | 6 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 846 | 6 | $self->{frontend_obj}->{test_data} = [ { method => 'GET', url => $self->_obj_url } ]; | |||||||||||||||||||||||||||||||||||||||||
| 847 | 6 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 848 | } | ||||||||||||||||||||||||||||||||||||||||||
| 849 | |||||||||||||||||||||||||||||||||||||||||||
| 850 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 851 | 0 | ▶ | eval { $self->_request( 'GET', $self->_obj_url ); 1; } or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 852 | |||||||||||||||||||||||||||||||||||||||||||
| 853 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 854 | } ## end sub check | ||||||||||||||||||||||||||||||||||||||||||
| 855 | |||||||||||||||||||||||||||||||||||||||||||
| 856 | =head2 flush | ||||||||||||||||||||||||||||||||||||||||||
| 857 | |||||||||||||||||||||||||||||||||||||||||||
| 858 | Removes all currently banned IPs at once by rendering an empty membership to | ||||||||||||||||||||||||||||||||||||||||||
| 859 | the address-list and forgetting them. | ||||||||||||||||||||||||||||||||||||||||||
| 860 | |||||||||||||||||||||||||||||||||||||||||||
| 861 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 862 | |||||||||||||||||||||||||||||||||||||||||||
| 863 | 0 | ▶ | sub flush { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
flush: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 864 | 0 | my ( $self, %opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 865 | |||||||||||||||||||||||||||||||||||||||||||
| 866 | 0 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||
| 867 | |||||||||||||||||||||||||||||||||||||||||||
| 868 | 0 | ▶ | if ( !$self->{inited} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 869 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 870 | 0 | $self->{errorString} = 'backend has not been inited'; | |||||||||||||||||||||||||||||||||||||||||
| 871 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 872 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 873 | } | ||||||||||||||||||||||||||||||||||||||||||
| 874 | |||||||||||||||||||||||||||||||||||||||||||
| 875 | # the rendered empty membership below removes both single IPs and CIDR ranges | ||||||||||||||||||||||||||||||||||||||||||
| 876 | 0 | $self->{banned} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 877 | 0 | $self->{banned_cidr} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||||||||||||||||
| 879 | 0 | my $body = $self->_render; | |||||||||||||||||||||||||||||||||||||||||
| 880 | |||||||||||||||||||||||||||||||||||||||||||
| 881 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 882 | 0 | $self->{frontend_obj}->{test_data} = [ { method => 'PUT', url => $self->_obj_url, content => $body } ]; | |||||||||||||||||||||||||||||||||||||||||
| 883 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 884 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 885 | 0 | ▶ | eval { $self->_request( 'PUT', $self->_obj_url, $body ); 1; } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 886 | 0 | $self->{error} = 25; | |||||||||||||||||||||||||||||||||||||||||
| 887 | 0 | $self->{errorString} = 'flush failed emptying the address-list... ' . $@; | |||||||||||||||||||||||||||||||||||||||||
| 888 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||
| 889 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 890 | } | ||||||||||||||||||||||||||||||||||||||||||
| 891 | } ## end sub flush | ||||||||||||||||||||||||||||||||||||||||||
| 892 | |||||||||||||||||||||||||||||||||||||||||||
| 893 | =head1 ERROR CODES / FLAGS | ||||||||||||||||||||||||||||||||||||||||||
| 894 | |||||||||||||||||||||||||||||||||||||||||||
| 895 | Error handling is provided by L<Error::Helper>. All | ||||||||||||||||||||||||||||||||||||||||||
| 896 | errors are considered fatal. | ||||||||||||||||||||||||||||||||||||||||||
| 897 | |||||||||||||||||||||||||||||||||||||||||||
| 898 | =head2 1, notInited | ||||||||||||||||||||||||||||||||||||||||||
| 899 | |||||||||||||||||||||||||||||||||||||||||||
| 900 | The backend has not been inited yet. | ||||||||||||||||||||||||||||||||||||||||||
| 901 | |||||||||||||||||||||||||||||||||||||||||||
| 902 | =head2 6, invalidPrefixSpecified | ||||||||||||||||||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||||||||||||||||
| 904 | The specified prefix did not match /^[a-zA-Z0-9]+$/. | ||||||||||||||||||||||||||||||||||||||||||
| 905 | |||||||||||||||||||||||||||||||||||||||||||
| 906 | =head2 7, invalidName | ||||||||||||||||||||||||||||||||||||||||||
| 907 | |||||||||||||||||||||||||||||||||||||||||||
| 908 | The name is either undef or does not match /^[a-zA-Z0-9\-]+$/. | ||||||||||||||||||||||||||||||||||||||||||
| 909 | |||||||||||||||||||||||||||||||||||||||||||
| 910 | =head2 8, optionsNotHash | ||||||||||||||||||||||||||||||||||||||||||
| 911 | |||||||||||||||||||||||||||||||||||||||||||
| 912 | The item passed to new for options is not a hash. | ||||||||||||||||||||||||||||||||||||||||||
| 913 | |||||||||||||||||||||||||||||||||||||||||||
| 914 | =head2 9, noBanItem | ||||||||||||||||||||||||||||||||||||||||||
| 915 | |||||||||||||||||||||||||||||||||||||||||||
| 916 | No IP or CIDR range specified to ban or unban. | ||||||||||||||||||||||||||||||||||||||||||
| 917 | |||||||||||||||||||||||||||||||||||||||||||
| 918 | =head2 10, banItemNotIP | ||||||||||||||||||||||||||||||||||||||||||
| 919 | |||||||||||||||||||||||||||||||||||||||||||
| 920 | The item to ban is not an IP. Either wrong ref type or regexp | ||||||||||||||||||||||||||||||||||||||||||
| 921 | test using L<Regexp::IPv4> and L<Regexp::IPv6> failed. | ||||||||||||||||||||||||||||||||||||||||||
| 922 | |||||||||||||||||||||||||||||||||||||||||||
| 923 | =head2 12, backendInitError | ||||||||||||||||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||||||||||||||||
| 925 | Failed to init the backend. | ||||||||||||||||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||||||||||||||||
| 927 | =head2 13, banFailed | ||||||||||||||||||||||||||||||||||||||||||
| 928 | |||||||||||||||||||||||||||||||||||||||||||
| 929 | Failed to ban the item. | ||||||||||||||||||||||||||||||||||||||||||
| 930 | |||||||||||||||||||||||||||||||||||||||||||
| 931 | =head2 14, unbanFailed | ||||||||||||||||||||||||||||||||||||||||||
| 932 | |||||||||||||||||||||||||||||||||||||||||||
| 933 | Failed to unban the item. | ||||||||||||||||||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||||||||||||||||
| 935 | =head2 15, listFailed | ||||||||||||||||||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||||||||||||||||
| 937 | Failed to get a list of bans. | ||||||||||||||||||||||||||||||||||||||||||
| 938 | |||||||||||||||||||||||||||||||||||||||||||
| 939 | =head2 16, reInitFailed | ||||||||||||||||||||||||||||||||||||||||||
| 940 | |||||||||||||||||||||||||||||||||||||||||||
| 941 | Failed to re_init the backend. | ||||||||||||||||||||||||||||||||||||||||||
| 942 | |||||||||||||||||||||||||||||||||||||||||||
| 943 | =head2 17, teardownFailed | ||||||||||||||||||||||||||||||||||||||||||
| 944 | |||||||||||||||||||||||||||||||||||||||||||
| 945 | Failed to teardown the backend. | ||||||||||||||||||||||||||||||||||||||||||
| 946 | |||||||||||||||||||||||||||||||||||||||||||
| 947 | =head2 18, alreadyInited | ||||||||||||||||||||||||||||||||||||||||||
| 948 | |||||||||||||||||||||||||||||||||||||||||||
| 949 | init called, but the backend has already been inited. | ||||||||||||||||||||||||||||||||||||||||||
| 950 | |||||||||||||||||||||||||||||||||||||||||||
| 951 | =head2 23, initFailed | ||||||||||||||||||||||||||||||||||||||||||
| 952 | |||||||||||||||||||||||||||||||||||||||||||
| 953 | Init failed. Probing the address-list object failed. | ||||||||||||||||||||||||||||||||||||||||||
| 954 | |||||||||||||||||||||||||||||||||||||||||||
| 955 | =head2 24, checkFailed | ||||||||||||||||||||||||||||||||||||||||||
| 956 | |||||||||||||||||||||||||||||||||||||||||||
| 957 | The backend check raised an error. | ||||||||||||||||||||||||||||||||||||||||||
| 958 | |||||||||||||||||||||||||||||||||||||||||||
| 959 | =head2 25, flushFailed | ||||||||||||||||||||||||||||||||||||||||||
| 960 | |||||||||||||||||||||||||||||||||||||||||||
| 961 | Failed to flush the bans. | ||||||||||||||||||||||||||||||||||||||||||
| 962 | |||||||||||||||||||||||||||||||||||||||||||
| 963 | =head2 26, portsNotSupported | ||||||||||||||||||||||||||||||||||||||||||
| 964 | |||||||||||||||||||||||||||||||||||||||||||
| 965 | The f5_bigip backend blocks whole IPs and does not support ports. | ||||||||||||||||||||||||||||||||||||||||||
| 966 | |||||||||||||||||||||||||||||||||||||||||||
| 967 | =head2 27, protocolsNotSupported | ||||||||||||||||||||||||||||||||||||||||||
| 968 | |||||||||||||||||||||||||||||||||||||||||||
| 969 | The f5_bigip backend blocks whole IPs and does not support protocols. | ||||||||||||||||||||||||||||||||||||||||||
| 970 | |||||||||||||||||||||||||||||||||||||||||||
| 971 | =head2 30, hostNotDefined | ||||||||||||||||||||||||||||||||||||||||||
| 972 | |||||||||||||||||||||||||||||||||||||||||||
| 973 | The option host is undef or blank. | ||||||||||||||||||||||||||||||||||||||||||
| 974 | |||||||||||||||||||||||||||||||||||||||||||
| 975 | =head2 31, userNotDefined | ||||||||||||||||||||||||||||||||||||||||||
| 976 | |||||||||||||||||||||||||||||||||||||||||||
| 977 | The option user is undef or blank. | ||||||||||||||||||||||||||||||||||||||||||
| 978 | |||||||||||||||||||||||||||||||||||||||||||
| 979 | =head2 32, passwordNotDefined | ||||||||||||||||||||||||||||||||||||||||||
| 980 | |||||||||||||||||||||||||||||||||||||||||||
| 981 | The option password is undef or blank. | ||||||||||||||||||||||||||||||||||||||||||
| 982 | |||||||||||||||||||||||||||||||||||||||||||
| 983 | =head2 33, banCidrFailed | ||||||||||||||||||||||||||||||||||||||||||
| 984 | |||||||||||||||||||||||||||||||||||||||||||
| 985 | Failed to ban the CIDR range. | ||||||||||||||||||||||||||||||||||||||||||
| 986 | |||||||||||||||||||||||||||||||||||||||||||
| 987 | =head2 34, unbanCidrFailed | ||||||||||||||||||||||||||||||||||||||||||
| 988 | |||||||||||||||||||||||||||||||||||||||||||
| 989 | Failed to unban the CIDR range. | ||||||||||||||||||||||||||||||||||||||||||
| 990 | |||||||||||||||||||||||||||||||||||||||||||
| 991 | =head2 35, cidrItemNotCidr | ||||||||||||||||||||||||||||||||||||||||||
| 992 | |||||||||||||||||||||||||||||||||||||||||||
| 993 | The item to ban is not a CIDR range. Either wrong ref type or it is not an | ||||||||||||||||||||||||||||||||||||||||||
| 994 | IPv4 or IPv6 address followed by a prefix length valid for its family. | ||||||||||||||||||||||||||||||||||||||||||
| 995 | |||||||||||||||||||||||||||||||||||||||||||
| 996 | =head2 36, cidrNotSupported | ||||||||||||||||||||||||||||||||||||||||||
| 997 | |||||||||||||||||||||||||||||||||||||||||||
| 998 | The backend does not support CIDR bans. | ||||||||||||||||||||||||||||||||||||||||||
| 999 | |||||||||||||||||||||||||||||||||||||||||||
| 1000 | =head2 37, listCidrFailed | ||||||||||||||||||||||||||||||||||||||||||
| 1001 | |||||||||||||||||||||||||||||||||||||||||||
| 1002 | Failed to get a list of CIDR bans. | ||||||||||||||||||||||||||||||||||||||||||
| 1003 | |||||||||||||||||||||||||||||||||||||||||||
| 1004 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 1005 | |||||||||||||||||||||||||||||||||||||||||||
| 1006 | Zane C. Bowers-Hadley, C<< <vvelox at vvelox.ent> >> | ||||||||||||||||||||||||||||||||||||||||||
| 1007 | |||||||||||||||||||||||||||||||||||||||||||
| 1008 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||
| 1009 | |||||||||||||||||||||||||||||||||||||||||||
| 1010 | This software is Copyright (c) 2023 by Zane C. Bowers-Hadley. | ||||||||||||||||||||||||||||||||||||||||||
| 1011 | |||||||||||||||||||||||||||||||||||||||||||
| 1012 | This is free software, licensed under: | ||||||||||||||||||||||||||||||||||||||||||
| 1013 | |||||||||||||||||||||||||||||||||||||||||||
| 1014 | The GNU Lesser General Public License, Version 2.1, February 1999 | ||||||||||||||||||||||||||||||||||||||||||
| 1015 | |||||||||||||||||||||||||||||||||||||||||||
| 1016 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1017 | |||||||||||||||||||||||||||||||||||||||||||
| 1018 | 1 | 1; # End of Net::Firewall::BlockerHelper::backends::f5_bigip | |||||||||||||||||||||||||||||||||||||||||