mosh: implement --local option for use without ssh
This commit is contained in:
@@ -165,6 +165,12 @@ Do not send the \fBsmcup\fP initialization string and \fBrmcup\fP
|
||||
deinitialization string to the client's terminal. On many terminals
|
||||
this disables alternate screen mode.
|
||||
|
||||
.TP
|
||||
.B \-\-local
|
||||
Invoke \fBmosh-server\fP locally, without using \fBssh\fP. This
|
||||
option requires the \fBhost\fP argument to be a local, numeric
|
||||
IPv4/IPv6 address. This option is useful for testing.
|
||||
|
||||
.SH ESCAPE SEQUENCES
|
||||
|
||||
The default escape character used by Mosh is ASCII RS (decimal 30).
|
||||
|
||||
+37
-20
@@ -51,6 +51,8 @@ my $ssh = 'ssh';
|
||||
|
||||
my $term_init = 1;
|
||||
|
||||
my $localhost = undef;
|
||||
|
||||
my $help = undef;
|
||||
my $version = undef;
|
||||
|
||||
@@ -81,6 +83,8 @@ qq{Usage: $0 [options] [--] [user@]host [command...]
|
||||
|
||||
--no-init do not send terminal initialization string
|
||||
|
||||
--local run mosh-server locally without using ssh
|
||||
|
||||
--help this message
|
||||
--version version and copyright information
|
||||
|
||||
@@ -117,6 +121,7 @@ GetOptions( 'client=s' => \$client,
|
||||
'p=s' => \$port_request,
|
||||
'ssh=s' => \$ssh,
|
||||
'init!' => \$term_init,
|
||||
'local' => \$localhost,
|
||||
'help' => \$help,
|
||||
'version' => \$version,
|
||||
'fake-proxy!' => \my $fake_proxy,
|
||||
@@ -157,20 +162,34 @@ if ( defined $port_request ) {
|
||||
|
||||
delete $ENV{ 'MOSH_PREDICTION_DISPLAY' };
|
||||
|
||||
my $userhost;
|
||||
my @command;
|
||||
my @bind_arguments;
|
||||
if ( not defined $bind_ip or $bind_ip =~ m{^ssh$}i ) {
|
||||
push @bind_arguments, '-s';
|
||||
} elsif ( $bind_ip =~ m{^any$}i ) {
|
||||
# do nothing
|
||||
} elsif ( $bind_ip =~ m{^[0-9\.]+$} ) {
|
||||
push @bind_arguments, ('-i', "$bind_ip");
|
||||
|
||||
if ( ! defined $fake_proxy ) {
|
||||
if ( scalar @ARGV < 1 ) {
|
||||
die $usage;
|
||||
}
|
||||
$userhost = shift;
|
||||
@command = @ARGV;
|
||||
if ( not defined $bind_ip or $bind_ip =~ m{^ssh$}i ) {
|
||||
if ( not defined $localhost ) {
|
||||
push @bind_arguments, '-s';
|
||||
} else {
|
||||
push @bind_arguments, ('-i', "$userhost");
|
||||
}
|
||||
} elsif ( $bind_ip =~ m{^any$}i ) {
|
||||
# do nothing
|
||||
} elsif ( $bind_ip =~ m{^[0-9\.]+$} ) {
|
||||
push @bind_arguments, ('-i', "$bind_ip");
|
||||
} else {
|
||||
print STDERR qq{$0: Unknown server binding option: $bind_ip\n};
|
||||
|
||||
die $usage;
|
||||
}
|
||||
} else {
|
||||
print STDERR qq{$0: Unknown server binding option: $bind_ip\n};
|
||||
my ( $host, $port ) = @ARGV;
|
||||
|
||||
die $usage;
|
||||
}
|
||||
|
||||
if ( defined $fake_proxy ) {
|
||||
use Errno qw(EINTR);
|
||||
my $have_ipv6 = eval {
|
||||
require IO::Socket::IP;
|
||||
@@ -189,8 +208,6 @@ if ( defined $fake_proxy ) {
|
||||
}
|
||||
}
|
||||
|
||||
my ( $host, $port ) = @ARGV;
|
||||
|
||||
# Resolve hostname and connect
|
||||
my $afstr = 'AF_' . uc( $family );
|
||||
my $af = eval { IO::Socket->$afstr } or die "$0: Invalid family $family\n";
|
||||
@@ -231,13 +248,6 @@ if ( defined $fake_proxy ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( scalar @ARGV < 1 ) {
|
||||
die $usage;
|
||||
}
|
||||
|
||||
my $userhost = shift;
|
||||
my @command = @ARGV;
|
||||
|
||||
# Count colors
|
||||
open COLORCOUNT, '-|', $client, ('-c') or die "Can't count colors: $!\n";
|
||||
my $colors = "";
|
||||
@@ -278,6 +288,13 @@ if ( $pid == 0 ) { # child
|
||||
push @server, '--', @command;
|
||||
}
|
||||
|
||||
if ( defined( $localhost )) {
|
||||
delete $ENV{ 'SSH_CONNECTION' };
|
||||
chdir; # $HOME
|
||||
print "MOSH IP ${userhost}\n";
|
||||
exec( $server, @server );
|
||||
die "Cannot exec $server: $!\n";
|
||||
}
|
||||
my $quoted_self = shell_quote( $0, "--family=$family" );
|
||||
exec "$ssh " . shell_quote( '-S', 'none', '-o', "ProxyCommand=$quoted_self --fake-proxy -- %h %p", '-n', '-tt', $userhost, '--', "$server " . shell_quote( @server ) );
|
||||
die "Cannot exec ssh: $!\n";
|
||||
|
||||
Reference in New Issue
Block a user