#! /usr/bin/env perl # The contents of this file are subject to the Mozilla Public License # Version 1.0 (the "License"); you may not use this file except in # compliance with the License. You may obtain a copy of the License at # http://www.mozilla.org/MPL/ # # Software distributed under the License is distributed on an "AS IS" # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the # License for the specific language governing rights and limitations # under the License. # # The Original Code is the Berkeley Open Infrastructure for Network Computing. # # The Initial Developer of the Original Code is the SETI@home project. # Portions created by the SETI@home project are Copyright (C) 2002 # University of California at Berkeley. All Rights Reserved. # # Contributor(s): # # Stripchart.cgi - Version 2.1 by Matt Lebofsky ( started: November 11, 2002 ) # # Requires: stripchart # stripchart.cnf (make sure you set the path the .cnf file below) # apache or other CGI-enabled web server # # Stripchart.cgi is a web-based GUI interface for stripchart, allowing # users to display multiple plots from various data sources. # # You should only need to edit the variables in the section # "GLOBAL/DEFAULT VARS" below # # Type "stripchart -h" for usage # # See doc/stripchart.txt for details use CGI; $query = CGI::new(); use File::Basename; ################ # READ IN .cnf ################ # Where is the .cnf file? $cnfpath = "./stripchart.cnf"; # Read it in: open (CNFFILE,$cnfpath) or die "cannot open configuration file: $cnfpath\nmake sure this variable is set properly"; while () { eval } close (CNFFILE); ############### # PREP ARRAYS ############### # Read in list of datafiles: @datafiles = `$grepexe -v '^#' $datafilelist`; # Read in list of queries: @querylist = `$grepexe -v '^#' $queryfilelist`; # Make file option list based on @datafiles $optionlist = ""; foreach $element (@datafiles) { chomp $element; $thisop = (split /:/, $element)[1]; $optionlist .= "\n"; } # Make query option list based on @querylist $queryoptionlist = ""; foreach $element (@querylist) { chomp $element; ($thisname,$thisquery) = (split /:/, $element)[0,1]; $queryoptionlist .= "\n"; } # Make year list based on time right now, and other lists $yearlist = ""; for ($i = $year; $i> 1999; $i--) { $yearlist .= "\n" } $monthlist = sprintf("\n",$month); foreach $i (01 .. 12) { $monthlist .= sprintf("\n",$i) } $daylist = sprintf("\n",$day); foreach $i (01 .. 31) { $daylist .= sprintf("\n",$i) } $hourlist = sprintf("\n",$hour); foreach $i (00 .. 23) { $hourlist .= sprintf("\n",$i) } $minlist = sprintf("\n",$min); for ($i=0; $i<59; $i+=5) { $minlist .= sprintf("\n",$i) } ############# # SUBS ############# sub to_unix_time { # same routine as in stripchart # no colons and no decimal point? must already be in unix time if ($_[0] !~ /:/ && $_[0] !~ /\./ ) { return $_[0] } # colons = civil time if ($_[0] =~ /:/) { (my $year, my $month, my $day, my $hour, my $minute) = split /:/, $_[0]; $month--; return timelocal(0,$minute,$hour,$day,$month,$year) } # must be julian date return (($_[0] - 2440587.5) * $daysecs); } ############# # MAIN ############# # ARE WE JUST PLOTTING A SINGLE GRAPH? # # stripchart.cgi calls itself via an "param("flags"); $outfile = "/tmp/tempout$$" . "." . rand(100000); print "Pragma: nocache\nCache-Control: no-cache\nContent-type: image/gif\n\n"; `$stripchartexe $flags > $outfile`; open (OUTFILE,"$outfile"); while ($dummy=read(OUTFILE,$buffer,1024)) { print $buffer } close (OUTFILE); unlink ($outfile); exit 0 } # ARE WE SAVING/DELETING A QUERY? # # If the user chose to save or delete a query, act on that and # then continue on with the standard plots: if ($query->param("sqname") ne "") { $sqname = $query->param("sqname"); # are we deleting it? if ($query->param("delq") eq "y") { @querylist = `$grepexe -v '^$sqname:' $queryfilelist`; open (QUERYLIST,">$queryfilelist"); flock (QUERYLIST,2); foreach $queryline (@querylist) { print QUERYLIST $queryline } } # must be saving it else { # first check to see if query already in the list $found = 0; foreach $checkline (@querylist) { ($key,$value) = split /:/, $checkline; if ($key eq $sqname) { $found = 1 } } # not found - add it to the end if (!$found) { open (QUERYLIST,">>$queryfilelist"); flock (QUERYLIST,2); $fullquery = $ENV{'QUERY_STRING'}; $fullquery =~ s/sqname=$sqname//; print QUERYLIST "$sqname:$fullquery\n"; close (QUERYLIST); } } } # PARSE INCOMING $datafile1 = $query->param("df1"); $numcharts = $query->param("numcharts"); if ($numcharts == 0) { $numcharts = $defaultnumcharts } print $query->header; print << "EOF"; Stripchart EOF if ($datafile1 ne "") { # stripcharts were selected, so plot them foreach $which (1 .. $numcharts) { $thisfile = $query->param("df$which"); if ($thisfile eq "No plot" || $thisfile =~ /^-+$/ || $thisfile eq "") { next } if ($thisfile eq "Same as datafile 1") { $thisfile = $query->param("df1") } $rangetype = $query->param("dr$which"); $trustnum = $which; $from = "-f "; $to = ""; if ($rangetype eq "sa1") { $rangetype = $query->param("dr1"); $trustnum = 1 } if ($rangetype eq "lh") { $from .= "-" .($query->param("lhv$trustnum") / 24) } elsif ($rangetype eq "ld") { $from .= "-" . ($query->param("ldv$trustnum")) } else { $fromstring = $query->param("dfy$trustnum") . ":" . $query->param("dfm$trustnum") . ":" . $query->param("dfd$trustnum") . ":" . $query->param("dfh$trustnum") . ":" . $query->param("dfn$trustnum"); $tostring = $query->param("dty$trustnum") . ":" . $query->param("dtm$trustnum") . ":" . $query->param("dtd$trustnum") . ":" . $query->param("dth$trustnum") . ":" . $query->param("dtn$trustnum"); $from .= to_unix_time($fromstring); $to = "-t " . to_unix_time($tostring) } foreach $element (@datafiles) { ($maybepath,$maybefile,$maybedatacol,$maybeflags) = split /:/, $element; if ($maybefile eq $thisfile) { $fullpath = $maybepath; $datacol = $maybedatacol; $flags = $maybeflags; } } $flags .= " $from $to"; if ($query->param("log$which")) { $flags .= " -L" } if ($query->param("bavg$which")) { $flags .= " -B " } if ($query->param("base$which")) { $flags .= " -b " . $query->param("basev$which") } if ($query->param("ymin$which")) { $flags .= " -d " . $query->param("yminv$which") } if ($query->param("ymax$which")) { $flags .= " -D " . $query->param("ymaxv$which") } if ($query->param("savem")) { $flags .= " -O /tmp/stripchart_plot_$which.gif" } $flags .= " -i $fullpath -y $datacol -T \"$thisfile RANGE\" $defaultflags"; $fixflags = $flags; $fixflags =~ s/ /+/g; $fixflags =~ s/"/%22/g; if ($cgiplotwidth == 0) { print "
\n" } else { print "
\n" } } print "
"; } # Now display the user entry form: print << "EOF";
Select a saved query if you like:
Number of stripcharts: EOF for ($i=1;$i<21;$i++) { $fullquery = $ENV{'QUERY_STRING'}; $fullquery =~ s/numcharts=\d+//; $fullquery =~ s/&+/&/g; $fullquery =~ s/^&//; print "$i\n" } print << "EOF";

to plot stripcharts - enter name: to save query (check here: to delete)

EOF foreach $which (1 .. $numcharts) { $thisoptionlist = $optionlist; if ($which > 1) { $thisoptionlist = "\n" . "\n" . "\n" . $optionlist } if ($dummy = $query->param("df$which")) { $dummy = ""; $newoptionlist = "$dummy\n"; foreach $thisline (split /\n/, $thisoptionlist) { if ($dummy ne $thisline) { $newoptionlist .= "$thisline\n" } } $thisoptionlist = $newoptionlist; } $lhc = ""; $ldc = ""; $ownc = ""; $sa1c = ""; if ($dummy = $query->param("dr$which")) { if ($dummy eq "lh") { $lhc = "checked" } elsif ($dummy eq "ld") { $ldc = "checked" } elsif ($dummy eq "own") { $ownc = "checked" } elsif ($dummy eq "sa1") { $sa1c = "checked" } } else { if ($which > 1) { $sa1c = "checked" } else { $lhc = "checked" } } $samerange = ""; if ($which > 1) { $samerange = " Same range as datafile 1" } $logcheck = ""; if ($query->param("log$which") eq "y") { $logcheck = "checked" } $bavgcheck = ""; if ($query->param("bavg$which") eq "y") { $bavgcheck = "checked" } $basecheck = ""; if ($query->param("base$which") eq "y") { $basecheck = "checked"; $baseval = $query->param("basev$which") } $ymincheck = ""; $ymaxcheck = ""; if ($query->param("ymin$which") eq "y") { $ymincheck = "checked"; $yminval = $query->param("yminv$which") } if ($query->param("ymax$which") eq "y") { $ymaxcheck = "checked"; $ymaxval = $query->param("ymaxv$which") } if ($dummy = $query->param("dfy$which")) { $dfytop = "\n\n" } else { $dfytop = "" } if ($dummy = $query->param("dfm$which")) { $dfmtop = "\n\n" } else { $dfmtop = "" } if ($dummy = $query->param("dfd$which")) { $dfdtop = "\n\n" } else { $dfdtop = "" } if ($dummy = $query->param("dfh$which")) { $dfhtop = "\n\n" } else { $dfhtop = "" } if ($dummy = $query->param("dfn$which")) { $dfntop = "\n\n" } else { $dfntop = "" } if ($dummy = $query->param("dty$which")) { $dtytop = "\n\n" } else { $dtytop = "" } if ($dummy = $query->param("dtm$which")) { $dtmtop = "\n\n" } else { $dtmtop = "" } if ($dummy = $query->param("dtd$which")) { $dtdtop = "\n\n" } else { $dtdtop = "" } if ($dummy = $query->param("dth$which")) { $dthtop = "\n\n" } else { $dthtop = "" } if ($dummy = $query->param("dtn$which")) { $dtntop = "\n\n" } else { $dtntop = "" } $lhourlist = ""; if ($query->param("lhv$which")) { $lhourlist = ""; } foreach $hourval (24,36,48,60,72) { if ($hourval != $query->param("lhv$which")) { $lhourlist .= ""; } } $ldaylist = ""; if ($query->param("ldv$which")) { $ldaylist = ""; } foreach $dayval (2,3,4,5,6,7,10,14,21,28,30,60,90,120,240,360,720) { if ($dayval != $query->param("ldv$which")) { $ldaylist .= ""; } } print << "EOF"; please select datafile $which:
Last hours    Last days    $samerange
Enter range:
// : -> // :
Log y axis? Baseline average, or Baseline at: Y min: Y max:


EOF } # end foreach $which print << "EOF"; Save images in /tmp?
to plot stripcharts

Reset Form

Stripchart version $majorversion.$minorversion by Matt Lebofsky. EOF