From 897083943e031e6657d7a394d143fe3e15e25686 Mon Sep 17 00:00:00 2001 From: Jakub Havrila Date: Mon, 12 Dec 2022 10:58:58 +0100 Subject: [PATCH 1/5] Added curl workaround when LWP module is not available --- pakiti-client | 48 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/pakiti-client b/pakiti-client index 90856e5..af0d9ed 100755 --- a/pakiti-client +++ b/pakiti-client @@ -17,7 +17,6 @@ use File::Temp qw(tempdir); use FindBin qw($Bin $Script); use Getopt::Long qw(GetOptions); use Pod::Usage qw(pod2usage); -use LWP::UserAgent (); # # constants @@ -369,9 +368,41 @@ sub encrypt_report ($) { # send a formatted report # +sub https { + my ($url, $report) = @_; + my($ua, $response); + my($code,$body); + eval { require LWP::UserAgent; LWP::UserAgent->import; }; + if ($@) { + if ($Option{"disable-tls-checks"}) { + ($code,$body) = `curl -sik -X POST $url -d "$report"` =~m{\A\S+ (\d+) .*?\r?\n\r?\n(.*)}s; + } else { + ($code,$body) = `curl -si -X POST $url -d "$report"` =~m{\A\S+ (\d+) .*?\r?\n\r?\n(.*)}s; + } + if ($body =~ m/200 OK/) { + print(STDERR "report successfully sent\n") if -t STDERR; + } else { + die($body); + } + } else { + my $ua = LWP::UserAgent->new(); + push @{$ua->requests_redirectable}, 'POST'; + + if ($Option{"disable-tls-checks"}) { + $ua->ssl_opts(verify_hostname => 0, SSL_verify_mode => 0x00); + } + + $response = $ua->post($url, Content => $report); + $response->is_success or die($response->status_line); + + print(STDERR "report successfully sent\n") if -t STDERR; + print $response->decoded_content; + } +} + sub send_report ($) { my($report) = @_; - my($response, $url, @pairs, $ua); + my($url, @pairs); # The caller may specify additional information that doesn't describe the # actual patch state but may be useful for the processing. Options recognized @@ -385,18 +416,7 @@ sub send_report ($) { $url = "$Option{url}"; $url = $url . '?' . join('&', @pairs) if @pairs; - $ua = LWP::UserAgent->new(); - push @{$ua->requests_redirectable}, 'POST'; - - if ($Option{"disable-tls-checks"}) { - $ua->ssl_opts(verify_hostname => 0, SSL_verify_mode => 0x00); - } - - $response = $ua->post($url, Content => $report); - $response->is_success or die($response->status_line); - - print(STDERR "report successfully sent\n") if -t STDERR; - print $response->decoded_content; + https ($url, $report); } # From a61c46cf29b96555902d640554108651da7d7417 Mon Sep 17 00:00:00 2001 From: Jakub Havrila Date: Wed, 25 Jan 2023 08:52:46 +0100 Subject: [PATCH 2/5] Added OK status to output --- pakiti-client | 1 + 1 file changed, 1 insertion(+) diff --git a/pakiti-client b/pakiti-client index af0d9ed..942d709 100755 --- a/pakiti-client +++ b/pakiti-client @@ -381,6 +381,7 @@ sub https { } if ($body =~ m/200 OK/) { print(STDERR "report successfully sent\n") if -t STDERR; + print "OK\n"; } else { die($body); } From c947b7499a14d7ce01f65860e2eecc301f44c3a6 Mon Sep 17 00:00:00 2001 From: Jakub Havrila Date: Mon, 17 Apr 2023 02:33:57 +0200 Subject: [PATCH 3/5] Fix reading response code --- pakiti-client | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pakiti-client b/pakiti-client index 942d709..e865102 100755 --- a/pakiti-client +++ b/pakiti-client @@ -371,19 +371,18 @@ sub encrypt_report ($) { sub https { my ($url, $report) = @_; my($ua, $response); - my($code,$body); eval { require LWP::UserAgent; LWP::UserAgent->import; }; if ($@) { - if ($Option{"disable-tls-checks"}) { - ($code,$body) = `curl -sik -X POST $url -d "$report"` =~m{\A\S+ (\d+) .*?\r?\n\r?\n(.*)}s; + if ($Option{"disable-tls-checks"}) { + $response = `curl -sik -o /dev/null -w "%{http_code}" -X POST $url -d "$report"`; } else { - ($code,$body) = `curl -si -X POST $url -d "$report"` =~m{\A\S+ (\d+) .*?\r?\n\r?\n(.*)}s; + $response = `curl -si -o /dev/null -w "%{http_code}" -X POST $url -d "$report"`; } - if ($body =~ m/200 OK/) { + if ($response == "200") { print(STDERR "report successfully sent\n") if -t STDERR; print "OK\n"; } else { - die($body); + die($response); } } else { my $ua = LWP::UserAgent->new(); From fa29fbf3006b956b20c83f9107c53ff11961ce42 Mon Sep 17 00:00:00 2001 From: Jakub Havrila Date: Mon, 15 May 2023 02:03:25 +0200 Subject: [PATCH 4/5] Fix code flow and response check --- pakiti-client | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/pakiti-client b/pakiti-client index e865102..fe7b33a 100755 --- a/pakiti-client +++ b/pakiti-client @@ -374,16 +374,14 @@ sub https { eval { require LWP::UserAgent; LWP::UserAgent->import; }; if ($@) { if ($Option{"disable-tls-checks"}) { - $response = `curl -sik -o /dev/null -w "%{http_code}" -X POST $url -d "$report"`; + $response = `curl -sqk -X POST $url -d "$report"`; } else { - $response = `curl -si -o /dev/null -w "%{http_code}" -X POST $url -d "$report"`; - } - if ($response == "200") { - print(STDERR "report successfully sent\n") if -t STDERR; - print "OK\n"; - } else { - die($response); + $response = `curl -sq -X POST $url -d "$report"`; } + ($response =~ /OK$/) or die($response); + + print(STDERR "report successfully sent\n") if -t STDERR; + print($response); } else { my $ua = LWP::UserAgent->new(); push @{$ua->requests_redirectable}, 'POST'; From 8b6052fcaf8edef26f914d6aa59ce653cd85aee5 Mon Sep 17 00:00:00 2001 From: Jakub Havrila Date: Sun, 30 Jul 2023 18:42:21 +0200 Subject: [PATCH 5/5] Add curl support --- pakiti-client | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pakiti-client b/pakiti-client index fe7b33a..7768da0 100755 --- a/pakiti-client +++ b/pakiti-client @@ -378,7 +378,8 @@ sub https { } else { $response = `curl -sq -X POST $url -d "$report"`; } - ($response =~ /OK$/) or die($response); + $ec = $? >> 8; + ($response =~ /OK$/) or die("Error: ".$ec); print(STDERR "report successfully sent\n") if -t STDERR; print($response);