« blib/lib/Ereshkigal/App/Command/status.pm
↑ Summary
blib/lib/Ereshkigal/App/Command/checkpoint.pm »
| 1 | package Ereshkigal::App::Command::cidr_ban; | ||||||||||||||||||||||||||||
| 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 Ereshkigal::App -command; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | Ereshkigal::App::Command::cidr_ban - Ban one or more CIDR ranges. | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 VERSION | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | Version 0.0.1 | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =cut | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 1 | our $VERSION = '0.0.1'; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | # ban on all kur instances | ||||||||||||||||||||||||||||
| 23 | ereshkigal cidr-ban 1.2.3.0/24 10.0.0.0/8 | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | # ban on just the kur instance sshd | ||||||||||||||||||||||||||||
| 26 | ereshkigal cidr-ban --kur sshd 1.2.3.0/24 | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # an hour long ban | ||||||||||||||||||||||||||||
| 29 | ereshkigal cidr-ban --ban-time 3600 1.2.3.0/24 | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # a permanent ban | ||||||||||||||||||||||||||||
| 32 | ereshkigal cidr-ban --ban-time 0 1.2.3.0/24 | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | Bans one or more CIDR ranges. The range form of | ||||||||||||||||||||||||||||
| 37 | L<ban|Ereshkigal::App::Command::ban>, behaving the same way... every kur | ||||||||||||||||||||||||||||
| 38 | unless C<--kur> names one, each range answered for separately, re-banning | ||||||||||||||||||||||||||||
| 39 | resetting the sentence, and C<--ban-time> in seconds with 0 meaning never. | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | Host bits are masked off, so C<1.2.3.4/24> is taken as C<1.2.3.0/24> and | ||||||||||||||||||||||||||||
| 42 | the two cannot become separate bans. | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | Only works on a kur whose backend supports CIDR bans and which has CIDR | ||||||||||||||||||||||||||||
| 45 | banning enabled. A kur that cannot or will not do CIDR either drops the | ||||||||||||||||||||||||||||
| 46 | command or reports an error per its cidr_silent_drop setting. | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =head1 METHODS | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | The App::Cmd hooks this subcommand supplies... command_names, abstract, | ||||||||||||||||||||||||||||
| 51 | description, usage_desc, opt_spec, validate_args, and execute. | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =cut | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | # accept both the dashed and underscored spellings | ||||||||||||||||||||||||||||
| 56 | 113 | ▶ | sub command_names { return ( 'cidr-ban', 'cidr_ban' ); } | ||||||||||||||||||||||||||
|
Subroutine
command_names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 1 | ▶ | sub abstract { return 'ban one or more CIDR ranges' } | ||||||||||||||||||||||||||
|
Subroutine
abstract: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 4 | ▶ | sub description { | ||||||||||||||||||||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 61 | 4 | return <<'DESCRIPTION'; | |||||||||||||||||||||||||||
| 62 | Banish one or more CIDR ranges to the underworld. | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | The range form of "ban", behaving the same way... every kur unless --kur | ||||||||||||||||||||||||||||
| 65 | names one, each range answered for separately, re-banning resets the | ||||||||||||||||||||||||||||
| 66 | sentence, and --ban-time in seconds with 0 meaning never. | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | Host bits are masked off, so 1.2.3.4/24 is taken as 1.2.3.0/24 and the | ||||||||||||||||||||||||||||
| 69 | two cannot become separate bans. | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | This only works where the operator has turned CIDR banning on, via | ||||||||||||||||||||||||||||
| 72 | enable_cidr, AND the backend can match on a prefix... several cannot. | ||||||||||||||||||||||||||||
| 73 | A kur that cannot oblige either refuses or quietly ignores the request | ||||||||||||||||||||||||||||
| 74 | per its cidr_silent_drop setting, which is what lets one command be fanned | ||||||||||||||||||||||||||||
| 75 | across a mixed set of kurs. "status --all" reports cidr_enabled and | ||||||||||||||||||||||||||||
| 76 | cidr_supported per kur if you are unsure which is which. | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | ereshkigal cidr-ban 1.2.3.0/24 | ||||||||||||||||||||||||||||
| 79 | ereshkigal cidr-ban --kur blocklist --ban-time 0 2001:db8::/32 | ||||||||||||||||||||||||||||
| 80 | DESCRIPTION | ||||||||||||||||||||||||||||
| 81 | } ## end sub description | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 8 | ▶ | sub usage_desc { return '%c cidr-ban %o <CIDR> [<CIDR> ...]'; } | ||||||||||||||||||||||||||
|
Subroutine
usage_desc: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 8 | ▶ | sub opt_spec { | ||||||||||||||||||||||||||
|
Subroutine
opt_spec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 86 | return ( | ||||||||||||||||||||||||||||
| 87 | 8 | [ 'kur=s', 'kur instance to send the ban to, defaulting to all of them' ], | |||||||||||||||||||||||||||
| 88 | [ 'ban-time=i', 'seconds the bans should last, 0 meaning never time out, defaulting to the kur default' ], | ||||||||||||||||||||||||||||
| 89 | ); | ||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 4 | ▶ | sub validate_args { | ||||||||||||||||||||||||||
|
Subroutine
validate_args: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||
| 93 | 4 | my ( $self, $opt, $args ) = @_; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 4 | ▶ | if ( !@{$args} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 1 | $self->usage_error('at least one CIDR must be specified'); | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | 3 | ▶ | if ( defined( $opt->ban_time ) && $opt->ban_time !~ /^[0-9]+$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $opt->ban_time and not $opt->ban_time =~ /^[0-9]+$/
MC/DC0%0/2
defined $opt->ban_time and not $opt->ban_time =~ /^[0-9]+$/
defined $opt->ban_time
not $opt->ban_time =~ /^[0-9]+$/
Truth table66%2/3
A and not(B)
A= defined $opt->ban_timeB= not $opt->ban_time =~ /^[0-9]+$/
| |||||||||||||||||||||||||||||
| 99 | 0 | $self->usage_error('--ban-time must be a non-negative integer of seconds'); | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 3 | return; | |||||||||||||||||||||||||||
| 103 | } ## end sub validate_args | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 3 | ▶ | sub execute { | ||||||||||||||||||||||||||
|
Subroutine
execute: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 106 | 3 | my ( $self, $opt, $args ) = @_; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 3 | my $ban_args = { 'cidrs' => $args }; | |||||||||||||||||||||||||||
| 109 | 3 | ▶ | if ( defined( $opt->kur ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 1 | $ban_args->{kur} = $opt->kur; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | 3 | ▶ | if ( defined( $opt->ban_time ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 1 | $ban_args->{ban_time} = $opt->ban_time; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 3 | $self->run_command( 'cidr_ban', $ban_args ); | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 2 | return; | |||||||||||||||||||||||||||
| 119 | } ## end sub execute | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 1 | 1; | |||||||||||||||||||||||||||