mirror of
				https://github.com/xcat2/xcat-core.git
				synced 2025-10-31 19:32:31 +00:00 
			
		
		
		
	Add xCAT::SSH to help ssh-ify blade.pm to cope with CMMs that do not do telnet by default
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@12059 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
		
							
								
								
									
										55
									
								
								xCAT-server/lib/perl/xCAT/SSH.pm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								xCAT-server/lib/perl/xCAT/SSH.pm
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,55 @@ | ||||
| package xCAT::SSH; | ||||
| use Exporter; | ||||
| use Net::Telnet; | ||||
| use strict; | ||||
| our @ISA = qw/Exporter Net::Telnet/; | ||||
| our @EXPORT_OK = (); | ||||
| use IO::Pty; | ||||
| use POSIX; | ||||
|  | ||||
| sub _startssh { | ||||
| 	my $pty = shift; | ||||
| 	my $name = shift; | ||||
| 	my $dest = shift; | ||||
| 	my $tty; | ||||
| 	my $tty_fd; | ||||
| 	my $pid = fork(); | ||||
| 	if ($pid) { | ||||
| 		return; | ||||
| 	} | ||||
| 	#in child | ||||
| 	$tty = $pty->slave or die "$!"; | ||||
| 	$tty_fd = $tty->fileno or die "$!"; | ||||
| 	close($pty); | ||||
| 	open STDIN, "<&", $tty_fd; | ||||
| 	open STDOUT,">&",$tty_fd; | ||||
| 	$pty->make_slave_controlling_terminal(); | ||||
| 	close($tty); | ||||
| 	exec ("ssh","-o","StrictHostKeyChecking=no","-l",$name,$dest); | ||||
| } | ||||
|  | ||||
| sub new { | ||||
| 	my $class = shift; | ||||
| 	my %args = @_; | ||||
| 	my $pty = IO::Pty->new or die "Unable to perform ssh: $!"; | ||||
| 	$args{"-fhopen"} = $pty; | ||||
| 	$args{"-telnetmode"} = 0; | ||||
| 	$args{"-telnetmode"} = 0; | ||||
| 	$args{"-cmd_remove_mode"} = 1; | ||||
| 	my $username = $args{"-username"}; | ||||
| 	my $host = $args{"-host"}; | ||||
| 	my $password = $args{"-password"}; | ||||
| 	delete $args{"-host"}; | ||||
| 	delete $args{"-username"}; | ||||
| 	delete $args{"-password"}; | ||||
| 	my $self = Net::Telnet->new(%args); | ||||
| 	_startssh($pty,$username,$host); | ||||
| 	$self->waitfor("-match" => '/password:/i', -errmode => "return") or die "Unable to reach host ",$self->lastline; | ||||
| 	$self->print($password); | ||||
| 	my $nextline = $self->getline(); | ||||
| 	if ($nextline =~ /^password:/ or $nextline =~ /Permission denieid, please try again/) { | ||||
| 		die "Incorrect Password"; | ||||
| 	} | ||||
| 	return bless($self,$class); | ||||
| } | ||||
| 1; | ||||
		Reference in New Issue
	
	Block a user