| 1 | package Net::Firewall::BlockerHelper::backends::opnsense; | ||||||||||||||||||||||||||||||||||||
| 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::opnsense - OPNsense firewall alias backend for Net::Firewall::BlockerHelper. | ||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||
| 14 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||
| 16 | Version 0.2.0 | ||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||
| 18 | =cut | ||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||
| 20 | 1 | our $VERSION = '0.2.0'; | |||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||
| 24 | use Net::Firewall::BlockerHelper::backends::opnsense; | ||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||
| 26 | my $backend; | ||||||||||||||||||||||||||||||||||||
| 27 | eval { | ||||||||||||||||||||||||||||||||||||
| 28 | $backend = Net::Firewall::BlockerHelper::backends::opnsense->new( | ||||||||||||||||||||||||||||||||||||
| 29 | name => 'ssh', | ||||||||||||||||||||||||||||||||||||
| 30 | options => { | ||||||||||||||||||||||||||||||||||||
| 31 | host => 'fw.example.org', | ||||||||||||||||||||||||||||||||||||
| 32 | key => 'someAPIkey', | ||||||||||||||||||||||||||||||||||||
| 33 | secret => 'someAPIsecret', | ||||||||||||||||||||||||||||||||||||
| 34 | alias => 'kur_ssh', | ||||||||||||||||||||||||||||||||||||
| 35 | }, | ||||||||||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||||||||||
| 37 | }; | ||||||||||||||||||||||||||||||||||||
| 38 | if ($@) { | ||||||||||||||||||||||||||||||||||||
| 39 | print 'Error: ' | ||||||||||||||||||||||||||||||||||||
| 40 | . $Error::Helper::error | ||||||||||||||||||||||||||||||||||||
| 41 | . "\nError String: " | ||||||||||||||||||||||||||||||||||||
| 42 | . $Error::Helper::errorString | ||||||||||||||||||||||||||||||||||||
| 43 | . "\nError Flag: " | ||||||||||||||||||||||||||||||||||||
| 44 | . $Error::Helper::errorFlag . "\n"; | ||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||
| 47 | $backend->init; | ||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||
| 49 | $backend->ban(ban => '1.2.3.4'); | ||||||||||||||||||||||||||||||||||||
| 50 | $backend->ban(ban => '4.3.2.1'); | ||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||
| 52 | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||
| 53 | print Dumper($backend->list); | ||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||
| 55 | $backend->unban(ban => '4.3.2.1'); | ||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||
| 57 | $backend->teardown; | ||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||
| 59 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||
| 61 | This backend blocks IPs by adding them to an OPNsense firewall alias via | ||||||||||||||||||||||||||||||||||||
| 62 | the C<os-firewall> C<alias_util> REST API, talked to via L<LWP::UserAgent>. | ||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||
| 64 | A single alias holds all of the banned IPs. Both IPv4 and IPv6 addresses | ||||||||||||||||||||||||||||||||||||
| 65 | are added to the same alias as OPNsense host/network aliases are family | ||||||||||||||||||||||||||||||||||||
| 66 | agnostic. | ||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||
| 68 | The alias B<must> already exist in OPNsense. It is created in the OPNsense | ||||||||||||||||||||||||||||||||||||
| 69 | web UI (Firewall -> Aliases) and referenced by a firewall rule that does | ||||||||||||||||||||||||||||||||||||
| 70 | the actual blocking. This backend only manages the contents of the alias, | ||||||||||||||||||||||||||||||||||||
| 71 | not the alias itself nor the rule referencing it. | ||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||
| 73 | L<LWP::UserAgent> is only loaded at run time, so it is only required if | ||||||||||||||||||||||||||||||||||||
| 74 | this backend is actually used. For https, L<LWP::Protocol::https> must be | ||||||||||||||||||||||||||||||||||||
| 75 | present as well. | ||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||
| 77 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||
| 79 | =head2 new | ||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||
| 81 | Initiates the the object. | ||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||
| 83 | - options :: Backend specific options. See below for further info. | ||||||||||||||||||||||||||||||||||||
| 84 | - Default :: {} | ||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||
| 86 | - ports :: Not used by this backend but is accepted for parity with | ||||||||||||||||||||||||||||||||||||
| 87 | Net::Firewall::BlockerHelper. | ||||||||||||||||||||||||||||||||||||
| 88 | - Default :: [] | ||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||
| 90 | - protocols :: Not used by this backend but is accepted for parity with | ||||||||||||||||||||||||||||||||||||
| 91 | Net::Firewall::BlockerHelper. | ||||||||||||||||||||||||||||||||||||
| 92 | - Default :: [] | ||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||
| 94 | - prefix :: Prefix to use when building the default alias name. | ||||||||||||||||||||||||||||||||||||
| 95 | - default :: kur | ||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||
| 97 | - name :: Name of this specific instance. This must be specified. | ||||||||||||||||||||||||||||||||||||
| 98 | - default :: undef | ||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||
| 100 | The options hash accepts the following. | ||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||
| 102 | - host :: OPNsense hostname or IP the API is reached at. May include a | ||||||||||||||||||||||||||||||||||||
| 103 | port, eg 'fw.example.org:8443'. This must be specified and can | ||||||||||||||||||||||||||||||||||||
| 104 | not be blank. | ||||||||||||||||||||||||||||||||||||
| 105 | - Default :: undef | ||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||
| 107 | - key :: The OPNsense API key. This must be specified and can not be | ||||||||||||||||||||||||||||||||||||
| 108 | blank. | ||||||||||||||||||||||||||||||||||||
| 109 | - Default :: undef | ||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||
| 111 | - secret :: The OPNsense API secret. This must be specified and can not | ||||||||||||||||||||||||||||||||||||
| 112 | be blank. | ||||||||||||||||||||||||||||||||||||
| 113 | - Default :: undef | ||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||
| 115 | - alias :: The name of the alias the IPs are added to. The alias must | ||||||||||||||||||||||||||||||||||||
| 116 | already exist in OPNsense. | ||||||||||||||||||||||||||||||||||||
| 117 | - Default :: <prefix>_<name> | ||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||
| 119 | - timeout :: HTTP timeout in seconds. | ||||||||||||||||||||||||||||||||||||
| 120 | - Default :: 30 | ||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||
| 122 | - insecure :: If true, certificate verification is disabled so | ||||||||||||||||||||||||||||||||||||
| 123 | self-signed certs are accepted. | ||||||||||||||||||||||||||||||||||||
| 124 | - Default :: 0 | ||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||
| 126 | - scheme :: The scheme used when building the URL, either 'https' or | ||||||||||||||||||||||||||||||||||||
| 127 | 'http'. | ||||||||||||||||||||||||||||||||||||
| 128 | - Default :: https | ||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||
| 130 | All errors are considered fatal, meaning if new fails it will die. | ||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||
| 132 | my $backend; | ||||||||||||||||||||||||||||||||||||
| 133 | eval { | ||||||||||||||||||||||||||||||||||||
| 134 | $backend = Net::Firewall::BlockerHelper::backends::opnsense->new( | ||||||||||||||||||||||||||||||||||||
| 135 | name => 'ssh', | ||||||||||||||||||||||||||||||||||||
| 136 | options => { | ||||||||||||||||||||||||||||||||||||
| 137 | host => 'fw.example.org', | ||||||||||||||||||||||||||||||||||||
| 138 | key => 'someAPIkey', | ||||||||||||||||||||||||||||||||||||
| 139 | secret => 'someAPIsecret', | ||||||||||||||||||||||||||||||||||||
| 140 | }, | ||||||||||||||||||||||||||||||||||||
| 141 | ); | ||||||||||||||||||||||||||||||||||||
| 142 | }; | ||||||||||||||||||||||||||||||||||||
| 143 | if ($@) { | ||||||||||||||||||||||||||||||||||||
| 144 | print 'Error: ' | ||||||||||||||||||||||||||||||||||||
| 145 | . $Error::Helper::error | ||||||||||||||||||||||||||||||||||||
| 146 | . "\nError String: " | ||||||||||||||||||||||||||||||||||||
| 147 | . $Error::Helper::errorString | ||||||||||||||||||||||||||||||||||||
| 148 | . "\nError Flag: " | ||||||||||||||||||||||||||||||||||||
| 149 | . $Error::Helper::errorFlag . "\n"; | ||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||
| 152 | =cut | ||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||
| 154 | 6 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=22 SCAR=34.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 155 | 6 | my ( $blank, %opts ) = @_; | |||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||
| 157 | 6 | my $self = { | |||||||||||||||||||||||||||||||||||
| 158 | perror => undef, | ||||||||||||||||||||||||||||||||||||
| 159 | error => undef, | ||||||||||||||||||||||||||||||||||||
| 160 | errorLine => undef, | ||||||||||||||||||||||||||||||||||||
| 161 | errorFilename => undef, | ||||||||||||||||||||||||||||||||||||
| 162 | errorString => "", | ||||||||||||||||||||||||||||||||||||
| 163 | errorExtra => { | ||||||||||||||||||||||||||||||||||||
| 164 | all_errors_fatal => 1, | ||||||||||||||||||||||||||||||||||||
| 165 | # all_fatal is what Error::Helper 2.1.0 actually checks; all_errors_fatal | ||||||||||||||||||||||||||||||||||||
| 166 | # is kept for the name documented in its POD | ||||||||||||||||||||||||||||||||||||
| 167 | all_fatal => 1, | ||||||||||||||||||||||||||||||||||||
| 168 | flags => { | ||||||||||||||||||||||||||||||||||||
| 169 | 1 => 'notInited', | ||||||||||||||||||||||||||||||||||||
| 170 | 8 => 'optionsNotHash', | ||||||||||||||||||||||||||||||||||||
| 171 | 9 => 'noBanItem', | ||||||||||||||||||||||||||||||||||||
| 172 | 10 => 'banItemNotIP', | ||||||||||||||||||||||||||||||||||||
| 173 | 12 => 'backendInitError', | ||||||||||||||||||||||||||||||||||||
| 174 | 13 => 'banFailed', | ||||||||||||||||||||||||||||||||||||
| 175 | 14 => 'unbanFailed', | ||||||||||||||||||||||||||||||||||||
| 176 | 15 => 'listFailed', | ||||||||||||||||||||||||||||||||||||
| 177 | 16 => 'reInitFailed', | ||||||||||||||||||||||||||||||||||||
| 178 | 17 => 'teardownFailed', | ||||||||||||||||||||||||||||||||||||
| 179 | 18 => 'alreadyInited', | ||||||||||||||||||||||||||||||||||||
| 180 | 24 => 'checkFailed', | ||||||||||||||||||||||||||||||||||||
| 181 | 25 => 'flushFailed', | ||||||||||||||||||||||||||||||||||||
| 182 | 30 => 'hostNotDefined', | ||||||||||||||||||||||||||||||||||||
| 183 | 31 => 'apiKeyNotDefined', | ||||||||||||||||||||||||||||||||||||
| 184 | 32 => 'apiSecretNotDefined', | ||||||||||||||||||||||||||||||||||||
| 185 | 33 => 'banCidrFailed', | ||||||||||||||||||||||||||||||||||||
| 186 | 34 => 'unbanCidrFailed', | ||||||||||||||||||||||||||||||||||||
| 187 | 35 => 'cidrItemNotCidr', | ||||||||||||||||||||||||||||||||||||
| 188 | 36 => 'cidrNotSupported', | ||||||||||||||||||||||||||||||||||||
| 189 | 37 => 'listCidrFailed', | ||||||||||||||||||||||||||||||||||||
| 190 | }, | ||||||||||||||||||||||||||||||||||||
| 191 | fatal_flags => {}, | ||||||||||||||||||||||||||||||||||||
| 192 | perror_not_fatal => 0, | ||||||||||||||||||||||||||||||||||||
| 193 | }, | ||||||||||||||||||||||||||||||||||||
| 194 | options => { | ||||||||||||||||||||||||||||||||||||
| 195 | timeout => 30, | ||||||||||||||||||||||||||||||||||||
| 196 | insecure => 0, | ||||||||||||||||||||||||||||||||||||
| 197 | scheme => 'https', | ||||||||||||||||||||||||||||||||||||
| 198 | }, | ||||||||||||||||||||||||||||||||||||
| 199 | ports => [], | ||||||||||||||||||||||||||||||||||||
| 200 | protocols => [], | ||||||||||||||||||||||||||||||||||||
| 201 | testing => undef, | ||||||||||||||||||||||||||||||||||||
| 202 | test_data => undef, | ||||||||||||||||||||||||||||||||||||
| 203 | prefix => 'kur', | ||||||||||||||||||||||||||||||||||||
| 204 | frontend_obj => undef, | ||||||||||||||||||||||||||||||||||||
| 205 | inited => 0, | ||||||||||||||||||||||||||||||||||||
| 206 | banned => {}, | ||||||||||||||||||||||||||||||||||||
| 207 | banned_cidr => {}, | ||||||||||||||||||||||||||||||||||||
| 208 | cidr_supported => 1, | ||||||||||||||||||||||||||||||||||||
| 209 | }; | ||||||||||||||||||||||||||||||||||||
| 210 | 6 | bless $self; | |||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||
| 212 | # make sure prefix is sane if defined | ||||||||||||||||||||||||||||||||||||
| 213 | 6 | ▶ | if ( defined( $opts{prefix} ) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 214 | 6 | $self->{prefix} = $opts{prefix}; | |||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||
| 217 | 6 | ▶ | if ( defined( $opts{name} ) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 218 | 6 | $self->{name} = $opts{name}; | |||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||
| 221 | # used internally for testing | ||||||||||||||||||||||||||||||||||||
| 222 | 6 | ▶ | if ( defined( $opts{testing} ) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 223 | 6 | $self->{testing} = $opts{testing}; | |||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||
| 225 | 6 | ▶ | if ( defined( $opts{frontend_obj} ) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 226 | 6 | $self->{frontend_obj} = $opts{frontend_obj}; | |||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||
| 229 | 6 | ▶ | if ( defined( $opts{options} ) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 230 | 6 | ▶ | if ( ref( $opts{options} ) ne 'HASH' ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 231 | 0 | $self->{perror} = 1; | |||||||||||||||||||||||||||||||||||
| 232 | 0 | $self->{error} = 8; | |||||||||||||||||||||||||||||||||||
| 233 | 0 | $self->{errorString} = 'ref for options is "' . ref( $opts{options} ) . '" and not HASH'; | |||||||||||||||||||||||||||||||||||
| 234 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||
| 236 | # merge the passed options over the defaults so unset knobs keep them | ||||||||||||||||||||||||||||||||||||
| 237 | 6 | foreach my $key ( keys( %{ $opts{options} } ) ) { | |||||||||||||||||||||||||||||||||||
| 238 | 18 | $self->{options}{$key} = $opts{options}{$key}; | |||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||
| 242 | # fill in the defaults for anything not passed | ||||||||||||||||||||||||||||||||||||
| 243 | 6 | ▶ | if ( !defined( $self->{options}{timeout} ) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 244 | 0 | $self->{options}{timeout} = 30; | |||||||||||||||||||||||||||||||||||
| 245 | } elsif ( $self->{options}{timeout} !~ /^[0-9]+$/ ) { | ||||||||||||||||||||||||||||||||||||
| 246 | 1 | $self->{perror} = 1; | |||||||||||||||||||||||||||||||||||
| 247 | 1 | $self->{error} = 12; | |||||||||||||||||||||||||||||||||||
| 248 | 1 | $self->{errorString} = 'the option timeout, "' . $self->{options}{timeout} . '", is not an int'; | |||||||||||||||||||||||||||||||||||
| 249 | 1 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||
| 251 | 5 | ▶ | if ( !defined( $self->{options}{insecure} ) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 252 | 0 | $self->{options}{insecure} = 0; | |||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||
| 254 | 5 | ▶ | if ( !defined( $self->{options}{scheme} ) || $self->{options}{scheme} eq '' ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $self->{"options"}{"scheme"} or $self->{"options"}{"scheme"} eq ""
MC/DC0%0/2
not defined $self->{"options"}{"scheme"} or $self->{"options"}{"scheme"} eq ""
not defined $self->{"options"}{"scheme"}
$self->{"options"}{"scheme"} eq ""
Truth table33%1/3
not(A) or B
A= not defined $self->{"options"}{"scheme"}B= $self->{"options"}{"scheme"} eq ""
| |||||||||||||||||||||||||||||||||||||
| 255 | 0 | $self->{options}{scheme} = 'https'; | |||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||
| 257 | 5 | ▶ | if ( !defined( $self->{options}{alias} ) || $self->{options}{alias} eq '' ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $self->{"options"}{"alias"} or $self->{"options"}{"alias"} eq ""
MC/DC0%0/2
not defined $self->{"options"}{"alias"} or $self->{"options"}{"alias"} eq ""
not defined $self->{"options"}{"alias"}
$self->{"options"}{"alias"} eq ""
Truth table33%1/3
not(A) or B
A= not defined $self->{"options"}{"alias"}B= $self->{"options"}{"alias"} eq ""
| |||||||||||||||||||||||||||||||||||||
| 258 | 5 | ▶ | $self->{options}{alias} = $self->{prefix} . '_' . ( defined( $self->{name} ) ? $self->{name} : '' ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||
| 261 | # host, key, and secret are all required to be able to talk to the API | ||||||||||||||||||||||||||||||||||||
| 262 | 5 | ▶ | if ( !defined( $self->{options}{host} ) || $self->{options}{host} eq '' ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
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 ""
| |||||||||||||||||||||||||||||||||||||
| 263 | 1 | $self->{perror} = 1; | |||||||||||||||||||||||||||||||||||
| 264 | 1 | $self->{error} = 30; | |||||||||||||||||||||||||||||||||||
| 265 | 1 | $self->{errorString} = 'host is not defined or is blank'; | |||||||||||||||||||||||||||||||||||
| 266 | 1 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 267 | ▶ | } elsif ( !defined( $self->{options}{key} ) || $self->{options}{key} eq '' ) { | |||||||||||||||||||||||||||||||||||
|
Condition66%2/3
not defined $self->{"options"}{"key"} or $self->{"options"}{"key"} eq ""
MC/DC50%1/2
not defined $self->{"options"}{"key"} or $self->{"options"}{"key"} eq ""
not defined $self->{"options"}{"key"}
$self->{"options"}{"key"} eq ""
Truth table66%2/3
not(A) or B
A= not defined $self->{"options"}{"key"}B= $self->{"options"}{"key"} eq ""
| |||||||||||||||||||||||||||||||||||||
| 268 | 1 | $self->{perror} = 1; | |||||||||||||||||||||||||||||||||||
| 269 | 1 | $self->{error} = 31; | |||||||||||||||||||||||||||||||||||
| 270 | 1 | $self->{errorString} = 'key is not defined or is blank'; | |||||||||||||||||||||||||||||||||||
| 271 | 1 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 272 | ▶ | } elsif ( !defined( $self->{options}{secret} ) || $self->{options}{secret} eq '' ) { | |||||||||||||||||||||||||||||||||||
|
Condition66%2/3
not defined $self->{"options"}{"secret"} or $self->{"options"}{"secret"} eq ""
MC/DC50%1/2
not defined $self->{"options"}{"secret"} or $self->{"options"}{"secret"} eq ""
not defined $self->{"options"}{"secret"}
$self->{"options"}{"secret"} eq ""
Truth table66%2/3
not(A) or B
A= not defined $self->{"options"}{"secret"}B= $self->{"options"}{"secret"} eq ""
| |||||||||||||||||||||||||||||||||||||
| 273 | 1 | $self->{perror} = 1; | |||||||||||||||||||||||||||||||||||
| 274 | 1 | $self->{error} = 32; | |||||||||||||||||||||||||||||||||||
| 275 | 1 | $self->{errorString} = 'secret is not defined or is blank'; | |||||||||||||||||||||||||||||||||||
| 276 | 1 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||
| 279 | 2 | return $self; | |||||||||||||||||||||||||||||||||||
| 280 | } ## end sub new | ||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||
| 282 | # Internal helper. Builds the full URL for an OPNsense firewall API endpoint. | ||||||||||||||||||||||||||||||||||||
| 283 | # Every request this backend makes goes through here. | ||||||||||||||||||||||||||||||||||||
| 284 | # | ||||||||||||||||||||||||||||||||||||
| 285 | # Everything this backend needs lives under the firewall module of the API, so | ||||||||||||||||||||||||||||||||||||
| 286 | # that much of the path is baked in and callers supply only the part below it. | ||||||||||||||||||||||||||||||||||||
| 287 | # | ||||||||||||||||||||||||||||||||||||
| 288 | # Args: | ||||||||||||||||||||||||||||||||||||
| 289 | # | ||||||||||||||||||||||||||||||||||||
| 290 | # method_path - The path below /api/firewall/, as a plain string, such as | ||||||||||||||||||||||||||||||||||||
| 291 | # 'alias_util/list/blocklist' or | ||||||||||||||||||||||||||||||||||||
| 292 | # 'alias_util/add/blocklist'. Appended as is, so any values | ||||||||||||||||||||||||||||||||||||
| 293 | # embedded in it are expected to have been percent encoded | ||||||||||||||||||||||||||||||||||||
| 294 | # by the caller already. | ||||||||||||||||||||||||||||||||||||
| 295 | # | ||||||||||||||||||||||||||||||||||||
| 296 | # Returns the complete URL as a string. The scheme and host come from the | ||||||||||||||||||||||||||||||||||||
| 297 | # options. | ||||||||||||||||||||||||||||||||||||
| 298 | # | ||||||||||||||||||||||||||||||||||||
| 299 | # $self->_url( 'alias_util/list/' . $alias ); | ||||||||||||||||||||||||||||||||||||
| 300 | # # https://opn.example.org/api/firewall/alias_util/list/blocklist | ||||||||||||||||||||||||||||||||||||
| 301 | # | ||||||||||||||||||||||||||||||||||||
| 302 | # $self->_url( 'alias_util/add/' . $alias ); | ||||||||||||||||||||||||||||||||||||
| 303 | # # https://opn.example.org/api/firewall/alias_util/add/blocklist | ||||||||||||||||||||||||||||||||||||
| 304 | 13 | ▶ | sub _url { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_url: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 305 | 13 | my ( $self, $method_path ) = @_; | |||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||
| 307 | 13 | return $self->{options}{scheme} . '://' . $self->{options}{host} . '/api/firewall/' . $method_path; | |||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||
| 310 | # Internal helper. Performs one HTTP request against the OPNsense API. Every | ||||||||||||||||||||||||||||||||||||
| 311 | # call this backend makes to the box goes through here. | ||||||||||||||||||||||||||||||||||||
| 312 | # | ||||||||||||||||||||||||||||||||||||
| 313 | # The user agent is built on first use and cached on the object, so a run of | ||||||||||||||||||||||||||||||||||||
| 314 | # requests shares one agent. LWP::UserAgent is loaded with require at that | ||||||||||||||||||||||||||||||||||||
| 315 | # point rather than at compile time, since only the HTTP backends need it; | ||||||||||||||||||||||||||||||||||||
| 316 | # failing to load it dies with an explanation naming this backend. The | ||||||||||||||||||||||||||||||||||||
| 317 | # insecure option turns off certificate verification, which is there because | ||||||||||||||||||||||||||||||||||||
| 318 | # an OPNsense box commonly presents a self signed certificate. | ||||||||||||||||||||||||||||||||||||
| 319 | # | ||||||||||||||||||||||||||||||||||||
| 320 | # Authentication is HTTP basic, but with the API key and secret standing in | ||||||||||||||||||||||||||||||||||||
| 321 | # for a username and password, which is how OPNsense issues API credentials. | ||||||||||||||||||||||||||||||||||||
| 322 | # | ||||||||||||||||||||||||||||||||||||
| 323 | # Any HTTP level failure dies rather than setting an error. The callers wrap | ||||||||||||||||||||||||||||||||||||
| 324 | # this in eval and turn the exception into the appropriate error code, which | ||||||||||||||||||||||||||||||||||||
| 325 | # is what lets one helper serve paths that report ban, unban, and teardown | ||||||||||||||||||||||||||||||||||||
| 326 | # failures differently. | ||||||||||||||||||||||||||||||||||||
| 327 | # | ||||||||||||||||||||||||||||||||||||
| 328 | # Never called in testing mode; those paths record the request instead. | ||||||||||||||||||||||||||||||||||||
| 329 | # | ||||||||||||||||||||||||||||||||||||
| 330 | # Args: | ||||||||||||||||||||||||||||||||||||
| 331 | # | ||||||||||||||||||||||||||||||||||||
| 332 | # method - The HTTP method, as a plain string, such as 'GET' or 'POST'. | ||||||||||||||||||||||||||||||||||||
| 333 | # | ||||||||||||||||||||||||||||||||||||
| 334 | # url - The full URL to request, as a plain string, from _url. | ||||||||||||||||||||||||||||||||||||
| 335 | # | ||||||||||||||||||||||||||||||||||||
| 336 | # body - Optional request body, as an already encoded JSON string. undef | ||||||||||||||||||||||||||||||||||||
| 337 | # for methods that carry no body. | ||||||||||||||||||||||||||||||||||||
| 338 | # | ||||||||||||||||||||||||||||||||||||
| 339 | # Returns the decoded response body as whatever structure the JSON held, | ||||||||||||||||||||||||||||||||||||
| 340 | # normally a hashref. Dies on any non success HTTP status. | ||||||||||||||||||||||||||||||||||||
| 341 | # | ||||||||||||||||||||||||||||||||||||
| 342 | # $self->_request( 'GET', $self->_url( 'alias_util/list/' . $alias ) ); | ||||||||||||||||||||||||||||||||||||
| 343 | # | ||||||||||||||||||||||||||||||||||||
| 344 | # # the usual shape at the call sites | ||||||||||||||||||||||||||||||||||||
| 345 | # eval { $self->_request( 'POST', $url, $body ); }; | ||||||||||||||||||||||||||||||||||||
| 346 | # if ($@) { ... raise banFailed ... } | ||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | sub _request { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_request: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||
| 348 | 0 | my ( $self, $method, $url, $body ) = @_; | |||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||
| 350 | 0 | ▶ | if ( !defined( $self->{ua} ) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 351 | 0 | local $@; | |||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | eval { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 353 | 0 | require LWP::UserAgent; | |||||||||||||||||||||||||||||||||||
| 354 | my %ua_opts = ( | ||||||||||||||||||||||||||||||||||||
| 355 | agent => 'Net::Firewall::BlockerHelper/' . $VERSION, | ||||||||||||||||||||||||||||||||||||
| 356 | timeout => $self->{options}{timeout}, | ||||||||||||||||||||||||||||||||||||
| 357 | 0 | ); | |||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | if ( $self->{options}{insecure} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 359 | 0 | $ua_opts{ssl_opts} = { verify_hostname => 0, SSL_verify_mode => 0 }; | |||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||
| 361 | 0 | $self->{ua} = LWP::UserAgent->new(%ua_opts); | |||||||||||||||||||||||||||||||||||
| 362 | 0 | 1; | |||||||||||||||||||||||||||||||||||
| 363 | } or die( 'failed to load LWP::UserAgent, which the opnsense backend requires... ' . $@ ); | ||||||||||||||||||||||||||||||||||||
| 364 | } ## end if ( !defined( $self->{ua...})) | ||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||
| 366 | 0 | require HTTP::Request; | |||||||||||||||||||||||||||||||||||
| 367 | 0 | my $request = HTTP::Request->new( $method, $url, [ 'Content-Type' => 'application/json' ], $body ); | |||||||||||||||||||||||||||||||||||
| 368 | 0 | $request->authorization_basic( $self->{options}{key}, $self->{options}{secret} ); | |||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||
| 370 | 0 | my $response = $self->{ua}->request($request); | |||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | if ( !$response->is_success ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 373 | 0 | die( $method . ' ' . $url . ' failed... HTTP status... ' . $response->status_line ); | |||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||
| 376 | 0 | my $decoded; | |||||||||||||||||||||||||||||||||||
| 377 | 0 | local $@; | |||||||||||||||||||||||||||||||||||
| 378 | 0 | eval { $decoded = $self->_json->decode( $response->decoded_content ); }; | |||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||
| 380 | 0 | return $decoded; | |||||||||||||||||||||||||||||||||||
| 381 | } ## end sub _request | ||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||
| 383 | =head2 init | ||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||
| 385 | Initiates the backend. This lists the alias via the API, with any | ||||||||||||||||||||||||||||||||||||
| 386 | connection or HTTP level failure, bad credentials included, raising an | ||||||||||||||||||||||||||||||||||||
| 387 | error. | ||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||
| 389 | No arguments are taken. | ||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||
| 391 | May called a second time, it will error. | ||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||
| 393 | $backend->init; | ||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||
| 395 | =cut | ||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||
| 397 | 2 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=4 SCAR=20.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 398 | 2 | my ( $self, %opts ) = @_; | |||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||
| 400 | 2 | $self->errorblank; | |||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||
| 402 | 2 | ▶ | if ( $self->{inited} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 403 | 0 | $self->{error} = 18; | |||||||||||||||||||||||||||||||||||
| 404 | 0 | $self->{errorString} = 'backend has already been inited'; | |||||||||||||||||||||||||||||||||||
| 405 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||
| 408 | 2 | my $url = $self->_url( 'alias_util/list/' . $self->{options}{alias} ); | |||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||
| 410 | 2 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 411 | 2 | $self->{frontend_obj}->{test_data} = [ { method => 'GET', url => $url } ]; | |||||||||||||||||||||||||||||||||||
| 412 | } else { | ||||||||||||||||||||||||||||||||||||
| 413 | 0 | local $@; | |||||||||||||||||||||||||||||||||||
| 414 | 0 | ▶ | eval { $self->_request( 'GET', $url ); 1; } or do { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 415 | 0 | $self->{error} = 12; | |||||||||||||||||||||||||||||||||||
| 416 | 0 | $self->{errorString} = 'init failed... listing the alias failed... ' . $@; | |||||||||||||||||||||||||||||||||||
| 417 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 418 | }; | ||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||
| 421 | 2 | $self->{inited} = 1; | |||||||||||||||||||||||||||||||||||
| 422 | } ## end sub init | ||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||
| 424 | =head2 ban | ||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||
| 426 | Bans an IP. The value of ban is validated as being a IPv4 or IPv6 address | ||||||||||||||||||||||||||||||||||||
| 427 | and lowercased, then added to the alias via a POST to the | ||||||||||||||||||||||||||||||||||||
| 428 | C<alias_util/add> API endpoint. Banning an already banned IP is | ||||||||||||||||||||||||||||||||||||
| 429 | a noop. | ||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||
| 431 | $backend->ban(ban => $ip); | ||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||
| 433 | =cut | ||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||
| 435 | 2 | ▶ | sub ban { | ||||||||||||||||||||||||||||||||||
|
Subroutine
ban: called CC=10 SCAR=36.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 436 | 2 | my ( $self, %opts ) = @_; | |||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||
| 438 | 2 | $self->errorblank; | |||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||
| 440 | 2 | ▶ | if ( !$self->{inited} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 441 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||
| 442 | 0 | $self->{errorString} = 'backend has not been inited'; | |||||||||||||||||||||||||||||||||||
| 443 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 444 | 0 | return; | |||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||
| 447 | 2 | ▶ | if ( !defined( $opts{ban} ) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||
| 448 | 0 | $self->{error} = 9; | |||||||||||||||||||||||||||||||||||
| 449 | 0 | $self->{errorString} = 'Nothing specified for the value ban'; | |||||||||||||||||||||||||||||||||||
| 450 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 451 | 0 | return; | |||||||||||||||||||||||||||||||||||
| 452 | } elsif ( ref( $opts{ban} ) ne '' ) { | ||||||||||||||||||||||||||||||||||||
| 453 | 0 | $self->{error} = 10; | |||||||||||||||||||||||||||||||||||
| 454 | 0 | $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"'; | |||||||||||||||||||||||||||||||||||
| 455 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 456 | 0 | return; | |||||||||||||||||||||||||||||||||||
| 457 | ▶ | } elsif ( $opts{ban} !~ /\A$IPv4_re\z/ | |||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::opnsense::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::opnsense::IPv6_re\z/
MC/DC0%0/2
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::opnsense::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::opnsense::IPv6_re\z/
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::opnsense::IPv4_re\z/
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::opnsense::IPv6_re\z/
Truth table66%2/3
A || B
A= $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::opnsense::IPv4_re\z/B= $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::opnsense::IPv6_re\z/
| |||||||||||||||||||||||||||||||||||||
| 458 | && $opts{ban} !~ /\A$IPv6_re\z/ ) | ||||||||||||||||||||||||||||||||||||
| 459 | { | ||||||||||||||||||||||||||||||||||||
| 460 | 0 | $self->{error} = 10; | |||||||||||||||||||||||||||||||||||
| 461 | 0 | $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 IP'; | |||||||||||||||||||||||||||||||||||
| 462 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 463 | 0 | return; | |||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||
| 466 | # lowercase so the same IPv6 IP in differing cases can't result in duplicate entries | ||||||||||||||||||||||||||||||||||||
| 467 | 2 | $opts{ban} = lc( $opts{ban} ); | |||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||
| 469 | 2 | ▶ | if ( $self->{banned}{ $opts{ban} } ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 470 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 471 | 0 | $self->{frontend_obj}->{test_data} = 'already banned'; | |||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||
| 473 | 0 | return; | |||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||
| 476 | 2 | my $url = $self->_url( 'alias_util/add/' . $self->{options}{alias} ); | |||||||||||||||||||||||||||||||||||
| 477 | 2 | my $body = $self->_json->encode( { address => $opts{ban} } ); | |||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||
| 479 | 2 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 480 | 2 | $self->{frontend_obj}->{test_data} = [ { method => 'POST', url => $url, content => $body } ]; | |||||||||||||||||||||||||||||||||||
| 481 | } else { | ||||||||||||||||||||||||||||||||||||
| 482 | 0 | local $@; | |||||||||||||||||||||||||||||||||||
| 483 | 0 | ▶ | eval { $self->_request( 'POST', $url, $body ); 1; } or do { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 484 | 0 | $self->{error} = 13; | |||||||||||||||||||||||||||||||||||
| 485 | 0 | $self->{errorString} = 'banning "' . $opts{ban} . '" failed... ' . $@; | |||||||||||||||||||||||||||||||||||
| 486 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 487 | 0 | return; | |||||||||||||||||||||||||||||||||||
| 488 | }; | ||||||||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||
| 491 | 2 | $self->{banned}{ $opts{ban} } = 1; | |||||||||||||||||||||||||||||||||||
| 492 | } ## end sub ban | ||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||
| 494 | =head2 unban | ||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||
| 496 | Unbans an IP. The value of ban is validated as being a IPv4 or IPv6 address | ||||||||||||||||||||||||||||||||||||
| 497 | and lowercased, then removed from the alias via a POST to the | ||||||||||||||||||||||||||||||||||||
| 498 | C<alias_util/delete> API endpoint. Unbanning an IP that is not | ||||||||||||||||||||||||||||||||||||
| 499 | banned is a noop. | ||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||
| 501 | $backend->unban(ban => $ip); | ||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||
| 503 | =cut | ||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||
| 505 | 1 | ▶ | sub unban { | ||||||||||||||||||||||||||||||||||
|
Subroutine
unban: called CC=10 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 506 | 1 | my ( $self, %opts ) = @_; | |||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||
| 508 | 1 | $self->errorblank; | |||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||
| 510 | 1 | ▶ | if ( !$self->{inited} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 511 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||
| 512 | 0 | $self->{errorString} = 'backend has not been inited'; | |||||||||||||||||||||||||||||||||||
| 513 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 514 | 0 | return; | |||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||
| 517 | 1 | ▶ | if ( !defined( $opts{ban} ) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||
| 518 | 0 | $self->{error} = 9; | |||||||||||||||||||||||||||||||||||
| 519 | 0 | $self->{errorString} = 'Nothing specified for the value ban'; | |||||||||||||||||||||||||||||||||||
| 520 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 521 | 0 | return; | |||||||||||||||||||||||||||||||||||
| 522 | } elsif ( ref( $opts{ban} ) ne '' ) { | ||||||||||||||||||||||||||||||||||||
| 523 | 0 | $self->{error} = 10; | |||||||||||||||||||||||||||||||||||
| 524 | 0 | $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"'; | |||||||||||||||||||||||||||||||||||
| 525 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 526 | 0 | return; | |||||||||||||||||||||||||||||||||||
| 527 | ▶ | } elsif ( $opts{ban} !~ /\A$IPv4_re\z/ | |||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::opnsense::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::opnsense::IPv6_re\z/
MC/DC0%0/2
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::opnsense::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::opnsense::IPv6_re\z/
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::opnsense::IPv4_re\z/
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::opnsense::IPv6_re\z/
Truth table33%1/3
A || B
A= $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::opnsense::IPv4_re\z/B= $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::opnsense::IPv6_re\z/
| |||||||||||||||||||||||||||||||||||||
| 528 | && $opts{ban} !~ /\A$IPv6_re\z/ ) | ||||||||||||||||||||||||||||||||||||
| 529 | { | ||||||||||||||||||||||||||||||||||||
| 530 | 0 | $self->{error} = 10; | |||||||||||||||||||||||||||||||||||
| 531 | 0 | $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 IP'; | |||||||||||||||||||||||||||||||||||
| 532 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 533 | 0 | return; | |||||||||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||
| 536 | # lowercase so the same IPv6 IP in differing cases can't result in duplicate entries | ||||||||||||||||||||||||||||||||||||
| 537 | 1 | $opts{ban} = lc( $opts{ban} ); | |||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||
| 539 | 1 | ▶ | if ( !$self->{banned}{ $opts{ban} } ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 540 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 541 | 0 | $self->{frontend_obj}->{test_data} = 'not banned'; | |||||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||||
| 543 | 0 | return; | |||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||
| 546 | 1 | my $url = $self->_url( 'alias_util/delete/' . $self->{options}{alias} ); | |||||||||||||||||||||||||||||||||||
| 547 | 1 | my $body = $self->_json->encode( { address => $opts{ban} } ); | |||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||
| 549 | 1 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 550 | 1 | $self->{frontend_obj}->{test_data} = [ { method => 'POST', url => $url, content => $body } ]; | |||||||||||||||||||||||||||||||||||
| 551 | } else { | ||||||||||||||||||||||||||||||||||||
| 552 | 0 | local $@; | |||||||||||||||||||||||||||||||||||
| 553 | 0 | ▶ | eval { $self->_request( 'POST', $url, $body ); 1; } or do { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 554 | 0 | $self->{error} = 14; | |||||||||||||||||||||||||||||||||||
| 555 | 0 | $self->{errorString} = 'unbanning "' . $opts{ban} . '" failed... ' . $@; | |||||||||||||||||||||||||||||||||||
| 556 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 557 | 0 | return; | |||||||||||||||||||||||||||||||||||
| 558 | }; | ||||||||||||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||
| 561 | 1 | delete( $self->{banned}{ $opts{ban} } ); | |||||||||||||||||||||||||||||||||||
| 562 | } ## end sub unban | ||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||
| 564 | =head2 ban_cidr | ||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||
| 566 | Bans a CIDR range by adding it to the alias via the C<alias_util/add> API | ||||||||||||||||||||||||||||||||||||
| 567 | endpoint. OPNsense aliases accept a network in the same manner as a single | ||||||||||||||||||||||||||||||||||||
| 568 | address. The value of ban is validated as being a IPv4 or IPv6 CIDR range | ||||||||||||||||||||||||||||||||||||
| 569 | and lowercased. Banning an already banned range is a noop. | ||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||
| 571 | $backend->ban_cidr(ban => '1.2.3.0/24'); | ||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||
| 573 | =cut | ||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||
| 575 | 1 | ▶ | sub ban_cidr { | ||||||||||||||||||||||||||||||||||
|
Subroutine
ban_cidr: called CC=9 SCAR=35.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 576 | 1 | my ( $self, %opts ) = @_; | |||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||
| 578 | 1 | $self->errorblank; | |||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||
| 580 | 1 | ▶ | if ( !$self->{inited} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 581 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||
| 582 | 0 | $self->{errorString} = 'backend has not been inited'; | |||||||||||||||||||||||||||||||||||
| 583 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 584 | 0 | return; | |||||||||||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||
| 587 | 1 | ▶ | if ( !defined( $opts{ban} ) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||
| 588 | 0 | $self->{error} = 9; | |||||||||||||||||||||||||||||||||||
| 589 | 0 | $self->{errorString} = 'Nothing specified for the value ban'; | |||||||||||||||||||||||||||||||||||
| 590 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 591 | 0 | return; | |||||||||||||||||||||||||||||||||||
| 592 | } elsif ( ref( $opts{ban} ) ne '' ) { | ||||||||||||||||||||||||||||||||||||
| 593 | 0 | $self->{error} = 35; | |||||||||||||||||||||||||||||||||||
| 594 | 0 | $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"'; | |||||||||||||||||||||||||||||||||||
| 595 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 596 | 0 | return; | |||||||||||||||||||||||||||||||||||
| 597 | } elsif ( !$self->_valid_cidr( $opts{ban} ) ) { | ||||||||||||||||||||||||||||||||||||
| 598 | 0 | $self->{error} = 35; | |||||||||||||||||||||||||||||||||||
| 599 | 0 | $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 CIDR'; | |||||||||||||||||||||||||||||||||||
| 600 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 601 | 0 | return; | |||||||||||||||||||||||||||||||||||
| 602 | } | ||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||
| 604 | # lowercase so the same IPv6 CIDR in differing cases can't result in duplicate entries | ||||||||||||||||||||||||||||||||||||
| 605 | 1 | $opts{ban} = lc( $opts{ban} ); | |||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||
| 607 | 1 | ▶ | if ( $self->{banned_cidr}{ $opts{ban} } ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 608 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 609 | 0 | $self->{frontend_obj}->{test_data} = 'already banned'; | |||||||||||||||||||||||||||||||||||
| 610 | } | ||||||||||||||||||||||||||||||||||||
| 611 | 0 | return; | |||||||||||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||
| 614 | 1 | my $url = $self->_url( 'alias_util/add/' . $self->{options}{alias} ); | |||||||||||||||||||||||||||||||||||
| 615 | 1 | my $body = $self->_json->encode( { address => $opts{ban} } ); | |||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||
| 617 | 1 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 618 | 1 | $self->{frontend_obj}->{test_data} = [ { method => 'POST', url => $url, content => $body } ]; | |||||||||||||||||||||||||||||||||||
| 619 | } else { | ||||||||||||||||||||||||||||||||||||
| 620 | 0 | local $@; | |||||||||||||||||||||||||||||||||||
| 621 | 0 | ▶ | eval { $self->_request( 'POST', $url, $body ); 1; } or do { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 622 | 0 | $self->{error} = 33; | |||||||||||||||||||||||||||||||||||
| 623 | 0 | $self->{errorString} = 'banning "' . $opts{ban} . '" failed... ' . $@; | |||||||||||||||||||||||||||||||||||
| 624 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 625 | 0 | return; | |||||||||||||||||||||||||||||||||||
| 626 | }; | ||||||||||||||||||||||||||||||||||||
| 627 | } | ||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||
| 629 | 1 | $self->{banned_cidr}{ $opts{ban} } = 1; | |||||||||||||||||||||||||||||||||||
| 630 | } ## end sub ban_cidr | ||||||||||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||||||||||
| 632 | =head2 unban_cidr | ||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||
| 634 | Unbans a CIDR range by removing it from the alias via the | ||||||||||||||||||||||||||||||||||||
| 635 | C<alias_util/delete> API endpoint. The value of ban is validated as being a | ||||||||||||||||||||||||||||||||||||
| 636 | IPv4 or IPv6 CIDR range and lowercased. Unbanning a range that is not | ||||||||||||||||||||||||||||||||||||
| 637 | banned is a noop. | ||||||||||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||||||||||
| 639 | $backend->unban_cidr(ban => '1.2.3.0/24'); | ||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||
| 641 | =cut | ||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||
| 643 | 1 | ▶ | sub unban_cidr { | ||||||||||||||||||||||||||||||||||
|
Subroutine
unban_cidr: called CC=9 SCAR=35.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 644 | 1 | my ( $self, %opts ) = @_; | |||||||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||||||
| 646 | 1 | $self->errorblank; | |||||||||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||||||||||
| 648 | 1 | ▶ | if ( !$self->{inited} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 649 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||
| 650 | 0 | $self->{errorString} = 'backend has not been inited'; | |||||||||||||||||||||||||||||||||||
| 651 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 652 | 0 | return; | |||||||||||||||||||||||||||||||||||
| 653 | } | ||||||||||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||||||||||
| 655 | 1 | ▶ | if ( !defined( $opts{ban} ) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||
| 656 | 0 | $self->{error} = 9; | |||||||||||||||||||||||||||||||||||
| 657 | 0 | $self->{errorString} = 'Nothing specified for the value ban'; | |||||||||||||||||||||||||||||||||||
| 658 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 659 | 0 | return; | |||||||||||||||||||||||||||||||||||
| 660 | } elsif ( ref( $opts{ban} ) ne '' ) { | ||||||||||||||||||||||||||||||||||||
| 661 | 0 | $self->{error} = 35; | |||||||||||||||||||||||||||||||||||
| 662 | 0 | $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"'; | |||||||||||||||||||||||||||||||||||
| 663 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 664 | 0 | return; | |||||||||||||||||||||||||||||||||||
| 665 | } elsif ( !$self->_valid_cidr( $opts{ban} ) ) { | ||||||||||||||||||||||||||||||||||||
| 666 | 0 | $self->{error} = 35; | |||||||||||||||||||||||||||||||||||
| 667 | 0 | $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 CIDR'; | |||||||||||||||||||||||||||||||||||
| 668 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 669 | 0 | return; | |||||||||||||||||||||||||||||||||||
| 670 | } | ||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||
| 672 | # lowercase so the same IPv6 CIDR in differing cases can't result in duplicate entries | ||||||||||||||||||||||||||||||||||||
| 673 | 1 | $opts{ban} = lc( $opts{ban} ); | |||||||||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||||||||||
| 675 | 1 | ▶ | if ( !$self->{banned_cidr}{ $opts{ban} } ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 676 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 677 | 0 | $self->{frontend_obj}->{test_data} = 'not banned'; | |||||||||||||||||||||||||||||||||||
| 678 | } | ||||||||||||||||||||||||||||||||||||
| 679 | 0 | return; | |||||||||||||||||||||||||||||||||||
| 680 | } | ||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||
| 682 | 1 | my $url = $self->_url( 'alias_util/delete/' . $self->{options}{alias} ); | |||||||||||||||||||||||||||||||||||
| 683 | 1 | my $body = $self->_json->encode( { address => $opts{ban} } ); | |||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||
| 685 | 1 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 686 | 1 | $self->{frontend_obj}->{test_data} = [ { method => 'POST', url => $url, content => $body } ]; | |||||||||||||||||||||||||||||||||||
| 687 | } else { | ||||||||||||||||||||||||||||||||||||
| 688 | 0 | local $@; | |||||||||||||||||||||||||||||||||||
| 689 | 0 | ▶ | eval { $self->_request( 'POST', $url, $body ); 1; } or do { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 690 | 0 | $self->{error} = 34; | |||||||||||||||||||||||||||||||||||
| 691 | 0 | $self->{errorString} = 'unbanning "' . $opts{ban} . '" failed... ' . $@; | |||||||||||||||||||||||||||||||||||
| 692 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 693 | 0 | return; | |||||||||||||||||||||||||||||||||||
| 694 | }; | ||||||||||||||||||||||||||||||||||||
| 695 | } | ||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||
| 697 | 1 | delete( $self->{banned_cidr}{ $opts{ban} } ); | |||||||||||||||||||||||||||||||||||
| 698 | } ## end sub unban_cidr | ||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||
| 700 | =head2 list_cidr | ||||||||||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||||||||||
| 702 | List banned CIDR ranges. Returns an array of the currently banned CIDR | ||||||||||||||||||||||||||||||||||||
| 703 | ranges. Single IPs are not included; for those see L</list>. | ||||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||||
| 705 | my @banned_cidrs = $backend->list_cidr; | ||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||
| 707 | =cut | ||||||||||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||||||||||
| 709 | 2 | ▶ | sub list_cidr { | ||||||||||||||||||||||||||||||||||
|
Subroutine
list_cidr: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 710 | 2 | my ( $self, %opts ) = @_; | |||||||||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||||||||||
| 712 | 2 | $self->errorblank; | |||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||
| 714 | 2 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 715 | 2 | $self->{frontend_obj}->{test_data} = 'list_cidr'; | |||||||||||||||||||||||||||||||||||
| 716 | } | ||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||
| 718 | 2 | return keys( %{ $self->{banned_cidr} } ); | |||||||||||||||||||||||||||||||||||
| 719 | } | ||||||||||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||||||||||
| 721 | =head2 list | ||||||||||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||||||||||
| 723 | List banned IPs. Returns an array of the currently banned single IPs. CIDR | ||||||||||||||||||||||||||||||||||||
| 724 | ranges are not included; for those see L</list_cidr>. | ||||||||||||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||||||||||
| 726 | my @banned = $backend->list; | ||||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||||
| 728 | =cut | ||||||||||||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||||||||||
| 730 | 0 | ▶ | sub list { | ||||||||||||||||||||||||||||||||||
|
Subroutine
list: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 731 | 0 | my ( $self, %opts ) = @_; | |||||||||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||||||||||
| 733 | 0 | $self->errorblank; | |||||||||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||||||||||
| 735 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 736 | 0 | $self->{frontend_obj}->{test_data} = 'list'; | |||||||||||||||||||||||||||||||||||
| 737 | } | ||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||
| 739 | 0 | return keys( %{ $self->{banned} } ); | |||||||||||||||||||||||||||||||||||
| 740 | } | ||||||||||||||||||||||||||||||||||||
| 741 | |||||||||||||||||||||||||||||||||||||
| 742 | =head2 re_init | ||||||||||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||||||||||
| 744 | Tells the backend to re-init it's self. | ||||||||||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||||||||||
| 746 | This will call teardown and init again. After that it will | ||||||||||||||||||||||||||||||||||||
| 747 | re-add all previously added bans. | ||||||||||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||||||||||
| 749 | $backend->re_init; | ||||||||||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||||||||||
| 751 | =cut | ||||||||||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||||||||||
| 753 | 0 | ▶ | sub re_init { | ||||||||||||||||||||||||||||||||||
|
Subroutine
re_init: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 754 | 0 | my ( $self, %opts ) = @_; | |||||||||||||||||||||||||||||||||||
| 755 | |||||||||||||||||||||||||||||||||||||
| 756 | 0 | $self->errorblank; | |||||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||||||
| 758 | # teardown is best effort here as a partially or fully wiped setup is | ||||||||||||||||||||||||||||||||||||
| 759 | # exactly what re_init needs to recover from; init cleans up any remnants | ||||||||||||||||||||||||||||||||||||
| 760 | { | ||||||||||||||||||||||||||||||||||||
| 761 | 0 | local $@; | |||||||||||||||||||||||||||||||||||
| 762 | 0 | eval { $self->teardown; }; | |||||||||||||||||||||||||||||||||||
| 763 | } | ||||||||||||||||||||||||||||||||||||
| 764 | 0 | $self->init; | |||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||
| 766 | 0 | my @to_re_ban = ( keys( %{ $self->{banned} } ), keys( %{ $self->{banned_cidr} } ) ); | |||||||||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||||||||||
| 768 | 0 | my @re_init_test_data; | |||||||||||||||||||||||||||||||||||
| 769 | 0 | foreach my $item (@to_re_ban) { | |||||||||||||||||||||||||||||||||||
| 770 | 0 | my $url = $self->_url( 'alias_util/add/' . $self->{options}{alias} ); | |||||||||||||||||||||||||||||||||||
| 771 | 0 | my $body = $self->_json->encode( { address => $item } ); | |||||||||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||||||||||
| 773 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 774 | 0 | push( @re_init_test_data, { method => 'POST', url => $url, content => $body } ); | |||||||||||||||||||||||||||||||||||
| 775 | } else { | ||||||||||||||||||||||||||||||||||||
| 776 | 0 | local $@; | |||||||||||||||||||||||||||||||||||
| 777 | 0 | ▶ | eval { $self->_request( 'POST', $url, $body ); 1; } or do { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 778 | 0 | $self->{error} = 13; | |||||||||||||||||||||||||||||||||||
| 779 | 0 | $self->{errorString} = 'banning "' . $item . '" failed... ' . $@; | |||||||||||||||||||||||||||||||||||
| 780 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 781 | }; | ||||||||||||||||||||||||||||||||||||
| 782 | } | ||||||||||||||||||||||||||||||||||||
| 783 | } ## end foreach my $item (@to_re_ban) | ||||||||||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||||||||||
| 785 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 786 | 0 | $self->{frontend_obj}->{test_data} = \@re_init_test_data; | |||||||||||||||||||||||||||||||||||
| 787 | } | ||||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||||
| 789 | 0 | $self->{inited} = 1; | |||||||||||||||||||||||||||||||||||
| 790 | } ## end sub re_init | ||||||||||||||||||||||||||||||||||||
| 791 | |||||||||||||||||||||||||||||||||||||
| 792 | =head2 teardown | ||||||||||||||||||||||||||||||||||||
| 793 | |||||||||||||||||||||||||||||||||||||
| 794 | Tears down the setup for the backend. | ||||||||||||||||||||||||||||||||||||
| 795 | |||||||||||||||||||||||||||||||||||||
| 796 | This flushes the alias, removing all of the banned IPs from it. The alias | ||||||||||||||||||||||||||||||||||||
| 797 | itself and the rule referencing it are left in place. | ||||||||||||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||||||||||
| 799 | $backend->teardown; | ||||||||||||||||||||||||||||||||||||
| 800 | |||||||||||||||||||||||||||||||||||||
| 801 | =cut | ||||||||||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||||||||||
| 803 | 0 | ▶ | sub teardown { | ||||||||||||||||||||||||||||||||||
|
Subroutine
teardown: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 804 | 0 | my ( $self, %opts ) = @_; | |||||||||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||||||||||
| 806 | 0 | $self->errorblank; | |||||||||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||||||||||
| 808 | 0 | $self->{inited} = 0; | |||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||||
| 810 | 0 | my $url = $self->_url( 'alias_util/flush/' . $self->{options}{alias} ); | |||||||||||||||||||||||||||||||||||
| 811 | |||||||||||||||||||||||||||||||||||||
| 812 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 813 | 0 | $self->{frontend_obj}->{test_data} = [ { method => 'POST', url => $url, content => '{}' } ]; | |||||||||||||||||||||||||||||||||||
| 814 | } else { | ||||||||||||||||||||||||||||||||||||
| 815 | 0 | local $@; | |||||||||||||||||||||||||||||||||||
| 816 | 0 | ▶ | eval { $self->_request( 'POST', $url, '{}' ); 1; } or do { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 817 | 0 | $self->{error} = 17; | |||||||||||||||||||||||||||||||||||
| 818 | 0 | $self->{errorString} = 'teardown failed... flushing the alias failed... ' . $@; | |||||||||||||||||||||||||||||||||||
| 819 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 820 | }; | ||||||||||||||||||||||||||||||||||||
| 821 | } | ||||||||||||||||||||||||||||||||||||
| 822 | } ## end sub teardown | ||||||||||||||||||||||||||||||||||||
| 823 | |||||||||||||||||||||||||||||||||||||
| 824 | =head2 stop | ||||||||||||||||||||||||||||||||||||
| 825 | |||||||||||||||||||||||||||||||||||||
| 826 | Alias for L</teardown>, provided for parity with the fail2ban C<actionstop> | ||||||||||||||||||||||||||||||||||||
| 827 | concept. | ||||||||||||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||||||||||
| 829 | $backend->stop; | ||||||||||||||||||||||||||||||||||||
| 830 | |||||||||||||||||||||||||||||||||||||
| 831 | =cut | ||||||||||||||||||||||||||||||||||||
| 832 | |||||||||||||||||||||||||||||||||||||
| 833 | 0 | ▶ | sub stop { | ||||||||||||||||||||||||||||||||||
|
Subroutine
stop: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 834 | 0 | my ( $self, %opts ) = @_; | |||||||||||||||||||||||||||||||||||
| 835 | |||||||||||||||||||||||||||||||||||||
| 836 | 0 | return $self->teardown(%opts); | |||||||||||||||||||||||||||||||||||
| 837 | } | ||||||||||||||||||||||||||||||||||||
| 838 | |||||||||||||||||||||||||||||||||||||
| 839 | =head2 check | ||||||||||||||||||||||||||||||||||||
| 840 | |||||||||||||||||||||||||||||||||||||
| 841 | Verifies the alias is still reachable by listing it via the API. A | ||||||||||||||||||||||||||||||||||||
| 842 | successful request is treated as healthy. This is the equivalent of | ||||||||||||||||||||||||||||||||||||
| 843 | fail2ban's C<actioncheck>. | ||||||||||||||||||||||||||||||||||||
| 844 | |||||||||||||||||||||||||||||||||||||
| 845 | if ( !$backend->check ) { | ||||||||||||||||||||||||||||||||||||
| 846 | $backend->re_init; | ||||||||||||||||||||||||||||||||||||
| 847 | } | ||||||||||||||||||||||||||||||||||||
| 848 | |||||||||||||||||||||||||||||||||||||
| 849 | =cut | ||||||||||||||||||||||||||||||||||||
| 850 | |||||||||||||||||||||||||||||||||||||
| 851 | 5 | ▶ | sub check { | ||||||||||||||||||||||||||||||||||
|
Subroutine
check: called CC=3 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 852 | 5 | my ( $self, %opts ) = @_; | |||||||||||||||||||||||||||||||||||
| 853 | |||||||||||||||||||||||||||||||||||||
| 854 | 5 | $self->errorblank; | |||||||||||||||||||||||||||||||||||
| 855 | |||||||||||||||||||||||||||||||||||||
| 856 | 5 | my $url = $self->_url( 'alias_util/list/' . $self->{options}{alias} ); | |||||||||||||||||||||||||||||||||||
| 857 | |||||||||||||||||||||||||||||||||||||
| 858 | 5 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 859 | 5 | $self->{frontend_obj}->{test_data} = [ { method => 'GET', url => $url } ]; | |||||||||||||||||||||||||||||||||||
| 860 | 5 | return 1; | |||||||||||||||||||||||||||||||||||
| 861 | } | ||||||||||||||||||||||||||||||||||||
| 862 | |||||||||||||||||||||||||||||||||||||
| 863 | 0 | local $@; | |||||||||||||||||||||||||||||||||||
| 864 | 0 | ▶ | return eval { $self->_request( 'GET', $url ); 1; } ? 1 : 0; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 865 | } ## end sub check | ||||||||||||||||||||||||||||||||||||
| 866 | |||||||||||||||||||||||||||||||||||||
| 867 | =head2 flush | ||||||||||||||||||||||||||||||||||||
| 868 | |||||||||||||||||||||||||||||||||||||
| 869 | Removes all currently banned IPs at once by flushing the alias, leaving the | ||||||||||||||||||||||||||||||||||||
| 870 | alias and the rule referencing it in place. This is the equivalent of | ||||||||||||||||||||||||||||||||||||
| 871 | fail2ban's C<actionflush>. | ||||||||||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||||||||||
| 873 | $backend->flush; | ||||||||||||||||||||||||||||||||||||
| 874 | |||||||||||||||||||||||||||||||||||||
| 875 | =cut | ||||||||||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||||||||||
| 877 | 1 | ▶ | sub flush { | ||||||||||||||||||||||||||||||||||
|
Subroutine
flush: called CC=4 SCAR=20.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 878 | 1 | my ( $self, %opts ) = @_; | |||||||||||||||||||||||||||||||||||
| 879 | |||||||||||||||||||||||||||||||||||||
| 880 | 1 | $self->errorblank; | |||||||||||||||||||||||||||||||||||
| 881 | |||||||||||||||||||||||||||||||||||||
| 882 | 1 | ▶ | if ( !$self->{inited} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 883 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||
| 884 | 0 | $self->{errorString} = 'backend has not been inited'; | |||||||||||||||||||||||||||||||||||
| 885 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 886 | 0 | return; | |||||||||||||||||||||||||||||||||||
| 887 | } | ||||||||||||||||||||||||||||||||||||
| 888 | |||||||||||||||||||||||||||||||||||||
| 889 | 1 | my $url = $self->_url( 'alias_util/flush/' . $self->{options}{alias} ); | |||||||||||||||||||||||||||||||||||
| 890 | |||||||||||||||||||||||||||||||||||||
| 891 | 1 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 892 | 1 | $self->{frontend_obj}->{test_data} = [ { method => 'POST', url => $url, content => '{}' } ]; | |||||||||||||||||||||||||||||||||||
| 893 | } else { | ||||||||||||||||||||||||||||||||||||
| 894 | 0 | local $@; | |||||||||||||||||||||||||||||||||||
| 895 | 0 | ▶ | eval { $self->_request( 'POST', $url, '{}' ); 1; } or do { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 896 | 0 | $self->{error} = 25; | |||||||||||||||||||||||||||||||||||
| 897 | 0 | $self->{errorString} = 'flush failed... flushing the alias failed... ' . $@; | |||||||||||||||||||||||||||||||||||
| 898 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||
| 899 | 0 | return; | |||||||||||||||||||||||||||||||||||
| 900 | }; | ||||||||||||||||||||||||||||||||||||
| 901 | } | ||||||||||||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||||||||||
| 903 | 1 | $self->{banned} = {}; | |||||||||||||||||||||||||||||||||||
| 904 | 1 | $self->{banned_cidr} = {}; | |||||||||||||||||||||||||||||||||||
| 905 | } ## end sub flush | ||||||||||||||||||||||||||||||||||||
| 906 | |||||||||||||||||||||||||||||||||||||
| 907 | =head1 ERROR CODES / FLAGS | ||||||||||||||||||||||||||||||||||||
| 908 | |||||||||||||||||||||||||||||||||||||
| 909 | Error handling is provided by L<Error::Helper>. All | ||||||||||||||||||||||||||||||||||||
| 910 | errors are considered fatal. | ||||||||||||||||||||||||||||||||||||
| 911 | |||||||||||||||||||||||||||||||||||||
| 912 | =head2 1, notInited | ||||||||||||||||||||||||||||||||||||
| 913 | |||||||||||||||||||||||||||||||||||||
| 914 | The backend has not been inited yet. | ||||||||||||||||||||||||||||||||||||
| 915 | |||||||||||||||||||||||||||||||||||||
| 916 | =head2 8, optionsNotHash | ||||||||||||||||||||||||||||||||||||
| 917 | |||||||||||||||||||||||||||||||||||||
| 918 | The item passed to new for options is not a hash. | ||||||||||||||||||||||||||||||||||||
| 919 | |||||||||||||||||||||||||||||||||||||
| 920 | =head2 9, noBanItem | ||||||||||||||||||||||||||||||||||||
| 921 | |||||||||||||||||||||||||||||||||||||
| 922 | No IP or CIDR range specified to ban or unban. | ||||||||||||||||||||||||||||||||||||
| 923 | |||||||||||||||||||||||||||||||||||||
| 924 | =head2 10, banItemNotIP | ||||||||||||||||||||||||||||||||||||
| 925 | |||||||||||||||||||||||||||||||||||||
| 926 | The item to ban is not an IP. Either wrong ref type or regexp | ||||||||||||||||||||||||||||||||||||
| 927 | test using L<Regexp::IPv4> and L<Regexp::IPv6> failed. | ||||||||||||||||||||||||||||||||||||
| 928 | |||||||||||||||||||||||||||||||||||||
| 929 | =head2 12, backendInitError | ||||||||||||||||||||||||||||||||||||
| 930 | |||||||||||||||||||||||||||||||||||||
| 931 | Failed to init the backend. | ||||||||||||||||||||||||||||||||||||
| 932 | |||||||||||||||||||||||||||||||||||||
| 933 | =head2 13, banFailed | ||||||||||||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||||||||||
| 935 | Failed to ban the item. | ||||||||||||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||||||||||
| 937 | =head2 14, unbanFailed | ||||||||||||||||||||||||||||||||||||
| 938 | |||||||||||||||||||||||||||||||||||||
| 939 | Failed to unban the item. | ||||||||||||||||||||||||||||||||||||
| 940 | |||||||||||||||||||||||||||||||||||||
| 941 | =head2 15, listFailed | ||||||||||||||||||||||||||||||||||||
| 942 | |||||||||||||||||||||||||||||||||||||
| 943 | Failed to get a list of bans. | ||||||||||||||||||||||||||||||||||||
| 944 | |||||||||||||||||||||||||||||||||||||
| 945 | =head2 16, reInitFailed | ||||||||||||||||||||||||||||||||||||
| 946 | |||||||||||||||||||||||||||||||||||||
| 947 | Failed to re_init the backend. | ||||||||||||||||||||||||||||||||||||
| 948 | |||||||||||||||||||||||||||||||||||||
| 949 | =head2 17, teardownFailed | ||||||||||||||||||||||||||||||||||||
| 950 | |||||||||||||||||||||||||||||||||||||
| 951 | Failed to teardown the backend. | ||||||||||||||||||||||||||||||||||||
| 952 | |||||||||||||||||||||||||||||||||||||
| 953 | =head2 18, alreadyInited | ||||||||||||||||||||||||||||||||||||
| 954 | |||||||||||||||||||||||||||||||||||||
| 955 | init called, but the backend has already been inited. | ||||||||||||||||||||||||||||||||||||
| 956 | |||||||||||||||||||||||||||||||||||||
| 957 | =head2 24, checkFailed | ||||||||||||||||||||||||||||||||||||
| 958 | |||||||||||||||||||||||||||||||||||||
| 959 | The backend check raised an error. | ||||||||||||||||||||||||||||||||||||
| 960 | |||||||||||||||||||||||||||||||||||||
| 961 | =head2 25, flushFailed | ||||||||||||||||||||||||||||||||||||
| 962 | |||||||||||||||||||||||||||||||||||||
| 963 | Failed to flush the bans. | ||||||||||||||||||||||||||||||||||||
| 964 | |||||||||||||||||||||||||||||||||||||
| 965 | =head2 30, hostNotDefined | ||||||||||||||||||||||||||||||||||||
| 966 | |||||||||||||||||||||||||||||||||||||
| 967 | The option host is undef or blank. | ||||||||||||||||||||||||||||||||||||
| 968 | |||||||||||||||||||||||||||||||||||||
| 969 | =head2 31, apiKeyNotDefined | ||||||||||||||||||||||||||||||||||||
| 970 | |||||||||||||||||||||||||||||||||||||
| 971 | The option key is undef or blank. | ||||||||||||||||||||||||||||||||||||
| 972 | |||||||||||||||||||||||||||||||||||||
| 973 | =head2 32, apiSecretNotDefined | ||||||||||||||||||||||||||||||||||||
| 974 | |||||||||||||||||||||||||||||||||||||
| 975 | The option secret is undef or blank. | ||||||||||||||||||||||||||||||||||||
| 976 | |||||||||||||||||||||||||||||||||||||
| 977 | =head2 33, banCidrFailed | ||||||||||||||||||||||||||||||||||||
| 978 | |||||||||||||||||||||||||||||||||||||
| 979 | Failed to ban the CIDR range. | ||||||||||||||||||||||||||||||||||||
| 980 | |||||||||||||||||||||||||||||||||||||
| 981 | =head2 34, unbanCidrFailed | ||||||||||||||||||||||||||||||||||||
| 982 | |||||||||||||||||||||||||||||||||||||
| 983 | Failed to unban the CIDR range. | ||||||||||||||||||||||||||||||||||||
| 984 | |||||||||||||||||||||||||||||||||||||
| 985 | =head2 35, cidrItemNotCidr | ||||||||||||||||||||||||||||||||||||
| 986 | |||||||||||||||||||||||||||||||||||||
| 987 | The item to ban is not a CIDR range. Either wrong ref type or it is not an | ||||||||||||||||||||||||||||||||||||
| 988 | IPv4 or IPv6 address followed by a prefix length valid for its family. | ||||||||||||||||||||||||||||||||||||
| 989 | |||||||||||||||||||||||||||||||||||||
| 990 | =head2 36, cidrNotSupported | ||||||||||||||||||||||||||||||||||||
| 991 | |||||||||||||||||||||||||||||||||||||
| 992 | The backend does not support CIDR bans. | ||||||||||||||||||||||||||||||||||||
| 993 | |||||||||||||||||||||||||||||||||||||
| 994 | =head2 37, listCidrFailed | ||||||||||||||||||||||||||||||||||||
| 995 | |||||||||||||||||||||||||||||||||||||
| 996 | Failed to get a list of CIDR bans. | ||||||||||||||||||||||||||||||||||||
| 997 | |||||||||||||||||||||||||||||||||||||
| 998 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||
| 999 | |||||||||||||||||||||||||||||||||||||
| 1000 | Zane C. Bowers-Hadley, C<< <vvelox at vvelox.ent> >> | ||||||||||||||||||||||||||||||||||||
| 1001 | |||||||||||||||||||||||||||||||||||||
| 1002 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||
| 1003 | |||||||||||||||||||||||||||||||||||||
| 1004 | Please report any bugs or feature requests to C<bug-net-firewall-blockerhelper at rt.cpan.org>, or through | ||||||||||||||||||||||||||||||||||||
| 1005 | the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Firewall-BlockerHelper>. I will be notified, and then you'll | ||||||||||||||||||||||||||||||||||||
| 1006 | automatically be notified of progress on your bug as I make changes. | ||||||||||||||||||||||||||||||||||||
| 1007 | |||||||||||||||||||||||||||||||||||||
| 1008 | |||||||||||||||||||||||||||||||||||||
| 1009 | |||||||||||||||||||||||||||||||||||||
| 1010 | |||||||||||||||||||||||||||||||||||||
| 1011 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||||
| 1012 | |||||||||||||||||||||||||||||||||||||
| 1013 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||||||||||
| 1014 | |||||||||||||||||||||||||||||||||||||
| 1015 | perldoc Net::Firewall::BlockerHelper | ||||||||||||||||||||||||||||||||||||
| 1016 | |||||||||||||||||||||||||||||||||||||
| 1017 | |||||||||||||||||||||||||||||||||||||
| 1018 | You can also look for information at: | ||||||||||||||||||||||||||||||||||||
| 1019 | |||||||||||||||||||||||||||||||||||||
| 1020 | =over 4 | ||||||||||||||||||||||||||||||||||||
| 1021 | |||||||||||||||||||||||||||||||||||||
| 1022 | =item * RT: CPAN's request tracker (report bugs here) | ||||||||||||||||||||||||||||||||||||
| 1023 | |||||||||||||||||||||||||||||||||||||
| 1024 | L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Firewall-BlockerHelper> | ||||||||||||||||||||||||||||||||||||
| 1025 | |||||||||||||||||||||||||||||||||||||
| 1026 | =item * Search CPAN | ||||||||||||||||||||||||||||||||||||
| 1027 | |||||||||||||||||||||||||||||||||||||
| 1028 | L<https://metacpan.org/release/Net-Firewall-BlockerHelper> | ||||||||||||||||||||||||||||||||||||
| 1029 | |||||||||||||||||||||||||||||||||||||
| 1030 | =back | ||||||||||||||||||||||||||||||||||||
| 1031 | |||||||||||||||||||||||||||||||||||||
| 1032 | |||||||||||||||||||||||||||||||||||||
| 1033 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||||||||||
| 1034 | |||||||||||||||||||||||||||||||||||||
| 1035 | |||||||||||||||||||||||||||||||||||||
| 1036 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||||||||||
| 1037 | |||||||||||||||||||||||||||||||||||||
| 1038 | This software is Copyright (c) 2023 by Zane C. Bowers-Hadley. | ||||||||||||||||||||||||||||||||||||
| 1039 | |||||||||||||||||||||||||||||||||||||
| 1040 | This is free software, licensed under: | ||||||||||||||||||||||||||||||||||||
| 1041 | |||||||||||||||||||||||||||||||||||||
| 1042 | The GNU Lesser General Public License, Version 2.1, February 1999 | ||||||||||||||||||||||||||||||||||||
| 1043 | |||||||||||||||||||||||||||||||||||||
| 1044 | |||||||||||||||||||||||||||||||||||||
| 1045 | =cut | ||||||||||||||||||||||||||||||||||||
| 1046 | |||||||||||||||||||||||||||||||||||||
| 1047 | 1 | 1; # End of Net::Firewall::BlockerHelper | |||||||||||||||||||||||||||||||||||