[Popcon-commits] cvs commit to popularity-contest by pere
popcon-commits@lists.alioth.debian.org
popcon-commits@lists.alioth.debian.org
Sat, 02 Jul 2005 17:18:08 +0000
Update of /cvsroot/popcon/popularity-contest
In directory haydn:/tmp/cvs-serv3864
Modified Files:
FAQ default.conf
Added Files:
popcon-submit-ubuntu.cgi popcon-submit.cgi popcon-upload
popcon-upload-ubuntu
Log Message:
* Add support for reporting using http POST.
* new script /usr/share/popularity-contest/popcon-upload
* new CGI /usr/share/doc/popularity-contest/popcon.cgi
* Uploading using content-type text/plain, content-encoding x-gzip.
* debian/cron.weekly:
- do not run sendmail if it is not available. This will make it
possible to downgrade mail-transport-agent from Depend to
Recommends if we move to HTTP.
- try to run /usr/share/popularity-contest/popcon-upload if
USEHTTP is enabled, disabled by default.
* Code done by Bill Allombert. Patch based on code from Ubuntu,
though reimplemented in perl to avoid python dependency. The
ubuntu versions are included in the source package as
popcon-submit-ubuntu.cgi and popcon-upload-ubuntu.
* Added simple FAQ entry about the http POST feature.
* Depend on ${misc:Depends} instead of debconf, to get the updated
debconf dependency.
* TODO:
+ Edit popcon-submit.cgi to report to the main server
+ Add timeout in the upload script.
+ Consider using existing perl module to submit file using http.
--- NEW FILE: popcon-submit-ubuntu.cgi ---
#!/usr/bin/python
import os, sys, cgi, errno
import cgitb; cgitb.enable()
uploadDir = '/srv/popcon.ubuntu.com/popcon-data/'
logDir = '/srv/popcon.ubuntu.com/logs/'
def mkdirs(newdir,mode=0777):
try: os.makedirs(newdir,mode)
except OSError, err:
if err.errno != errno.EEXIST or not os.path.isdir(newdir):
raise
formStorage = cgi.FieldStorage()
fileitem = formStorage["popcondata"]
if fileitem.file:
header = fileitem.file.readline()
try:
id = header.split()[2].split(":")[1]
hash = id[:2]
hashDir = uploadDir + hash + '/'
filename = hashDir + id
mode = 'w'
except IndexError:
filename = logDir + "panic-popcon-submit-log"
mode = 'a'
mkdirs(hashDir,0755)
data = file(filename,mode)
data.writelines(header)
data.writelines(fileitem.file)
data.close()
print """Content-Type: text/plain
Thanks!
"""
--- NEW FILE: popcon-submit.cgi ---
#!/usr/bin/perl -wT
use strict;
my $email='test@popcon.debian.org';
$ENV{PATH}="";
print "Content-Type: text/plain\n\n";
if ($ENV{REQUEST_METHOD} ne "POST")
{
print "Debian Popularity-Contest HTTP-POST submission URL\n";
exit 0;
}
open POPCON, "|/usr/lib/sendmail -oi $email" or die "sendmail";
open GZIP, '/bin/gzip -dc|' or die "gzip";
close STDIN;
open STDIN, "<&GZIP";
print POPCON <<"EOF";
To: $email
Subject: popularity-contest submission
EOF
print POPCON while(<GZIP>);
close POPCON;
print "Thanks for your submission to Debian Popularity-Contest\n";
exit 0;
--- NEW FILE: 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;
use Getopt::Std;
getopt("uf", \%opts);
my ($submiturl) = $opts{'u'} || "http://popcon.debian.org/cgi-bin/popcon.cgi";
my ($file) = $opts{'f'} || "-";
($host) = $submiturl =~ m%http://([^/]+)%;
# 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 $submiturl HTTP/1.1
Host: $host
Content-Type: text/plain; charset=utf-8
Content-Encoding: x-gzip
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);
--- NEW FILE: popcon-upload-ubuntu ---
#!/usr/bin/env python
import httplib, mimetypes, sys
def post_multipart(host, uri, fields, files):
content_type, body = encode_multipart_formdata(fields,files)
h = httplib.HTTPConnection(host)
h.putrequest('POST', uri)
h.putheader('content-type', content_type)
h.putheader('content-length', str(len(body)))
h.endheaders()
h.send(body)
response = h.getresponse()
return response.read()
def encode_multipart_formdata(fields, files):
BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_$'
CRLF = '\r\n'
L = []
for (key, value) in fields:
L.append('--' + BOUNDARY)
L.append('Content-Disposition: form-data; name="%s"' % key)
L.append('')
L.append(value)
for (key, filename, value) in files:
L.append('--' + BOUNDARY)
L.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (key, filename))
L.append('Content-Type: %s' % get_content_type(filename))
L.append('')
L.append(value)
L.append('--' + BOUNDARY + '--')
L.append('')
body = CRLF.join(L)
content_type= 'multipart/form-data; boundary=%s' % BOUNDARY
return content_type, body
def get_content_type(filename):
return mimetypes.guess_type(filename)[0] or 'application/octet-stream'
upfile = 'popcon-data'
uploadname = 'popcondata'
val = sys.stdin.read()
data = ((uploadname,upfile,val),)
ret= post_multipart('popcon.ubuntulinux.org', '/popcon-submit.cgi', '' , data)
if not ret == 'Thanks!\n':
sys.stderr.write("%s\n" % ret)
sys.exit(1)
Index: FAQ
===================================================================
RCS file: /cvsroot/popcon/popularity-contest/FAQ,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- FAQ 18 Feb 2005 17:39:07 -0000 1.7
+++ FAQ 2 Jul 2005 17:18:05 -0000 1.8
@@ -76,4 +76,10 @@
Make sure myuser account is properly configured to send email with a valid
return address.
+Q) My system are unable to send email out to the Internet. How can I
+participate.
+
+An alternative is to use the new experimental http submission support.
+This can be enabled using this command:
+ echo USEHTTP="yes" >> /etc/popularity-contest.conf
Index: default.conf
===================================================================
RCS file: /cvsroot/popcon/popularity-contest/default.conf,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- default.conf 26 Jan 2004 15:27:14 -0000 1.2
+++ default.conf 2 Jul 2005 17:18:05 -0000 1.3
@@ -28,6 +28,12 @@
#
#MAILFROM="root@example.org"
+# SUBMITURL is where to submit popularity-contest reports using http.
+SUBMITURL=http://popcon.debian.org/cgi-bin/popcon.cgi
+
+# USEHTTP enables http reporting. Set this to 'yes' to enable it.
+USEHTTP="no"
+
# MY_HOSTID is a secret number that the popularity-contest receiver
# uses to keep track of your submissions. Whenever you send in a
# new entry, it overwrites the last one that had the same HOSTID.