summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2014-04-23 09:16:25 -0700
committerDaniil Baturin <daniil@baturin.org>2014-04-23 09:16:25 -0700
commitf3aff11b3f2b701f19634b8e6dc3e1944194e825 (patch)
tree19c2b8c6fb794aa2b38794dff4bac1d240cde894
parenta0cd6509535981bf0af1ac6385a9f275b888e59f (diff)
parentb720eeb8e328efcf34cafaf40d8bcbbf7b1cbb25 (diff)
downloadvyatta-cfg-f3aff11b3f2b701f19634b8e6dc3e1944194e825.tar.gz
vyatta-cfg-f3aff11b3f2b701f19634b8e6dc3e1944194e825.zip
Merge pull request #2 from hiroyuki-sato/patch-for-vyos
Bug #180 save config using scp fails.
-rwxr-xr-xscripts/vyatta-save-config.pl45
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) {