]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/hardwaregraphs.cgi
Ein Paar Dateien fuer die GPLv3 angepasst.
[people/teissler/ipfire-2.x.git] / html / cgi-bin / hardwaregraphs.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 %color = ();
34 my %mainsettings = ();
35 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
36 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
37
38 my %cgiparams=();
39 my @cgigraphs=();
40
41 &Header::showhttpheaders();
42
43 my $graphdir = "/srv/web/ipfire/html/graphs";
44
45 my @disks = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
46 foreach (@disks){
47 my $disk = $_;
48 chomp $disk;
49 &Graphs::updatehddgraph ($disk,"day");&Graphs::updatehddgraph ($disk,"week");&Graphs::updatehddgraph ($disk,"month");&Graphs::updatehddgraph ($disk,"year");
50 }
51
52 &Graphs::updatetempgraph ("day");
53 &Graphs::updatefangraph ("day");
54 &Graphs::updatevoltgraph ("day");
55
56 my @graphs=();
57
58 &Header::getcgihash(\%cgiparams);
59
60 $ENV{'QUERY_STRING'} =~ s/&//g;
61 @cgigraphs = split(/graph=/,$ENV{'QUERY_STRING'});
62 $cgigraphs[1] = '' unless defined $cgigraphs[1];
63
64 my %mbmon_settings = ();
65 my %mbmon_values = ();
66 &General::readhash("/var/log/mbmon-values", \%mbmon_values);
67 my $key;
68
69 if ( $cgiparams{'ACTION'} eq $Lang::tr{'save'} )
70 {
71 $mbmon_settings{'GRAPH_TEMP'} = ($cgiparams{'TEMP'} eq 'on');
72 $mbmon_settings{'GRAPH_FAN'} = ($cgiparams{'FAN'} eq 'on');
73 $mbmon_settings{'GRAPH_VOLT'} = ($cgiparams{'VOLT'} eq 'on');
74 $mbmon_settings{'GRAPH_HDD'} = ($cgiparams{'HDD'} eq 'on');
75
76 foreach my $line (sort keys %cgiparams)
77 {
78 if ( index($line, "LINE-") != -1 )
79 {
80 $mbmon_settings{$line} = 'on';
81 }
82
83 if ( index($line, "LABEL-") != -1 )
84 {
85 $mbmon_settings{$line} = $cgiparams{$line};
86 }
87 }
88
89 &General::writehash("${General::swroot}/mbmon/settings", \%mbmon_settings);
90 }
91 else
92 {
93 &General::readhash("${General::swroot}/mbmon/settings", \%mbmon_settings);
94 }
95
96 my $selected_temp = '';
97 my $selected_fan = '';
98 my $selected_volt = '';
99 my $selected_hdd = '';
100
101 $selected_temp = "checked='checked'" if ( $mbmon_settings{'GRAPH_TEMP'} == 1 );
102 $selected_fan = "checked='checked'" if ( $mbmon_settings{'GRAPH_FAN'} == 1 );
103 $selected_volt = "checked='checked'" if ( $mbmon_settings{'GRAPH_VOLT'} == 1 );
104 $selected_hdd = "checked='checked'" if ( $mbmon_settings{'GRAPH_HDD'} == 1 );
105
106 my %mbmon_graphs = ();
107 foreach $key ( sort(keys %mbmon_values) )
108 {
109 $mbmon_graphs{$key} = "checked='checked'" if ( $mbmon_settings{'LINE-'.$key} eq 'on' );
110 if ( !defined($mbmon_settings{'LABEL-'.$key}) )
111 {
112 $mbmon_settings{'LABEL-'.$key} = $key;
113 }
114 }
115
116 &Header::openpage($Lang::tr{'harddisk temperature graphs'}, 1, '');
117
118 &Header::openbigbox('100%', 'left');
119
120 ###############
121 # DEBUG DEBUG
122 #&Header::openbox('100%', 'left', 'DEBUG');
123 #my $debugCount = 0;
124 #foreach my $line (sort keys %cgiparams) {
125 # print "$line = $cgiparams{$line}<br />\n";
126 # $debugCount++;
127 #}
128 #print "&nbsp;Count: $debugCount<br />\n";
129 #print "&nbsp;CGIParams: $cgigraphs[1]\n";
130 #&Header::closebox();
131 # DEBUG DEBUG
132 ###############
133
134 if ($cgigraphs[1] =~ /hddtemp/)
135 {
136 my $graph = $cgigraphs[1];
137 my $graphname = $Lang::tr{"harddisk temperature"};
138 &Header::openbox('100%', 'center', "$graphname $Lang::tr{'graph'}");
139
140 if (-e "$graphdir/${graph}-day.png")
141 {
142 my $ftime = localtime((stat("$graphdir/${graph}-day.png"))[9]);
143 print "<center>";
144 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br /><hr />\n";
145 print "<img src='/graphs/${graph}-day.png' border='0' /><hr />";
146 print "<img src='/graphs/${graph}-week.png' border='0' /><hr />";
147 print "<img src='/graphs/${graph}-month.png' border='0' /><hr />";
148 print "<img src='/graphs/${graph}-year.png' border='0' />";
149 if ( -e "/var/log/smartctl_out_${graph}" )
150 {
151 my $output = `/bin/cat /var/log/smartctl_out_${graph}`;
152 $output = &Header::cleanhtml($output);
153 print "<hr><table border=0><tr><td align=left><pre>$output</pre></table>\n";
154 }
155 }
156 else
157 {
158 print $Lang::tr{'no information available'};
159 }
160 &Header::closebox();
161 print "<div align='center'><table width='80%'><tr><td align='center'>";
162 print "<a href='/cgi-bin/hardwaregraphs.cgi'>";
163 print "$Lang::tr{'back'}</a></td></tr></table></div>\n";
164 }
165 elsif ($cgigraphs[1] =~ /(temp|fan|volt)/)
166 {
167 if ($cgigraphs[1] =~ /temp/) {&Graphs::updatetempgraph ("week");&Graphs::updatetempgraph ("month");&Graphs::updatetempgraph ("year");}
168 if ($cgigraphs[1] =~ /fan/) {&Graphs::updatefangraph ("week");&Graphs::updatefangraph ("month");&Graphs::updatefangraph ("year");}
169 if ($cgigraphs[1] =~ /volt/) {&Graphs::updatevoltgraph ("week");&Graphs::updatevoltgraph ("month");&Graphs::updatevoltgraph ("year");}
170
171 my $graph = $cgigraphs[1];
172 my $graphname = $Lang::tr{"mbmon $cgigraphs[1]"};
173 &Header::openbox('100%', 'center', "$graphname $Lang::tr{'graph'}");
174
175 if (-e "$graphdir/mbmon-${graph}-day.png")
176 {
177 my $ftime = localtime((stat("$graphdir/mbmon-${graph}-day.png"))[9]);
178 print "<center>";
179 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br /><hr />\n";
180 print "<img src='/graphs/mbmon-${graph}-day.png' border='0' /><hr />";
181 print "<img src='/graphs/mbmon-${graph}-week.png' border='0' /><hr />";
182 print "<img src='/graphs/mbmon-${graph}-month.png' border='0' /><hr />";
183 print "<img src='/graphs/mbmon-${graph}-year.png' border='0' />";
184 }
185 else
186 {
187 print $Lang::tr{'no information available'};
188 }
189 &Header::closebox();
190 print "<div align='center'><table width='80%'><tr><td align='center'>";
191 print "<a href='/cgi-bin/hardwaregraphs.cgi'>";
192 print "$Lang::tr{'back'}</a></td></tr></table></div>\n";
193 }
194 else
195 {
196 if ( $mbmon_settings{'GRAPH_TEMP'} == 1 )
197 {
198 &Header::openbox('100%', 'center', "$Lang::tr{'mbmon temp'} $Lang::tr{'graph'}");
199 if (-e "$graphdir/mbmon-temp-day.png")
200 {
201 my $ftime = localtime((stat("$graphdir/mbmon-temp-day.png"))[9]);
202 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
203 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=temp'>";
204 print "<img src='/graphs/mbmon-temp-day.png' border='0' />";
205 print "</a>";
206 }
207 else
208 {
209 print $Lang::tr{'no information available'};
210 }
211 print "<br />\n";
212 &Header::closebox();
213 }
214
215 if ( $mbmon_settings{'GRAPH_FAN'} == 1 )
216 {
217 &Header::openbox('100%', 'center', "$Lang::tr{'mbmon fan'} $Lang::tr{'graph'}");
218 if (-e "$graphdir/mbmon-fan-day.png")
219 {
220 my $ftime = localtime((stat("$graphdir/mbmon-fan-day.png"))[9]);
221 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
222 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=fan'>";
223 print "<img src='/graphs/mbmon-fan-day.png' border='0' />";
224 print "</a>";
225 }
226 else
227 {
228 print $Lang::tr{'no information available'};
229 }
230 print "<br />\n";
231 &Header::closebox();
232 }
233
234 if ( $mbmon_settings{'GRAPH_VOLT'} == 1 )
235 {
236 &Header::openbox('100%', 'center', "$Lang::tr{'mbmon volt'} $Lang::tr{'graph'}");
237 if (-e "$graphdir/mbmon-volt-day.png")
238 {
239 my $ftime = localtime((stat("$graphdir/mbmon-volt-day.png"))[9]);
240 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
241 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=volt'>";
242 print "<img src='/graphs/mbmon-volt-day.png' border='0' />";
243 print "</a>";
244 }
245 else
246 {
247 print $Lang::tr{'no information available'};
248 }
249 print "<br />\n";
250 &Header::closebox();
251 }
252
253 if ( $mbmon_settings{'GRAPH_HDD'} == 1 )
254 {
255 my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
256 foreach (@devices) {
257 my $device = $_;
258 chomp($device);
259 hddtempbox($device);}
260 }
261
262 &Header::openbox('100%', 'center', $Lang::tr{'settings'});
263 print <<END
264 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
265 <table width='100%'>
266 <tr><td colspan='2' align='left'><input type='checkbox' name='TEMP' $selected_temp />&nbsp;$Lang::tr{'mbmon temp'} $Lang::tr{'graph'}</td></tr>
267 <tr><td colspan='2' align='left'><input type='checkbox' name='FAN' $selected_fan />&nbsp;$Lang::tr{'mbmon fan'} $Lang::tr{'graph'}</td></tr>
268 <tr><td colspan='2' align='left'><input type='checkbox' name='VOLT' $selected_volt />&nbsp;$Lang::tr{'mbmon volt'} $Lang::tr{'graph'}</td></tr>
269 <tr><td colspan='2' align='left'><input type='checkbox' name='HDD' $selected_hdd />&nbsp;$Lang::tr{'harddisk temperature'}-$Lang::tr{'graph'}</td></tr>
270 </table>
271 <hr />
272 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
273 <tr><td align='center' width='10%'><b>$Lang::tr{'mbmon display'}</b></td><td align='center' width='15%'>&nbsp;</td><td align='center' width='15%'><b>$Lang::tr{'mbmon value'}</b></td><td align='left'><b>$Lang::tr{'mbmon label'}</b></td></tr>
274 END
275 ;
276
277 my $i = 0;
278 foreach $key ( sort(keys %mbmon_values) )
279 {
280 if ( $i % 2 )
281 {
282 print("<tr bgcolor='$color{'color22'}'>");
283 }
284 else
285 {
286 print("<tr bgcolor='$color{'color20'}'>");
287 }
288 $mbmon_settings{'LABEL-'.$key} = &Header::cleanhtml($mbmon_settings{'LABEL-'.$key});
289 print("<td align='center'><input type='checkbox' name='LINE-$key' $mbmon_graphs{$key}/></td>");
290 print("<td>$key</td><td align='center'>$mbmon_values{$key}</td>\n");
291 print("<td>&nbsp;<input type='text' name='LABEL-$key' value='$mbmon_settings{'LABEL-'.$key}' size='25' /></td></tr>\n");
292 $i++;
293 }
294
295 print <<END
296 </table>
297
298 <table width='100%'>
299 <tr><td class='base' valign='top'>&nbsp;</td><td width='40%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td></tr>
300 </table>
301
302 </form>
303 END
304 ;
305 &Header::closebox();
306 }
307
308 &Header::closebigbox();
309 &Header::closepage();
310
311 sub hddtempbox {
312 my $disk = $_[0];
313 if (-e "$graphdir/hddtemp-$disk-day.png") {
314
315 &Header::openbox('100%', 'center', "Disk /dev/$disk $Lang::tr{'graph'}");
316 my $ftime = localtime((stat("$graphdir/hddtemp-$disk-day.png"))[9]);
317 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
318 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=hddtemp-$disk'>";
319 print "<img src='/graphs/hddtemp-$disk-day.png' border='0' />";
320 print "</a>";
321 print "<br />\n";
322 &Header::closebox();
323 }
324 }