]> git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/graphs.cgi
Ein Paar Dateien fuer die GPLv3 angepasst.
[ipfire-2.x.git] / html / cgi-bin / graphs.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 use strict;
23
24 # enable only the following on debugging purpose
25 #use warnings;
26 #use CGI::Carp 'fatalsToBrowser';
27
28 require '/var/ipfire/general-functions.pl';
29 require "${General::swroot}/lang.pl";
30 require "${General::swroot}/header.pl";
31 require "${General::swroot}/graphs.pl";
32
33 my %cgiparams=();
34 my %pppsettings=();
35 my %netsettings=();
36 my @cgigraphs=();
37 my @graphs=();
38 my $iface='';
39
40 &Header::showhttpheaders();
41
42 my $graphdir = "/srv/web/ipfire/html/graphs";
43 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
44
45 $ENV{'QUERY_STRING'} =~ s/&//g;
46 @cgigraphs = split(/graph=/,$ENV{'QUERY_STRING'});
47 $cgigraphs[1] = '' unless defined $cgigraphs[1];
48
49 if ($cgigraphs[1] =~ /(load)/) {&Graphs::updateloadgraph ("week");&Graphs::updateloadgraph ("month");&Graphs::updateloadgraph ("year");}
50 if ($cgigraphs[1] =~ /(cpu)/) {&Graphs::updatecpugraph ("week");&Graphs::updatecpugraph ("month");&Graphs::updatecpugraph ("year");}
51 if ($cgigraphs[1] =~ /(memory|swap)/) {&Graphs::updatememgraph ("week");&Graphs::updatememgraph ("month");&Graphs::updatememgraph ("year");}
52 if ($cgigraphs[1] =~ /disk/){
53 my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
54
55 foreach (@devices) {
56 my $device = $_;
57 chomp($device);
58 &Graphs::updatediskgraph ("week",$device);
59 &Graphs::updatediskgraph ("month",$device);
60 &Graphs::updatediskgraph ("year",$device);}}
61 if ($cgigraphs[1] =~ /lq/) {&Graphs::updatelqgraph("week");&Graphs::updatelqgraph("month");&Graphs::updatelqgraph("year");}
62 if ($cgigraphs[1] =~ /RED/) {&Graphs::updateifgraph("RED", "week");&Graphs::updateifgraph("RED", "month");&Graphs::updateifgraph("RED", "year");}
63 if ($cgigraphs[1] =~ /GREEN/) {&Graphs::updateifgraph("GREEN", "week");&Graphs::updateifgraph("GREEN", "month");&Graphs::updateifgraph("GREEN", "year");}
64 if ($cgigraphs[1] =~ /BLUE/) {&Graphs::updateifgraph("BLUE", "week");&Graphs::updateifgraph("BLUE", "month");&Graphs::updateifgraph("BLUE", "year");}
65 if ($cgigraphs[1] =~ /ORANGE/) {&Graphs::updateifgraph("ORANGE", "week");&Graphs::updateifgraph("ORANGE", "month");&Graphs::updateifgraph("ORANGE", "year");}
66
67 if ($cgigraphs[1] =~ /(network|GREEN|BLUE|ORANGE|RED|lq)/) {
68 &Header::openpage($Lang::tr{'network traffic graphs'}, 1, '');
69 } else {
70 &Header::openpage($Lang::tr{'system graphs'}, 1, '');
71 }
72
73 &Header::openbigbox('100%', 'left');
74
75 if ($cgigraphs[1] =~ /(GREEN|BLUE|ORANGE|RED|lq|cpu|memory|swap|disk|load)/) {
76 my $graph = $cgigraphs[1];
77 my $graphname = ucfirst(lc($cgigraphs[1]));
78 &Header::openbox('100%', 'center', "$graphname $Lang::tr{'graph'}");
79
80 if (-e "$graphdir/${graph}-day.png") {
81 my $ftime = localtime((stat("$graphdir/${graph}-day.png"))[9]);
82 print "<center>";
83 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br /><hr />\n";
84 print "<img alt='' src='/graphs/${graph}-day.png' border='0' /><hr />";
85 print "<img alt='' src='/graphs/${graph}-week.png' border='0' /><hr />";
86 print "<img alt='' src='/graphs/${graph}-month.png' border='0' /><hr />";
87 print "<img alt='' src='/graphs/${graph}-year.png' border='0' />";
88 } else {
89 print $Lang::tr{'no information available'};
90 }
91 &Header::closebox();
92 } elsif ($cgigraphs[1] =~ /network/) {
93 push (@graphs, ('GREEN'));
94 if ($netsettings{'BLUE_DEV'}) {
95 push (@graphs, ('BLUE')); }
96 if ($netsettings{'ORANGE_DEV'}) {
97 push (@graphs, ('ORANGE')); }
98 push (@graphs, ("RED"));
99 push (@graphs, ('lq'));
100
101 foreach my $graphname (@graphs) {
102 &Header::openbox('100%', 'center', "$graphname $Lang::tr{'graph'}");
103
104 if (-e "$graphdir/${graphname}-day.png") {
105 my $ftime = localtime((stat("$graphdir/${graphname}-day.png"))[9]);
106 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
107 print "<a href='/cgi-bin/graphs.cgi?graph=$graphname'>";
108 print "<img alt='' src='/graphs/${graphname}-day.png' border='0' />";
109 print "</a>";
110 } else {
111 print $Lang::tr{'no information available'};
112 }
113 print "<br />\n";
114 &Header::closebox();
115 }
116 }
117
118 &Header::closebigbox();
119 &Header::closepage();