summaryrefslogtreecommitdiff
path: root/scripts/vyatta-save-config.pl
diff options
context:
space:
mode:
authorJohn Southworth <john.southworth@vyatta.com>2012-03-01 01:40:27 +0000
committerJohn Southworth <john.southworth@vyatta.com>2012-03-01 01:40:27 +0000
commit9d3c49bc435d04c727f4500155139ab0e0fa3204 (patch)
treed5ced3fda0eaa13790a07431cf2d367f705c5ed0 /scripts/vyatta-save-config.pl
parentc7c36d6cbe650197fe188f2d720c549d8cc15f97 (diff)
downloadvyatta-cfg-9d3c49bc435d04c727f4500155139ab0e0fa3204.tar.gz
vyatta-cfg-9d3c49bc435d04c727f4500155139ab0e0fa3204.zip
Bugfix 7555: Allow users to import ssh keys when running 'save'
Diffstat (limited to 'scripts/vyatta-save-config.pl')
-rwxr-xr-xscripts/vyatta-save-config.pl23
1 files changed, 23 insertions, 0 deletions
diff --git a/scripts/vyatta-save-config.pl b/scripts/vyatta-save-config.pl
index 00f5854..913a44c 100755
--- a/scripts/vyatta-save-config.pl
+++ b/scripts/vyatta-save-config.pl
@@ -23,6 +23,8 @@ use strict;
use lib "/opt/vyatta/share/perl5";
use Vyatta::ConfigOutput;
use File::Sync qw(fsync);
+use FileHandle;
+use IO::Prompt;
use Vyatta::Misc qw(get_short_config_path);
my $etcdir = "/opt/vyatta/etc";
@@ -120,6 +122,27 @@ close $save;
if ($mode eq 'url') {
my $rc = system("curl -# -T $url_tmp_file $save_file");
+ if ($proto eq 'scp' && ($rc >> 8) == 51){
+ $save_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 $save_file");
+ print "\n";
+ }
+ }
system("rm -f $url_tmp_file");
if ($rc) {
print "Error saving $save_file\n";