#!/usr/bin/perl -w # --- # RC5-64 history graph CGI script # Dominique Pelle # # todo: use tainted mode # # $Id: rc5_history.cgi,v 1.1 2001/03/30 21:59:39 dpelle Exp dpelle $ use CGI qw(:standard); # --- You may want to customize these variables ------------------- my $default_id=262060; my $rc5_history_script="/home/dpelle/RC5/rc5_history.pl"; # relative dir on web server containing generated graphs # nobody user must have permission to create graphs in that dir my $graph_dir="graphs"; # ----------------------------------------------------------------- # location of web site (is DOCUMENT_ROOT env var always set?) my $web_root=$ENV{'DOCUMENT_ROOT'} || '/home/www'; # --- Autoflush stdout $| = 1; print header; print start_html('RC5 history graphs'); print "installation error: graph directory ", tt("$web_root/$graph_dir"), " does not exist", p unless (-d "$web_root/$graph_dir"); print "installation error: nobody user does not have write ", "permission in ", tt("$web_root/$graph_dir/"), p unless (-w "$web_root/$graph_dir"); print h1("Create your " . "RC5-64 " . "personal graphs"), p, start_form, "RC5 participant ID ", textfield(-name => 'id', -default => $default_id), submit, end_form; my $id=param('id'); if ($id) { # --- make sure id a numeric and untaint it $id =~ /^(\d+)$/; $id = $1; } if ($id) { my $rel_blocks_img="$graph_dir/b$id.png"; my $rel_rates_img="$graph_dir/r$id.png"; my $abs_blocks_img="$web_root/$rel_blocks_img"; my $abs_rates_img="$web_root/$rel_rates_img"; my $url_blocks_img="http://" . server_name() . "/$rel_blocks_img"; my $url_rates_img="http://" . server_name() . "/$rel_rates_img"; # --- cache images (for 2 hours) to avoid hogging d.net # web server if the same user comes back several times # if (-f $abs_blocks_img and -f $abs_rates_img and -M $abs_blocks_img < 2./24. and -M $abs_rates_img < 2./24.) { print p, "using cached graphs", p; } else { system("$rc5_history_script --quiet --id=$id " . "--output_blocks_graph=$abs_blocks_img " . "--output_rates_graph=$abs_rates_img"); if ($?) { print p, "cannot create graphs, ", "distributed.net is probably updating stats"; } } if (-f $abs_blocks_img and -f $abs_rates_img) { print p, "", p, ""; } } print hr, 'Check-out ', '', 'http://dominique.pelle.free.fr/rc5_stats.html ', 'for RC5 scripts', end_html;