--- lib/PXElator/ssh.pm 2009/08/29 18:07:49 348 +++ lib/PXElator/ssh.pm 2009/08/29 21:10:21 351 @@ -1,8 +1,13 @@ package ssh; +use warnings; +use strict; + use Net::OpenSSH; use English; use Data::Dump qw/dump/; +use client; +use CouchDB; my $id = 2; @@ -31,27 +36,37 @@ } sub shell { - my $host = shift; + my $ip = shift; - my $ssh = Net::OpenSSH->new( $host ); + my $ssh = Net::OpenSSH->new( $ip ); my $html; + my @shell; foreach my $command ( @_ ) { - warn "root\@$host:# $command\n"; + warn "root\@$ip:# $command\n"; my ($out,$err) = $ssh->capture2( $command ) or die "$command ", $ssh->error; warn "$out\n$err"; - $html .= qq|root\@$host:# $command
$out
|; + CouchDB::audit( $ip, $command, { ip => $ip, command => $command, out => $out, err => $err } ); + + $html .= qq|root\@$ip:# $command
$out
|; $html .= qq|
$err
| if $err; } return $html; } +my $id_pub = '/root/.ssh/id_rsa.pub'; + sub copy_id { - my $host = shift; - system 'sudo ssh-copy-id -i /root/.ssh/id_rsa.pub root@' . $host; + my $ip = shift; + my $ssh = client::ip_path( $ip, 'ssh' ); + return if -l $ssh; + my $cmd = "sudo ssh-copy-id -i $id_pub root\@$ip"; + warn "# $cmd\n"; + system $cmd; + symlink $id_pub, $ssh; } 1;