summaryrefslogtreecommitdiffstats
path: root/qooxdoo/source/smokeping.cgi
blob: 86abd8c4814226f69597f3d9cd4192a9141eb90a (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
72
73
74
75
76
77
78
79
80
81
82
#!/usr/sepp/bin/perl-5.8.8 -w
use strict;
use lib qw( perl );

use CGI;
use CGI::Util qw(expires);
use CGI::Session;
use Qooxdoo::JSONRPC;
use lib qw(/home/oetiker/scratch/rrd-13dev/lib/perl);
use lib qw(/usr/pack/rrdtool-1.2.23-mo/lib/perl/);
use RRDs;

$Qooxdoo::JSONRPC::debug=1;

# Change this space-separated list of directories to include
# Qooxdoo::JSONRPC.pm and co-located Services

# If this module can't be found, the previous line is incorrect

# Instantiating the CGI module which parses the HTTP request

my $cgi     = new CGI;
my $session = new CGI::Session;

# You can customise this harness here to handle cases before treating
# the request as being JSON-RPC
if ($cgi->param('g')){
    if (defined $ENV{HTTP_IF_MODIFIED_SINCE}){
        # if the browser needs reassurance, give it!
        print "Status: 304 Not Modified\n";
        print "Last-Modified: $ENV{HTTP_IF_MODIFIED_SINCE}\n\n";
        exit 0;
    };
    my $graph = $cgi->param('g');
    my $width = $cgi->param('w');
    my $height = $cgi->param('h');
    my $start = $cgi->param('s');
    my $end = $cgi->param('e');
    my $top = $cgi->param('t');	
    my $bottom = $cgi->param('b');
    warn "groesse: $width $height\n";
    RRDs::graph("/tmp/$$.tmpgraph",
		    '--title'		=> "Demo ".$graph,
	            '--vertical-label'	=> "Bytes/s",
		    '--start'		=> $start,			
		    '--end' 		=> $end,
		    '--upper-limit'	=> $top,
		    '--lower-limit'	=> $bottom,
		    '--rigid',
#		    '--zoom' 		=> '0.75',
		    '--width' 		=> $width,
		    '--height' 		=> $height,
		    '--color'		=> 'BACK#f0f0f0ff',
		    '--color'		=> 'SHADEA#f0f0f0ff',
		    '--color'		=> 'SHADEB#f0f0f0ff',		
		    'DEF:in=lan.rrd:out:AVERAGE',
		    'CDEF:green=in,100000,LT,in,100000,IF',
		    'AREA:green#00ff00',
		    'CDEF:red=in,50000,LT,in,50000,IF',
		    'AREA:red#ff0000',
		    'LINE1:in#2020ff:Input',
		    'CDEF:flip=LTIME,172800,%,86400,LT,in,UNKN,IF',
		    'AREA:flip#00000088');
    my $ERROR = RRDs::error();
    die $ERROR if $ERROR;
    if (open (my $fh,"</tmp/$$.tmpgraph")){
        local $/=undef;
        my $image = <$fh>;
	unlink "/tmp/$$.tmpgraph";
	close $fh;
        print "Content-Type: image/png\n";
        print "Expires: ".expires(3600,'http')."\n";
        print "Last-Modified: ".expires(-3600,'http')."\n";
        print "Cache-Control: Public\n";
	print "Length: ".length($image)."\n";
	print "\n";
	print $image;
    };
} else {
	Qooxdoo::JSONRPC::handle_request ($cgi, $session);
}