diff options
author | John Hood <cgull@glup.org> | 2015-07-29 22:53:43 -0400 |
---|---|---|
committer | John Hood <cgull@glup.org> | 2015-10-03 03:43:18 -0400 |
commit | 448f9f1babafe596f865f5be3ab4b241600fadb4 (patch) | |
tree | d0d5b50b6dc15415bfebf4e51d7d3fdfe2463ba2 /scripts | |
parent | 5a206268801bbdb38b7a7f3032151a2ed2779b17 (diff) |
mosh: implement --local option for use without ssh
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/mosh.pl | 57 |
1 files changed, 37 insertions, 20 deletions
diff --git a/scripts/mosh.pl b/scripts/mosh.pl index 7cf69e1..a18b4f1 100755 --- a/scripts/mosh.pl +++ b/scripts/mosh.pl @@ -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"); -} else { - print STDERR qq{$0: Unknown server binding option: $bind_ip\n}; - die $usage; -} +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 { + my ( $host, $port ) = @ARGV; -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"; |