Hinzugefuegt:
[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 # $Id: graphs.cgi,v 1.9.2.6 2005/02/22 22:21:55 gespinasse Exp $
10 #
11
12 use strict;
13
14 # enable only the following on debugging purpose
15 #use warnings;
16 #use CGI::Carp 'fatalsToBrowser';
17
18 require '/var/ipfire/general-functions.pl';
19 require "${General::swroot}/lang.pl";
20 require "${General::swroot}/header.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 = "/home/httpd/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] =~ /(network|GREEN|BLUE|ORANGE|RED|lq)/) {
39 &Header::openpage($Lang::tr{'network traffic graphs'}, 1, '');
40 } else {
41 &Header::openpage($Lang::tr{'system graphs'}, 1, '');
42 }
43
44 sub diskbox {
45 my $disk = $_[0];
46 if (-e "$graphdir/disk-$disk-day.png") {
47
48 &Header::openbox('100%', 'center', "Disk /dev/$disk $Lang::tr{'graph'}");
49 my $ftime = localtime((stat("$graphdir/disk-$disk-day.png"))[9]);
50 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
51 print "<a href='/cgi-bin/graphs.cgi?graph=disk-$disk'>";
52 print "<img src='/graphs/disk-$disk-day.png' border='0' />";
53 print "</a>";
54 print "<br />\n";
55 if (-e "/usr/local/bin/hddshutdown-state") {
56 system("/usr/local/bin/hddshutdown-state $disk");
57 }
58 &Header::closebox();
59 }
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 src='/graphs/${graph}-day.png' border='0' /><hr />";
74 print "<img src='/graphs/${graph}-week.png' border='0' /><hr />";
75 print "<img src='/graphs/${graph}-month.png' border='0' /><hr />";
76 print "<img src='/graphs/${graph}-year.png' border='0' />";
77 } else {
78 print $Lang::tr{'no information available'};
79 }
80 &Header::closebox();
81 print "<div align='center'><table width='80%'><tr><td align='center'>";
82 if ($cgigraphs[1] =~ /(GREEN|BLUE|ORANGE|RED|lq)/) {
83 print "<a href='/cgi-bin/graphs.cgi?graph=network'>";
84 } else {
85 print "<a href='/cgi-bin/graphs.cgi'>";
86 }
87 print "$Lang::tr{'back'}</a></td></tr></table></div>\n";
88 ;
89 } elsif ($cgigraphs[1] =~ /network/) {
90 push (@graphs, ('GREEN'));
91 if ($netsettings{'BLUE_DEV'}) {
92 push (@graphs, ('BLUE')); }
93 if ($netsettings{'ORANGE_DEV'}) {
94 push (@graphs, ('ORANGE')); }
95 push (@graphs, ("RED"));
96 push (@graphs, ('lq'));
97
98 foreach my $graphname (@graphs) {
99 &Header::openbox('100%', 'center', "$graphname $Lang::tr{'graph'}");
100
101 if (-e "$graphdir/${graphname}-day.png") {
102 my $ftime = localtime((stat("$graphdir/${graphname}-day.png"))[9]);
103 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
104 print "<a href='/cgi-bin/graphs.cgi?graph=$graphname'>";
105 print "<img src='/graphs/${graphname}-day.png' border='0' />";
106 print "</a>";
107 } else {
108 print $Lang::tr{'no information available'};
109 }
110 print "<br />\n";
111 &Header::closebox();
112 }
113 } else {
114 &Header::openbox('100%', 'center', "CPU $Lang::tr{'graph'}");
115 if (-e "$graphdir/cpu-day.png") {
116 my $ftime = localtime((stat("$graphdir/cpu-day.png"))[9]);
117 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
118 print "<a href='/cgi-bin/graphs.cgi?graph=cpu'>";
119 print "<img src='/graphs/cpu-day.png' border='0' />";
120 print "</a>";
121 } else {
122 print $Lang::tr{'no information available'};
123 }
124 print "<br />\n";
125 &Header::closebox();
126
127 &Header::openbox('100%', 'center', "Load $Lang::tr{'graph'}");
128 if (-e "$graphdir/load-day.png") {
129 my $ftime = localtime((stat("$graphdir/load-day.png"))[9]);
130 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
131 print "<a href='/cgi-bin/graphs.cgi?graph=load'>";
132 print "<img src='/graphs/load-day.png' border='0' />";
133 print "</a>";
134 } else {
135 print $Lang::tr{'no information available'};
136 }
137 print "<br />\n";
138 &Header::closebox();
139
140 &Header::openbox('100%', 'center', "Memory $Lang::tr{'graph'}");
141 if (-e "$graphdir/memory-day.png") {
142 my $ftime = localtime((stat("$graphdir/memory-day.png"))[9]);
143 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
144 print "<a href='/cgi-bin/graphs.cgi?graph=memory'>";
145 print "<img src='/graphs/memory-day.png' border='0' />";
146 print "</a>";
147 } else {
148 print $Lang::tr{'no information available'};
149 }
150 print "<br />\n";
151 &Header::closebox();
152
153 &Header::openbox('100%', 'center', "Swap $Lang::tr{'graph'}");
154 if (-e "$graphdir/swap-day.png") {
155 my $ftime = localtime((stat("$graphdir/swap-day.png"))[9]);
156 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
157 print "<a href='/cgi-bin/graphs.cgi?graph=swap'>";
158 print "<img src='/graphs/swap-day.png' border='0' />";
159 print "</a>";
160 } else {
161 print $Lang::tr{'no information available'};
162 }
163 print "<br />\n";
164 &Header::closebox();
165
166 &Header::openbox('100%', 'center', "Disk $Lang::tr{'graph'}");
167 if (-e "$graphdir/disk-day.png") {
168 my $ftime = localtime((stat("$graphdir/disk-day.png"))[9]);
169 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
170 print "<a href='/cgi-bin/graphs.cgi?graph=disk'>";
171 print "<img src='/graphs/disk-day.png' border='0' />";
172 print "</a>";
173 } else {
174 print $Lang::tr{'no information available'};
175 }
176 print "<br />\n";
177 &Header::closebox();
178
179 diskbox("hda");
180 diskbox("hdb");
181 diskbox("hdc");
182 diskbox("hdd");
183 diskbox("hde");
184 diskbox("hdf");
185 diskbox("hdg");
186 diskbox("hdh");
187 }
188
189 &Header::closebigbox();
190 &Header::closepage();