From b18bbaf1898fa25f87efca7e9ae68fc5057d1998 Mon Sep 17 00:00:00 2001
From: John Southworth <john.southworth@vyatta.com>
Date: Thu, 1 Mar 2012 00:00:52 +0000
Subject: Bugfix 7555: Allow users to import keys when using the 'load' command
 from config mode

---
 scripts/vyatta-load-config.pl | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

(limited to 'scripts')

diff --git a/scripts/vyatta-load-config.pl b/scripts/vyatta-load-config.pl
index 7bf7779..dc9ad6e 100755
--- a/scripts/vyatta-load-config.pl
+++ b/scripts/vyatta-load-config.pl
@@ -127,6 +127,27 @@ elsif ( $mode eq 'url' ) {
         }
     }
     my $rc = system("curl -# -o $url_tmp_file $load_file");
+    if ($proto eq 'scp' && ($rc >> 8) == 51){
+        $load_file =~ 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 -# -o $url_tmp_file $load_file");
+            print "\n";
+        }
+    }
     if ($rc) {
         print "Can not open remote configuration file $load_file\n";
         exit 1;
-- 
cgit v1.2.3