summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2021-12-16 23:17:44 +0700
committerGitHub <noreply@github.com>2021-12-16 23:17:44 +0700
commit3bd260433c62dd571a53538dae8d367b97b00e37 (patch)
tree84f9f5f427ce0981d336ca6e3d1b682ca33f200a
parent80cf05ed8257afc102e568cdc126e19e13a8837e (diff)
parentc3691b8aecc7fd22a27e47c134e3e68fc88e37ff (diff)
downloadvyatta-cfg-3bd260433c62dd571a53538dae8d367b97b00e37.tar.gz
vyatta-cfg-3bd260433c62dd571a53538dae8d367b97b00e37.zip
Merge pull request #45 from erkin/equuleus
remote: T3356: Backport remote module use to Equuleus
-rwxr-xr-xscripts/vyatta-save-config.pl66
1 files changed, 16 insertions, 50 deletions
diff --git a/scripts/vyatta-save-config.pl b/scripts/vyatta-save-config.pl
index 19941a7..9f1ec5c 100755
--- a/scripts/vyatta-save-config.pl
+++ b/scripts/vyatta-save-config.pl
@@ -57,16 +57,20 @@ if ($save_file =~ /^[^\/]\w+:\//) {
if ($save_file =~ /^(\w+):\/\/\w/) {
$mode = 'url';
$proto = lc($1);
- if ($proto eq 'tftp') {
- } elsif ($proto eq 'ftp') {
- } elsif ($proto eq 'scp') {
- } elsif ($proto eq 'sftp') {
- } else {
- print "Invalid url protocol [$proto]\n";
+ if ($proto eq "ftp") {}
+ elsif ($proto eq "ftps") {}
+ elsif ($proto eq "http") {}
+ elsif ($proto eq "https") {}
+ elsif ($proto eq "scp") {}
+ elsif ($proto eq "sftp") {}
+ elsif ($proto eq "ssh") {}
+ elsif ($proto eq "tftp") {}
+ else {
+ print "Invalid URL protocol [$proto]\n";
exit 1;
}
} else {
- print "Invalid url [$save_file]\n";
+ print "Invalid URL [$save_file]\n";
exit 1;
}
}
@@ -86,7 +90,7 @@ print "Saving configuration to '$shortened_save_file'...\n";
my $save;
if ($mode eq 'local') {
- # first check if this file exists, and if so ensure this is a config file.
+ # First check if this file exists, and if so ensure this is a config file.
if (-e $save_file) {
my $result = `grep -e ' === vyatta-config-version:' -e '// vyos-config-version:' $save_file`;
if (!defined $result || length($result) == 0) {
@@ -94,15 +98,11 @@ if ($mode eq 'local') {
exit 1;
}
}
+ # TODO: This overwrites the file if it exists. We should create a backup first.
+ open $save, '>', $save_file or die "Can not open file '$save_file': $!\n";
- # this overwrites the file if it exists. we could create a backup first.
- open $save, '>', $save_file
- or die "Can not open file '$save_file': $!\n";
} elsif ($mode eq 'url') {
- die "Package [curl] not installed\n" unless (-f '/usr/bin/curl');
-
- open $save, '>', $url_tmp_file
- or die "Cannot open file '$url_tmp_file': $!\n";
+ open $save, '>', $url_tmp_file or die "Cannot open file '$url_tmp_file': $!\n";
}
select $save;
@@ -122,42 +122,8 @@ fsync $save;
close $save;
if ($mode eq 'url') {
-
- my $rc = 0;
- if ($proto =~ /^(scp|sftp)$/){
- $save_file =~ m/(?:scp|sftp):\/\/(.*?)\//;
- my $host = $1;
- 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("python3 -c 'from vyos.remote import upload; upload(\"$url_tmp_file\", \"$save_file\")'");
system("rm -f $url_tmp_file");
- if ($rc) {
- print "Error saving $save_file\n";
- exit 1;
- }
}
print "Done\n";