#!/usr/bin/perl -w
print "Content-type: text/html \n\n";

#########################################
# Yu.Semenov ITEP	march 2010	#
# GNUPLOT-test for CHART-Graph-3.2	#
# 					#
#########################################

use Chart::Graph::Gnuplot qw(gnuplot);
use Time::Local;
use Time::localtime;

my $y_max=0;
my (@t_mark,@n_val);
my $i=0;
my @mons=("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

$p="/home/httpd/htdocs/saturn/attacks/ids/delta1.txt";
sysopen(AFT, $p, O_RDWR) or die$!;      #

while (!eof(AFT))       {       # Cycle for <delta1.txt>
$line=readline(AFT);
chop($line);
@L=split/\s/,$line;
$t_mark[$i]=$L[0];
$n_val[$i]=$L[1];
#print "n_val=",$n_val[1],"\n";
if($n_val[$i]>$y_max)   {$y_max=$n_val[$i];}
$i++;
                        }
if($y_max > 1000){$y_max=int($y_max/1000)*1000;}
else{if($y_max >100){$y_max=int($y_max/100)*100;}}
$y_max=$y_max+1000;
$y1=int($y_max/500)*100;
$y2=int($y_max/500)*200;
$y3=int($y_max/500)*300;
$y4=int($y_max/500)*400;
$y5=$y_max;
print "y1=",$y1," y2=",$y2," y3=",$y3," y4=",$y4," y5=",$y5,"\n";
$t_mid=$t_mark[720];
$tm0=$t_mark[0];
$tmm=$t_mark[1439];
$tm=localtime($tm0);
$year=$tm->year+1900;
$mon=($tm->mon);
$mon=$mons[$mon];
$day=$tm->mday;
$secs=$tm->sec;
$hours=$tm->hour;
$mins=$tm->min;
$dat1=$year."-".$mon."-".$day." ".$hours.":".$mins.":".$secs;
$tm=localtime($tmm);
$year=$tm->year+1900;
$mon=($tm->mon);
$mon=$mons[$mon];
$day=$tm->mday;
$secs=$tm->sec;
$hours=$tm->hour;
$mins=$tm->min;
$dat2=$year."-".$mon."-".$day." ".$hours.":".$mins.":".$secs;
print "date1=",$dat1," date2=",$dat2,"\n";
print "Y-max=",$y_max," tm0=",$tm0," tmm=",$tmm," mid=",$t_mid,"\n";

gnuplot({'title' => 'The last day requests ('.$dat1.' - '.$dat2.')',
        'x2-axis label' => 'time',
#	'xtics' => [ ['\n9pm UTC', $t_mid] ],
#	'color' => 'blue',
        'size' => [1.0, 0.4],
	'y-axis label'=> 'bytes/min',
	'x-axis label' => 'time',
	'output type' => 'gif',
	'output file' => '/home/httpd/htdocs/saturn/attacks/ids/gnuplot7.gif',
	'ytics' => [$y1,$y2,$y3,$y4,$y5],
	'extra_opts' => 'set nokey',
	'uts' => [$tm0, $tmm, 1,1]},

	[{'title' => 'data1',
	'style' => 'lines',
	'type' => 'file'}, '/home/httpd/htdocs/saturn/attacks/ids/delta1.txt'],
);
