diff options
author | John Southworth <john.southworth@vyatta.com> | 2012-03-01 17:14:09 +0000 |
---|---|---|
committer | John Southworth <john.southworth@vyatta.com> | 2012-03-01 17:14:09 +0000 |
commit | 4fcfe39b817ee636a2e84eb7d9298b291314ae52 (patch) | |
tree | fd0dec9e50c30948be084746c926fdd16cc35390 /scripts | |
parent | 0ab594222d460347b624894710dec3a8f5441880 (diff) | |
download | vyatta-op-4fcfe39b817ee636a2e84eb7d9298b291314ae52.tar.gz vyatta-op-4fcfe39b817ee636a2e84eb7d9298b291314ae52.zip |
Allow users to import ssh keys when using image commands
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/vyatta-image-tools.pl | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/scripts/vyatta-image-tools.pl b/scripts/vyatta-image-tools.pl index f1d2d26..657aae3 100755 --- a/scripts/vyatta-image-tools.pl +++ b/scripts/vyatta-image-tools.pl @@ -3,6 +3,7 @@ use Getopt::Long; use lib "/opt/vyatta/share/perl5/"; use strict; +use IO::Prompt; my ($show, $delete, $updateone); my @copy; @@ -214,13 +215,55 @@ sub rsync { sub curl_to { my ($from, $to) = @_; - my $rc = system("curl -# -k -T $from $to"); + my $rc = system("curl -# -T $from $to"); + if ($to =~ /scp/ && ($rc >> 8) == 51){ + $to =~ m/scp:\/\/(.*?)\//; + my $host = $1; + if ($host =~ m/.*@(.*)/) { + $host = $1; + } + my $rsa_key = `ssh-keyscan -t rsa $host 2>/dev/null`; + print "The authenticity of host '$host' can't be established.\n"; + my $fingerprint = `ssh-keygen -lf /dev/stdin <<< \"$rsa_key\" | awk {' print \$2 '}`; + chomp $fingerprint; + print "RSA key fingerprint is $fingerprint.\n"; + if (prompt("Are you sure you want to continue connecting (yes/no) [Yes]? ", -tynd=>"y")) { + mkdir "~/.ssh/"; + open(my $known_hosts, ">>", "$ENV{HOME}/.ssh/known_hosts") + or die "Cannot open known_hosts: $!"; + print $known_hosts "$rsa_key\n"; + close($known_hosts); + $rc = system("curl -# -T $from $to"); + print "\n"; + } + } print "\n"; } sub curl_from { my ($from, $to) = @_; - my $rc = system("curl -# -k $from > $to"); + my $rc = system("curl -# $from > $to"); + if ($from =~ /scp/ && ($rc >> 8) == 51){ + $from =~ m/scp:\/\/(.*?)\//; + my $host = $1; + if ($host =~ m/.*@(.*)/) { + $host = $1; + } + my $rsa_key = `ssh-keyscan -t rsa $host 2>/dev/null`; + print "The authenticity of host '$host' can't be established.\n"; + my $fingerprint = `ssh-keygen -lf /dev/stdin <<< \"$rsa_key\" | awk {' print \$2 '}`; + chomp $fingerprint; + print "RSA key fingerprint is $fingerprint.\n"; + if (prompt("Are you sure you want to continue connecting (yes/no) [Yes]? ", -tynd=>"y")) { + mkdir "~/.ssh/"; + open(my $known_hosts, ">>", "$ENV{HOME}/.ssh/known_hosts") + or die "Cannot open known_hosts: $!"; + print $known_hosts "$rsa_key\n"; + close($known_hosts); + $rc = system("curl -# $from > $to"); + print "\n"; + } + } print "\n"; } |