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