diff options
| author | Petter Reinholdtsen <pere@hungry.com> | 2006-08-24 07:52:09 +0000 | 
|---|---|---|
| committer | Petter Reinholdtsen <pere@hungry.com> | 2006-08-24 07:52:09 +0000 | 
| commit | 82b3fba2afb70839ee1ebd94d6ceae9641ac42c6 (patch) | |
| tree | 26879984f02eb0db11eea093d7c162448eb22650 /sitesummary-collector.cgi | |
| parent | 81e37e97121b47fb83ca5cfd2780e4d2257154c9 (diff) | |
| download | sitesummary-82b3fba2afb70839ee1ebd94d6ceae9641ac42c6.tar.gz sitesummary-82b3fba2afb70839ee1ebd94d6ceae9641ac42c6.tar.bz2 sitesummary-82b3fba2afb70839ee1ebd94d6ceae9641ac42c6.tar.xz | |
First draft for collector.  Not working yet.
Diffstat (limited to 'sitesummary-collector.cgi')
| -rw-r--r-- | sitesummary-collector.cgi | 76 | 
1 files changed, 73 insertions, 3 deletions
| diff --git a/sitesummary-collector.cgi b/sitesummary-collector.cgi index afdeb50..e4217cd 100644 --- a/sitesummary-collector.cgi +++ b/sitesummary-collector.cgi @@ -1,5 +1,75 @@ -#!/bin +#!/usr/bin/perl -wT +# +# Receive HTTP post request with a file upload and process it as a +# sitesummary submission. +# +# Handle three different submission methods +#  - simple post message, where the complete body is the popcon report +#    (used by popcon version 1.30). +#  - mime-encoded upload with report in compressed form (used by +#    popcon version 1.31 and newer). +#  - mime-encoded upload with report in uncompressed form (used by +#    ubuntu popcon). -# Script to collect HW info using HTTP put +use strict; +use CGI; -true +my $basedir   = "/var/lib/sitesummary"; + +$ENV{PATH}=""; + +print "Content-Type: text/plain\n\n"; +if (exists $ENV{REQUEST_METHOD} && $ENV{REQUEST_METHOD} ne "POST") +{ +    print "Sitesummary  HTTP-POST submission URL\n"; +    print "Visit http://debian-edu.alioth.debian.org/ for more info.\n"; +    exit 0; +} + +# Extract post data, handle both simple and multipart way +my @entry; +if (exists $ENV{CONTENT_TYPE} && $ENV{CONTENT_TYPE} =~ m%multipart/form-data%){ +    my $query = new CGI; +    my $fh = $query->upload("popcondata"); +    if ($fh) { +        my $filename = $query->param("popcondata"); +        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)!"; +            die; +        } else { +            my $encoding = $query->uploadInfo($filename)->{'Content-Encoding'}; +            if ("x-gzip" eq $encoding || "gzip" eq $encoding) { +                # Uncompress +                print "Compressed ($encoding) encoding detected.\n"; +                my $data; +                # $data = join("", <$fh>); +                my $len = (stat($fh))[7]; +                read $fh, $data, $len; +                $data = Compress::Zlib::memGunzip($data); +                @entry = ($data); +            } else { # Pass throught +                print "Identity encoding detected.\n"; +                @entry = <$fh>; +            } +        } +    } else { +        print $query->cgi_error; +        die; +    } +} else { +    print <<EOF; +Unsupported submission method. +EOF +} + +open(SITESUMMARY, "$basedir/storage") or die "Unable to pipe to prepop.pl"; +print SITESUMMARY @entry; +close SITESUMMARY; + +print "Thanks for your submission to site-summary!\n"; +print "SITESUMMARY HTTP-POST OK\n"; + +exit 0; | 
