Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions pakiti-client
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ sub find_packages ($) {
my($data) = @_;
my($cmd, $format, @list);
my(@output);

#The user wants to send svmon data
if ($Option{"svmonreport"}) {
$cmd = $Option{"svmon"} or die("the svmon command is not available");
Expand Down Expand Up @@ -372,20 +372,20 @@ sub encrypt_report ($) {
#

sub https {
my ($url, $report) = @_;
my($ua, $response, $ec);
my($url, $report) = @_;
my($response);
eval { require LWP::UserAgent; LWP::UserAgent->import; };
if ($@) {
if ($Option{"disable-tls-checks"}) {
$response = `curl -sqk -X POST $url -d "$report"`;
} else {
$response = `curl -sq -X POST $url -d "$report"`;
}
$ec = $? >> 8;
($response =~ /OK$/) or die("Error: ".$ec);
my $ec = $? >> 8;
die("Error: ".$ec) if ($ec != 0);

print(STDERR "report successfully sent\n") if -t STDERR;
print($response);
return($response);
} else {
my $ua = LWP::UserAgent->new();
push @{$ua->requests_redirectable}, 'POST';
Expand All @@ -395,16 +395,17 @@ sub https {
}

$response = $ua->post($url, Content => $report);
$response->is_success or die($response->status_line);
die($response->status_line) if (!$response->is_success);

print(STDERR "report successfully sent\n") if -t STDERR;
print $response->decoded_content;
return($response->decoded_content);
}
}

sub send_report ($) {
my($report) = @_;
my($url, @pairs);
my($response);

# The caller may specify additional information that doesn't describe the
# actual patch state but may be useful for the processing. Options recognized
Expand All @@ -418,7 +419,10 @@ sub send_report ($) {
$url = "$Option{url}";
$url = $url . '?' . join('&', @pairs) if @pairs;

https ($url, $report);
$response = https($url, $report);
print($response)
if -t STDOUT or ($response !~ /^OK$/);
return($response =~ /OK$/);
}

#
Expand Down Expand Up @@ -574,8 +578,9 @@ sub main () {
if -t STDERR;
}
}
send_report($report)
if $Option{"url"};
if ($Option{"url"}) {
send_report($report) or exit 1;
}
}

#
Expand Down