| 1 | package WWW::Hetzner::Robot::CLI::Cmd::Rdns; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Robot reverse DNS commands | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 1 | our $VERSION = '0.102'; | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use MooX::Cmd; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use MooX::Options protect_argv => 0, usage_string => 'USAGE: hrobot.pl rdns [<ip> [--ptr <hostname> | --delete]]'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | option ptr => ( | |||||||||||||||||||||||||||
| 12 | is => 'ro', | ||||||||||||||||||||||||||||
| 13 | format => 's', | ||||||||||||||||||||||||||||
| 14 | doc => 'Set the PTR record for the given IP', | ||||||||||||||||||||||||||||
| 15 | ); | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | option delete => ( | |||||||||||||||||||||||||||
| 18 | is => 'ro', | ||||||||||||||||||||||||||||
| 19 | short => 'd', | ||||||||||||||||||||||||||||
| 20 | doc => 'Delete the reverse DNS entry of the given IP', | ||||||||||||||||||||||||||||
| 21 | default => 0, | ||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 5 | ▶ | sub execute { | ||||||||||||||||||||||||||
|
Subroutine
execute: called CC=12 SCAR=26.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | 5 | my ($self, $args, $chain) = @_; | |||||||||||||||||||||||||||
| 26 | 5 | my $root = $chain->[0]; | |||||||||||||||||||||||||||
| 27 | 5 | my $robot = $root->robot; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 5 | my $ip = $args->[0]; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 5 | ▶ | unless ($ip) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 2 | ▶ | die "An IP address is required with --ptr\n" if defined $self->ptr; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 1 | ▶ | die "An IP address is required with --delete\n" if $self->delete; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 1 | return $self->_list($robot, $root); | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 3 | ▶ | die "--ptr and --delete are mutually exclusive\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->ptr and $self->delete
MC/DC0%0/2
defined $self->ptr and $self->delete
defined $self->ptr
$self->delete
Truth table66%2/3
A and B
A= defined $self->ptrB= $self->delete
| |||||||||||||||||||||||||||||
| 38 | if defined $self->ptr && $self->delete; | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 3 | ▶ | if ($self->delete) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 1 | $robot->rdns->delete($ip); | |||||||||||||||||||||||||||
| 42 | 1 | ▶ | print "Reverse DNS entry for $ip deleted\n" unless $root->output eq 'json'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 1 | return; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 2 | ▶ | my $entry = defined $self->ptr | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | ? $robot->rdns->update($ip, $self->ptr) | ||||||||||||||||||||||||||||
| 48 | : $robot->rdns->get($ip); | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 2 | ▶ | if ($root->output eq 'json') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | require JSON::MaybeXS; | |||||||||||||||||||||||||||
| 52 | 0 | print JSON::MaybeXS::encode_json({ ip => $entry->ip, ptr => $entry->ptr }); | |||||||||||||||||||||||||||
| 53 | 0 | print "\n"; | |||||||||||||||||||||||||||
| 54 | } else { | ||||||||||||||||||||||||||||
| 55 | 2 | ▶ | print "IP: ", $entry->ip // '', "\n"; | ||||||||||||||||||||||||||
|
Condition50%1/2
$entry->ip // ""
MC/DC0%0/1
$entry->ip // ""
$entry->ip
Truth table50%1/2
A
A= $entry->ip
| |||||||||||||||||||||||||||||
| 56 | 2 | ▶ | print "PTR: ", $entry->ptr // '', "\n"; | ||||||||||||||||||||||||||
|
Condition50%1/2
$entry->ptr // ""
MC/DC0%0/1
$entry->ptr // ""
$entry->ptr
Truth table50%1/2
A
A= $entry->ptr
| |||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 1 | ▶ | sub _list { | ||||||||||||||||||||||||||
|
Subroutine
_list: called CC=5 SCAR=19.6
| |||||||||||||||||||||||||||||
| 61 | 1 | my ($self, $robot, $root) = @_; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 1 | my $entries = $robot->rdns->list; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 1 | ▶ | if ($root->output eq 'json') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | require JSON::MaybeXS; | |||||||||||||||||||||||||||
| 67 | 0 | print JSON::MaybeXS::encode_json([map { +{ | |||||||||||||||||||||||||||
| 68 | 0 | ip => $_->ip, | |||||||||||||||||||||||||||
| 69 | ptr => $_->ptr, | ||||||||||||||||||||||||||||
| 70 | } } @$entries]); | ||||||||||||||||||||||||||||
| 71 | 0 | print "\n"; | |||||||||||||||||||||||||||
| 72 | } else { | ||||||||||||||||||||||||||||
| 73 | 1 | printf "%-40s %s\n", 'IP', 'PTR'; | |||||||||||||||||||||||||||
| 74 | 1 | for my $e (@$entries) { | |||||||||||||||||||||||||||
| 75 | 2 | ▶ | printf "%-40s %s\n", $e->ip // '', $e->ptr // ''; | ||||||||||||||||||||||||||
|
Condition50%2/4
$e->ip // ""
$e->ptr // ""
MC/DC0%0/1
$e->ip // ""
$e->ip
MC/DC0%0/1
$e->ptr // ""
$e->ptr
Truth table50%1/2
A
A= $e->ip
Truth table50%1/2
A
A= $e->ptr
| |||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 1 | 1. | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | __END__ | ||||||||||||||||||||||||||||