blob: fa47e08a351ce626475d2098ec979f335ddb78e4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
#!/usr/bin/perl -wT
#
# Receive HTTP post request with a file upload and process it as a
# sitesummary submission.
#
# Handle three different submission methods
# - mime-encoded upload with sitesummary report in compressed form
use strict;
use CGI;
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("sitesummary");
if ($fh) {
my $filename = $query->param("sitesummary");
my $type = $query->uploadInfo($filename)->{'Content-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'};
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
}
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;
print "Thanks for your submission to site-summary!\n";
print "SITESUMMARY HTTP-POST OK\n";
exit 0;
|