65 lines
1.0 KiB
Perl
Executable File
65 lines
1.0 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
# SPDX-License-Identifier: MIT
|
|
#
|
|
# raregetty
|
|
# written by Jan Engelhardt, 2004-2007
|
|
|
|
chdir "/var/lib/empty";
|
|
chroot "/var/lib/empty";
|
|
|
|
use Getopt::Long;
|
|
use strict;
|
|
|
|
my($Clearscr, $Noreopen);
|
|
my $Defaulthost = "127.0.0.1";
|
|
my $Host = "*";
|
|
|
|
&Getopt::Long::Configure(qw(bundling pass_through));
|
|
&GetOptions(
|
|
"c" => \$Clearscr,
|
|
"d=s" => \$Defaulthost,
|
|
"h=s" => \$Host,
|
|
"n" => \$Noreopen,
|
|
);
|
|
|
|
my $Tty = pop @ARGV;
|
|
&query4ssh();
|
|
|
|
sub query4ssh ()
|
|
{
|
|
my $login;
|
|
|
|
&reopen_ttys();
|
|
$< = $> = 65534;
|
|
|
|
while ($login eq "") {
|
|
if ($Clearscr) {
|
|
print "\e[1;1H\e[2J";
|
|
}
|
|
print "login: ";
|
|
chomp($login = <STDIN>);
|
|
}
|
|
|
|
if ($Host eq "*") {
|
|
print "host [$Defaulthost]: ";
|
|
chomp($Host = <STDIN>);
|
|
if( $Host eq "") {
|
|
$Host = $Defaulthost;
|
|
}
|
|
}
|
|
|
|
exit(exec "ssh", $login."\@".$Host);
|
|
}
|
|
|
|
sub reopen_ttys ()
|
|
{
|
|
if (!$Noreopen) {
|
|
open(STDIN, "< /dev/$Tty");
|
|
open(STDOUT, "> /dev/$Tty");
|
|
open(STDERR, "> /dev/$Tty");
|
|
}
|
|
select((select(STDOUT), $| = 1)[0]);
|
|
select((select(STDERR), $| = 1)[0]);
|
|
return;
|
|
}
|