diff options
author | Hiroyuki Sato <hiroysato@gmail.com> | 2014-04-22 23:48:30 +0900 |
---|---|---|
committer | Hiroyuki Sato <hiroysato@gmail.com> | 2014-04-22 23:48:30 +0900 |
commit | b720eeb8e328efcf34cafaf40d8bcbbf7b1cbb25 (patch) | |
tree | 19c2b8c6fb794aa2b38794dff4bac1d240cde894 | |
parent | a0cd6509535981bf0af1ac6385a9f275b888e59f (diff) | |
download | vyatta-cfg-b720eeb8e328efcf34cafaf40d8bcbbf7b1cbb25.tar.gz vyatta-cfg-b720eeb8e328efcf34cafaf40d8bcbbf7b1cbb25.zip |
Bug #180 save config using scp fails.
-rwxr-xr-x | scripts/vyatta-save-config.pl | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/scripts/vyatta-save-config.pl b/scripts/vyatta-save-config.pl index 8695d53..b397195 100755 --- a/scripts/vyatta-save-config.pl +++ b/scripts/vyatta-save-config.pl @@ -121,27 +121,36 @@ fsync $save; close $save; if ($mode eq 'url') { - my $rc = system("curl -# -T $url_tmp_file $save_file"); - if ($proto eq 'scp' && ($rc >> 8) == 51){ + + my $rc = 0; + if ($proto eq 'scp' ){ $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 -# -T $url_tmp_file $save_file"); - print "\n"; + my $user = getpwuid($<); + if ($host =~ m/(.*)@(.*)/) { + $user = $1; + $host = $2; } + + $rc = system("curl -u $user -# -T $url_tmp_file $save_file"); + if( $rc >> 8 == 51 ){ + 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 "$ENV{HOME}/.ssh/",0700 unless -d "$ENV{HOME}/.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 -u $user -# -T $url_tmp_file $save_file"); + print "\n"; + } + } + } else { + $rc = system("curl -# -T $url_tmp_file $save_file"); } system("rm -f $url_tmp_file"); if ($rc) { |