]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/graphs.cgi
19bbafeb3f6c993425399ae355375e2f2dc1c05a
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / graphs.cgi
1 #!/usr/bin/perl
2 #
3 # SmoothWall CGIs
4 #
5 # This code is distributed under the terms of the GPL
6 #
7 # (c) The SmoothWall Team
8 #
9 #
10
11 use strict;
12
13 # enable only the following on debugging purpose
14 use warnings;
15 use CGI::Carp 'fatalsToBrowser';
16
17 require '/var/ipfire/general-functions.pl';
18 require "${General::swroot}/lang.pl";
19 require "${General::swroot}/header.pl";
20 require "${General::swroot}/graphs.pl";
21
22 my %cgiparams=();
23 my %pppsettings=();
24 my %netsettings=();
25 my @cgigraphs=();
26 my @graphs=();
27 my $iface='';
28
29 &Header::showhttpheaders();
30
31 my $graphdir = "/srv/web/ipfire/html/graphs";
32 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
33
34 $ENV{'QUERY_STRING'} =~ s/&//g;
35 @cgigraphs = split(/graph=/,$ENV{'QUERY_STRING'});
36 $cgigraphs[1] = '' unless defined $cgigraphs[1];
37
38 if ($cgigraphs[1] =~ /(load)/) {&Graphs::updateloadgraph ("week");&Graphs::updateloadgraph ("month");&Graphs::updateloadgraph ("year");}
39 if ($cgigraphs[1] =~ /(cpu)/) {&Graphs::updatecpugraph ("week");&Graphs::updatecpugraph ("month");&Graphs::updatecpugraph ("year");}
40 if ($cgigraphs[1] =~ /(memory|swap)/) {&Graphs::updatememgraph ("week");&Graphs::updatememgraph ("month");&Graphs::updatememgraph ("year");}
41 if ($cgigraphs[1] =~ /disk/){
42 my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
43
44 foreach (@devices) {
45 my $device = $_;
46 chomp($device);
47 &Graphs::updatediskgraph ("week",$device);
48 &Graphs::updatediskgraph ("month",$device);
49 &Graphs::updatediskgraph ("year",$device);}}
50 if ($cgigraphs[1] =~ /lq/) {&Graphs::updatelqgraph("week");&Graphs::updatelqgraph("month");&Graphs::updatelqgraph("year");}
51 if ($cgigraphs[1] =~ /RED/) {&Graphs::updateifgraph("RED", "week");&Graphs::updateifgraph("RED", "month");&Graphs::updateifgraph("RED", "year");}
52 if ($cgigraphs[1] =~ /GREEN/) {&Graphs::updateifgraph("GREEN", "week");&Graphs::updateifgraph("GREEN", "month");&Graphs::updateifgraph("GREEN", "year");}
53 if ($cgigraphs[1] =~ /BLUE/) {&Graphs::updateifgraph("BLUE", "week");&Graphs::updateifgraph("BLUE", "month");&Graphs::updateifgraph("BLUE", "year");}
54 if ($cgigraphs[1] =~ /ORANGE/) {&Graphs::updateifgraph("ORANGE", "week");&Graphs::updateifgraph("ORANGE", "month");&Graphs::updateifgraph("ORANGE", "year");}
55
56 if ($cgigraphs[1] =~ /(network|GREEN|BLUE|ORANGE|RED|lq)/) {
57 &Header::openpage($Lang::tr{'network traffic graphs'}, 1, '');
58 } else {
59 &Header::openpage($Lang::tr{'system graphs'}, 1, '');
60 }
61
62 &Header::openbigbox('100%', 'left');
63
64 if ($cgigraphs[1] =~ /(GREEN|BLUE|ORANGE|RED|lq|cpu|memory|swap|disk|load)/) {
65 my $graph = $cgigraphs[1];
66 my $graphname = ucfirst(lc($cgigraphs[1]));
67 &Header::openbox('100%', 'center', "$graphname $Lang::tr{'graph'}");
68
69 if (-e "$graphdir/${graph}-day.png") {
70 my $ftime = localtime((stat("$graphdir/${graph}-day.png"))[9]);
71 print "<center>";
72 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br /><hr />\n";
73 print "<img alt='' src='/graphs/${graph}-day.png' border='0' /><hr />";
74 print "<img alt='' src='/graphs/${graph}-week.png' border='0' /><hr />";
75 print "<img alt='' src='/graphs/${graph}-month.png' border='0' /><hr />";
76 print "<img alt='' src='/graphs/${graph}-year.png' border='0' />";
77 } else {
78 print $Lang::tr{'no information available'};
79 }
80 &Header::closebox();
81 } elsif ($cgigraphs[1] =~ /network/) {
82 push (@graphs, ('GREEN'));
83 if ($netsettings{'BLUE_DEV'}) {
84 push (@graphs, ('BLUE')); }
85 if ($netsettings{'ORANGE_DEV'}) {
86 push (@graphs, ('ORANGE')); }
87 push (@graphs, ("RED"));
88 push (@graphs, ('lq'));
89
90 foreach my $graphname (@graphs) {
91 &Header::openbox('100%', 'center', "$graphname $Lang::tr{'graph'}");
92
93 if (-e "$graphdir/${graphname}-day.png") {
94 my $ftime = localtime((stat("$graphdir/${graphname}-day.png"))[9]);
95 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
96 print "<a href='/cgi-bin/graphs.cgi?graph=$graphname'>";
97 print "<img alt='' src='/graphs/${graphname}-day.png' border='0' />";
98 print "</a>";
99 } else {
100 print $Lang::tr{'no information available'};
101 }
102 print "<br />\n";
103 &Header::closebox();
104 }
105 }
106
107 &Header::closebigbox();
108 &Header::closepage();