]> git.ipfire.org Git - ipfire-2.x.git/blame - html/cgi-bin/graphs.cgi
Corrected guardian
[ipfire-2.x.git] / html / cgi-bin / graphs.cgi
CommitLineData
ac1cfefa 1#!/usr/bin/perl
70df8302
MT
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###############################################################################
ac1cfefa
MT
21
22use strict;
23
24# enable only the following on debugging purpose
cb5e9c6c
CS
25#use warnings;
26#use CGI::Carp 'fatalsToBrowser';
ac1cfefa 27
986e08d9 28require '/var/ipfire/general-functions.pl';
ac1cfefa
MT
29require "${General::swroot}/lang.pl";
30require "${General::swroot}/header.pl";
b05768be 31require "${General::swroot}/graphs.pl";
ac1cfefa
MT
32
33my %cgiparams=();
34my %pppsettings=();
35my %netsettings=();
36my @cgigraphs=();
37my @graphs=();
38my $iface='';
39
40&Header::showhttpheaders();
41
fd0763dc 42my $graphdir = "/srv/web/ipfire/html/graphs";
ac1cfefa
MT
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
a332b303
CS
49if ($cgigraphs[1] =~ /(load)/) {&Graphs::updateloadgraph ("hour");&Graphs::updateloadgraph ("week");&Graphs::updateloadgraph ("month");&Graphs::updateloadgraph ("year");}
50if ($cgigraphs[1] =~ /(cpu)/) {&Graphs::updatecpugraph ("hour");&Graphs::updatecpugraph ("week");&Graphs::updatecpugraph ("month");&Graphs::updatecpugraph ("year");}
51if ($cgigraphs[1] =~ /(memory|swap)/) {&Graphs::updatememgraph ("hour");&Graphs::updatememgraph ("week");&Graphs::updatememgraph ("month");&Graphs::updatememgraph ("year");}
b05768be
CS
52if ($cgigraphs[1] =~ /disk/){
53 my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
a332b303 54 push(@devices,"uba");
b05768be
CS
55 foreach (@devices) {
56 my $device = $_;
57 chomp($device);
a332b303 58 &Graphs::updatediskgraph ("hour",$device);
b05768be
CS
59 &Graphs::updatediskgraph ("week",$device);
60 &Graphs::updatediskgraph ("month",$device);
61 &Graphs::updatediskgraph ("year",$device);}}
a332b303
CS
62if ($cgigraphs[1] =~ /lq/) {&Graphs::updatelqgraph("hour");&Graphs::updatelqgraph("week");&Graphs::updatelqgraph("month");&Graphs::updatelqgraph("year");}
63if ($cgigraphs[1] =~ /fwhits/) {&Graphs::updatefwhitsgraph("hour");&Graphs::updatefwhitsgraph("week");&Graphs::updatefwhitsgraph("month");&Graphs::updatefwhitsgraph("year");}
64if ($cgigraphs[1] =~ /green/ || $cgigraphs[1] =~ /blue/ || $cgigraphs[1] =~ /ipsec/ || $cgigraphs[1] =~ /orange/ || $cgigraphs[1] =~ /red/ ) {&Graphs::updateifgraph($cgigraphs[1], "hour");&Graphs::updateifgraph($cgigraphs[1], "week");&Graphs::updateifgraph($cgigraphs[1], "month");&Graphs::updateifgraph($cgigraphs[1], "year");}
b05768be 65
a332b303 66if ($cgigraphs[1] =~ /(network|green|blue|orange|red|ipsec|lq)/) {
ac1cfefa
MT
67 &Header::openpage($Lang::tr{'network traffic graphs'}, 1, '');
68} else {
69 &Header::openpage($Lang::tr{'system graphs'}, 1, '');
70}
6c666a3b 71
ac1cfefa
MT
72&Header::openbigbox('100%', 'left');
73
a332b303 74if ($cgigraphs[1] =~ /(green|blue|orange|red|ipsec|lq|cpu|memory|swap|disk|load|fwhits)/) {
ac1cfefa
MT
75 my $graph = $cgigraphs[1];
76 my $graphname = ucfirst(lc($cgigraphs[1]));
77 &Header::openbox('100%', 'center', "$graphname $Lang::tr{'graph'}");
78
79 if (-e "$graphdir/${graph}-day.png") {
80 my $ftime = localtime((stat("$graphdir/${graph}-day.png"))[9]);
81 print "<center>";
82 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br /><hr />\n";
a332b303 83 print "<img alt='' src='/graphs/${graph}-hour.png' border='0' /><hr />";
e455cafe
MT
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' />";
ac1cfefa
MT
88 } else {
89 print $Lang::tr{'no information available'};
90 }
91 &Header::closebox();
ac1cfefa
MT
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"));
072cd997 99 push (@graphs, ('lq'));
ac1cfefa
MT
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'>";
e455cafe 108 print "<img alt='' src='/graphs/${graphname}-day.png' border='0' />";
ac1cfefa
MT
109 print "</a>";
110 } else {
111 print $Lang::tr{'no information available'};
112 }
113 print "<br />\n";
114 &Header::closebox();
115 }
ac1cfefa
MT
116}
117
19f5a6cc
CS
118print "<div align='center'><table width='80%'><tr><td align='center'>";
119if ( $cgigraphs[1] eq "cpu" || $cgigraphs[1] eq "load" ) { print "<a href='/cgi-bin/system.cgi'>"; }
120elsif ( $cgigraphs[1] eq "memory" || $cgigraphs[1] eq "swap" ) { print "<a href='/cgi-bin/memory.cgi'>"; }
121elsif ( $cgigraphs[1] eq "memory" || $cgigraphs[1] eq "swap" ) { print "<a href='/cgi-bin/memory.cgi'>"; }
122elsif ( $cgigraphs[1] =~ /disk/ ) { print "<a href='/cgi-bin/media.cgi'>"; }
123elsif ( $cgigraphs[1] eq "RED" || $cgigraphs[1] eq "lq" ) { print "<a href='/cgi-bin/network.cgi?network=red'>"; }
124elsif ( $cgigraphs[1] eq "GREEN" || $cgigraphs[1] eq "BLUE" || $cgigraphs[1] eq "ORANGE" ) { print "<a href='/cgi-bin/network.cgi?network=other'>"; }
125print "$Lang::tr{'back'}</a></td></tr></table></div>\n";
126
ac1cfefa
MT
127&Header::closebigbox();
128&Header::closepage();