| 1 | package Net::CLI::Interact::Transport::SSH; | ||||||||||||||||||||||||||||||||
| 2 | $Net::CLI::Interact::Transport::SSH::VERSION = '2.400001'; | ||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Sub::Quote; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use MooX::Types::MooseLike::Base qw(InstanceOf); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | extends 'Net::CLI::Interact::Transport::Base'; | ||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | { | ||||||||||||||||||||||||||||||||
| 10 | package # hide from pause | ||||||||||||||||||||||||||||||||
| 11 | Net::CLI::Interact::Transport::SSH::Options; | ||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Sub::Quote; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use MooX::Types::MooseLike::Base qw(Str Bool ArrayRef Any); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | extends 'Net::CLI::Interact::Transport::Options'; | ||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | has 'host' => ( | ||||||||||||||||||||||||||||||||
| 20 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 21 | isa => Str, | ||||||||||||||||||||||||||||||||
| 22 | required => 1, | ||||||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | has 'username' => ( | ||||||||||||||||||||||||||||||||
| 26 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 27 | isa => Str, | ||||||||||||||||||||||||||||||||
| 28 | predicate => 1, | ||||||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | has 'shkc' => ( | ||||||||||||||||||||||||||||||||
| 32 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 33 | isa => Bool, | ||||||||||||||||||||||||||||||||
| 34 | default => quote_sub('0'), | ||||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | has 'ignore_host_checks' => ( | ||||||||||||||||||||||||||||||||
| 38 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 39 | isa => Bool, | ||||||||||||||||||||||||||||||||
| 40 | default => quote_sub('1'), | ||||||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | has 'opts' => ( | ||||||||||||||||||||||||||||||||
| 44 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 45 | isa => ArrayRef[Any], | ||||||||||||||||||||||||||||||||
| 46 | default => sub { [] }, | ||||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||
| 49 | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | has 'connect_options' => ( | ||||||||||||||||||||||||||||||||
| 52 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 53 | isa => InstanceOf['Net::CLI::Interact::Transport::SSH::Options'], | ||||||||||||||||||||||||||||||||
| 54 | coerce => quote_sub(q{ (ref '' eq ref $_[0]) ? $_[0] : | ||||||||||||||||||||||||||||||||
| 55 | Net::CLI::Interact::Transport::SSH::Options->new(@_) }), | ||||||||||||||||||||||||||||||||
| 56 | required => 1, | ||||||||||||||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | sub _build_app { | ||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_build_app: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | die "please pass location of plink.exe in 'app' parameter to new()\n" | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 62 | if $self->is_win32; | ||||||||||||||||||||||||||||||||
| 63 | 0 | return 'ssh'; | |||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||
| 66 | sub runtime_options { | ||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
runtime_options: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if ($self->is_win32) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 69 | return ( | ||||||||||||||||||||||||||||||||
| 70 | '-ssh', | ||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | @{$self->connect_options->opts}, | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 72 | ($self->connect_options->has_username | ||||||||||||||||||||||||||||||||
| 73 | ? ($self->connect_options->username . '@') : '') | ||||||||||||||||||||||||||||||||
| 74 | . $self->connect_options->host, | ||||||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||
| 77 | else { | ||||||||||||||||||||||||||||||||
| 78 | return ( | ||||||||||||||||||||||||||||||||
| 79 | (($self->connect_options->ignore_host_checks and not $self->connect_options->shkc) | ||||||||||||||||||||||||||||||||
| 80 | ? ( | ||||||||||||||||||||||||||||||||
| 81 | '-o', 'StrictHostKeyChecking=no', | ||||||||||||||||||||||||||||||||
| 82 | '-o', 'UserKnownHostsFile=/dev/null', | ||||||||||||||||||||||||||||||||
| 83 | '-o', 'CheckHostIP=no', | ||||||||||||||||||||||||||||||||
| 84 | ) : ()), | ||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | @{$self->connect_options->opts}, | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$self->connect_options->ignore_host_checks and not $self->connect_options->shkc
MC/DC0%0/2
$self->connect_options->ignore_host_checks and not $self->connect_options->shkc
$self->connect_options->ignore_host_checks
not $self->connect_options->shkc
Truth table0%0/3
A and not(B)
A= $self->connect_options->ignore_host_checksB= not $self->connect_options->shkc
| |||||||||||||||||||||||||||||||||
| 86 | ($self->connect_options->has_username | ||||||||||||||||||||||||||||||||
| 87 | ? ('-l', $self->connect_options->username) : ()), | ||||||||||||||||||||||||||||||||
| 88 | $self->connect_options->host, | ||||||||||||||||||||||||||||||||
| 89 | ); | ||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||
| 93 | 1; | ||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | =pod | ||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | Net::CLI::Interact::Transport::SSH - SSH based CLI connection | ||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||
| 101 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | This module provides a wrapped instance of an SSH client for use by | ||||||||||||||||||||||||||||||||
| 104 | L<Net::CLI::Interact>. | ||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | =head1 INTERFACE | ||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | =head2 app | ||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | On Windows platforms you B<must> download the C<plink.exe> program, and pass its | ||||||||||||||||||||||||||||||||
| 111 | location to the library in this parameter. On other platforms, this defaults to | ||||||||||||||||||||||||||||||||
| 112 | C<ssh> (openssh). | ||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||
| 114 | =head2 runtime_options | ||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | Based on the C<connect_options> hash provided to Net::CLI::Interact on | ||||||||||||||||||||||||||||||||
| 117 | construction, selects and formats parameters to provide to C<app> on the | ||||||||||||||||||||||||||||||||
| 118 | command line. Supported attributes: | ||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||
| 120 | =over 4 | ||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||
| 122 | =item host (required) | ||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | Host name or IP address of the host to which the SSH application is to | ||||||||||||||||||||||||||||||||
| 125 | connect. Alternatively you can pass a value of the form C<user@host>, but it's | ||||||||||||||||||||||||||||||||
| 126 | probably better to use the separate C<username> parameter instead. | ||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||
| 128 | =item username | ||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||
| 130 | Optionally pass in the username for the SSH connection, otherwise the SSH | ||||||||||||||||||||||||||||||||
| 131 | client defaults to the current user's username. When using this option, you | ||||||||||||||||||||||||||||||||
| 132 | should obviously I<only> pass the host name to C<host>. | ||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | =item ignore_host_checks | ||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||
| 136 | Under normal interactive use C<openssh> tracks the identity of connected hosts | ||||||||||||||||||||||||||||||||
| 137 | and verifies these identities upon each connection. In automation this behaviour | ||||||||||||||||||||||||||||||||
| 138 | can be irritating because it is interactive. | ||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | This option, enabled by default, causes C<openssh> to skip or ignore this host | ||||||||||||||||||||||||||||||||
| 141 | identity verification. This means the default setting is less secure, but also | ||||||||||||||||||||||||||||||||
| 142 | less likely to trip you up. It is equivalent to the following: | ||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | StrictHostKeyChecking=no | ||||||||||||||||||||||||||||||||
| 145 | UserKnownHostsFile=/dev/null | ||||||||||||||||||||||||||||||||
| 146 | CheckHostIP=no | ||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||
| 148 | Pass a false value to this option to disable the above and return C<openssh> to | ||||||||||||||||||||||||||||||||
| 149 | its default configured settings. | ||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||
| 151 | =item opts | ||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||
| 153 | If you want to pass any other options to openssh on its command line, then use | ||||||||||||||||||||||||||||||||
| 154 | this option, which should be an array reference. Each item in the list will be | ||||||||||||||||||||||||||||||||
| 155 | passed to C<openssh>, separated by a single space character. For example: | ||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||
| 157 | $s->new({ | ||||||||||||||||||||||||||||||||
| 158 | # ...other parameters to new()... | ||||||||||||||||||||||||||||||||
| 159 | connect_options => { | ||||||||||||||||||||||||||||||||
| 160 | opts => [ | ||||||||||||||||||||||||||||||||
| 161 | '-p', '222', # connect to non-standard port on remote host | ||||||||||||||||||||||||||||||||
| 162 | '-o', 'CheckHostIP=no', # don't check host IP in known_hosts file | ||||||||||||||||||||||||||||||||
| 163 | ], | ||||||||||||||||||||||||||||||||
| 164 | }, | ||||||||||||||||||||||||||||||||
| 165 | }); | ||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||
| 167 | =item reap | ||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||
| 169 | Only used on Unix platforms, this installs a signal handler which attempts to | ||||||||||||||||||||||||||||||||
| 170 | reap the C<ssh> child process. Pass a true value to enable this feature only | ||||||||||||||||||||||||||||||||
| 171 | if you notice zombie processes are being left behind after use. | ||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||
| 173 | =back | ||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||
| 175 | =head1 COMPOSITION | ||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||
| 177 | See the following for further interface details: | ||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||
| 179 | =over 4 | ||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||
| 181 | =item * | ||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||
| 183 | L<Net::CLI::Interact::Transport::Base> | ||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||
| 185 | =back | ||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||
| 187 | =cut | ||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||