| 1 | package Net::Appliance::Session::Transport; | ||||||||||||||||||||||||||||
| 2 | 1 | { $Net::Appliance::Session::Transport::VERSION = '4.300003' } | |||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | { | ||||||||||||||||||||||||||||
| 5 | 1 | package # hide from pause | |||||||||||||||||||||||||||
| 6 | Net::Appliance::Session::Transport::ConnectOptions; | ||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use MooX::Types::MooseLike::Base qw(Str); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | has username => ( | |||||||||||||||||||||||||||
| 11 | is => 'ro', | ||||||||||||||||||||||||||||
| 12 | isa => Str, | ||||||||||||||||||||||||||||
| 13 | required => 0, | ||||||||||||||||||||||||||||
| 14 | predicate => 1, | ||||||||||||||||||||||||||||
| 15 | ); | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | has password => ( | |||||||||||||||||||||||||||
| 18 | is => 'ro', | ||||||||||||||||||||||||||||
| 19 | isa => Str, | ||||||||||||||||||||||||||||
| 20 | required => 0, | ||||||||||||||||||||||||||||
| 21 | predicate => 1, | ||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | has privileged_password => ( | |||||||||||||||||||||||||||
| 25 | is => 'ro', | ||||||||||||||||||||||||||||
| 26 | isa => Str, | ||||||||||||||||||||||||||||
| 27 | required => 0, | ||||||||||||||||||||||||||||
| 28 | predicate => 1, | ||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 1 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | sub connect { | ||||||||||||||||||||||||||||
| 35 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
connect: not called CC=17 SCAR=57.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 36 | 0 | my $options = Net::Appliance::Session::Transport::ConnectOptions->new(@_); | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | foreach my $slot (qw/ username password privileged_password /) { | |||||||||||||||||||||||||||
| 39 | 0 | my $has = 'has_' . $slot; | |||||||||||||||||||||||||||
| 40 | 0 | my $set = 'set_' . $slot; | |||||||||||||||||||||||||||
| 41 | 0 | ▶ | $self->$set($options->$slot) if $options->$has; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if ($self->nci->transport->is_win32 and $self->has_password) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->nci->transport->is_win32 and $self->has_password
MC/DC0%0/2
$self->nci->transport->is_win32 and $self->has_password
$self->nci->transport->is_win32
$self->has_password
Truth table0%0/3
A and B
A= $self->nci->transport->is_win32B= $self->has_password
| |||||||||||||||||||||||||||||
| 45 | 0 | $self->set_password($self->get_password . $self->nci->transport->ors); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | # SSH transport takes a username if we have one | ||||||||||||||||||||||||||||
| 49 | 0 | ▶ | $self->nci->transport->connect_options->username($self->get_username) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->has_username and $self->nci->transport->connect_options->can("username")
MC/DC0%0/2
$self->has_username and $self->nci->transport->connect_options->can("username")
$self->has_username
$self->nci->transport->connect_options->can("username")
Truth table0%0/3
A and B
A= $self->has_usernameB= $self->nci->transport->connect_options->can("username")
| |||||||||||||||||||||||||||||
| 50 | if $self->has_username | ||||||||||||||||||||||||||||
| 51 | and $self->nci->transport->connect_options->can('username'); | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | # poke remote device (whether logging in or not) | ||||||||||||||||||||||||||||
| 54 | 0 | $self->find_prompt($self->wake_up); | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # optionally, log in to the remote host | ||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if ($self->do_login and not $self->prompt_looks_like('generic')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->do_login and not $self->prompt_looks_like("generic")
MC/DC0%0/2
$self->do_login and not $self->prompt_looks_like("generic")
$self->do_login
not $self->prompt_looks_like("generic")
Truth table0%0/3
A and not(B)
A= $self->do_loginB= not $self->prompt_looks_like("generic")
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if ($self->nci->phrasebook->has_prompt('user') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->nci->phrasebook->has_prompt("user") and $self->prompt_looks_like("user")
MC/DC0%0/2
$self->nci->phrasebook->has_prompt("user") and $self->prompt_looks_like("user")
$self->nci->phrasebook->has_prompt("user")
$self->prompt_looks_like("user")
Truth table0%0/3
A and B
A= $self->nci->phrasebook->has_prompt("user")B= $self->prompt_looks_like("user")
| |||||||||||||||||||||||||||||
| 60 | and $self->prompt_looks_like('user')) { | ||||||||||||||||||||||||||||
| 61 | 0 | ▶ | die 'a set username is required to connect to this host' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | if not $self->has_username; | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | $self->cmd($self->get_username, { match => 'pass' }); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | die 'a set password is required to connect to this host' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | if not $self->has_password; | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | # support for serial console servers where, after loggin in to the | ||||||||||||||||||||||||||||
| 71 | # server, the console is asleep and needs waking up to show its prompt | ||||||||||||||||||||||||||||
| 72 | 0 | $self->say($self->get_password); | |||||||||||||||||||||||||||
| 73 | 0 | $self->find_prompt($self->wake_up); | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | $self->prompt_looks_like('generic') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | or die 'login failed to remote host - prompt does not match'; | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | $self->close_called(0); | |||||||||||||||||||||||||||
| 80 | 0 | $self->logged_in(1); | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | $self->in_privileged_mode( $self->do_privileged_mode ? 0 : 1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | $self->in_configure_mode( $self->do_configure_mode ? 0 : 1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | # disable paging... this is undone in our close() method | ||||||||||||||||||||||||||||
| 86 | 0 | ▶ | $self->disable_paging if $self->do_paging; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | return $self; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | sub close { | ||||||||||||||||||||||||||||
| 92 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
close: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | # protect against death spiral (rt.cpan #53796) | ||||||||||||||||||||||||||||
| 95 | 0 | ▶ | return if $self->close_called; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 0 | $self->close_called(1); | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | if ($self->nci->transport->connect_ready) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | $self->end_configure | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->do_configure_mode and $self->in_configure_mode
MC/DC0%0/2
$self->do_configure_mode and $self->in_configure_mode
$self->do_configure_mode
$self->in_configure_mode
Truth table0%0/3
A and B
A= $self->do_configure_modeB= $self->in_configure_mode
| |||||||||||||||||||||||||||||
| 100 | if $self->do_configure_mode and $self->in_configure_mode; | ||||||||||||||||||||||||||||
| 101 | 0 | ▶ | $self->end_privileged | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->do_privileged_mode and $self->in_privileged_mode
MC/DC0%0/2
$self->do_privileged_mode and $self->in_privileged_mode
$self->do_privileged_mode
$self->in_privileged_mode
Truth table0%0/3
A and B
A= $self->do_privileged_modeB= $self->in_privileged_mode
| |||||||||||||||||||||||||||||
| 102 | if $self->do_privileged_mode and $self->in_privileged_mode; | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | # re-enable paging | ||||||||||||||||||||||||||||
| 105 | 0 | ▶ | $self->enable_paging if $self->do_paging; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | # issue disconnect macro if the phrasebook has one | ||||||||||||||||||||||||||||
| 108 | 0 | ▶ | if ($self->nci->phrasebook->has_macro('disconnect')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 0 | eval { $self->macro('disconnect') }; | |||||||||||||||||||||||||||
| 110 | # this should die as there's no returned prompt (NCI pump() fails) | ||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 0 | $self->nci->transport->disconnect; | |||||||||||||||||||||||||||
| 114 | # there is no longer a transport | ||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | $self->logged_in(0); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 1 | 1; | |||||||||||||||||||||||||||