sub send_image($)
{
my ($file)= @_;
-r $file or do {
print "Content-type: text/plain\n\nERROR: can't find $file\n";
exit 1;
};
print "Content-type: image/png\n";
print "Content-length: ".((stat($file))[7])."\n";
print "\n";
open(IMG, $file) or die;
my $data;
print $data while read(IMG, $data, 16384)>0;
}
sub main()
{
my $uri = $ENV{REQUEST_URI} || '';
$uri =~ s/\/[^\/]+$//;
$uri =~ s/\//,/g;
$uri =~ s/(\~|\%7E)/tilde,/g;
mkdir $tmp_dir, 0777 unless -d $tmp_dir;
mkdir "$tmp_dir/$uri", 0777 unless -d "$tmp_dir/$uri";
my $img = $ENV{QUERY_STRING};
if(defined $img and $img =~ /\S/) {
if($img =~ /^(\d+)-n$/) {
my $file = "$tmp_dir/$uri/mailgraph_$1.png";
graph($graphs[$1]{seconds}, $file);
send_image($file);
}
elsif($img =~ /^(\d+)-e$/) {
my $file = "$tmp_dir/$uri/mailgraph_$1_err.png";
graph_err($graphs[$1]{seconds}, $file);
send_image($file);
}
else {
die "ERROR: invalid argument\n";
}
}
else {
print_html;
}
}