From 493aa2868fa552d4bd397bbe5dc650f861aabe82 Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Tue, 2 Nov 2010 18:32:25 -0700 Subject: Convert perl system call to use WWW::Curl module --- debian/control | 1 + scripts/vyatta-commit-push.pl | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/debian/control b/debian/control index e1206ff..0a1364d 100644 --- a/debian/control +++ b/debian/control @@ -11,5 +11,6 @@ Depends: perl, vyatta-cfg (>= 0.15.33), vyatta-cfg-system, vyatta-op, + libwww-curl-perl, Description: Vyatta commands for config-mgmt Vyatta configuration/operational templates and scripts for the config management system. diff --git a/scripts/vyatta-commit-push.pl b/scripts/vyatta-commit-push.pl index 2cbd887..da6c29e 100755 --- a/scripts/vyatta-commit-push.pl +++ b/scripts/vyatta-commit-push.pl @@ -36,6 +36,7 @@ use Vyatta::Config; use POSIX; use File::Basename; use URI; +use WWW::Curl::Easy; my $debug = 0; @@ -52,7 +53,7 @@ if (scalar(@uris) < 1) { my $upload_file = '/opt/vyatta/etc/config/config.boot'; my $timestamp = strftime("_%Y%m%d_%H%M%S", localtime); -my $same_file = basename($upload_file) . $timestamp; +my $save_file = basename($upload_file) . $timestamp; print "Archiving config...\n"; foreach my $uri (@uris) { @@ -68,15 +69,19 @@ foreach my $uri (@uris) { } $remote .= "$scheme://$host"; $remote .= "$path" if defined $path; - print " $remote "; - my $cmd = "curl -s -T $upload_file $uri/$same_file"; - print "cmd [$cmd]\n" if $debug; - my $rc = system($cmd); - if ($rc eq 0) { - print " OK\n"; + open(my $FILE, '<', $upload_file) or die "Error: read $!"; + my $curl = new WWW::Curl::Easy; + $curl->setopt(CURLOPT_NOPROGRESS, 1); + $curl->setopt(CURLOPT_URL, "$uri/$save_file"); + $curl->setopt(CURLOPT_UPLOAD, 1); + $curl->setopt(CURLOPT_INFILE, $FILE); + $curl->setopt(CURLOPT_VERBOSE, $debug); + my $retcode = $curl->perform; + if ($retcode == 0) { + print "Ok\n"; } else { - print " failed\n"; + print "Failed: " . $curl->strerror($retcode) . "\n"; } } -- cgit v1.2.3