]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/hardwaregraphs.cgi
Einige CGI Fixes
[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 %color = ();
22 my %mainsettings = ();
23 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
24 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
25
26 my %cgiparams=();
27 my @cgigraphs=();
28
29 &Header::showhttpheaders();
30
31 my $graphdir = "/srv/web/ipfire/html/graphs";
32
33 my @disks = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
34 foreach (@disks){
35 my $disk = $_;
36 chomp $disk;
37 &Graphs::updatehddgraph ($disk,"day");
38 }
39
40 &Graphs::updatetempgraph ("day");
41 &Graphs::updatefangraph ("day");
42 &Graphs::updatevoltgraph ("day");
43
44 my @graphs=();
45
46 &Header::getcgihash(\%cgiparams);
47
48 $ENV{'QUERY_STRING'} =~ s/&//g;
49 @cgigraphs = split(/graph=/,$ENV{'QUERY_STRING'});
50 $cgigraphs[1] = '' unless defined $cgigraphs[1];
51
52 my %mbmon_settings = ();
53 my %mbmon_values = ();
54 &General::readhash("/var/log/mbmon-values", \%mbmon_values);
55 my $key;
56
57 if ( $cgiparams{'ACTION'} eq $Lang::tr{'save'} )
58 {
59 $mbmon_settings{'GRAPH_TEMP'} = ($cgiparams{'TEMP'} eq 'on');
60 $mbmon_settings{'GRAPH_FAN'} = ($cgiparams{'FAN'} eq 'on');
61 $mbmon_settings{'GRAPH_VOLT'} = ($cgiparams{'VOLT'} eq 'on');
62 $mbmon_settings{'GRAPH_HDD'} = ($cgiparams{'HDD'} eq 'on');
63
64 foreach my $line (sort keys %cgiparams)
65 {
66 if ( index($line, "LINE-") != -1 )
67 {
68 $mbmon_settings{$line} = 'on';
69 }
70
71 if ( index($line, "LABEL-") != -1 )
72 {
73 $mbmon_settings{$line} = $cgiparams{$line};
74 }
75 }
76
77 &General::writehash("${General::swroot}/mbmon/settings", \%mbmon_settings);
78 }
79 else
80 {
81 &General::readhash("${General::swroot}/mbmon/settings", \%mbmon_settings);
82 }
83
84 my $selected_temp = '';
85 my $selected_fan = '';
86 my $selected_volt = '';
87 my $selected_hdd = '';
88
89 $selected_temp = "checked='checked'" if ( $mbmon_settings{'GRAPH_TEMP'} == 1 );
90 $selected_fan = "checked='checked'" if ( $mbmon_settings{'GRAPH_FAN'} == 1 );
91 $selected_volt = "checked='checked'" if ( $mbmon_settings{'GRAPH_VOLT'} == 1 );
92 $selected_hdd = "checked='checked'" if ( $mbmon_settings{'GRAPH_HDD'} == 1 );
93
94 my %mbmon_graphs = ();
95 foreach $key ( sort(keys %mbmon_values) )
96 {
97 $mbmon_graphs{$key} = "checked='checked'" if ( $mbmon_settings{'LINE-'.$key} eq 'on' );
98 if ( !defined($mbmon_settings{'LABEL-'.$key}) )
99 {
100 $mbmon_settings{'LABEL-'.$key} = $key;
101 }
102 }
103
104 &Header::openpage($Lang::tr{'harddisk temperature graphs'}, 1, '');
105
106 &Header::openbigbox('100%', 'left');
107
108 ###############
109 # DEBUG DEBUG
110 #&Header::openbox('100%', 'left', 'DEBUG');
111 #my $debugCount = 0;
112 #foreach my $line (sort keys %cgiparams) {
113 # print "$line = $cgiparams{$line}<br />\n";
114 # $debugCount++;
115 #}
116 #print "&nbsp;Count: $debugCount<br />\n";
117 #print "&nbsp;CGIParams: $cgigraphs[1]\n";
118 #&Header::closebox();
119 # DEBUG DEBUG
120 ###############
121
122 if ($cgigraphs[1] =~ /hddtemp/)
123 {
124 my $graph = $cgigraphs[1];
125 my $graphname = $Lang::tr{"harddisk temperature"};
126 &Header::openbox('100%', 'center', "$graphname $Lang::tr{'graph'}");
127
128 if (-e "$graphdir/${graph}-day.png")
129 {
130 my $ftime = localtime((stat("$graphdir/${graph}-day.png"))[9]);
131 print "<center>";
132 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br /><hr />\n";
133 print "<img src='/graphs/${graph}-day.png' border='0' /><hr />";
134 print "<img src='/graphs/${graph}-week.png' border='0' /><hr />";
135 print "<img src='/graphs/${graph}-month.png' border='0' /><hr />";
136 print "<img src='/graphs/${graph}-year.png' border='0' />";
137 if ( -e "/var/log/smartctl_out_${graph}" )
138 {
139 my $output = `/bin/cat /var/log/smartctl_out_${graph}`;
140 $output = &Header::cleanhtml($output);
141 print "<hr><table border=0><tr><td align=left><pre>$output</pre></table>\n";
142 }
143 }
144 else
145 {
146 print $Lang::tr{'no information available'};
147 }
148 &Header::closebox();
149 print "<div align='center'><table width='80%'><tr><td align='center'>";
150 print "<a href='/cgi-bin/hardwaregraphs.cgi'>";
151 print "$Lang::tr{'back'}</a></td></tr></table></div>\n";
152 }
153 elsif ($cgigraphs[1] =~ /(temp|fan|volt)/)
154 {
155 if ($cgigraphs[1] =~ /temp/) {&Graphs::updatetempgraph ("week");&Graphs::updatetempgraph ("month");&Graphs::updatetempgraph ("year");}
156 if ($cgigraphs[1] =~ /fan/) {&Graphs::updatefangraph ("week");&Graphs::updatefangraph ("month");&Graphs::updatefangraph ("year");}
157 if ($cgigraphs[1] =~ /volt/) {&Graphs::updatevoltgraph ("week");&Graphs::updatevoltgraph ("month");&Graphs::updatevoltgraph ("year");}
158 if ($cgigraphs[1] =~ /hddtemp/){
159 my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
160
161 foreach (@devices) {
162 my $device = $_;
163 chomp($device);
164 &Graphs::updatehddgraph ($device,"week");
165 &Graphs::updatehddgraph ($device,"month");
166 &Graphs::updatehddgraph ($device,"year");}}
167
168 my $graph = $cgigraphs[1];
169 my $graphname = $Lang::tr{"mbmon $cgigraphs[1]"};
170 &Header::openbox('100%', 'center', "$graphname $Lang::tr{'graph'}");
171
172 if (-e "$graphdir/mbmon-${graph}-day.png")
173 {
174 my $ftime = localtime((stat("$graphdir/mbmon-${graph}-day.png"))[9]);
175 print "<center>";
176 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br /><hr />\n";
177 print "<img src='/graphs/mbmon-${graph}-day.png' border='0' /><hr />";
178 print "<img src='/graphs/mbmon-${graph}-week.png' border='0' /><hr />";
179 print "<img src='/graphs/mbmon-${graph}-month.png' border='0' /><hr />";
180 print "<img src='/graphs/mbmon-${graph}-year.png' border='0' />";
181 }
182 else
183 {
184 print $Lang::tr{'no information available'};
185 }
186 &Header::closebox();
187 print "<div align='center'><table width='80%'><tr><td align='center'>";
188 print "<a href='/cgi-bin/hardwaregraphs.cgi'>";
189 print "$Lang::tr{'back'}</a></td></tr></table></div>\n";
190 }
191 else
192 {
193 if ( $mbmon_settings{'GRAPH_TEMP'} == 1 )
194 {
195 &Header::openbox('100%', 'center', "$Lang::tr{'mbmon temp'} $Lang::tr{'graph'}");
196 if (-e "$graphdir/mbmon-temp-day.png")
197 {
198 my $ftime = localtime((stat("$graphdir/mbmon-temp-day.png"))[9]);
199 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
200 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=temp'>";
201 print "<img src='/graphs/mbmon-temp-day.png' border='0' />";
202 print "</a>";
203 }
204 else
205 {
206 print $Lang::tr{'no information available'};
207 }
208 print "<br />\n";
209 &Header::closebox();
210 }
211
212 if ( $mbmon_settings{'GRAPH_FAN'} == 1 )
213 {
214 &Header::openbox('100%', 'center', "$Lang::tr{'mbmon fan'} $Lang::tr{'graph'}");
215 if (-e "$graphdir/mbmon-fan-day.png")
216 {
217 my $ftime = localtime((stat("$graphdir/mbmon-fan-day.png"))[9]);
218 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
219 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=fan'>";
220 print "<img src='/graphs/mbmon-fan-day.png' border='0' />";
221 print "</a>";
222 }
223 else
224 {
225 print $Lang::tr{'no information available'};
226 }
227 print "<br />\n";
228 &Header::closebox();
229 }
230
231 if ( $mbmon_settings{'GRAPH_VOLT'} == 1 )
232 {
233 &Header::openbox('100%', 'center', "$Lang::tr{'mbmon volt'} $Lang::tr{'graph'}");
234 if (-e "$graphdir/mbmon-volt-day.png")
235 {
236 my $ftime = localtime((stat("$graphdir/mbmon-volt-day.png"))[9]);
237 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
238 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=volt'>";
239 print "<img src='/graphs/mbmon-volt-day.png' border='0' />";
240 print "</a>";
241 }
242 else
243 {
244 print $Lang::tr{'no information available'};
245 }
246 print "<br />\n";
247 &Header::closebox();
248 }
249
250 if ( $mbmon_settings{'GRAPH_HDD'} == 1 )
251 {
252 hddtempbox("hda");
253 hddtempbox("hdb");
254 hddtempbox("hdc");
255 hddtempbox("hdd");
256 hddtempbox("hde");
257 hddtempbox("hdf");
258 hddtempbox("hdg");
259 hddtempbox("hdh");
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 }