blib/lib/Ereshkigal/App/Command/unban.pm

filter: Statementstmt 100% 32 / 32 Branchbran 100% 6 / 6 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 10 / 10 Podpod 100% 6 / 6 totaltotal 100% 64 / 64 CC 6 SCAR 9.0
CC
6
Cov
100%
validate_args
5.0
execute
2.0
BEGIN
1.0
CRAP 2.5
« /usr/local/bin/perldoc ↑ Summary blib/lib/Ereshkigal/App/Command/ban.pm »
1 package Ereshkigal::App::Command::unban;
2  
3 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Ereshkigal::App -command;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Ereshkigal::App::Command::unban - Unban an IP or everything.
11  
12 =head1 VERSION
13  
14 Version 0.0.1
15  
16 =cut
17  
18 2 our $VERSION = '0.0.1';
19  
20 =head1 SYNOPSIS
21  
22 # check every kur for the IP and unban it where present
23 ereshkigal unban 1.2.3.4
24  
25 # remove all bans everywhere
26 ereshkigal unban --all
27  
28 =head1 DESCRIPTION
29  
30 With an IP, every kur is asked whether it is holding that address and it is
31 released from each one that is, reporting C<was_banned> per kur. A kur that
32 never had it says so rather than erroring, so it is safe to fire at all of
33 them. There is deliberately no C<--kur>... an unban goes wherever the address
34 actually is.
35  
36 With C<--all> every kur is flushed instead. That is both single IP and range
37 bans on every kur, released in one go, with no confirmation and no undo. The
38 tablets are rewritten straight after, so a restart will not bring any of them
39 back.
40  
41 Ranges banned with L<cidr_ban|Ereshkigal::App::Command::cidr_ban> are matched
42 by L<cidr_unban|Ereshkigal::App::Command::cidr_unban> rather than by naming
43 an IP inside them, though C<--all> takes those too.
44  
45 =head1 METHODS
46  
47 The App::Cmd hooks this subcommand supplies... abstract, description,
48 usage_desc, opt_spec, validate_args, and execute.
49  
50 =cut
51  
52 1 ▶sub abstract { return 'unban an IP or everything' }
Subroutine abstract: called CC=1 SCAR=0.0
Pod documented
53  
54 5 ▶sub description {
Subroutine description: called CC=1 SCAR=0.0
Pod documented
55 5 return <<'DESCRIPTION';
56 Release an IP from the underworld, or empty it entirely.
57  
58 With an IP, every kur is asked whether it is holding that address and it is
59 released from each one that is. A kur that never had it says so rather
60 than erroring, so it is safe to fire at all of them.
61  
62 With --all, every kur is flushed instead. That means BOTH single IP and
63 range bans on every kur, released in one go, with no confirmation and no
64 undo... the ban books are emptied and the firewall rules removed. The
65 tablets are rewritten straight after, so a restart will not bring any of
66 them back. If you meant one address, name it.
67  
68 ereshkigal unban 1.2.3.4 # release the one
69 ereshkigal unban --all # empty every underworld, everywhere
70  
71 Ranges banned with cidr-ban are matched by "cidr-unban", not by naming
72 an IP inside them... but --all takes those too.
73 DESCRIPTION
74 } ## end sub description
75  
76 11 ▶sub usage_desc { return '%c unban %o [<IP>]'; }
Subroutine usage_desc: called CC=1 SCAR=0.0
Pod documented
77  
78 11 ▶sub opt_spec {
Subroutine opt_spec: called CC=1 SCAR=0.0
Pod documented
79 11 return ( [ 'all', 'remove all bans from every kur' ], );
80 }
81  
82 6 ▶sub validate_args {
Subroutine validate_args: called CC=5 SCAR=16.1
Pod documented
83 6 my ( $self, $opt, $args ) = @_;
84  
85 6 ▶ if ( $opt->all && @{$args} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->all and @{$args;}) 1 5 6
Condition100%3/3
$opt->all and @{$args;}
!ll&&!rl&&r
321
MC/DC100%2/2
$opt->all and @{$args;}
$opt->all @{$args;}
Truth table100%3/3
A and B
A= $opt->allB= @{$args;}
ABresult
0X0
100
111
86 1 $self->usage_error('--all and an IP may not be used together');
87 }
88 5 ▶ if ( !$opt->all && @{$args} != 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $opt->all and @{$args;} != 1) 2 3 5
Condition100%3/3
not $opt->all and @{$args;} != 1
!ll&&!rl&&r
212
MC/DC100%2/2
not $opt->all and @{$args;} != 1
not $opt->all @{$args;} != 1
Truth table100%3/3
not(A) and B
A= not $opt->allB= @{$args;} != 1
ABresult
0X0
100
111
89 2 $self->usage_error('either --all or a single IP must be specified');
90 }
91  
92 3 return;
93 } ## end sub validate_args
94  
95 3 ▶sub execute {
Subroutine execute: called CC=2 SCAR=6.9
Pod documented
96 3 my ( $self, $opt, $args ) = @_;
97  
98 3 my $unban_args;
99 3 ▶ if ( $opt->all ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->all) { } 2 1 3
100 2 $unban_args = { 'all' => 1 };
101 } else {
102 1 $unban_args = { 'ip' => $args->[0] };
103 }
104  
105 3 $self->run_command( 'unban', $unban_args );
106  
107 2 return;
108 } ## end sub execute
109  
110 2 1;
« /usr/local/bin/perldoc ↑ Summary blib/lib/Ereshkigal/App/Command/ban.pm »