@@ -17,13 +17,14 @@ use File::Temp qw(tempdir);
1717use FindBin qw( $Bin $Script) ;
1818use Getopt::Long qw( GetOptions) ;
1919use Pod::Usage qw( pod2usage) ;
20+ use LWP::UserAgent ();
2021
2122#
2223# constants
2324#
2425
2526use constant COMMANDS => qw(
26- curl dpkg-query hostname lsb_release openssl pkg rpm svmon uname wget
27+ dpkg-query hostname lsb_release openssl pkg rpm svmon uname
2728) ;
2829
2930use constant PROTOCOL_VERSION => " 5" ;
@@ -373,24 +374,8 @@ sub encrypt_report ($) {
373374
374375sub send_report ($) {
375376 my ($report ) = @_ ;
376- my ($data , @command , $output , $ url , @pairs );
377+ my ($response , $ url , @pairs , $ua );
377378
378- $TempDir ||= tempdir(CLEANUP => 1);
379- $data = " $TempDir /data" ;
380- write_file($data , $report );
381- if ($Option {curl }) {
382- @command = ($Option {curl });
383- push (@command , qw( -q --silent -X POST) );
384- push (@command , qw( --include --show-error) ) if $Option {debug };
385- push (@command , " --data-binary" , " \@ " . $data );
386- } elsif ($Option {wget }) {
387- @command = ($Option {wget });
388- push (@command , qw( --tries=1 --output-document=-) );
389- push (@command , qw( --server-response) ) if $Option {debug };
390- push (@command , " --post-file" , $data );
391- } else {
392- die (" $Script : cannot send to $Option {url}: curl/wget not installed\n " );
393- }
394379 # The caller may specify additional information that doesn't describe the
395380 # actual patch state but may be useful for the processing. Options recognized
396381 # as such are sent in the query string.
@@ -402,15 +387,15 @@ sub send_report ($) {
402387
403388 $url = " $Option {url}" ;
404389 $url = $url . ' ?' . join (' &' , @pairs ) if @pairs ;
405- # # no critic 'InputOutput::ProhibitBacktickOperators'
406- $output = qx( @command " $url " 2>&1 ) ;
407- if ( $output =~ / $Option {expect} $ / and $? == 0) {
408- print ( STDERR " report successfully sent \n " ) if -t STDERR ;
409- print $output if $output ;
410- return ;
411- }
412- warn ( $output ) if $output ;
413- die ( " $Script : failed to send data using $command [0] \n " ) ;
390+
391+ $ua = LWP::UserAgent -> new ;
392+ push @{ $ua -> requests_redirectable}, ' POST ' ;
393+
394+ $response = $ua -> post( $url , Content => $report ) ;
395+ $response -> is_success or die ( $response -> status_line) ;
396+
397+ print ( STDERR " report successfully sent \n " ) if -t STDERR ;
398+ print $response -> decoded_content ;
414399}
415400
416401#
@@ -459,9 +444,7 @@ sub init () {
459444 $| = 1;
460445 %spec = (
461446 " config" => " |conf=s" ,
462- " debug" => " |d" ,
463447 " encrypt" => " =s" ,
464- " expect" => " =s" ,
465448 " help" => " |h|?" ,
466449 " host" => " =s" ,
467450 " input" => " |i=s" ,
@@ -494,11 +477,8 @@ sub init () {
494477 foreach my $name (COMMANDS()) {
495478 $Option {$name } = which($name ) unless defined ($Option {$name });
496479 }
497- $Option {expect } = " OK" unless defined ($Option {expect });
498480 die (" $Script : option --encrypt requires openssl\n " )
499481 if $Option {encrypt } and not $Option {openssl };
500- die (" $Script : option --url requires curl or wget\n " )
501- if $Option {url } and not $Option {curl } and not $Option {wget };
502482}
503483
504484#
@@ -611,14 +591,6 @@ with (using bash):
611591
612592use this configuration file before processing the command line parameters
613593
614- =item B<--curl > I<PATH >
615-
616- set the path of the C<curl > command to use
617-
618- =item B<--debug > , B<-d >
619-
620- enable debug mode
621-
622594=item B<--dpkg-query > I<PATH >
623595
624596set the path of the C<dpkg-query > command to use
@@ -629,11 +601,6 @@ use this certificate to encrypt the report; the value can either be the path
629601of the file containing the certificate or the certificate itself as multi-line
630602ASCII armored contents
631603
632- =item B<--expect > I<STRING >
633-
634- set the response string to expect from the server in case of success
635- (default: C<OK > )
636-
637604=item B<--help > , B<-h > , B<-? >
638605
639606show some help
@@ -712,10 +679,6 @@ set the path of the C<uname> command to use
712679
713680send the prepared report to the collecting server at the given URL
714681
715- =item B<--wget > I<PATH >
716-
717- set the path of the C<wget > command to use
718-
719682=back
720683
721684=head1 CONFIGURATION FILE
@@ -777,6 +740,20 @@ A I<package line> contains the package name, a tab character (0x09), the package
777740full version, another tab and the package architecture. For C<rpm > based systems,
778741the full version is in fact I<EPOCH > :I<VERSION > :I<RELEASE > .
779742
743+ =head1 PROTOCOL
744+
745+ The messages are sent using the HTTP protocol and the POST method. The
746+ messages are sent over an TLS-protected channel unless the report is sent as
747+ an encrypted blob, in which case a plain HTTP connection is recommended to
748+ use. Messages containing the encrypted blob are label using the
749+ application/octet-stream mime type. The server uses HTTP codes to signal the
750+ status of delivery. Servers may return human-readable information
751+ in the body of HTTP response, which provides additional details about the
752+ processing.
753+
754+ The client can use query string attributes to pass additional parameters
755+ important for the processing.
756+
780757=head1 AUTHOR
781758
782759Lionel Cons L<http://cern.ch/lionel.cons>
0 commit comments