[Popcon-developers] HTTP POST support and popcon

Bill Allombert allomber@math.u-bordeaux.fr
Fri, 15 Apr 2005 00:51:36 +0200


--tKW2IUtsqtDRztdT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Sat, Apr 02, 2005 at 11:45:38AM +0200, Petter Reinholdtsen wrote:
> > One good point: I should improve the script+CGI so that it is
> > possible to know with certainty if the HTTP worked so we can skip
> > smtp in that case.
> 
> Yes, we should do this.

Could you try the attached popcon-upload file ?
This one read the answer from the CGI script and check for
the string "DEBIAN POPCON HTTP-POST OK".
If the string is not found, it report an error.

This is safe, but maybe you have a better idea ?

Sorry it took so long, but there was a stupid bug, and after that 
gluck went down and I could not test anymore.

Cheers,
-- 
Bill. <ballombe@debian.org>

Imagine a large red swirl here. 

--tKW2IUtsqtDRztdT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=popcon-upload

#!/usr/bin/perl -w
# Written by Bill Allombert for the Debian popularity-contest project.
# This file is placed in the public domain.

use strict;
use IO::Socket;

my ($host)  = "popcon.debian.org";
my ($file)  = defined($ARGV[0])?$ARGV[0]:"";

# Configure the proxy:
my ($http_proxy,$proxy,$port,$remote);

$http_proxy=$ENV{'http_proxy'};
if (defined($http_proxy))
{
  $http_proxy =~ m{http://([^:]*)(?::([0-9]+))?} 
        or die ("unrecognized http_proxy");
  $proxy=$1; $port=$2;
}
  
$proxy=$host unless (defined($proxy));
$port=80 unless (defined($port));

# Compress the report:
my ($str,$len);
open GZIP, "gzip -c $file |" or die "gzip -c $file";
$str .= $_ while(<GZIP>); 
close(GZIP);
$len = length($str);

# Connect to server
$remote = IO::Socket::INET->new(Proto => "tcp", PeerAddr => $proxy, 
                                                PeerPort => $port); 
unless ($remote) { die "cannot connect to $proxy:$port" }

#Send data
print $remote <<"EOF";
POST http://$host/cgi-bin/popcon.cgi HTTP/1.1
Host: $host
Content-Type: application/octet-stream
Content-Length: $len

EOF
print $remote $str;

#Get answer
my($answer)="";
$answer.=$_ while(<$remote>);
close ($remote);
#Check answer
exit (($answer =~ m/DEBIAN POPCON HTTP-POST OK/)?0:1);

--tKW2IUtsqtDRztdT--