]> git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/hardwaregraphs.cgi
Uploads.cgi entfernt. Die war noch ueber.
[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");&Graphs::updatehddgraph ($disk,"week");&Graphs::updatehddgraph ($disk,"month");&Graphs::updatehddgraph ($disk,"year");
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
159 my $graph = $cgigraphs[1];
160 my $graphname = $Lang::tr{"mbmon $cgigraphs[1]"};
161 &Header::openbox('100%', 'center', "$graphname $Lang::tr{'graph'}");
162
163 if (-e "$graphdir/mbmon-${graph}-day.png")
164 {
165 my $ftime = localtime((stat("$graphdir/mbmon-${graph}-day.png"))[9]);
166 print "<center>";
167 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br /><hr />\n";
168 print "<img src='/graphs/mbmon-${graph}-day.png' border='0' /><hr />";
169 print "<img src='/graphs/mbmon-${graph}-week.png' border='0' /><hr />";
170 print "<img src='/graphs/mbmon-${graph}-month.png' border='0' /><hr />";
171 print "<img src='/graphs/mbmon-${graph}-year.png' border='0' />";
172 }
173 else
174 {
175 print $Lang::tr{'no information available'};
176 }
177 &Header::closebox();
178 print "<div align='center'><table width='80%'><tr><td align='center'>";
179 print "<a href='/cgi-bin/hardwaregraphs.cgi'>";
180 print "$Lang::tr{'back'}</a></td></tr></table></div>\n";
181 }
182 else
183 {
184 if ( $mbmon_settings{'GRAPH_TEMP'} == 1 )
185 {
186 &Header::openbox('100%', 'center', "$Lang::tr{'mbmon temp'} $Lang::tr{'graph'}");
187 if (-e "$graphdir/mbmon-temp-day.png")
188 {
189 my $ftime = localtime((stat("$graphdir/mbmon-temp-day.png"))[9]);
190 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
191 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=temp'>";
192 print "<img src='/graphs/mbmon-temp-day.png' border='0' />";
193 print "</a>";
194 }
195 else
196 {
197 print $Lang::tr{'no information available'};
198 }
199 print "<br />\n";
200 &Header::closebox();
201 }
202
203 if ( $mbmon_settings{'GRAPH_FAN'} == 1 )
204 {
205 &Header::openbox('100%', 'center', "$Lang::tr{'mbmon fan'} $Lang::tr{'graph'}");
206 if (-e "$graphdir/mbmon-fan-day.png")
207 {
208 my $ftime = localtime((stat("$graphdir/mbmon-fan-day.png"))[9]);
209 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
210 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=fan'>";
211 print "<img src='/graphs/mbmon-fan-day.png' border='0' />";
212 print "</a>";
213 }
214 else
215 {
216 print $Lang::tr{'no information available'};
217 }
218 print "<br />\n";
219 &Header::closebox();
220 }
221
222 if ( $mbmon_settings{'GRAPH_VOLT'} == 1 )
223 {
224 &Header::openbox('100%', 'center', "$Lang::tr{'mbmon volt'} $Lang::tr{'graph'}");
225 if (-e "$graphdir/mbmon-volt-day.png")
226 {
227 my $ftime = localtime((stat("$graphdir/mbmon-volt-day.png"))[9]);
228 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
229 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=volt'>";
230 print "<img src='/graphs/mbmon-volt-day.png' border='0' />";
231 print "</a>";
232 }
233 else
234 {
235 print $Lang::tr{'no information available'};
236 }
237 print "<br />\n";
238 &Header::closebox();
239 }
240
241 if ( $mbmon_settings{'GRAPH_HDD'} == 1 )
242 {
243 my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
244 foreach (@devices) {
245 my $device = $_;
246 chomp($device);
247 hddtempbox($device);}
248 }
249
250 &Header::openbox('100%', 'center', $Lang::tr{'settings'});
251 print <<END
252 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
253 <table width='100%'>
254 <tr><td colspan='2' align='left'><input type='checkbox' name='TEMP' $selected_temp />&nbsp;$Lang::tr{'mbmon temp'} $Lang::tr{'graph'}</td></tr>
255 <tr><td colspan='2' align='left'><input type='checkbox' name='FAN' $selected_fan />&nbsp;$Lang::tr{'mbmon fan'} $Lang::tr{'graph'}</td></tr>
256 <tr><td colspan='2' align='left'><input type='checkbox' name='VOLT' $selected_volt />&nbsp;$Lang::tr{'mbmon volt'} $Lang::tr{'graph'}</td></tr>
257 <tr><td colspan='2' align='left'><input type='checkbox' name='HDD' $selected_hdd />&nbsp;$Lang::tr{'harddisk temperature'}-$Lang::tr{'graph'}</td></tr>
258 </table>
259 <hr />
260 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
261 <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>
262 END
263 ;
264
265 my $i = 0;
266 foreach $key ( sort(keys %mbmon_values) )
267 {
268 if ( $i % 2 )
269 {
270 print("<tr bgcolor='$color{'color22'}'>");
271 }
272 else
273 {
274 print("<tr bgcolor='$color{'color20'}'>");
275 }
276 $mbmon_settings{'LABEL-'.$key} = &Header::cleanhtml($mbmon_settings{'LABEL-'.$key});
277 print("<td align='center'><input type='checkbox' name='LINE-$key' $mbmon_graphs{$key}/></td>");
278 print("<td>$key</td><td align='center'>$mbmon_values{$key}</td>\n");
279 print("<td>&nbsp;<input type='text' name='LABEL-$key' value='$mbmon_settings{'LABEL-'.$key}' size='25' /></td></tr>\n");
280 $i++;
281 }
282
283 print <<END
284 </table>
285
286 <table width='100%'>
287 <tr><td class='base' valign='top'>&nbsp;</td><td width='40%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td></tr>
288 </table>
289
290 </form>
291 END
292 ;
293 &Header::closebox();
294 }
295
296 &Header::closebigbox();
297 &Header::closepage();
298
299 sub hddtempbox {
300 my $disk = $_[0];
301 if (-e "$graphdir/hddtemp-$disk-day.png") {
302
303 &Header::openbox('100%', 'center', "Disk /dev/$disk $Lang::tr{'graph'}");
304 my $ftime = localtime((stat("$graphdir/hddtemp-$disk-day.png"))[9]);
305 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
306 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=hddtemp-$disk'>";
307 print "<img src='/graphs/hddtemp-$disk-day.png' border='0' />";
308 print "</a>";
309 print "<br />\n";
310 &Header::closebox();
311 }
312 }