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