diff options
author | Petter Reinholdtsen <pere@hungry.com> | 2006-08-25 15:21:17 +0000 |
---|---|---|
committer | Petter Reinholdtsen <pere@hungry.com> | 2006-08-25 15:21:17 +0000 |
commit | 080b37d0ed5d04702452743bbeb7ae38a7f3d415 (patch) | |
tree | 8f37f53d8d7b91db90ebd4ec07129457b0738d14 | |
parent | 066354fec00687bc2325ae58963b7df2816caa01 (diff) | |
download | sitesummary-080b37d0ed5d04702452743bbeb7ae38a7f3d415.tar.gz sitesummary-080b37d0ed5d04702452743bbeb7ae38a7f3d415.tar.bz2 sitesummary-080b37d0ed5d04702452743bbeb7ae38a7f3d415.tar.xz |
More work on the server. Make gpg encryption optional for now, as it does not work.
-rw-r--r-- | sitesummary-client | 39 | ||||
-rw-r--r-- | sitesummary-client.conf | 3 | ||||
-rw-r--r-- | sitesummary-collector.cgi | 15 | ||||
-rwxr-xr-x | sitesummary-upload | 102 |
4 files changed, 137 insertions, 22 deletions
diff --git a/sitesummary-client b/sitesummary-client index 144bf79..8188ce3 100644 --- a/sitesummary-client +++ b/sitesummary-client @@ -11,12 +11,23 @@ set -e # storage area on diskless clients, so use /tmp/. tmpdir=/tmp/sitesummary-$$ +#serverurls="http://developer.skolelinux.no/cgi-bin/popcon-submit.cgi" +serverurls="http://localhost/cgi-bin/sitesummary-collector.cgi" +fragdirs="/usr/lib/sitesummary/collect.d \ + /etc/sitesummary/collect.d" +gpgencrypt=false + log() { msg="$@" echo "$msg" logger -p user.info -t sitesummary-client "$msg" } +error() { + msg="$@" + log "error: $msg" +} + # Check or get GPG key, return false if it is unavailable get_gpg_key_if_missing() { url="$1" @@ -39,10 +50,10 @@ for confdir in \ /usr/share/sitesummary/config.d \ /etc/sitesummary/config.d do - [ -d $confdir ] || continue - for config in $confdir/* ; do - [ -f $conf ] && . $conf - done + [ -d $confdir ] || continue + for config in $confdir/* ; do + [ -f $conf ] && . $conf + done done mkdir $tmpdir && cd $tmpdir @@ -59,15 +70,19 @@ hostsummaryfile=$tmpdir.tar.gz tar zcf $hostsummaryfile . for url in $serverurls ; do - #WGETOPTS="--no-check-certificate" - if get_gpg_key_if_missing $url ; then - gpg_encrypt_for_url $url $hostsummaryfile $hostsummaryfile.gpg - if wget -q $WGETOPTS --post-file $hostsummaryfile.gpg -O $tmpdir.result $url ; then - : - else - log "error: unable to submit to '$url'" + if [ "$gpgencrypt" != false ] ; then + if get_gpg_key_if_missing $url ; then + error "gpg key for '$url' is unavailable. refusing to submit." + continue fi + gpg_encrypt_for_url $url "$hostsummaryfile" "$hostsummaryfile.gpg" + hostsummaryfile="$hostsummaryfile.gpg" + fi + + #WGETOPTS="--no-check-certificate" + if /home/pere/src/debiancvs/debianedusvn/src/sitesummary/sitesummary-upload -u $url -f $hostsummaryfile -d; then + : else - log "error: gpg key for '$url' is unavailable. refusing to submit." + error "unable to submit to '$url'" fi done diff --git a/sitesummary-client.conf b/sitesummary-client.conf index 2eabc40..e69de29 100644 --- a/sitesummary-client.conf +++ b/sitesummary-client.conf @@ -1,3 +0,0 @@ -serverurls="http://localhost/cgi-bin/sitesummary-collector.cgi" -fragdirs="/usr/lib/sitesummary/collect.d \ - /etc/sitesummary/collect.d" diff --git a/sitesummary-collector.cgi b/sitesummary-collector.cgi index 778e85c..fa47e08 100644 --- a/sitesummary-collector.cgi +++ b/sitesummary-collector.cgi @@ -25,14 +25,12 @@ if (exists $ENV{REQUEST_METHOD} && $ENV{REQUEST_METHOD} ne "POST") my @entry; if (exists $ENV{CONTENT_TYPE} && $ENV{CONTENT_TYPE} =~ m%multipart/form-data%){ my $query = new CGI; - my $fh = $query->upload("popcondata"); + my $fh = $query->upload("sitesummary"); if ($fh) { - my $filename = $query->param("popcondata"); + my $filename = $query->param("sitesummary"); my $type = $query->uploadInfo($filename)->{'Content-Type'}; - if ("text/plain; charset=utf-8" ne $type && - "application/octet-stream" ne $type) { # Used by ubuntu script - print "Only 'text/plain; charset=utf-8' and 'application/octet-stream -' is supported (not $type)!"; + if ("application/octet-stream" ne $type) { + print "Only 'application/octet-stream' is supported (not $type)!"; die; } else { my $encoding = $query->uploadInfo($filename)->{'Content-Encoding'}; @@ -60,7 +58,10 @@ Unsupported submission method. EOF } -open(SITESUMMARY, "$basedir/storage") or die "Unable to write to storage"; +my $ip "127.0.0.1"; +my $timestamp = "2006-08-25T11:30:30"; + +open(SITESUMMARY, "$basedir/tmpstorage/storage-$ip-$timestamp") or die "Unable to write to storage"; print SITESUMMARY @entry; close SITESUMMARY; diff --git a/sitesummary-upload b/sitesummary-upload new file mode 100755 index 0000000..6e5504c --- /dev/null +++ b/sitesummary-upload @@ -0,0 +1,102 @@ +#!/usr/bin/perl -w +# Written by Bill Allombert for the Debian popularity-contest project. +# This file is placed in the public domain. +# Rewritten for sitesummary by Petter Reinholdtsen + +use strict; +use IO::Socket; +use Getopt::Std; +use File::Basename; + +my %opts; +getopts("du:f:", \%opts); + +sub usage { + print <<"EOF"; +Usage: $0 [-Cd] [-u <url>] [-f <file>] + -d enable debugging + -u <url> submit to the given URL (default localhost) + -f <file> read popcon report from file (default stdin) +EOF +} + +my ($submiturl) = $opts{'u'} || "http://localhost/cgi-bin/sitesummary-collector.cgi"; +my ($file) = $opts{'f'} || "-"; + +my ($host) = $submiturl =~ m%http://([^/]+)%; + +print "Unable to parse url\n" if ($opts{'d'} && ! $host); + +# 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); +my $encoding; +open FILE, "< $file" or die "reading from '$file'"; +$encoding = "identity"; +$str .= $_ while(<FILE>); +close(FILE); +$len = length($str); + +# 30 second timeout on http connections +$SIG{ALRM} = sub { die "timeout in sitesummary-upload\n" }; +alarm(30); + +# Connect to server +$remote = IO::Socket::INET->new(Proto => "tcp", PeerAddr => $proxy, + PeerPort => $port); +unless ($remote) { die "cannot connect to $proxy:$port" } + +my $boundary = "----------ThIs_Is_tHe_bouNdaRY_\$"; + +my $basefile = basename($file); + +#Content-Length: $len +# text/plain; charset=utf-8 +my $ORS = "\r\n"; # Use DOS line endings to make HTTP happy +my $form; +$form .= "--${boundary}$ORS"; +$form .= "Content-Disposition: form-data; name=\"sitesummary\"; filename=\"$basefile\"$ORS"; +$form .= "Content-Encoding: $encoding$ORS"; +$form .= "Content-Type: application/octet-stream$ORS$ORS"; +$form .= "$str$ORS"; +$form .= "--${boundary}--$ORS"; +$form .= "$ORS"; + +my $formlen = length($form); + +#Send data +print $remote <<"EOF"; +POST $submiturl HTTP/1.1 +User-Agent: sitesummary-upload +Host: $host +content-type: multipart/form-data; boundary=$boundary +content-length: $formlen + +$form +EOF + +#Get answer +my($answer)=""; +while(<$remote>) +{ + $answer.=$_; + m/SITESUMMARY HTTP-POST OK/ and last; +} +close ($remote); +#Check answer +my $status = ($answer =~ m/SITESUMMARY HTTP-POST OK/) ? 0 : 1; +print "Failed to upload, answer '$answer'\n" if $status && $opts{'d'}; +exit $status; |